Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[(z_)vcpkg_prettify_command(_line)] Scripts Tree Audit #16130

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/maintainers/internal/z_vcpkg_function_arguments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# z_vcpkg_function_arguments
strega-nil marked this conversation as resolved.
Show resolved Hide resolved

**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)
19 changes: 19 additions & 0 deletions docs/maintainers/internal/z_vcpkg_prettify_command_line.md
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 2 additions & 1 deletion docs/maintainers/portfile-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion docs/maintainers/vcpkg_execute_required_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 0 additions & 17 deletions docs/maintainers/vcpkg_prettify_command.md

This file was deleted.

3 changes: 1 addition & 2 deletions scripts/cmake/vcpkg_execute_build_process.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"
Expand Down
9 changes: 3 additions & 6 deletions scripts/cmake/vcpkg_execute_required_process.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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.
Expand Down Expand Up @@ -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})
strega-nil marked this conversation as resolved.
Show resolved Hide resolved
message(FATAL_ERROR
" Command failed: ${vcpkg_execute_required_process_COMMAND_PRETTY}\n"
" Working Directory: ${vcpkg_execute_required_process_WORKING_DIRECTORY}\n"
Expand Down
5 changes: 2 additions & 3 deletions scripts/cmake/vcpkg_execute_required_process_repeat.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"
Expand Down
28 changes: 0 additions & 28 deletions scripts/cmake/vcpkg_prettify_command.cmake

This file was deleted.

48 changes: 48 additions & 0 deletions scripts/cmake/z_vcpkg_function_arguments.cmake
Original file line number Diff line number Diff line change
@@ -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}")
ras0219-msft marked this conversation as resolved.
Show resolved Hide resolved
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}}")
strega-nil marked this conversation as resolved.
Show resolved Hide resolved

math(EXPR z_vcpkg_function_arguments_LAST_ARG "${z_vcpkg_function_arguments_ARGC} - 1")
strega-nil marked this conversation as resolved.
Show resolved Hide resolved
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()
33 changes: 33 additions & 0 deletions scripts/cmake/z_vcpkg_prettify_command_line.cmake
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 4 additions & 1 deletion scripts/ports.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
strega-nil marked this conversation as resolved.
Show resolved Hide resolved

include(${CURRENT_PORT_DIR}/portfile.cmake)
if(DEFINED PORT)
include(${SCRIPTS}/build_info.cmake)
Expand Down