11# shellcheck shell=bash
2-
32init () {
43 if [ -f ~ /.dotfiles/os-unix/data/setup-private.sh ]; then
54 source ~ /.dotfiles/os-unix/data/setup-private.sh
@@ -9,6 +8,10 @@ init() {
98task.init () {
109 git config set --local filter.npmrc.clean ' ./scripts/npmrc-clean.sh'
1110 git config set --local filter.oscrc.clean ' ./scripts/oscrc-clean.sh'
11+ git config set --local filter.homedir.clean ' ./scripts/homedir-clean.sh'
12+ git config set --local filter.npmrc.required true
13+ git config set --local filter.oscrc.required true
14+ git config set --local filter.homedir.required true
1215 cat > .clangd << EOF
1316# DO NOT MODIFY! This file is auto-autogenerated from Bakefile.sh.
1417CompileFlags:
3134task.build () {
3235 ./os-unix/scripts/lint-scripts.py --internal-test-regex
3336
37+ err=0
38+ while read -r file; do
39+ if grep -q ' _setup ' " $file " && grep -q ' ^main()' " $file " ; then
40+ printf ' Should not call _setup but define main(): %s\n' " $file "
41+ err=1
42+ fi
43+
44+ if grep -q ' _setup ' " $file " && ! grep -q ' ^installed' " $file " ; then
45+ printf ' If calls _setup, must define installed(): %s\n' " $file "
46+ err=1
47+ fi
48+ done < <( find . \( -name ' *.sh' -not -name ' Bakefile.sh' \) -type f)
49+
50+ # Should have proper ordering of functions.
51+ node --input-type=module << 'EOF '
52+ import { readFileSync } from 'fs'
53+ import { glob } from 'fs/promises'
54+
55+ const EXPECTED_ORDER = [
56+ 'install.any',
57+ 'install.debian',
58+ 'install.ubuntu',
59+ 'install.fedora',
60+ 'install.opensuse',
61+ 'install.arch',
62+ 'installed',
63+ 'configure',
64+ 'caveats',
65+ ]
66+
67+ let err = 0
68+
69+ for await (const file of glob('**/*.sh', { exclude: (p) => p === '.data' || p === 'vendor' })) {
70+ const lines = readFileSync(file, 'utf8').split('\n')
71+
72+ if (!lines.some(l => l.includes('_setup '))) continue
73+
74+ const order = []
75+ for (const line of lines) {
76+ for (const name of EXPECTED_ORDER) {
77+ if (line.startsWith(name + '(')) order.push(name)
78+ }
79+ }
80+
81+ for (let i = 0; i < order.length; i++) {
82+ for (let j = i + 1; j < order.length; j++) {
83+ const pi = EXPECTED_ORDER.indexOf(order[i])
84+ const pj = EXPECTED_ORDER.indexOf(order[j])
85+ if (pi > pj) {
86+ console.log(`Bad ordering in ${file}: ${order[j]}() must be before ${order[i]}()`)
87+ err = 1
88+ }
89+ }
90+ }
91+ }
92+ process.exit(err)
93+ EOF
94+
3495 # grep '-P' not compatible with with multiple arguments using '-e'.
3596 for pattern in " ${_private_forbidden_patterns[@]} " ; do
36- if grep -IPr --exclude setup-private.* --exclude .clangd --exclude-dir node_modules --exclude-dir .data --exclude-dir vendor --color=always " $pattern " ./ | grep -Ev ' (#|//|") lint-ignore' ; then
37- bake.die " Expected to find no matches for '$pattern '"
97+ if grep -IPr --exclude setup-private.* --exclude .clangd --exclude-dir node_modules --exclude-dir .data --exclude-dir vendor --exclude-dir target --exclude-dir .jekyll-cache --color=always " $pattern " ./ | grep -Ev ' (#|//|") lint-ignore' ; then
98+ printf ' Expected to find no matches for: %s\n' " $pattern "
99+ err=1
38100 fi
39101 done
40102
41103 cd " ./os-unix/config-linux-rice/.config/X11/resources" || exit
42104 printf ' %s\n' " ! GENERATED BY 'bake build'" > uxterm.Xresources
43105 sed ' s/XTerm/UXTerm/g' xterm.Xresources >> uxterm.Xresources
106+
107+ return $err
44108}
45109
46110task.lint () {
0 commit comments