Skip to content

Commit

Permalink
Node build stuff (#31)
Browse files Browse the repository at this point in the history
This PR gets `bashy-node` to use `opt-multi` instead of the ad-hoc thing
it was doing before.
  • Loading branch information
danfuzz authored Nov 7, 2023
2 parents 5b8333e + 34345f5 commit 5aaef1f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 43 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ versioning principles. Unstable releases do not.

### [Unreleased]

This is a stable-ish release. No further breaking changes are currently
contemplated for the 2.* release series.

Breaking changes:
* None.
* `bashy-node`: Reworked build options to use the newly-standardized multi-value
forms. Only _nominally_ breaking in that use of `bashy-node` at all is
pretty minimal.

Other notable changes:
* `bashy-basics`: New utility functions `env-clean`, `env-minimize`, and
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

0 comments on commit 5aaef1f

Please sign in to comment.