This is an archive of the discontinued LLVM Phabricator instance.

Add command line argument parsing to the Windows packaging script.
AcceptedPublic

Authored by CarlosAlbertoEnciso on Sep 8 2022, 3:45 AM.

Details

Reviewers
hans
thieta
Summary

As discussed here:
https://discourse.llvm.org/t/build-llvm-release-bat-script-options

Add a function to parse command line arguments: parse_args.

The format for the arguments is:
Boolean: --option
Value: --option<separator>value
with <separator> being: space, colon, semicolon or equal sign

Command line usage example:
my-batch-file.bat --build --type=release --version 123
It will create 3 variables:
build with the value true
type with the value release
version with the value 123

Usage:

set "build="
set "type="
set "version="

REM Parse arguments.
call :parse_args %*

if defined build (
  ...
)
if %type%=='release' (
  ...
)
if %version%=='123' (
  ...
)

Diff Detail

Event Timeline

CarlosAlbertoEnciso requested review of this revision.Sep 8 2022, 3:45 AM
CarlosAlbertoEnciso created this revision.

After this patch, we can introduce the options presented in https://reviews.llvm.org/D127938 on incremental patches.

hans added a comment.Sep 8 2022, 7:24 AM

Can you change the description from "Update Windows packaging script" which is pretty generic to something like "Add command line argument parsing to the Windows packaging script"?

llvm/utils/release/build_llvm_release.bat
295

I'm probably missing something, but for --type=release it seems like this would set arg_name to type=release? Or does it get split into the name and value in some way?

Or, it looks like the code would maybe work for --type release, but in that case the example above would need updating.

CarlosAlbertoEnciso retitled this revision from Update Windows packaging script. to Add command line argument parsing to the Windows packaging script..Sep 9 2022, 12:39 AM
CarlosAlbertoEnciso edited the summary of this revision. (Show Details)
CarlosAlbertoEnciso edited the summary of this revision. (Show Details)Sep 9 2022, 2:13 AM
CarlosAlbertoEnciso edited the summary of this revision. (Show Details)

Update title, example and how to use the function.

llvm/utils/release/build_llvm_release.bat
295

I'm probably missing something, but for --type=release it seems like this would set arg_name to type=release? Or does it get split into the name and value in some way?

The = sign in the command line is interpreted as argument separator. The same for space, comma and semicolon.

--type=release and type release are splitted in 2 arguments --type and release.

hans accepted this revision.Sep 9 2022, 4:59 AM

lgtm

llvm/utils/release/build_llvm_release.bat
295

Interesting, I did not know Windows did that.

This revision is now accepted and ready to land.Sep 9 2022, 4:59 AM