Commit 5e877eb5 authored by Drew's avatar Drew

Add ATBUILD_BIN_PATH

This adds a new environment variable to point to the bin path.  This is useful for custom tool packagers.

We also unified the implementation of shell and custom tool environments in the new Shell.environment function.

There are some minor changes to the custom tool environment that come along with this change, such as running in the directory of the imported package.  To my knowledge, I'm the only one who will notice.
parent 6c8802e0
Pipeline #1900 passed with stage
......@@ -24,12 +24,8 @@ final class CustomTool: Tool {
}
cmd += "--\(key) \"\(evaluateSubstitutions(input: value, package: task.package))\" "
}
setenv("ATBUILD_USER_PATH", userPath().description, 1)
setenv("ATBUILD_PLATFORM", "\(Platform.targetPlatform)", 1)
if let version = task.package.version {
setenv("ATBUILD_PACKAGE_VERSION", version, 1)
Shell.environvironment(task: task) {
anarchySystem(cmd)
}
anarchySystem(cmd)
}
}
\ No newline at end of file
......@@ -27,31 +27,46 @@ import atpkg
* If the tool returns with an error code of non-zero, the tool will fail.
*/
final class Shell : Tool {
func run(task: Task, toolchain: String) {
///Sets the environment for the specified task.
static func environvironment(task: Task, block: () -> ()) {
setenv("ATBUILD_PLATFORM", "\(Platform.targetPlatform)", 1)
setenv("ATBUILD_USER_PATH", userPath().description, 1)
if let version = task.package.version {
setenv("ATBUILD_PACKAGE_VERSION", version, 1)
}
guard var script = task["script"]?.string else { fatalError("Invalid 'script' argument to shell tool.") }
script = evaluateSubstitutions(input: script, package: task.package)
do {
let oldPath = try FS.getWorkingDirectory()
defer {
do {
try FS.changeWorkingDirectory(path: oldPath)
} catch {
print("Can not revert to previous working directory '\(oldPath)': \(error)")
exit(42)
}
}
try FS.changeWorkingDirectory(path: task.importedPath)
//does bin path not exist?
//let's create it!
let binPath = try! FS.getWorkingDirectory().appending("bin")
if !FS.fileExists(path: binPath) {
try! FS.createDirectory(path: binPath)
}
setenv("ATBUILD_BIN_PATH",binPath.description,1)
anarchySystem("/bin/sh -c \"\(script)\"")
} catch {
print("Can not change working directory to '\(task.importedPath)': \(error)")
exit(42)
//deal with directory nonsense
let oldPath = try! FS.getWorkingDirectory()
defer {
do {
try FS.changeWorkingDirectory(path: oldPath)
} catch {
print("Can not revert to previous working directory '\(oldPath)': \(error)")
exit(42)
}
}
do {
try FS.changeWorkingDirectory(path: task.importedPath)
}
catch {
print("Cannot change working directory to \(task.importedPath)")
}
block()
}
func run(task: Task, toolchain: String) {
guard var script = task["script"]?.string else { fatalError("Invalid 'script' argument to shell tool.") }
script = evaluateSubstitutions(input: script, package: task.package)
Shell.environvironment(task: task) {
anarchySystem(script)
}
}
}
\ No newline at end of file
......@@ -25,6 +25,7 @@
:userpath "\${ATBUILD_USER_PATH}"
:platform "\${ATBUILD_PLATFORM}"
:version "\${ATBUILD_PACKAGE_VERSION}"
:bindir "\${ATBUILD_BIN_PATH}"
:dependencies ["a"]
}
}
......
......@@ -4,7 +4,7 @@
:tasks {
:second {
:tool "shell"
:script "echo SECOND >> $ATBUILD_USER_PATH/test"
:script "echo SECOND >> $ATBUILD_USER_PATH/test && echo SECOND >> $ATBUILD_BIN_PATH/test"
}
}
)
\ No newline at end of file
......@@ -5,11 +5,12 @@
:tasks {
:first {
:tool "shell"
:script "echo FIRST >> $ATBUILD_USER_PATH/test"
;; note that binpath is not recreated, therefore we use single > here to force a new file
:script "echo FIRST >> $ATBUILD_USER_PATH/test && echo FIRST > $ATBUILD_BIN_PATH/test"
}
:third {
:tool "shell"
:script "echo THIRD >> $ATBUILD_USER_PATH/test"
:script "echo THIRD >> $ATBUILD_USER_PATH/test && echo THIRD >> $ATBUILD_BIN_PATH/test"
:dependencies ["first" "b.second"]
}
:compiledep {
......
......@@ -196,9 +196,9 @@ echo "****************PLUGIN TEST**************"
cd $DIR/tests/fixtures/attool
$ATBUILD > /tmp/plugin.txt
if [ "$UNAME" == "Darwin" ]; then
SEARCHTEXT="\-key value --platform osx --test test_substitution --userpath .*tests/fixtures/attool/user --version 1.0"
SEARCHTEXT="\-bindir .*tests/fixtures/attool/bin --key value --platform osx --test test_substitution --userpath .*tests/fixtures/attool/user --version 1.0"
else
SEARCHTEXT="\-key value --platform linux --test test_substitution --userpath .*tests/fixtures/attool/user --version 1.0"
SEARCHTEXT="\-bindir .*tests/fixtures/attool/bin --key value --platform linux --test test_substitution --userpath .*tests/fixtures/attool/user --version 1.0"
fi
if ! grep "$SEARCHTEXT" /tmp/plugin.txt; then
......@@ -369,6 +369,11 @@ if [ "$RESULT" != "$RESULT2" ]; then
echo "Unusual user path concoction $RESULT $RESULT2"
exit 1
fi
RESULT=`cat bin/test`
if [ "$RESULT" != "$RESULT2" ]; then
echo "Unusual bin path concoction $RESULT $RESULT2"
exit 1
fi
$ATBUILD compile
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment