diff --git a/bits_helpers/args.py b/bits_helpers/args.py index e5ca80b..628d319 100644 --- a/bits_helpers/args.py +++ b/bits_helpers/args.py @@ -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'.")) diff --git a/bits_helpers/build.py b/bits_helpers/build.py index b4bd70b..c635983 100644 --- a/bits_helpers/build.py +++ b/bits_helpers/build.py @@ -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) @@ -1299,10 +1299,12 @@ 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) @@ -1310,12 +1312,13 @@ def performPreferCheckWithTempDir(pkg, cmd): 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), @@ -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"])), @@ -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"]): @@ -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)), diff --git a/bits_helpers/build_template.sh b/bits_helpers/build_template.sh index a9e7a4c..9757acc 100644 --- a/bits_helpers/build_template.sh +++ b/bits_helpers/build_template.sh @@ -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 diff --git a/bits_helpers/relocate-me.sh b/bits_helpers/relocate-me.sh index fbb0e3d..6fb9988 100644 --- a/bits_helpers/relocate-me.sh +++ b/bits_helpers/relocate-me.sh @@ -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" diff --git a/tests/test_build.py b/tests/test_build.py index 842bd50..7bdbe06 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -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"],