Skip to content

Commit 630d389

Browse files
committed
Refactor taskfiles and add build, install, and example tasks for all targets and build types.
1 parent caff1ae commit 630d389

File tree

5 files changed

+209
-71
lines changed

5 files changed

+209
-71
lines changed

taskfile.yaml

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ includes:
77
build: "./taskfiles/build.yaml"
88
deps: "./taskfiles/deps.yaml"
99
lint: "./taskfiles/lint.yaml"
10-
utils: "tools/yscope-dev-utils/exports/taskfiles/utils/utils.yaml"
10+
test: "./taskfiles/test.yaml"
11+
utils: "./tools/yscope-dev-utils/exports/taskfiles/utils/utils.yaml"
1112

1213
vars:
1314
G_BUILD_DIR: "{{.ROOT_DIR}}/build"
1415
G_CPP_SRC_DIR: "{{.ROOT_DIR}}/src"
15-
G_DEPS_DIR: "{{.G_BUILD_DIR}}/deps"
1616

17-
# These should be kept in-sync with its usage in CMakeLists.txt
18-
G_DEPS_CMAKE_SETTINGS_DIR: "{{.G_DEPS_DIR}}/cmake-settings"
19-
G_DEPS_CMAKE_SETTINGS_FILE: "{{.G_DEPS_CMAKE_SETTINGS_DIR}}/settings.cmake"
20-
21-
G_TEST_BIN_DIR: "{{.G_BUILD_DIR}}/testbin"
22-
G_TEST_TARGET_SUFFIXES:
17+
G_VALID_BUILD_TYPES:
18+
- "debug"
19+
- "release"
20+
G_VALID_TARGETS:
2321
- "all"
2422
- "containers"
2523
- "error_handling"
@@ -38,12 +36,44 @@ tasks:
3836
cmds:
3937
- "mkdir -p '{{.G_BUILD_DIR}}'"
4038

41-
test-*:
42-
desc: "Runs unit tests for the specified test target."
43-
vars:
44-
TEST_TARGET: >-
45-
{{printf "unit-test-%s" (index .MATCH 0)}}
46-
deps:
47-
- "build:{{.TEST_TARGET}}"
39+
validate-args:
40+
internal: true
41+
requires:
42+
vars: ["BUILD_TYPE", "TARGET"]
4843
cmds:
49-
- "{{.G_TEST_BIN_DIR}}/{{.TEST_TARGET}}"
44+
- task: "validate-build-type"
45+
vars:
46+
BUILD_TYPE: "{{.BUILD_TYPE}}"
47+
- task: "validate-target"
48+
vars:
49+
TARGET: "{{.TARGET}}"
50+
51+
validate-build-type:
52+
internal: true
53+
requires:
54+
vars: ["BUILD_TYPE"]
55+
preconditions:
56+
- sh: >-
57+
{{has .BUILD_TYPE .G_VALID_BUILD_TYPES}}
58+
msg: |-
59+
{{- if not (has .BUILD_TYPE .G_VALID_BUILD_TYPES)}}
60+
{{.BUILD_TYPE}} is not a valid build type. List of valid build types:
61+
{{- range .G_VALID_BUILD_TYPES}}
62+
{{.}}
63+
{{- end}}
64+
{{- end}}
65+
66+
validate-target:
67+
internal: true
68+
requires:
69+
vars: ["TARGET"]
70+
preconditions:
71+
- sh: >-
72+
{{has .TARGET .G_VALID_TARGETS}}
73+
msg: |-
74+
{{- if not (has .TARGET .G_VALID_TARGETS)}}
75+
{{.TARGET}} is not a valid build target. List of valid build targets:
76+
{{- range .G_VALID_TARGETS}}
77+
{{.}}
78+
{{- end}}
79+
{{- end}}

taskfiles/build.yaml

Lines changed: 114 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,139 @@
11
version: "3"
22

3+
includes:
4+
deps:
5+
internal: true
6+
taskfile: "deps.yaml"
7+
utils:
8+
internal: true
9+
taskfile: "../tools/yscope-dev-utils/exports/taskfiles/utils/utils.yaml"
10+
311
vars:
4-
G_CMAKE_CACHE: "{{.G_BUILD_DIR}}/CMakeCache.txt"
5-
G_COMPILE_COMMANDS_DB: "{{.G_BUILD_DIR}}/compile_commands.json"
12+
G_EXAMPLES_BUILD_DIR: "{{.G_BUILD_DIR}}/examples"
13+
G_YSTDLIB_BUILD_DIR: "{{.G_BUILD_DIR}}/ystdlib"
614

715
tasks:
8-
all:
9-
desc: "Builds all of ystdlib."
16+
build-*-*:
17+
desc: "build-<target>-<build type>: Builds the specified build target with build type."
18+
vars:
19+
BUILD_TYPE: "{{index .MATCH 1}}"
20+
TARGET: "{{index .MATCH 0}}"
1021
deps:
11-
- "init"
22+
- task: ":validate-args"
23+
vars:
24+
BUILD_TYPE: "{{.BUILD_TYPE}}"
25+
TARGET: "{{.TEST_TARGET}}"
1226
cmds:
13-
- task: ":utils:cmake:build"
27+
- task: "build"
1428
vars:
15-
BUILD_DIR: "{{.G_BUILD_DIR}}"
29+
BUILD_TYPE: "{{.BUILD_TYPE}}"
30+
TARGET: "{{.TARGET}}"
1631

17-
target-*:
18-
desc: "Builds a CMake target."
32+
clean-*:
33+
desc: "clean-<build type>: Clean the build type."
1934
vars:
20-
TARGET: "{{index .MATCH 0}}"
35+
BUILD_TYPE: "{{index .MATCH 0}}"
2136
deps:
22-
- "init"
37+
- task: ":validate-build-type"
38+
vars:
39+
BUILD_TYPE: "{{.BUILD_TYPE}}"
2340
cmds:
24-
- task: ":utils:cmake:build"
41+
- task: "utils:cmake:clean"
2542
vars:
26-
BUILD_DIR: "{{.G_BUILD_DIR}}"
27-
TARGETS:
28-
- "{{.TARGET}}"
43+
BUILD_DIR: "{{.G_YSTDLIB_DIR}}/{{.BUILD_TYPE}}"
2944

30-
unit-test-*:
31-
desc: "Builds the specified unit test target."
45+
examples-*:
46+
desc: "examples-<build type>: Builds the examples with build type."
3247
vars:
33-
TARGET_SUFFIX: >-
34-
{{index .MATCH 0}}
35-
TARGET_NAME: >-
36-
{{printf "unit-test-%s" .TARGET_SUFFIX}}
37-
preconditions:
38-
- sh: >-
39-
{{has .TARGET_SUFFIX .G_TEST_TARGET_SUFFIXES}}
40-
msg: |-
41-
{{.TARGET_NAME}} is not a valid unit test target!
42-
List of unit test targets:
43-
{{- range .G_TEST_TARGET_SUFFIXES }}
44-
unit-test-{{.}}
45-
{{- end}}
48+
BUILD_TYPE: "{{index .MATCH 0}}"
49+
deps:
50+
- task: ":validate-build-type"
51+
vars:
52+
BUILD_TYPE: "{{.BUILD_TYPE}}"
4653
cmds:
47-
- task: "target-{{.TARGET_NAME}}"
54+
- task: "examples"
55+
vars:
56+
BUILD_TYPE: "{{.BUILD_TYPE}}"
4857

49-
clean:
50-
desc: "Removes all built artifacts."
58+
install-*-*:
59+
desc: >-
60+
install-<target>-<build type> INSTALL_PREFIX="<prefix path>": Install the specified build
61+
target with build type to the prefix path."
62+
vars:
63+
BUILD_TYPE: "{{index .MATCH 1}}"
64+
TARGET: "{{index .MATCH 0}}"
65+
requires:
66+
vars: ["INSTALL_PREFIX"]
5167
deps:
52-
- task: ":utils:cmake:clean"
68+
- task: ":validate-args"
69+
vars:
70+
BUILD_TYPE: "{{.BUILD_TYPE}}"
71+
TARGET: "{{.TEST_TARGET}}"
72+
cmds:
73+
- task: "install"
5374
vars:
54-
BUILD_DIR: "{{.G_BUILD_DIR}}"
75+
BUILD_TYPE: "{{.BUILD_TYPE}}"
76+
INSTALL_PREFIX: "{{.INSTALL_PREFIX}}"
77+
TARGET: "{{.TARGET}}"
5578

56-
init:
79+
build:
5780
internal: true
81+
requires:
82+
vars: ["BUILD_TYPE", "TARGET"]
5883
deps:
59-
- ":deps:install-all"
60-
run: "once"
84+
- "deps:all"
6185
cmds:
62-
- task: ":utils:cmake:generate"
86+
- task: "utils:cmake:generate"
6387
vars:
64-
BUILD_DIR: "{{.G_BUILD_DIR}}"
88+
BUILD_DIR: "{{.G_YSTDLIB_BUILD_DIR}}/{{.BUILD_TYPE}}"
89+
EXTRA_ARGS:
90+
- "-DCMAKE_BUILD_TYPE={{.BUILD_TYPE}}"
6591
SOURCE_DIR: "{{.ROOT_DIR}}"
92+
- task: "utils:cmake:build"
93+
vars:
94+
BUILD_DIR: "{{.G_YSTDLIB_BUILD_DIR}}/{{.BUILD_TYPE}}"
95+
TARGETS:
96+
- "{{.TARGET}}"
97+
98+
examples:
99+
internal: true
100+
requires:
101+
vars: ["BUILD_TYPE"]
102+
vars:
103+
INSTALL_PREFIX: "{{.G_EXAMPLES_BUILD_DIR}}/deps/ystdlib/{{.BUILD_TYPE}}"
104+
deps:
105+
- task: "build"
106+
vars:
107+
BUILD_TYPE: "{{.BUILD_TYPE}}"
108+
TARGET: "{{.TARGET}}"
109+
cmds:
110+
- task: "install"
111+
vars:
112+
BUILD_TYPE: "{{.BUILD_TYPE}}"
113+
INSTALL_PREFIX: "{{.INSTALL_PREFIX}}"
114+
TARGET: "{{.TARGET}}"
115+
- task: "utils:cmake:generate"
116+
vars:
117+
BUILD_DIR: "{{.G_EXAMPLES_BUILD_DIR}}/{{.BUILD_TYPE}}"
118+
EXTRA_ARGS:
119+
- "-DCMAKE_BUILD_TYPE={{.BUILD_TYPE}}"
120+
- "-Dystdlib_ROOT={{.INSTALL_PREFIX}}"
121+
SOURCE_DIR: "{{.ROOT_DIR}}/examples"
122+
- task: "utils:cmake:build"
123+
vars:
124+
BUILD_DIR: "{{.G_EXAMPLES_BUILD_DIR}}/{{.BUILD_TYPE}}"
125+
126+
install:
127+
internal: true
128+
requires:
129+
vars: ["BUILD_TYPE", "INSTALL_PREFIX", "TARGET"]
130+
deps:
131+
- task: "build"
132+
vars:
133+
BUILD_TYPE: "{{.BUILD_TYPE}}"
134+
TARGET: "{{.TARGET}}"
135+
cmds:
136+
- task: "utils:cmake:install"
137+
vars:
138+
BUILD_DIR: "{{.G_YSTDLIB_BUILD_DIR}}/{{.BUILD_TYPE}}"
139+
INSTALL_PREFIX: "{{.INSTALL_PREFIX}}"

taskfiles/deps.yaml

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,56 @@
11
version: "3"
22

3+
includes:
4+
utils:
5+
internal: true
6+
taskfile: "../tools/yscope-dev-utils/exports/taskfiles/utils/utils.yaml"
7+
38
vars:
49
G_CATCH2_LIB_NAME: "Catch2"
5-
G_CATCH2_WORK_DIR: "{{.G_DEPS_DIR}}/{{.G_CATCH2_LIB_NAME}}"
10+
G_DEPS_DIR: "{{.G_BUILD_DIR}}/deps"
11+
12+
# This path must be kept in-sync with its usage in CMakeLists.txt and examples/CMakeLists.txt.
13+
G_DEPS_CMAKE_SETTINGS_DIR: "{{.G_DEPS_DIR}}/cmake-settings"
614

715
tasks:
8-
install-all:
16+
all:
917
desc: "Install all dependencies required by ystdlib."
1018
run: "once"
1119
cmds:
12-
- "rm -rf '{{.G_DEPS_CMAKE_SETTINGS_DIR}}'"
13-
- "mkdir -p '{{.G_DEPS_CMAKE_SETTINGS_DIR}}'"
14-
- task: ":utils:cmake:install-deps-and-generate-settings"
20+
- task: "utils:cmake:install-deps-and-generate-settings"
1521
vars:
1622
CMAKE_SETTINGS_DIR: "{{.G_DEPS_CMAKE_SETTINGS_DIR}}"
17-
CMAKE_SETTINGS_FILE: "{{.G_DEPS_CMAKE_SETTINGS_FILE}}"
18-
DEP_TASK: "deps:install-all-parallel"
23+
DEP_TASK: "all-parallel"
1924

20-
install-all-parallel:
25+
all-parallel:
2126
internal: true
27+
run: "once"
2228
deps:
23-
- "install-boost"
24-
- "install-Catch2"
29+
- "boost"
30+
- "Catch2"
2531

26-
install-Catch2:
32+
Catch2:
2733
internal: true
2834
run: "once"
2935
cmds:
30-
- task: ":utils:cmake:install-remote-tar"
36+
- task: "utils:cmake:install-remote-tar"
3137
vars:
3238
CMAKE_PACKAGE_NAME: "{{.G_CATCH2_LIB_NAME}}"
3339
CMAKE_SETTINGS_DIR: "{{.G_DEPS_CMAKE_SETTINGS_DIR}}"
3440
TAR_SHA256: "1ab2de20460d4641553addfdfe6acd4109d871d5531f8f519a52ea4926303087"
3541
TAR_URL: "https://github.com/catchorg/Catch2/archive/refs/tags/v3.8.0.tar.gz"
36-
WORK_DIR: "{{.G_CATCH2_WORK_DIR}}"
42+
WORK_DIR: "{{.G_DEPS_DIR}}"
3743

38-
install-boost:
44+
boost:
3945
internal: true
4046
run: "once"
4147
cmds:
48+
# NOTE: boost:download-and-install only works when included from the top level taskfile
4249
- task: ":utils:boost:download-and-install"
4350
vars:
4451
CMAKE_SETTINGS_DIR: "{{.G_DEPS_CMAKE_SETTINGS_DIR}}"
4552
FILE_SHA256: "d6c69e4459eb5d6ec208250291221e7ff4a2affde9af6e49c9303b89c687461f"
4653
URL: "https://github.com/boostorg/boost/releases/download/boost-1.87.0\
4754
/boost-1.87.0-b2-nodocs.tar.gz"
4855
TARGETS: ["headers"]
49-
WORK_DIR: "{{.G_DEPS_DIR}}/boost"
56+
WORK_DIR: "{{.G_DEPS_DIR}}"

taskfiles/lint-cpp.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
version: "3"
22

33
vars:
4+
G_COMPILE_COMMANDS_DB: "{{.G_BUILD_DIR}}/compile_commands.json"
45
G_LINT_CLANG_TIDY_DIR: "{{.G_BUILD_DIR}}/lint-clang-tidy"
56

67
tasks:

taskfiles/test.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: "3"
2+
3+
includes:
4+
build:
5+
internal: true
6+
taskfile: "build.yaml"
7+
8+
tasks:
9+
test-*-*:
10+
desc: >-
11+
test-<target>-<build type>: Runs unit tests for the specified test target and build type.
12+
vars:
13+
BUILD_TYPE: "{{index .MATCH 1}}"
14+
TARGET: "{{index .MATCH 0}}"
15+
TEST_TARGET: "unit-test-{{.TARGET}}"
16+
deps:
17+
- task: ":validate-args"
18+
vars:
19+
BUILD_TYPE: "{{.BUILD_TYPE}}"
20+
TARGET: "{{.TARGET}}"
21+
cmds:
22+
- task: "build:build"
23+
vars:
24+
BUILD_TYPE: "{{.BUILD_TYPE}}"
25+
TARGET: "{{.TEST_TARGET}}"
26+
- "{{.G_BUILD_DIR}}/testbin/{{.TEST_TARGET}}"

0 commit comments

Comments
 (0)