Skip to content
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
3 changes: 3 additions & 0 deletions bits_helpers/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ def doParseArgs():
help=("Command-line arguments to pass to 'docker run'. "
"Passed through verbatim -- separate multiple arguments "
"with spaces, and make sure quoting is correct! Implies --docker."))
build_docker.add_argument("--container-use-workdir", dest="containerUseWorkDir", action="store_true", default=False,
help="Use the host work directory inside container. "
"By default it uses /container/bits/sw directory inside container.")
build_docker.add_argument("-v", dest="volumes", action="append", default=[],
help=("Additional volume to be mounted inside the Docker container, if one is used. "
"May be specified multiple times. Passed verbatim to 'docker run'."))
Expand Down
28 changes: 18 additions & 10 deletions bits_helpers/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,10 +732,10 @@ def doBuild(args, parser):

install_wrapper_script("git", workDir)

extra_env = {"BITS_CONFIG_DIR": "/alidist" if args.docker else os.path.abspath(args.configDir)}
extra_env = {"BITS_CONFIG_DIR": "/pkgdist" if args.docker else os.path.abspath(args.configDir)}
extra_env.update(dict([e.partition('=')[::2] for e in args.environment]))

with DockerRunner(args.dockerImage, args.docker_extra_args, extra_env=extra_env, extra_volumes=[f"{os.path.abspath(args.configDir)}:/alidist:ro"] if args.docker else []) as getstatusoutput_docker:
with DockerRunner(args.dockerImage, args.docker_extra_args, extra_env=extra_env, extra_volumes=[f"{os.path.abspath(args.configDir)}:/pkgdist:ro"] if args.docker else []) as getstatusoutput_docker:
def performPreferCheckWithTempDir(pkg, cmd):
with tempfile.TemporaryDirectory(prefix=f"bits_prefer_check_{pkg['package']}_") as temp_dir:
return getstatusoutput_docker(cmd, cwd=temp_dir)
Expand Down Expand Up @@ -1299,23 +1299,26 @@ def performPreferCheckWithTempDir(pkg, cmd):
cmd_raw = fp.read()
fp.close()

container_workDir = ""
cachedTarball = spec["cachedTarball"]
if args.docker:
cachedTarball = re.sub("^" + workDir, "/sw", spec["cachedTarball"])
else:
cachedTarball = spec["cachedTarball"]
container_workDir = "/container/bits/sw" if not args.containerUseWorkDir else workDir
if not args.containerUseWorkDir:
cachedTarball = re.sub("^" + workDir, container_workDir, cachedTarball)

if not cachedTarball:
checkout_sources(spec, workDir, args.referenceSources, args.docker)

scriptDir = join(workDir, "SPECS", args.architecture, spec["package"],
spec["version"] + "-" + spec["revision"])

init_workDir = container_workDir if args.docker else args.workDir
makedirs(scriptDir, exist_ok=True)
writeAll("{}/{}.sh".format(scriptDir, spec["package"]), spec["recipe"])
writeAll("%s/build.sh" % scriptDir, cmd_raw % {
"provenance": create_provenance_info(spec["package"], specs, args),
"initdotsh_deps": generate_initdotsh(p, specs, args.architecture, workDir=args.workDir, post_build=False),
"initdotsh_full": generate_initdotsh(p, specs, args.architecture, workDir=args.workDir, post_build=True),
"initdotsh_deps": generate_initdotsh(p, specs, args.architecture, workDir=init_workDir, post_build=False),
"initdotsh_full": generate_initdotsh(p, specs, args.architecture, workDir=init_workDir, post_build=True),
"develPrefix": develPrefix,
"workDir": workDir,
"configDir": abspath(args.configDir),
Expand All @@ -1327,6 +1330,7 @@ def performPreferCheckWithTempDir(pkg, cmd):

# Define the environment so that it can be passed up to the
# actual build script
bits_dir = dirname(dirname(realpath(__file__)))
buildEnvironment = [
("ARCHITECTURE", args.architecture),
("BUILD_REQUIRES", " ".join(spec["build_requires"])),
Expand All @@ -1353,7 +1357,7 @@ def performPreferCheckWithTempDir(pkg, cmd):
("FULL_BUILD_REQUIRES", " ".join(spec["full_build_requires"])),
("FULL_REQUIRES", " ".join(spec["full_requires"])),
("BITS_PREFER_SYSTEM_KEY", spec.get("key", "")),
("BITS_SCRIPT_DIR", dirname(realpath(__file__))),
("BITS_SCRIPT_DIR", "/bits" if args.docker else bits_dir),
]
if "sources" in spec:
for idx, src in enumerate(spec["sources"]):
Expand All @@ -1378,12 +1382,16 @@ def performPreferCheckWithTempDir(pkg, cmd):
if args.docker:
build_command = (
"docker run --rm --entrypoint= --user $(id -u):$(id -g) "
"-v {workdir}:/sw -v{configDir}:/alidist:ro -v {scriptDir}/build.sh:/build.sh:ro "
"-v {workdir}:{container_workDir} -v{configDir}:/pkgdist:ro "
"-v {scriptDir}/build.sh:/build.sh:ro "
"-v {bits_dir}:/bits "
"{mirrorVolume} {develVolumes} {additionalEnv} {additionalVolumes} "
"-e WORK_DIR_OVERRIDE=/sw -e BITS_CONFIG_DIR_OVERRIDE=/alidist {extraArgs} {image} bash -ex /build.sh"
"-e WORK_DIR_OVERRIDE={container_workDir} -e BITS_CONFIG_DIR_OVERRIDE=/pkgdist {extraArgs} {image} bash -ex /build.sh"
).format(
image=quote(args.dockerImage),
workdir=quote(abspath(args.workDir)),
container_workDir=container_workDir,
bits_dir=bits_dir,
configDir=quote(abspath(args.configDir)),
scriptDir=quote(scriptDir),
extraArgs=" ".join(map(quote, args.docker_extra_args)),
Expand Down
2 changes: 1 addition & 1 deletion bits_helpers/build_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ PH=${PKGHASH}
PKG_DIR="$WORK_DIR"
EoF

cp "${BITS_SCRIPT_DIR}/relocate-me.sh" "$INSTALLROOT/"
install "${BITS_SCRIPT_DIR}/bits_helpers/relocate-me.sh" "$INSTALLROOT/"

# Always relocate the modulefile (if present) so that it works also in devel mode.
if [[ ! -s "$INSTALLROOT/etc/profile.d/.bits-relocate" && -f "$INSTALLROOT/etc/modulefiles/$PKGNAME" ]]; then
Expand Down
6 changes: 4 additions & 2 deletions bits_helpers/relocate-me.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ source ${THISDIR}/etc/profile.d/.bits-pkginfo
INSTALL_BASE=$(echo $THISDIR | sed "s|/$PP$||")
if [[ -s ${THISDIR}/etc/profile.d/.bits-relocate ]] ; then
for f in $(cat ${THISDIR}/etc/profile.d/.bits-relocate) ; do
sed -i -e "s|${PKG_DIR}/INSTALLROOT/$PH|$INSTALL_BASE|g;s|${PKG_DIR}|$INSTALL_BASE|g" "${THISDIR}/$f"
sed -i.unrelocated -e "s|${PKG_DIR}/INSTALLROOT/$PH|$INSTALL_BASE|g;s|${PKG_DIR}|$INSTALL_BASE|g" "${THISDIR}/$f"
rm -f "${THISDIR}/${f}.unrelocated"
done
fi
sed -i -e "s|^PKG_DIR=.*|PKG_DIR="${INSTALL_BASE}"|" $THISDIR/etc/profile.d/.bits-pkginfo
sed -i.unrelocated -e "s|^PKG_DIR=.*|PKG_DIR="${INSTALL_BASE}"|" "$THISDIR/etc/profile.d/.bits-pkginfo"
rm -f "$THISDIR/etc/profile.d/.bits-pkginfo.unrelocated"

1 change: 1 addition & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ def test_coverDoBuild(self, mock_debug, mock_listdir, mock_warning, mock_git_git
docker=False,
dockerImage=None,
docker_extra_args=["--network=host"],
containerWorkDir=False,
architecture=TEST_ARCHITECTURE,
workDir="/sw",
pkgname=["root"],
Expand Down