From 545c165ce08bff237b1468f42b0607e899dab959 Mon Sep 17 00:00:00 2001 From: nicole mazzuca Date: Tue, 9 Feb 2021 15:53:36 -0800 Subject: [PATCH] [(z_)vcpkg_prettify_command(_line)] Scripts Tree Audit (#16130) * [vcpkg_prettify_command] Audit * rename file * rename out-var in docs * fix file path * add internal use message to docs * escapin' in z_vcpkg_prettify_command_line * regenerate docs --- .../internal/z_vcpkg_function_arguments.md | 27 +++++++++++ .../internal/z_vcpkg_prettify_command_line.md | 19 ++++++++ docs/maintainers/portfile-functions.md | 3 +- .../vcpkg_execute_required_process.md | 2 +- docs/maintainers/vcpkg_prettify_command.md | 17 ------- .../cmake/vcpkg_execute_build_process.cmake | 3 +- .../vcpkg_execute_required_process.cmake | 9 ++-- ...cpkg_execute_required_process_repeat.cmake | 5 +- scripts/cmake/vcpkg_prettify_command.cmake | 28 ----------- .../cmake/z_vcpkg_function_arguments.cmake | 48 +++++++++++++++++++ .../cmake/z_vcpkg_prettify_command_line.cmake | 33 +++++++++++++ scripts/ports.cmake | 5 +- 12 files changed, 140 insertions(+), 59 deletions(-) create mode 100644 docs/maintainers/internal/z_vcpkg_function_arguments.md create mode 100644 docs/maintainers/internal/z_vcpkg_prettify_command_line.md delete mode 100644 docs/maintainers/vcpkg_prettify_command.md delete mode 100644 scripts/cmake/vcpkg_prettify_command.cmake create mode 100644 scripts/cmake/z_vcpkg_function_arguments.cmake create mode 100644 scripts/cmake/z_vcpkg_prettify_command_line.cmake diff --git a/docs/maintainers/internal/z_vcpkg_function_arguments.md b/docs/maintainers/internal/z_vcpkg_function_arguments.md new file mode 100644 index 0000000000..e60407f205 --- /dev/null +++ b/docs/maintainers/internal/z_vcpkg_function_arguments.md @@ -0,0 +1,27 @@ +# z_vcpkg_function_arguments + +**Only for internal use in vcpkg helpers. Behavior and arguments will change without notice.** +Get a list of the arguments which were passed in. +Unlike `ARGV`, which is simply the arguments joined with `;`, +so that `(A B)` is not distinguishable from `("A;B")`, +this macro gives `"A;B"` for the first argument list, +and `"A\;B"` for the second. + +```cmake +z_vcpkg_function_arguments( []) +``` + +`z_vcpkg_function_arguments` gets the arguments between `ARGV` and the last argument. +`` defaults to `0`, so that all arguments are taken. + +## Example: +```cmake +function(foo_replacement) + z_vcpkg_function_arguments(ARGS) + foo(${ARGS}) + ... +endfunction() +``` + +## Source +[scripts/cmake/z_vcpkg_function_arguments.cmake](https://github.com/Microsoft/vcpkg/blob/master/scripts/cmake/z_vcpkg_function_arguments.cmake) diff --git a/docs/maintainers/internal/z_vcpkg_prettify_command_line.md b/docs/maintainers/internal/z_vcpkg_prettify_command_line.md new file mode 100644 index 0000000000..1b76366303 --- /dev/null +++ b/docs/maintainers/internal/z_vcpkg_prettify_command_line.md @@ -0,0 +1,19 @@ +# z_vcpkg_prettify_command_line + +**Only for internal use in vcpkg helpers. Behavior and arguments will change without notice.** +Turn a command line into a formatted string. + +```cmake +z_vcpkg_prettify_command_line( ...) +``` + +This command is for internal use, when printing out to a message. + +## Examples + +* `scripts/cmake/vcpkg_execute_build_process.cmake` +* `scripts/cmake/vcpkg_execute_required_process.cmake` +* `scripts/cmake/vcpkg_execute_required_process_repeat.cmake` + +## Source +[scripts/cmake/z_vcpkg_prettify_command_line.cmake](https://github.com/Microsoft/vcpkg/blob/master/scripts/cmake/z_vcpkg_prettify_command_line.cmake) diff --git a/docs/maintainers/portfile-functions.md b/docs/maintainers/portfile-functions.md index 9cebaf40af..c92abc2c67 100644 --- a/docs/maintainers/portfile-functions.md +++ b/docs/maintainers/portfile-functions.md @@ -53,9 +53,10 @@ - [vcpkg\_install\_nmake](vcpkg_install_nmake.md) - [vcpkg\_install\_qmake](vcpkg_install_qmake.md) - [vcpkg\_minimum\_required](vcpkg_minimum_required.md) -- [vcpkg\_prettify\_command](vcpkg_prettify_command.md) - [vcpkg\_replace\_string](vcpkg_replace_string.md) ## Internal Functions - [vcpkg\_internal\_get\_cmake\_vars](internal/vcpkg_internal_get_cmake_vars.md) +- [z\_vcpkg\_function\_arguments](internal/z_vcpkg_function_arguments.md) +- [z\_vcpkg\_prettify\_command\_line](internal/z_vcpkg_prettify_command_line.md) diff --git a/docs/maintainers/vcpkg_execute_required_process.md b/docs/maintainers/vcpkg_execute_required_process.md index a14e2bcbb3..21b1029eb8 100644 --- a/docs/maintainers/vcpkg_execute_required_process.md +++ b/docs/maintainers/vcpkg_execute_required_process.md @@ -15,7 +15,7 @@ vcpkg_execute_required_process( ``` ## Parameters ### ALLOW_IN_DOWNLOAD_MODE -Allows the command to execute in Download Mode. +Allows the command to execute in Download Mode. [See execute_process() override](../../scripts/cmake/execute_process.cmake). ### COMMAND diff --git a/docs/maintainers/vcpkg_prettify_command.md b/docs/maintainers/vcpkg_prettify_command.md deleted file mode 100644 index c9ef234e2b..0000000000 --- a/docs/maintainers/vcpkg_prettify_command.md +++ /dev/null @@ -1,17 +0,0 @@ -# vcpkg_prettify_command - -Turns list of command arguments into a formatted string. - -## Usage -```cmake -vcpkg_prettify_command( ) -``` - -## Examples - -* `scripts/cmake/vcpkg_execute_build_process.cmake` -* `scripts/cmake/vcpkg_execute_required_process.cmake` -* `scripts/cmake/vcpkg_execute_required_process_repeat.cmake` - -## Source -[scripts/cmake/vcpkg_prettify_command.cmake](https://github.com/Microsoft/vcpkg/blob/master/scripts/cmake/vcpkg_prettify_command.cmake) diff --git a/scripts/cmake/vcpkg_execute_build_process.cmake b/scripts/cmake/vcpkg_execute_build_process.cmake index 2fc583d220..13af95703d 100644 --- a/scripts/cmake/vcpkg_execute_build_process.cmake +++ b/scripts/cmake/vcpkg_execute_build_process.cmake @@ -34,7 +34,6 @@ conflict when building multiple at once. * [icu](https://github.com/Microsoft/vcpkg/blob/master/ports/icu/portfile.cmake) #]===] -include(vcpkg_prettify_command) function(vcpkg_execute_build_process) # parse parameters such that semicolons in options arguments to COMMAND don't get erased cmake_parse_arguments(PARSE_ARGV 0 _ebp "" "WORKING_DIRECTORY;LOGNAME" "COMMAND;NO_PARALLEL_COMMAND") @@ -141,7 +140,7 @@ function(vcpkg_execute_build_process) file(TO_NATIVE_PATH "${LOG}" NATIVE_LOG) list(APPEND STRINGIFIED_LOGS " ${NATIVE_LOG}\n") endforeach() - vcpkg_prettify_command(_ebp_COMMAND _ebp_COMMAND_PRETTY) + z_vcpkg_prettify_command_line(_ebp_COMMAND_PRETTY ${_ebp_COMMAND}) message(FATAL_ERROR " Command failed: ${_ebp_COMMAND_PRETTY}\n" " Working Directory: ${_ebp_WORKING_DIRECTORY}\n" diff --git a/scripts/cmake/vcpkg_execute_required_process.cmake b/scripts/cmake/vcpkg_execute_required_process.cmake index 4b8d247616..c38fd2ed80 100644 --- a/scripts/cmake/vcpkg_execute_required_process.cmake +++ b/scripts/cmake/vcpkg_execute_required_process.cmake @@ -16,7 +16,7 @@ vcpkg_execute_required_process( ``` ## Parameters ### ALLOW_IN_DOWNLOAD_MODE -Allows the command to execute in Download Mode. +Allows the command to execute in Download Mode. [See execute_process() override](../../scripts/cmake/execute_process.cmake). ### COMMAND @@ -47,9 +47,6 @@ This should be a unique name for different triplets so that the logs don't confl * [qt5](https://github.com/Microsoft/vcpkg/blob/master/ports/qt5/portfile.cmake) #]===] -include(vcpkg_prettify_command) -include(vcpkg_execute_in_download_mode) - function(vcpkg_execute_required_process) # parse parameters such that semicolons in options arguments to COMMAND don't get erased cmake_parse_arguments(PARSE_ARGV 0 vcpkg_execute_required_process "ALLOW_IN_DOWNLOAD_MODE" "WORKING_DIRECTORY;LOGNAME;TIMEOUT;OUTPUT_VARIABLE;ERROR_VARIABLE" "COMMAND") @@ -73,7 +70,7 @@ function(vcpkg_execute_required_process) endif() if (DEFINED VCPKG_DOWNLOAD_MODE AND NOT vcpkg_execute_required_process_ALLOW_IN_DOWNLOAD_MODE) - message(FATAL_ERROR + message(FATAL_ERROR [[ This command cannot be executed in Download Mode. Halting portfile execution. @@ -104,7 +101,7 @@ Halting portfile execution. file(TO_NATIVE_PATH "${LOG}" NATIVE_LOG) list(APPEND STRINGIFIED_LOGS " ${NATIVE_LOG}\n") endforeach() - vcpkg_prettify_command(vcpkg_execute_required_process_COMMAND vcpkg_execute_required_process_COMMAND_PRETTY) + z_vcpkg_prettify_command_line(vcpkg_execute_required_process_COMMAND_PRETTY ${vcpkg_execute_required_process_COMMAND}) message(FATAL_ERROR " Command failed: ${vcpkg_execute_required_process_COMMAND_PRETTY}\n" " Working Directory: ${vcpkg_execute_required_process_WORKING_DIRECTORY}\n" diff --git a/scripts/cmake/vcpkg_execute_required_process_repeat.cmake b/scripts/cmake/vcpkg_execute_required_process_repeat.cmake index ba9debfadc..3e63a998c6 100644 --- a/scripts/cmake/vcpkg_execute_required_process_repeat.cmake +++ b/scripts/cmake/vcpkg_execute_required_process_repeat.cmake @@ -14,13 +14,12 @@ vcpkg_execute_required_process_repeat( ``` #]===] -include(vcpkg_prettify_command) function(vcpkg_execute_required_process_repeat) # parse parameters such that semicolons in options arguments to COMMAND don't get erased cmake_parse_arguments(PARSE_ARGV 0 vcpkg_execute_required_process_repeat "ALLOW_IN_DOWNLOAD_MODE" "COUNT;WORKING_DIRECTORY;LOGNAME" "COMMAND") #debug_message("vcpkg_execute_required_process_repeat(${vcpkg_execute_required_process_repeat_COMMAND})") if (DEFINED VCPKG_DOWNLOAD_MODE AND NOT vcpkg_execute_required_process_repeat_ALLOW_IN_DOWNLOAD_MODE) - message(FATAL_ERROR + message(FATAL_ERROR [[ This command cannot be executed in Download Mode. Halting portfile execution. @@ -42,7 +41,7 @@ Halting portfile execution. endif() endforeach(loop_count) if (NOT SUCCESSFUL_EXECUTION) - vcpkg_prettify_command(vcpkg_execute_required_process_repeat_COMMAND vcpkg_execute_required_process_repeat_COMMAND_PRETTY) + z_vcpkg_prettify_command_line(vcpkg_execute_required_process_repeat_COMMAND_PRETTY ${vcpkg_execute_required_process_repeat_COMMAND}) message(FATAL_ERROR " Command failed: ${vcpkg_execute_required_process_repeat_COMMAND_PRETTY}\n" " Working Directory: ${vcpkg_execute_required_process_repeat_WORKING_DIRECTORY}\n" diff --git a/scripts/cmake/vcpkg_prettify_command.cmake b/scripts/cmake/vcpkg_prettify_command.cmake deleted file mode 100644 index 25ad95eecb..0000000000 --- a/scripts/cmake/vcpkg_prettify_command.cmake +++ /dev/null @@ -1,28 +0,0 @@ -#[===[.md: -# vcpkg_prettify_command - -Turns list of command arguments into a formatted string. - -## Usage -```cmake -vcpkg_prettify_command( ) -``` - -## Examples - -* `scripts/cmake/vcpkg_execute_build_process.cmake` -* `scripts/cmake/vcpkg_execute_required_process.cmake` -* `scripts/cmake/vcpkg_execute_required_process_repeat.cmake` -#]===] - -macro(vcpkg_prettify_command INPUT_VAR OUTPUT_VAR) - set(${OUTPUT_VAR} "") - foreach(v ${${INPUT_VAR}}) - if(v MATCHES "( )") - list(APPEND ${OUTPUT_VAR} "\"${v}\"") - else() - list(APPEND ${OUTPUT_VAR} "${v}") - endif() - endforeach() - list(JOIN ${OUTPUT_VAR} " " ${OUTPUT_VAR}) -endmacro() diff --git a/scripts/cmake/z_vcpkg_function_arguments.cmake b/scripts/cmake/z_vcpkg_function_arguments.cmake new file mode 100644 index 0000000000..a189c816de --- /dev/null +++ b/scripts/cmake/z_vcpkg_function_arguments.cmake @@ -0,0 +1,48 @@ +#[===[.md: +# z_vcpkg_function_arguments + +**Only for internal use in vcpkg helpers. Behavior and arguments will change without notice.** +Get a list of the arguments which were passed in. +Unlike `ARGV`, which is simply the arguments joined with `;`, +so that `(A B)` is not distinguishable from `("A;B")`, +this macro gives `"A;B"` for the first argument list, +and `"A\;B"` for the second. + +```cmake +z_vcpkg_function_arguments( []) +``` + +`z_vcpkg_function_arguments` gets the arguments between `ARGV` and the last argument. +`` defaults to `0`, so that all arguments are taken. + +## Example: +```cmake +function(foo_replacement) + z_vcpkg_function_arguments(ARGS) + foo(${ARGS}) + ... +endfunction() +``` +#]===] +macro(z_vcpkg_function_arguments OUT_VAR) + if("${ARGC}" EQUAL 1) + set(z_vcpkg_function_arguments_FIRST_ARG 0) + elseif("${ARGC}" EQUAL 2) + set(z_vcpkg_function_arguments_FIRST_ARG "${ARGV1}") + else() + # vcpkg bug + message(FATAL_ERROR "z_vcpkg_function_arguments: invalid arguments (${ARGV})") + endif() + + set("${OUT_VAR}") + + # this allows us to get the value of the enclosing function's ARGC + set(z_vcpkg_function_arguments_ARGC_NAME "ARGC") + set(z_vcpkg_function_arguments_ARGC "${${z_vcpkg_function_arguments_ARGC_NAME}}") + + math(EXPR z_vcpkg_function_arguments_LAST_ARG "${z_vcpkg_function_arguments_ARGC} - 1") + foreach(z_vcpkg_function_arguments_N RANGE "${z_vcpkg_function_arguments_FIRST_ARG}" "${z_vcpkg_function_arguments_LAST_ARG}") + string(REPLACE ";" "\\;" z_vcpkg_function_arguments_ESCAPED_ARG "${ARGV${z_vcpkg_function_arguments_N}}") + list(APPEND "${OUT_VAR}" "${z_vcpkg_function_arguments_ESCAPED_ARG}") + endforeach() +endmacro() diff --git a/scripts/cmake/z_vcpkg_prettify_command_line.cmake b/scripts/cmake/z_vcpkg_prettify_command_line.cmake new file mode 100644 index 0000000000..766d269fd5 --- /dev/null +++ b/scripts/cmake/z_vcpkg_prettify_command_line.cmake @@ -0,0 +1,33 @@ +#[===[.md: +# z_vcpkg_prettify_command_line + +**Only for internal use in vcpkg helpers. Behavior and arguments will change without notice.** +Turn a command line into a formatted string. + +```cmake +z_vcpkg_prettify_command_line( ...) +``` + +This command is for internal use, when printing out to a message. + +## Examples + +* `scripts/cmake/vcpkg_execute_build_process.cmake` +* `scripts/cmake/vcpkg_execute_required_process.cmake` +* `scripts/cmake/vcpkg_execute_required_process_repeat.cmake` +#]===] + +function(z_vcpkg_prettify_command_line OUT_VAR) + set(OUTPUT "") + z_vcpkg_function_arguments(ARGS 1) + foreach(v IN LISTS ARGS) + string(REPLACE [[\]] [[\\]] v "${v}") + if(v MATCHES "( )") + string(REPLACE [["]] [[\"]] v "${v}") + list(APPEND OUTPUT "\"${v}\"") + else() + list(APPEND OUTPUT "${v}") + endif() + endforeach() + list(JOIN "${OUT_VAR}" " " OUTPUT) +endfunction() diff --git a/scripts/ports.cmake b/scripts/ports.cmake index 9e1ba6b320..58294d81ce 100644 --- a/scripts/ports.cmake +++ b/scripts/ports.cmake @@ -122,9 +122,12 @@ if(CMD MATCHES "^BUILD$") include(vcpkg_install_nmake) include(vcpkg_install_qmake) include(vcpkg_internal_get_cmake_vars) - include(vcpkg_prettify_command) include(vcpkg_replace_string) include(vcpkg_test_cmake) + + include("${SCRIPTS}/cmake/z_vcpkg_prettify_command_line.cmake") + include("${SCRIPTS}/cmake/z_vcpkg_function_arguments.cmake") + include(${CURRENT_PORT_DIR}/portfile.cmake) if(DEFINED PORT) include(${SCRIPTS}/build_info.cmake)