diff --git a/tools/mason/MasonTest.chpl b/tools/mason/MasonTest.chpl index 131566ca1849..4847ea51408b 100644 --- a/tools/mason/MasonTest.chpl +++ b/tools/mason/MasonTest.chpl @@ -20,7 +20,6 @@ use ArgumentParser; -use ChplConfig; use FileSystem; use List; use Map; @@ -422,14 +421,16 @@ proc getTestPath(fullPath: string, testPath = "") : string { proc getRuntimeComm() throws { var line: string; var python: string; - var findPython = spawn([CHPL_HOME:string+"/util/config/find-python.sh"], - stdout = pipeStyle.pipe); + var findPython = spawn( + [MasonUtils.CHPL_HOME:string+"/util/config/find-python.sh"], + stdout = pipeStyle.pipe); while findPython.stdout.readLine(line) { python = line.strip(); } - var checkComm = spawn([python, CHPL_HOME:string+"/util/chplenv/chpl_comm.py"], - stdout = pipeStyle.pipe); + var checkComm = spawn( + [python, MasonUtils.CHPL_HOME:string+"/util/chplenv/chpl_comm.py"], + stdout = pipeStyle.pipe); while checkComm.stdout.readLine(line) { comm = line.strip(); } diff --git a/tools/mason/MasonUtils.chpl b/tools/mason/MasonUtils.chpl index 62e69e99af12..5485139206c5 100644 --- a/tools/mason/MasonUtils.chpl +++ b/tools/mason/MasonUtils.chpl @@ -22,6 +22,7 @@ /* A helper file of utilities for Mason */ private use CTypes; +private use ChplConfig; public use FileSystem; private use List; private use Map; @@ -170,6 +171,41 @@ proc SPACK_ROOT : string { return spackRoot; } + +/* + Returns the current CHPL_HOME. Tries the following in order: + 1. The CHPL_HOME environment variable + 2. Using the `chpl` in PATH to print CHPL_HOME + 3. The CHPL_HOME of the chpl that built this mason (`ChplConfig.CHPL_HOME`) +*/ +proc CHPL_HOME : string { + + proc CHPL_HOME_inner() : string { + proc getChplHomeFromChpl(): string { + var chplHome = ""; + try { + var process = spawn(["chpl", "--print-chpl-home"], + stdout=pipeStyle.pipe); + for line in process.stdout.lines() { + chplHome = line.strip(); + } + } catch { + chplHome = ""; + } + return chplHome; + } + + const env = getEnv("CHPL_HOME"); + const chplHome = if !env.isEmpty() then env else getChplHomeFromChpl(); + return if !chplHome.isEmpty() then chplHome else ChplConfig.CHPL_HOME; + } + + @functionStatic + ref chplHome = CHPL_HOME_inner(); + return chplHome; +} + + /* This fetches the mason-installed spack registry only. Users that define SPACK_ROOT to their own spack installation will use diff --git a/util/packaging/apt/test/Dockerfile.template b/util/packaging/apt/test/Dockerfile.template index def08d7b0f6a..21f81d207df1 100644 --- a/util/packaging/apt/test/Dockerfile.template +++ b/util/packaging/apt/test/Dockerfile.template @@ -22,4 +22,5 @@ WORKDIR /home/user/MyPackage RUN chplcheck src/*.chpl RUN mason build RUN mason run -- -nl 1 +RUN mkdir test && touch test/test.chpl mason test WORKDIR /home/user diff --git a/util/packaging/rpm/test/Dockerfile.template b/util/packaging/rpm/test/Dockerfile.template index 6661c5dbea43..4c811eb75fcd 100644 --- a/util/packaging/rpm/test/Dockerfile.template +++ b/util/packaging/rpm/test/Dockerfile.template @@ -20,4 +20,5 @@ WORKDIR /home/user/MyPackage RUN chplcheck src/*.chpl RUN mason build RUN mason run -- -nl 1 +RUN mkdir test && touch test/test.chpl mason test WORKDIR /home/user