-
Notifications
You must be signed in to change notification settings - Fork 9
fix(cmake): Split CMake settings generation from library install tasks to support multi-project dependency builds. #88
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
base: main
Are you sure you want to change the base?
Changes from all commits
60e4436
2e05b9f
025e070
00bb47b
1126ba6
022fe92
73d6e96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
version: "3" | ||
|
||
includes: | ||
misc: "misc.yaml" | ||
remote: "remote.yaml" | ||
|
||
set: ["u", "pipefail"] | ||
shopt: ["globstar"] | ||
|
||
tasks: | ||
# Runs the CMake build step for the given build directory. The caller must have previously called | ||
# `generate` on `BUILD_DIR` for this task to succeed. We purposely omit `sources` and `generates` | ||
# as we defer to `cmake` to decide whether it should perform any actions. | ||
# `generate` on `BUILD_DIR` for this task to succeed. | ||
# | ||
# NOTE: We purposely omit `sources` and `generates` as we defer to `cmake` to decide whether it | ||
# should perform any actions. | ||
# | ||
# @param {string} BUILD_DIR Directory containing the generated build system to use. | ||
# @param {string[]} [EXTRA_ARGS] Any additional arguments to pass to the build command. | ||
|
@@ -60,9 +63,10 @@ tasks: | |
ref: ".EXTRA_ARGS" | ||
TARGETS: ["clean"] | ||
|
||
# Runs the CMake generate step for the given source and build directories. We purposely omit | ||
# `sources` and `generates` as we defer to `cmake` to decide whether it should perform any | ||
# actions. | ||
# Runs the CMake generate step for the given source and build directories. | ||
# | ||
# NOTE: We purposely omit `sources` and `generates` as we defer to `cmake` to decide whether it | ||
# should perform any actions. | ||
# | ||
# @param {string} BUILD_DIR Directory in which to generate the build system. | ||
# @param {string} SOURCE_DIR Project source directory containing the CMakeLists.txt file. | ||
|
@@ -85,38 +89,22 @@ tasks: | |
{{- end}} | ||
|
||
# Runs the CMake install step for the given build directory. The caller must have previously | ||
# called `build` on `BUILD_DIR` for this task to succeed. If `CMAKE_SETTINGS_DIR` is set, a | ||
# settings file will be created in that directory, containing a `{{.CMAKE_PACKAGE_NAME}}_ROOT` | ||
# CMake variable that points to `INSTALL_PREFIX`. | ||
# called `build` on `BUILD_DIR` for this task to succeed. | ||
# | ||
# NOTE: We purposely omit `sources` and `generates` as we defer to `cmake` to decide whether it | ||
# should perform any actions. | ||
# | ||
# @param {string} BUILD_DIR Directory containing the completed build to use. | ||
# @param {string} INSTALL_PREFIX Path prefix of where the project should be installed. | ||
# @param {string} [CMAKE_PACKAGE_NAME] CMake project name (used in directory names and the CMake | ||
# settings file). Required if `CMAKE_SETTINGS_DIR` is set. | ||
# @param {string} [CMAKE_SETTINGS_DIR] If set, the directory where the project's CMake settings | ||
# file should be stored. | ||
# @param {string[]} [EXTRA_ARGS] Any additional arguments to pass to the install command. | ||
install: | ||
internal: true | ||
label: "{{.TASK}}:{{.BUILD_DIR}}-{{.INSTALL_PREFIX}}-{{.EXTRA_ARGS}}" | ||
vars: | ||
CMAKE_SETTINGS_DIR: >- | ||
{{default "" .CMAKE_SETTINGS_DIR}} | ||
EXTRA_ARGS: | ||
ref: "default (list) .EXTRA_ARGS" | ||
requires: | ||
vars: ["BUILD_DIR", "INSTALL_PREFIX"] | ||
preconditions: | ||
- sh: >- | ||
{{if .CMAKE_SETTINGS_DIR}} | ||
{{not (empty .CMAKE_PACKAGE_NAME)}} | ||
{{end}} | ||
msg: |- | ||
CMAKE_PACKAGE_NAME must be set if CMAKE_SETTINGS_DIR is set. | ||
CMAKE_SETTINGS_DIR: {{.CMAKE_SETTINGS_DIR}} | ||
cmds: | ||
- >- | ||
cmake | ||
|
@@ -125,18 +113,12 @@ tasks: | |
{{- range .EXTRA_ARGS}} | ||
{{.}} | ||
{{- end}} | ||
- >- | ||
{{- if .CMAKE_SETTINGS_DIR}} | ||
echo "set({{.CMAKE_PACKAGE_NAME}}_ROOT | ||
\"{{.INSTALL_PREFIX}}\" | ||
CACHE PATH | ||
\"Package root for {{.CMAKE_PACKAGE_NAME}}.\" | ||
)" >> "{{.CMAKE_SETTINGS_DIR}}/{{.CMAKE_PACKAGE_NAME}}.cmake" | ||
{{- end}} | ||
|
||
# Downloads a CMake project tar file from `TAR_URL` and then generates, builds, and installs the | ||
# project. We purposely omit `sources` and `generates` as we defer to `cmake` to decide whether it | ||
# should perform any actions. However, the download and extraction will be skipped if unnecessary. | ||
# project. | ||
# | ||
# NOTE: We purposely omit `sources` and `generates` as we defer to `cmake` to decide whether it | ||
# should perform any actions. | ||
# | ||
# Required parameters | ||
# @param {string} CMAKE_PACKAGE_NAME CMake package name. | ||
|
@@ -154,8 +136,6 @@ tasks: | |
# command. | ||
# @param {int} [CMAKE_JOBS] The maximum number of concurrent processes to use when building. If | ||
# omitted, the native build tool's default number is used. See `man cmake`. | ||
# @param {string} [CMAKE_SETTINGS_DIR] The directory where the project's CMake settings file | ||
# should be stored. | ||
# @param {string} [CMAKE_SOURCE_DIR=.] The path, within the extraction directory, containing the | ||
# project's top level CMakeLists.txt. | ||
# @param {string[]} [CMAKE_TARGETS] A list of specific targets to build instead of the default | ||
|
@@ -173,8 +153,6 @@ tasks: | |
ref: "default (list) .CMAKE_INSTALL_ARGS" | ||
CMAKE_JOBS: >- | ||
{{default "" .CMAKE_JOBS}} | ||
CMAKE_SETTINGS_DIR: >- | ||
{{default "" .CMAKE_SETTINGS_DIR}} | ||
CMAKE_SOURCE_DIR: >- | ||
{{default "." .CMAKE_SOURCE_DIR}} | ||
CMAKE_TARGETS: | ||
|
@@ -211,12 +189,33 @@ tasks: | |
- task: "install" | ||
vars: | ||
BUILD_DIR: "{{.BUILD_DIR}}" | ||
CMAKE_PACKAGE_NAME: "{{.CMAKE_PACKAGE_NAME}}" | ||
CMAKE_SETTINGS_DIR: "{{.CMAKE_SETTINGS_DIR}}" | ||
EXTRA_ARGS: | ||
ref: ".CMAKE_INSTALL_ARGS" | ||
INSTALL_PREFIX: "{{.INSTALL_PREFIX}}" | ||
|
||
# Create a settings file in CMAKE_SETTINGS_DIR, containing a `{{.CMAKE_PACKAGE_NAME}}_ROOT` CMake | ||
# variable that points to `PACKAGE_INSTALL_PREFIX`. | ||
# | ||
# Required parameters | ||
# @param {string} CMAKE_PACKAGE_NAME CMake package name. | ||
# @param {string} CMAKE_SETTINGS_DIR The directory where the project's CMake settings file should | ||
# be stored. | ||
# @param {string} PACKAGE_INSTALL_PREFIX The location where the project is installed. | ||
generate-cmake-settings: | ||
internal: true | ||
label: "{{.TASK}}:{{.CMAKE_PACKAGE_NAME}}-{{.CMAKE_SETTINGS_DIR}}-{{.PACKAGE_INSTALL_PREFIX}}" | ||
requires: | ||
vars: ["CMAKE_PACKAGE_NAME", "CMAKE_SETTINGS_DIR", "PACKAGE_INSTALL_PREFIX"] | ||
run: "when_changed" | ||
cmds: | ||
- "mkdir -p {{.CMAKE_SETTINGS_DIR}}" | ||
- >- | ||
echo "set({{.CMAKE_PACKAGE_NAME}}_ROOT | ||
\"{{.PACKAGE_INSTALL_PREFIX}}\" | ||
CACHE PATH | ||
\"Package root for {{.CMAKE_PACKAGE_NAME}}.\" | ||
)" >> "{{.CMAKE_SETTINGS_DIR}}/{{.CMAKE_PACKAGE_NAME}}.cmake" | ||
|
||
# Sets up all CMake dependencies for a project by: | ||
# | ||
# 1. creating a directory to contain all CMake settings files (CMAKE_SETTINGS_DIR). | ||
|
@@ -227,8 +226,7 @@ tasks: | |
# @param {string} CMAKE_SETTINGS_DIR The directory where CMake settings files should be stored. | ||
# @param {string} DEP_TASK The task to run that will install all dependencies. NOTE: | ||
# - The task name must be qualified from the root of the project. | ||
# - The task must not require any arguments (to use a task with arguments create a new task that | ||
# calls the original with any arguments set). | ||
Comment on lines
-230
to
-231
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this is a little misleading. We should say that the task must take two arguments |
||
# - The task takes in CMAKE_SETTINGS_DIR and CMAKE_SETTINGS_FILE as optional arguments. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From previous part of the docstring and the task's |
||
# - Dependencies must write their settings file to CMAKE_SETTINGS_DIR in order to have them | ||
# included in CMAKE_SETTINGS_FILE. | ||
# @param {string} [CMAKE_SETTINGS_FILE={{.CMAKE_SETTINGS_DIR}}/all.cmake] The file in which to | ||
|
@@ -242,12 +240,20 @@ tasks: | |
requires: | ||
vars: ["CMAKE_SETTINGS_DIR", "DEP_TASK"] | ||
cmds: | ||
- "rm -rf {{.CMAKE_SETTINGS_DIR}}" | ||
- "mkdir -p {{.CMAKE_SETTINGS_DIR}}" | ||
- task: "misc:reset-dir" | ||
vars: | ||
DIR_PATH: "{{.CMAKE_SETTINGS_DIR}}" | ||
- task: "misc:reset-file" | ||
vars: | ||
FILE_PATH: "{{.CMAKE_SETTINGS_FILE}}" | ||
|
||
# NOTE: We prefix DEP_TASK with `::` assuming that this taskfile is included through the | ||
# `utils` taskfile, and that in turn is included in the user's taskfile. | ||
- task: "::{{.DEP_TASK}}" | ||
vars: | ||
CMAKE_SETTINGS_DIR: "{{.CMAKE_SETTINGS_DIR}}" | ||
CMAKE_SETTINGS_FILE: "{{.CMAKE_SETTINGS_FILE}}" | ||
|
||
- |- | ||
for file in {{.CMAKE_SETTINGS_DIR}}/*.cmake; do | ||
if [[ "$file" != "{{.CMAKE_SETTINGS_FILE}}" ]]; then | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,25 @@ tasks: | |
. "{{.OUTPUT_DIR}}/bin/activate" | ||
pip3 install --upgrade pip | ||
pip3 install --upgrade -r "{{.REQUIREMENTS_FILE}}" | ||
|
||
reset-dir: | ||
desc: "Removes the given directory and create it empty. Runs once per directory path." | ||
internal: true | ||
label: "{{.TASK}}:{{.DIR_PATH}}" | ||
requires: | ||
vars: ["DIR_PATH"] | ||
run: "when_changed" | ||
cmds: | ||
- "rm -rf {{.DIR_PATH}}" | ||
- "mkdir -p {{.DIR_PATH}}" | ||
|
||
reset-file: | ||
desc: "Removes the given file. Runs once per file path." | ||
internal: true | ||
label: "{{.TASK}}:{{.FILE_PATH}}" | ||
requires: | ||
vars: ["FILE_PATH"] | ||
run: "when_changed" | ||
cmds: | ||
- "rm -rf {{.FILE_PATH}}" | ||
- "mkdir -p $(dirname -- {{.FILE_PATH}})" | ||
Comment on lines
+45
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quote the reset commands to avoid clobbering the wrong paths Both - - "rm -rf {{.DIR_PATH}}"
- - "mkdir -p {{.DIR_PATH}}"
+ - 'rm -rf "{{.DIR_PATH}}"'
+ - 'mkdir -p "{{.DIR_PATH}}"'
...
- - "rm -rf {{.FILE_PATH}}"
- - "mkdir -p $(dirname -- {{.FILE_PATH}})"
+ - 'rm -rf "{{.FILE_PATH}}"'
+ - 'mkdir -p "$(dirname -- "{{.FILE_PATH}}")"'
🤖 Prompt for AI Agents
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Bill-hbrhbr This makes sense to me. Could you fix this by applying what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.