[llvm] f671eb1 - Add command line argument parsing to the Windows packaging script.

Carlos Alberto Enciso via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 9 06:37:40 PDT 2022


Author: Carlos Alberto Enciso
Date: 2022-09-09T14:36:40+01:00
New Revision: f671eb17be5cce4db3b4a6ba683921c2727e26cf

URL: https://github.com/llvm/llvm-project/commit/f671eb17be5cce4db3b4a6ba683921c2727e26cf
DIFF: https://github.com/llvm/llvm-project/commit/f671eb17be5cce4db3b4a6ba683921c2727e26cf.diff

LOG: Add command line argument parsing to the Windows packaging script.

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' (
    ...
  )

Added: 
    

Modified: 
    llvm/utils/release/build_llvm_release.bat

Removed: 
    


################################################################################
diff  --git a/llvm/utils/release/build_llvm_release.bat b/llvm/utils/release/build_llvm_release.bat
index ce942220e94bf..d0e3256cdd4fe 100755
--- a/llvm/utils/release/build_llvm_release.bat
+++ b/llvm/utils/release/build_llvm_release.bat
@@ -251,3 +251,63 @@ cd ..
 
 exit /b 0
 ::==============================================================================
+
+::=============================================================================
+:: Parse command line arguments.
+:: 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' (
+::     ...
+::   )
+::=============================================================================
+:parse_args
+  set "arg_name="
+  :parse_args_start
+  if "%1" == "" (
+    :: Set a seen boolean argument.
+    if "%arg_name%" neq "" (
+      set "%arg_name%=true"
+    )
+    goto :parse_args_done
+  )
+  set aux=%1
+  if "%aux:~0,2%" == "--" (
+    :: Set a seen boolean argument.
+    if "%arg_name%" neq "" (
+      set "%arg_name%=true"
+    )
+    set "arg_name=%aux:~2,250%"
+  ) else (
+    set "%arg_name%=%1"
+    set "arg_name="
+  )
+  shift
+  goto :parse_args_start
+
+:parse_args_done
+exit /b 0
+::==============================================================================


        


More information about the llvm-commits mailing list