Skip to content
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

Build stuff #198

Merged
merged 5 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ Changelog
**Note:** Version numbers for _stable_ (so marked) releases follow semantic
versioning principles. Unstable releases do not.

### [Unreleased]

Breaking changes:
* None.

Other notable changes:
* Pulled in improved `bashy-lib`, and adjusted accordingly.

### v0.5.18 -- 2023-11-02

Breaking changes:
Expand Down
34 changes: 34 additions & 0 deletions scripts/lib/bashy-basics/_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,40 @@ function check-json-output-args {
fi
}

# Removes from the environment all the variables except for the ones listed.
# Note that it is probably best to only run this in a subshell, e.g. just before
# running code that can't be fully trusted with a fuller set of environment
# variables.
function env-clean {
local allowList=" $* " # Minor cleverness for easier regex matching below.

local allNames
allNames=($(env-names)) || return "$?"

local n
for n in "${allNames[@]}"; do
if [[ ! (${allowList} =~ " ${n} ") ]]; then
export -n "${n}"
fi
done
}

# Runs `env-clean` passing it a reasonably "minimal" set of environment
# variables to keep.
function env-minimize {
env-clean HOME HOSTNAME LANG LOGNAME PATH PWD SHELL SHLVL TERM TMPDIR USER
}

# Prints a list of the names of all defined environment variables.
function env-names {
# It turns out that the most straightforward way to get a list of
# currently-defined environment variables is arguably to use `awk`. Notably,
# the output of `declare -x` can't be trivially parsed in the case where an
# environment variable contains a newline (perhaps followed by a line that
# mimics the output of `declare -x`).
awk 'BEGIN { for (x in ENVIRON) print x; }'
}

# Interprets standardized (for this project) JSON "post-processing" arguments.
# This processes `stdin`. The arguments must start with `::`. After that are
# options and arguments just as with `jval`, except `--input` is not accepted.
Expand Down
29 changes: 14 additions & 15 deletions scripts/lib/bashy-node/node-project/build-main-module
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ define-usage --with-help $'
--allow-platform-specific-files
If specified, the build does *not* check to see if any platform-specific
files ended up in the built output.
--modules-dir=<dir>
Path to a directory containing all module sources to be used.
--modules-dirs=<json>
JSON array of one or more paths to directories containing module sources.
If the same-named module exists in more than one modules directory, the
first one listed "wins."
--modules-dirs=<dir>
--modules-dirs[]=<dir> ...
Paths to one or more module source directories, collectively containing
all module sources to be used. If there are same-named modules under more
than one of the given paths, the first-listed path\'s one "wins."
--out=<dir>
Directory where built output goes. Defaults to `out` directly under the
main product directory.
Expand All @@ -46,11 +45,8 @@ define-usage --with-help $'
# Allow the build to be platform-specific?
opt-toggle --var=platformSpecific allow-platform-specific-files

# Directory or directories containing all the modules.
modulesOpt=''
opt-value --call='{ modulesOpt="--modules-dir=$1" }' --filter='/./' modules-dir
opt-value --call='{ modulesOpt="--modules-dirs=$1" }' --filter='/^\[.*\]$/' modules-dirs
require-exactly-one-arg-of modules-dir modules-dirs
# Paths to all module directories.
opt-multi --required --var=modulesDirs --filter='/./' modules-dirs

# Built output directory.
opt-value --var=outDir out
Expand All @@ -71,8 +67,9 @@ process-args "$@" || exit "$?"
# The main actions of this script.
function build-project {
local projectName="$1"
local modulesOpt="$2"
local destDir="$3"
local destDir="$2"
shift 2
local modulesDirs=("$@")

local destLibDir="${destDir}/lib"
local mainModule="main-${projectName}"
Expand All @@ -91,7 +88,9 @@ function build-project {

local deps
deps="$(
lib . find-module-dependencies "${modulesOpt}" "${mainModule}"
lib . find-module-dependencies \
--modules-dirs[]="$(vals "${modulesDirs[@]}")" \
"${mainModule}"
)" \
|| return "$?"

Expand Down Expand Up @@ -372,7 +371,7 @@ if [[ ! -d ${outProjectDir} ]]; then
|| exit "$?"
fi

build-project "${projectName}" "${modulesOpt}" "${outProjectDir}" \
build-project "${projectName}" "${outProjectDir}" "${modulesDirs[@]}" \
|| exit "$?"

if (( !platformSpecific )); then
Expand Down
37 changes: 10 additions & 27 deletions scripts/lib/bashy-node/node-project/find-module-dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
define-usage --with-help $'
${name} [<opt> ...] [--] <module-name>

Transitively finds all module dependencies from the one given, which must
be the name of a module defined under the indicated modules directory.
Prints out a JSON object with bindings as follows:
Transitively finds all module dependencies from the given <module-name>,
which must be the name of a module defined under one of the indicated
modules directories. Prints out a JSON object with bindings as follows:

* `main: string` -- The originally requested module.
* `localDeps: [name, ...]` -- Local module dependencies.
Expand All @@ -30,20 +30,15 @@ define-usage --with-help $'
This tool is opinionated: The modules directories are taken to define
submodules (in the Node sense) under the top-level name `@this`.

**Note:** Exactly one of the two `--modules-*` options must be specified.

--modules-dir=<dir>
Path to a directory containing all module sources to be used.
--modules-dirs=<json>
JSON array of one or more paths to directories containing module sources.
If the same-named module exists in more than one modules directory, the
first one listed "wins."
--modules-dirs=<dir>
--modules-dirs[]=<dir> ...
Paths to one or more module source directories, collectively containing
all module sources to be used. If there are same-named modules under more
than one of the given paths, the first-listed path\'s one "wins."
'

# Directory or directories containing all the modules.
opt-value --var=modulesDir --filter='/./' modules-dir
opt-value --var=modulesDirsJson --filter='/^\[.*\]$/' modules-dirs
require-exactly-one-arg-of modules-dir modules-dirs
# Paths to all module directories.
opt-multi --required --var=modulesDirs --filter='/./' modules-dirs

# The module to start at.
positional-arg --required --var=moduleName module-name
Expand All @@ -55,18 +50,6 @@ process-args "$@" || exit "$?"
# Main script
#

modulesDirs=()
if [[ ${modulesDir} != '' ]]; then
if [[ ! (-d ${modulesDir} && -r ${modulesDir}) ]]; then
error-msg "Not a readable directory: ${modulesDir}"
exit 1
fi
modulesDirs=("${modulesDir}")
else
jset-array --raw modulesDirs "${modulesDirsJson}" \
|| exit "$?"
fi

# Collect all of the modules referenced by this package, transitively including
# all referenced local modules. The result is two lists, one of local modules
# and one of regular (published via npm) dependencies. This uses a work queue
Expand Down
9 changes: 6 additions & 3 deletions scripts/lib/lactoserv/build
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ srcDir="$(base-dir)/src"
etcDir="$(base-dir)/etc"
outDir="$(set-up-out-dir)"

lib node-project build-main-module \
--out="${outDir}" --modules-dir="${srcDir}" lactoserv \
|| exit "$?"
(
true \
&& env-minimize \
&& lib node-project build-main-module \
--out="${outDir}" --modules-dirs="${srcDir}" lactoserv \
) || exit "$?"

if (( doDistro )); then
progress-msg
Expand Down
2 changes: 1 addition & 1 deletion scripts/lib/lactoserv/lint
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function linter-path {
# Build the linter, if necessary.
if [[ ! -x ${toolPath} ]]; then
lib 1>&2 node-project build-main-module \
--out="${outDir}" --modules-dir="${srcDir}" "${toolModule}" \
--out="${outDir}" --modules-dirs="${srcDir}" "${toolModule}" \
|| return "$?"
fi

Expand Down
2 changes: 1 addition & 1 deletion scripts/lib/lactoserv/run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function tester-path {
if [[ ! -x ${toolPath} ]]; then
lib 1>&2 node-project build-main-module \
--allow-platform-specific-files \
--out="${outDir}" --modules-dir="${srcDir}" "${toolModule}" \
--out="${outDir}" --modules-dirs="${srcDir}" "${toolModule}" \
|| return "$?"
fi

Expand Down