Skip to content

Commit 2031918

Browse files
committed
more code reuse
1 parent 38eee04 commit 2031918

File tree

1 file changed

+19
-26
lines changed

1 file changed

+19
-26
lines changed

nurfile

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ def --wrapped run-cmd [...cmd: string] {
88
^($cmd | first) ...($cmd | skip 1)
99
}
1010

11+
def flush-artifacts [
12+
build_dir: string, dirty: bool
13+
] {
14+
if ($build_dir | path exists) {
15+
if $dirty == false {
16+
print $"(ansi yellow)Removing artifacts(ansi reset) ($build_dir)"
17+
rm -r $build_dir
18+
}
19+
}
20+
}
1121
# Build the docs.
1222
#
1323
# Note, there is no check against what
@@ -17,12 +27,7 @@ def "nur docs" [
1727
--open (-o) # Open the built docs in your default browser
1828
] {
1929
let build_dir = "docs/html"
20-
if ($build_dir | path exists) {
21-
if $dirty == false {
22-
print $"(ansi yellow)Removing artifacts(ansi reset) ($build_dir)"
23-
rm -r $build_dir
24-
}
25-
}
30+
flush-artifacts $build_dir $dirty
2631
cd docs
2732
run-cmd doxygen
2833
if $open {
@@ -53,12 +58,7 @@ def "nur examples" [
5358
let src_dir = "examples_linux"
5459
let build_dir = $"($src_dir)/build"
5560

56-
if ($build_dir | path exists) {
57-
if $dirty == false {
58-
print $"(ansi yellow)Removing artifacts(ansi reset) ($build_dir)"
59-
rm -r $build_dir
60-
}
61-
}
61+
flush-artifacts $build_dir $dirty
6262

6363
if $dirty == false {
6464
run-cmd cmake -B $build_dir $src_dir ...$cmake_opts
@@ -87,12 +87,8 @@ def --wrapped "nur lib" [
8787
...cmake_opts: string # additional args passed to cmake when configuring the build env
8888
] {
8989
let build_dir = "build"
90-
if ($build_dir | path exists) {
91-
if $dirty == false {
92-
print $"(ansi yellow)Removing artifacts(ansi reset) ($build_dir)"
93-
rm -r $build_dir
94-
}
95-
}
90+
flush-artifacts $build_dir $dirty
91+
9692
if $dirty == false {
9793
run-cmd cmake -B build -S . ...$cmake_opts
9894
}
@@ -111,12 +107,7 @@ def --wrapped "nur pico" [
111107
] {
112108
let src_dir = "examples_pico"
113109
let build_dir = $"($src_dir)/build"
114-
if ($build_dir | path exists) {
115-
if $dirty == false {
116-
print $"(ansi yellow)Removing artifacts(ansi reset) ($build_dir)"
117-
rm -r $build_dir
118-
}
119-
}
110+
flush-artifacts $build_dir $dirty
120111

121112
let use_ninja = '-G Ninja'
122113
let opts = if (is-windows) {
@@ -142,8 +133,10 @@ def "nur py" [
142133
print $"(ansi green)Found wrapper(ansi reset) in ($dir)"
143134
let artifacts = glob $"($dir)/{build,*.egg-info}"
144135
if ($artifacts | length) > 0 {
145-
print $"(ansi yellow)Removing artifacts(ansi reset) ($artifacts | str join ' ')"
146-
rm -r ...$artifacts
136+
if $dirty == false {
137+
print $"(ansi yellow)Removing artifacts(ansi reset) ($artifacts | str join ' ')"
138+
rm -r ...$artifacts
139+
}
147140
}
148141
run-cmd pip install -v $"./($dir)"
149142
}

0 commit comments

Comments
 (0)