[(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
This commit is contained in:
nicole mazzuca 2021-02-09 15:53:36 -08:00 committed by GitHub
parent 4502f8ed68
commit 545c165ce0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 140 additions and 59 deletions

View File

@ -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(<out-var> [<N>])
```
`z_vcpkg_function_arguments` gets the arguments between `ARGV<N>` and the last argument.
`<N>` 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)

View File

@ -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(<out-var> <argument>...)
```
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)

View File

@ -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)

View File

@ -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

View File

@ -1,17 +0,0 @@
# vcpkg_prettify_command
Turns list of command arguments into a formatted string.
## Usage
```cmake
vcpkg_prettify_command(<INPUT_VAR> <OUTPUT_VAR>)
```
## 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)

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -1,28 +0,0 @@
#[===[.md:
# vcpkg_prettify_command
Turns list of command arguments into a formatted string.
## Usage
```cmake
vcpkg_prettify_command(<INPUT_VAR> <OUTPUT_VAR>)
```
## 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()

View File

@ -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(<out-var> [<N>])
```
`z_vcpkg_function_arguments` gets the arguments between `ARGV<N>` and the last argument.
`<N>` 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()

View File

@ -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(<out-var> <argument>...)
```
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()

View File

@ -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)