Skip to content

Commit

Permalink
Merge pull request #66 from terhorstd/add_buildrc_var
Browse files Browse the repository at this point in the history
Add BUILDER_CONFIG environment variable
  • Loading branch information
terhorstd authored Sep 6, 2023
2 parents f69b76a + c953f9c commit 74dc68f
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 32 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ Optional Dependencies:

You can install any software with Builder if a plan file is available. The
default location where Builder looks for plan files is configured as
`PLANFILE_PATH` in `~/.buildrc`. You will find many files in the scheme
`<package>/<version>/<variant>`, where the `<variant>` uses `default` as its
default value.
`PLANFILE_PATH` in the [configuration](doc/Configuration.md). You will find
many files in the scheme `<package>/<version>/<variant>`, where the `<variant>`
uses `default` as its default value.

To install a package replace `<package>` and `<version>` with an available
build plan:
Expand Down
27 changes: 15 additions & 12 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ set -euo pipefail
if [ -z "${BUILDER_PATH+x}" ]; then
BUILDER_PATH="$(dirname "$(realpath "$0")")"
fi
# Use ~/.buildrc as default config, unless specified explicitly in an
# environment variable.
BUILDER_CONFIG="${BUILDER_CONFIG:-${HOME}/.buildrc}"


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Expand Down Expand Up @@ -49,7 +52,7 @@ Usage: build -h|--help
Options:
-h or --help this text is printed
configure installs ~/.buildrc and exits
configure installs ~/.buildrc or the file pointed to by BUILDER_CONFIG and exits
--dry-run skip build
-s or --silent skip build if installation folder exists
-f or --force rebuild even if installation folder exists, delete source folder if it exits
Expand Down Expand Up @@ -104,18 +107,18 @@ esac
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Setup Builder configuration

if [ "${PACKAGE}" == "configure" -a -e "${HOME}/.buildrc" ]; then
if [ "${PACKAGE}" == "configure" -a -e "${BUILDER_CONFIG}" ]; then
cat <<ENDNOTICE
!!!
!!! ~/.buildrc already exists.
!!! ${BUILDER_CONFIG} already exists.
!!!
!!! Edit manually or delete it to install a new default configuration.
!!!
ENDNOTICE
fi
if [ ! -e "${HOME}/.buildrc" ]; then
echo ">>> installing default configuration '${HOME}/.buildrc'..."
cat >"${HOME}/.buildrc" <<ENDRC
if [ ! -e "${BUILDER_CONFIG}" ]; then
echo ">>> installing default configuration '${BUILDER_CONFIG}'..."
cat >"${BUILDER_CONFIG}" <<ENDRC
#
# This is the configuration file for Builder
# (auto-generated on $(date))
Expand Down Expand Up @@ -154,15 +157,15 @@ LOG_PATH="\\\${BUILD}/logs"
# define the number of cores to use in standard build_package()
#MAKE_THREADS=\$(( \$(nproc) / 4 ))
ENDRC
cat "${HOME}/.buildrc"
cat "${BUILDER_CONFIG}"
cat <<ENDNOTE
!!!
!!! You probably want to modify at least the \$TARGET_PATH in your
!!! configuration in '~/.buildrc'.
!!! configuration in '${BUILDER_CONFIG}'.
!!!
ENDNOTE
echo -e "\n>>> default configuration has been written to"
echo -e " ${HOME}/.buildrc\n"
echo -e " ${BUILDER_CONFIG}\n"
if [ "$PACKAGE" != "configure" ]; then
echo "!!! Please check that the guessed paths are correct and"
echo "!!! rerun the build command."
Expand All @@ -172,10 +175,10 @@ ENDNOTE
fi

# load configuration
if [ -r "${HOME}/.buildrc" ]; then
. "${HOME}/.buildrc"
if [ -r "${BUILDER_CONFIG}" ]; then
. "${BUILDER_CONFIG}"
else
echo "ERROR: Could not read ~/.buildrc"
echo "ERROR: Could not read ${BUILDER_CONFIG}"
exit 1
fi

Expand Down
25 changes: 13 additions & 12 deletions doc/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

Builder is designed to require only very minimal configuration. Upon its
first build or when explicitly called with `build configure` a file
`.buildrc` is created if it does not exist yet. This file contains variables
that define various locations used in the build and install process. When
the file is generated automatically Builder pre-fills some guessed defaults
that point to your home directory. While this quickly gets you started,
installing a lot of software into your `$HOME` is usually not a good idea and
you should set `$TARGET_PATH` to a better location.
`~/.buildrc` is created if it does not exist yet. This file contains
variables that define various locations used in the build and install
process. When the file is generated automatically Builder pre-fills some
guessed defaults that point to your home directory. While this quickly gets
you started, installing a lot of software into your `$HOME` is usually not a
good idea and you should set `$TARGET_PATH` to a better location.

The builder configuration defines variables of the build system itself.
Mostly paths where Builder can put its work-space and where to put the
Expand All @@ -22,12 +22,13 @@

## `.buildrc` variables

Builder configuriation is automatically loaded from `$HOME/.buildrc`. If this
file does not exist, it will be created and the build will abort for you to
check the settings. The variables expected to be available after sourcing
`.buildrc` are described in the following table. The variables marked
"optional", if undefined, will be filled with appropriate default values by
builder for each build.
Builder configuriation is automatically loaded from `$HOME/.buildrc` (or the
file pointed to by the `$BUILDER_CONFIG` variable). If this file does not
exist, it will be created and the build will abort for you to check the
settings. The variables expected to be available after sourcing `.buildrc`
are described in the following table. The variables marked "optional", if
undefined, will be filled with appropriate default values by builder for each
build.

Note that the expressions need not be constants, but are evaluated according
to normal bash expansion rules (see man bash(1)). By this, you can
Expand Down
25 changes: 21 additions & 4 deletions doc/Install.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ We can however call Builder directly and start building env modules
./build.sh environment-modules

This will build environment-modules as a normal package into your set install
path (see `~/.buildrc`). Alternative implementations like 'lmod' may be built
in a similar manner. Since many things depend on your choice here, you may want
to look into the install instructions and probably manually change things here
and there.
path (see [configuration](Configuration.md)). Alternative implementations like
'lmod' may be built in a similar manner. Since many things depend on your
choice here, you may want to look into the install instructions and probably
manually change things here and there.

less ~/install/environment-modules/4.7.1/default/share/doc/INSTALL.txt

Expand All @@ -71,3 +71,20 @@ still available.

After this you can install or load Builder and go on extending your deployment.


### Multi-configuration Environments

When using Builder in a multi-user or CI setup it is inconvenient to have the
`.buildrc` loaded from the user-account home directory. To circumvent this the
variable `$BUILDER_CONFIG` can be defined to override the default path. For
example, suppose you keep your configuration in a repository
`repo/builder.conf`. You can use any Builder installation available and point
it to your current setup:

```bash
#cd repo # wherever this is
export BUILDER_CONFIG="${PWD}/builder.conf"
```

With this, `build` can be called from any location and will find the right
config file.
1 change: 1 addition & 0 deletions plans/nest-simulator/3.1/default
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ SHA256SUM=5c11dd6b451c4c6bf93037bf29d5231c6c75a0e1a8863344f6fb9bb225f279ca

CMAKEFLAGS+=" -Dwith-boost=ON -Dwith-python=ON -Dwith-mpi=ON -Dwith-detailed-timers=ON -Dwith-ltdl=OFF"

# shellcheck source=plans/nest-simulator/common
source "$(dirname "${PLAN}")/../common"
2 changes: 1 addition & 1 deletion plans/nest-simulator/common
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module_install () {
log_status ">>> installing module file to ${module_path}"
mkdir -pv "$(dirname "${module_path}")"
module="$(cat "${PLAN}.module")"
if version_gt $BASH_VERSION 4.4; then
if version_gt "${BASH_VERSION}" "4.4"; then
echo -e "${module@P}" >"${module_path}"
else
# this is a bad substitute for the power of the bash>4.4 notation.
Expand Down
1 change: 1 addition & 0 deletions plans/nest-simulator/master/default
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ URL="https://github.com/nest/nest-simulator/archive/${VERSION}.tar.gz"

CMAKEFLAGS+=" -Dwith-boost=ON -Dwith-python=ON -Dwith-mpi=ON -Dwith-detailed-timers=ON -Dwith-ltdl=OFF"

# shellcheck source=plans/nest-simulator/common
source "$(dirname "${PLAN}")/../common"

0 comments on commit 74dc68f

Please sign in to comment.