Skip to content

Commit c95db9b

Browse files
authored
chore: use nushell as task runner (#54)
Same as nRF24/RF24#1038 except this repo only has the following tasks: - `nur docs` - `nur fmt` All others tasks in nRF24/RF24#1038 are only applicable to Linux or the Pico SDK. * ran `nur fmt -a` * disable clang-format on 1 line avoids adding the wrong indentation to a line.
1 parent ff7e6b2 commit c95db9b

File tree

3 files changed

+172
-3
lines changed

3 files changed

+172
-3
lines changed

RF24Ethernet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,9 @@ void RF24EthernetClass::network_send()
322322
Serial.print(millis());
323323
Serial.println(F(" *** RF24Ethernet Network Write Fail ***"));
324324
}
325-
#else
325+
#else // clang-format off
326326
RF24Ethernet.network.write(headerOut, uip_buf, uip_len);
327-
#endif
327+
#endif // clang-format on
328328

329329
#if defined ETH_DEBUG_L2
330330
if (ok) {

examples/Getting_Started_SimpleClient_Mesh_DNS/Getting_Started_SimpleClient_Mesh_DNS.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ EthernetClient client;
2929
// The hosts we will be connecting to
3030
// Note: The gateway will need to be able to forward traffic for internet hosts, see the documentation
3131
// Note: DNS responses for www.domain.com will typically be shorter than requests for domain.com.
32-
char icewind[] = { "109.120.203.163" }; //http://109.120.203.163/web/blyad.club/library/litrature/Salvatore,%20R.A/Salvatore,%20R.A%20-%20Icewind%20Dale%20Trilogy%201%20-%20Crystal%20Shard,%20The.txt
32+
char icewind[] = { "109.120.203.163" }; //http://109.120.203.163/web/blyad.club/library/litrature/Salvatore,%20R.A/Salvatore,%20R.A%20-%20Icewind%20Dale%20Trilogy%201%20-%20Crystal%20Shard,%20The.txt
3333
char ascii[] = { "artscene.textfiles.com" }; //http://artscene.textfiles.com/asciiart/texthistory.txt
3434
char* host = ascii;
3535

nurfile

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
2+
3+
def is-windows [] {
4+
$nu.os-info | get "family" | str starts-with "windows"
5+
}
6+
7+
8+
def --wrapped run-cmd [...cmd: string] {
9+
print $"\n(ansi blue)Running(ansi reset) ($cmd | str join ' ')"
10+
let elapsed = timeit {|| ^($cmd | first) ...($cmd | skip 1)}
11+
print $"(ansi magenta)($cmd | first) took ($elapsed)(ansi reset)"
12+
}
13+
14+
15+
def flush-artifacts [
16+
build_dir: string, dirty: bool
17+
] {
18+
if ($build_dir | path exists) {
19+
if $dirty == false {
20+
print $"(ansi yellow)Removing artifacts(ansi reset) ($build_dir)"
21+
rm -r $build_dir
22+
}
23+
}
24+
}
25+
26+
27+
# Build the docs.
28+
#
29+
# Note, there is no check against what
30+
# version of doxygen is used.
31+
def "nur docs" [
32+
--dirty (-d) # Do not flush previous build artifacts
33+
--open (-o) # Open the built docs in your default browser
34+
] {
35+
let build_dir = "docs/html"
36+
flush-artifacts $build_dir $dirty
37+
cd docs
38+
run-cmd doxygen
39+
if $open {
40+
let root_pg = $nur.project-path | path join $"($build_dir)/index.html"
41+
start $root_pg
42+
}
43+
}
44+
45+
46+
def changed-files [] {
47+
let status = git status --short | lines
48+
if ($status | length) == 0 {
49+
print $"(ansi red)No file changes detected via (ansi cyan)`git status`(ansi reset)"
50+
print $"Perhaps you want to format all files? (ansi cyan)`nur fmt -a`"
51+
return []
52+
}
53+
let changed = (
54+
$status
55+
| each {$in | str trim | split column --regex '\s+' -n 2}
56+
| flatten
57+
| rename "state" "name"
58+
)
59+
# print $changed
60+
let result = (
61+
$changed
62+
| where {$in.state | split chars | each {$in in ['A' 'M' 'R']} | any {$in}}
63+
| get "name"
64+
| each {
65+
if ($in | str contains " -> ") {
66+
$in | parse "{a} -> {b}" | get "b" | $in.0
67+
} else { $in }
68+
}
69+
)
70+
# print $result
71+
$result
72+
}
73+
74+
75+
def get-clang-format-version [bin_name: string] {
76+
if (which $bin_name | is-empty) {
77+
null
78+
} else {
79+
let version = (
80+
^$bin_name --version
81+
| split column ' '
82+
| values
83+
| flatten
84+
| last
85+
)
86+
print $"($bin_name) --version: ($version)"
87+
$version | parse "{major}.{minor}.{patch}"
88+
}
89+
}
90+
91+
92+
def match-version [
93+
bin_name: string,
94+
expected: string = "14",
95+
--throw
96+
] {
97+
let version = get-clang-format-version $bin_name
98+
if ($version | is-empty) {
99+
if $throw {
100+
error make {
101+
msg: $"($bin_name) not found. Ensure it is installed and added to your PATH."
102+
}
103+
}
104+
false
105+
} else {
106+
if ($version.major.0 == $expected) {
107+
true
108+
} else if $throw {
109+
error make {
110+
msg: $"Failed to find clang-format v($expected).x"
111+
}
112+
} else {
113+
false
114+
}
115+
}
116+
}
117+
118+
119+
# Run clang-format on C++ files.
120+
#
121+
# By default, only changed C++ sources are formatted (uses `git status`).
122+
# The clang-format version is expected to be v14.
123+
# If v14 is not found, then an error is thrown.
124+
def "nur fmt" [
125+
--all (-a) # Format all C++ sources
126+
] {
127+
let all_files = glob "**/*.{h,cpp,c,ino}" --exclude [
128+
"**/build/**"
129+
"utility/**"
130+
"clock-arch.*"
131+
"Dns.*"
132+
] | path relative-to $nur.project-path
133+
let files = if $all {
134+
$all_files
135+
} else {
136+
let changes = changed-files
137+
(
138+
$all_files
139+
| where {
140+
($in | path split) in (
141+
$changes | each {$in | path split}
142+
)
143+
}
144+
)
145+
}
146+
147+
let bin_name = if (is-windows) {
148+
let bin_name = "clang-format"
149+
let is_expected = match-version $bin_name --throw
150+
"clang-format"
151+
} else {
152+
let bin_name = "clang-format-14"
153+
let is_expected = match-version $bin_name
154+
if ($is_expected == false) {
155+
let bin_name = "clang-format"
156+
let is_expected = match-version $bin_name --throw
157+
$bin_name
158+
} else {
159+
$bin_name
160+
}
161+
}
162+
163+
if ($files | length) > 0 {
164+
print $files
165+
let elapsed = timeit {|| $files | par-each {|f| ^$bin_name "-i" "--style" "file" $f}}
166+
print $"clang-format took ($elapsed) using parallelism!"
167+
}
168+
print $"(ansi blue)Applied clang-format to ($files | length) files(ansi reset)"
169+
}

0 commit comments

Comments
 (0)