Commit 409cc69b authored by Drew's avatar Drew

Allow variable expansion for shell tool

This allows the execution of a shell tool with the "collected sources"
of another task.

The intent here is to allow the creation of arbitrary tasks that accept
source files as arguments. xcode-emit is an obvious candidate, and
would allow it to break its dependence on atpkg, which it only uses for
this single feature.

There are other obvious programs that we might want to call with "all
sources" (e.g. preprocessors, etc.) and they may not want to take a
dependency on atpkg either.

See https://github.com/AnarchyTools/atpkg/pull/23
parent ac691a13
Pipeline #1353 passed with stage
Subproject commit 75a694a703109643d900b485903abd1a791234f4
Subproject commit edafd8e485a982a21dc5ec4ea44cd39d70ff5727
......@@ -24,7 +24,8 @@ import atpkg
final class Shell : Tool {
func run(task: Task) {
setenv("ATBUILD_USER_PATH", userPath(), 1)
guard let script = task["script"]?.string else { fatalError("Invalid 'script' argument to shell tool.") }
guard var script = task["script"]?.string else { fatalError("Invalid 'script' argument to shell tool.") }
script = evaluateSubstitutions(script, package: task.package)
do {
let oldPath = NSFileManager.defaultManager().currentDirectoryPath
defer { NSFileManager.defaultManager().changeCurrentDirectoryPath(oldPath) }
......
......@@ -10,10 +10,10 @@ commands:
<atllbuild-swiftc>:
tool: swift-compiler
executable: "/usr/local/bin/swiftc"
inputs: ["atpkg/src/CollectSources.swift", "atpkg/src/ExternalDependency.swift", "atpkg/src/ICantBelieveItsNotFoundation.swift", "atpkg/src/Package.swift", "atpkg/src/parsing/Parser.swift", "atpkg/src/parsing/Scanner.swift", "atpkg/src/parsing/Tokenization.swift", "atpkg/src/PathWithTrailingSlash.swift", "atpkg/src/Task.swift"]
sources: ["atpkg/src/CollectSources.swift", "atpkg/src/ExternalDependency.swift", "atpkg/src/ICantBelieveItsNotFoundation.swift", "atpkg/src/Package.swift", "atpkg/src/parsing/Parser.swift", "atpkg/src/parsing/Scanner.swift", "atpkg/src/parsing/Tokenization.swift", "atpkg/src/PathWithTrailingSlash.swift", "atpkg/src/Task.swift"]
objects: [".atllbuild/objects/CollectSources.swift.o", ".atllbuild/objects/ExternalDependency.swift.o", ".atllbuild/objects/ICantBelieveItsNotFoundation.swift.o", ".atllbuild/objects/Package.swift.o", ".atllbuild/objects/Parser.swift.o", ".atllbuild/objects/Scanner.swift.o", ".atllbuild/objects/Tokenization.swift.o", ".atllbuild/objects/PathWithTrailingSlash.swift.o", ".atllbuild/objects/Task.swift.o"]
outputs: ["<atllbuild-swiftc>", ".atllbuild/objects/CollectSources.swift.o", ".atllbuild/objects/ExternalDependency.swift.o", ".atllbuild/objects/ICantBelieveItsNotFoundation.swift.o", ".atllbuild/objects/Package.swift.o", ".atllbuild/objects/Parser.swift.o", ".atllbuild/objects/Scanner.swift.o", ".atllbuild/objects/Tokenization.swift.o", ".atllbuild/objects/PathWithTrailingSlash.swift.o", ".atllbuild/objects/Task.swift.o"]
inputs: ["atpkg/src/CollectSources.swift", "atpkg/src/ExternalDependency.swift", "atpkg/src/ICantBelieveItsNotFoundation.swift", "atpkg/src/Package.swift", "atpkg/src/parsing/Parser.swift", "atpkg/src/parsing/Scanner.swift", "atpkg/src/parsing/Tokenization.swift", "atpkg/src/PathWithTrailingSlash.swift", "atpkg/src/Substitutions.swift", "atpkg/src/Task.swift"]
sources: ["atpkg/src/CollectSources.swift", "atpkg/src/ExternalDependency.swift", "atpkg/src/ICantBelieveItsNotFoundation.swift", "atpkg/src/Package.swift", "atpkg/src/parsing/Parser.swift", "atpkg/src/parsing/Scanner.swift", "atpkg/src/parsing/Tokenization.swift", "atpkg/src/PathWithTrailingSlash.swift", "atpkg/src/Substitutions.swift", "atpkg/src/Task.swift"]
objects: [".atllbuild/objects/CollectSources.swift.o", ".atllbuild/objects/ExternalDependency.swift.o", ".atllbuild/objects/ICantBelieveItsNotFoundation.swift.o", ".atllbuild/objects/Package.swift.o", ".atllbuild/objects/Parser.swift.o", ".atllbuild/objects/Scanner.swift.o", ".atllbuild/objects/Tokenization.swift.o", ".atllbuild/objects/PathWithTrailingSlash.swift.o", ".atllbuild/objects/Substitutions.swift.o", ".atllbuild/objects/Task.swift.o"]
outputs: ["<atllbuild-swiftc>", ".atllbuild/objects/CollectSources.swift.o", ".atllbuild/objects/ExternalDependency.swift.o", ".atllbuild/objects/ICantBelieveItsNotFoundation.swift.o", ".atllbuild/objects/Package.swift.o", ".atllbuild/objects/Parser.swift.o", ".atllbuild/objects/Scanner.swift.o", ".atllbuild/objects/Tokenization.swift.o", ".atllbuild/objects/PathWithTrailingSlash.swift.o", ".atllbuild/objects/Substitutions.swift.o", ".atllbuild/objects/Task.swift.o"]
is-library: true
module-name: atpkg
module-output-path: .atllbuild/products/atpkg.swiftmodule
......@@ -21,7 +21,7 @@ commands:
other-args: ["-j8", "-D", "ATBUILD", "-I", ".atllbuild/products/"]
<atllbuild>:
tool: shell
inputs: ["<atllbuild-swiftc>", ".atllbuild/objects/CollectSources.swift.o", ".atllbuild/objects/ExternalDependency.swift.o", ".atllbuild/objects/ICantBelieveItsNotFoundation.swift.o", ".atllbuild/objects/Package.swift.o", ".atllbuild/objects/Parser.swift.o", ".atllbuild/objects/Scanner.swift.o", ".atllbuild/objects/Tokenization.swift.o", ".atllbuild/objects/PathWithTrailingSlash.swift.o", ".atllbuild/objects/Task.swift.o"]
inputs: ["<atllbuild-swiftc>", ".atllbuild/objects/CollectSources.swift.o", ".atllbuild/objects/ExternalDependency.swift.o", ".atllbuild/objects/ICantBelieveItsNotFoundation.swift.o", ".atllbuild/objects/Package.swift.o", ".atllbuild/objects/Parser.swift.o", ".atllbuild/objects/Scanner.swift.o", ".atllbuild/objects/Tokenization.swift.o", ".atllbuild/objects/PathWithTrailingSlash.swift.o", ".atllbuild/objects/Substitutions.swift.o", ".atllbuild/objects/Task.swift.o"]
outputs: ["<atllbuild>", ".atllbuild/products/atpkg.a"]
args: ["/bin/sh","-c",rm -rf .atllbuild/products/atpkg.a; ar cr '.atllbuild/products/atpkg.a' '.atllbuild/objects/CollectSources.swift.o' '.atllbuild/objects/ExternalDependency.swift.o' '.atllbuild/objects/ICantBelieveItsNotFoundation.swift.o' '.atllbuild/objects/Package.swift.o' '.atllbuild/objects/Parser.swift.o' '.atllbuild/objects/Scanner.swift.o' '.atllbuild/objects/Tokenization.swift.o' '.atllbuild/objects/PathWithTrailingSlash.swift.o' '.atllbuild/objects/Task.swift.o']
args: ["/bin/sh","-c",rm -rf .atllbuild/products/atpkg.a; ar cr '.atllbuild/products/atpkg.a' '.atllbuild/objects/CollectSources.swift.o' '.atllbuild/objects/ExternalDependency.swift.o' '.atllbuild/objects/ICantBelieveItsNotFoundation.swift.o' '.atllbuild/objects/Package.swift.o' '.atllbuild/objects/Parser.swift.o' '.atllbuild/objects/Scanner.swift.o' '.atllbuild/objects/Tokenization.swift.o' '.atllbuild/objects/PathWithTrailingSlash.swift.o' '.atllbuild/objects/Substitutions.swift.o' '.atllbuild/objects/Task.swift.o']
description: "Linking Library: .atllbuild/products/atpkg.a"
\ No newline at end of file
......@@ -10,10 +10,10 @@ commands:
<atllbuild-swiftc>:
tool: swift-compiler
executable: "/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/swiftc"
inputs: ["atpkg/src/CollectSources.swift", "atpkg/src/ExternalDependency.swift", "atpkg/src/ICantBelieveItsNotFoundation.swift", "atpkg/src/Package.swift", "atpkg/src/parsing/Parser.swift", "atpkg/src/parsing/Scanner.swift", "atpkg/src/parsing/Tokenization.swift", "atpkg/src/PathWithTrailingSlash.swift", "atpkg/src/Task.swift"]
sources: ["atpkg/src/CollectSources.swift", "atpkg/src/ExternalDependency.swift", "atpkg/src/ICantBelieveItsNotFoundation.swift", "atpkg/src/Package.swift", "atpkg/src/parsing/Parser.swift", "atpkg/src/parsing/Scanner.swift", "atpkg/src/parsing/Tokenization.swift", "atpkg/src/PathWithTrailingSlash.swift", "atpkg/src/Task.swift"]
objects: [".atllbuild/objects/CollectSources.swift.o", ".atllbuild/objects/ExternalDependency.swift.o", ".atllbuild/objects/ICantBelieveItsNotFoundation.swift.o", ".atllbuild/objects/Package.swift.o", ".atllbuild/objects/Parser.swift.o", ".atllbuild/objects/Scanner.swift.o", ".atllbuild/objects/Tokenization.swift.o", ".atllbuild/objects/PathWithTrailingSlash.swift.o", ".atllbuild/objects/Task.swift.o"]
outputs: ["<atllbuild-swiftc>", ".atllbuild/objects/CollectSources.swift.o", ".atllbuild/objects/ExternalDependency.swift.o", ".atllbuild/objects/ICantBelieveItsNotFoundation.swift.o", ".atllbuild/objects/Package.swift.o", ".atllbuild/objects/Parser.swift.o", ".atllbuild/objects/Scanner.swift.o", ".atllbuild/objects/Tokenization.swift.o", ".atllbuild/objects/PathWithTrailingSlash.swift.o", ".atllbuild/objects/Task.swift.o"]
inputs: ["atpkg/src/CollectSources.swift", "atpkg/src/ExternalDependency.swift", "atpkg/src/ICantBelieveItsNotFoundation.swift", "atpkg/src/Package.swift", "atpkg/src/parsing/Parser.swift", "atpkg/src/parsing/Scanner.swift", "atpkg/src/parsing/Tokenization.swift", "atpkg/src/PathWithTrailingSlash.swift", "atpkg/src/Substitutions.swift", "atpkg/src/Task.swift"]
sources: ["atpkg/src/CollectSources.swift", "atpkg/src/ExternalDependency.swift", "atpkg/src/ICantBelieveItsNotFoundation.swift", "atpkg/src/Package.swift", "atpkg/src/parsing/Parser.swift", "atpkg/src/parsing/Scanner.swift", "atpkg/src/parsing/Tokenization.swift", "atpkg/src/PathWithTrailingSlash.swift", "atpkg/src/Substitutions.swift", "atpkg/src/Task.swift"]
objects: [".atllbuild/objects/CollectSources.swift.o", ".atllbuild/objects/ExternalDependency.swift.o", ".atllbuild/objects/ICantBelieveItsNotFoundation.swift.o", ".atllbuild/objects/Package.swift.o", ".atllbuild/objects/Parser.swift.o", ".atllbuild/objects/Scanner.swift.o", ".atllbuild/objects/Tokenization.swift.o", ".atllbuild/objects/PathWithTrailingSlash.swift.o", ".atllbuild/objects/Substitutions.swift.o", ".atllbuild/objects/Task.swift.o"]
outputs: ["<atllbuild-swiftc>", ".atllbuild/objects/CollectSources.swift.o", ".atllbuild/objects/ExternalDependency.swift.o", ".atllbuild/objects/ICantBelieveItsNotFoundation.swift.o", ".atllbuild/objects/Package.swift.o", ".atllbuild/objects/Parser.swift.o", ".atllbuild/objects/Scanner.swift.o", ".atllbuild/objects/Tokenization.swift.o", ".atllbuild/objects/PathWithTrailingSlash.swift.o", ".atllbuild/objects/Substitutions.swift.o", ".atllbuild/objects/Task.swift.o"]
is-library: true
module-name: atpkg
module-output-path: .atllbuild/products/atpkg.swiftmodule
......@@ -21,7 +21,7 @@ commands:
other-args: ["-j8", "-D", "ATBUILD", "-I", ".atllbuild/products/", "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk"]
<atllbuild>:
tool: shell
inputs: ["<atllbuild-swiftc>", ".atllbuild/objects/CollectSources.swift.o", ".atllbuild/objects/ExternalDependency.swift.o", ".atllbuild/objects/ICantBelieveItsNotFoundation.swift.o", ".atllbuild/objects/Package.swift.o", ".atllbuild/objects/Parser.swift.o", ".atllbuild/objects/Scanner.swift.o", ".atllbuild/objects/Tokenization.swift.o", ".atllbuild/objects/PathWithTrailingSlash.swift.o", ".atllbuild/objects/Task.swift.o"]
inputs: ["<atllbuild-swiftc>", ".atllbuild/objects/CollectSources.swift.o", ".atllbuild/objects/ExternalDependency.swift.o", ".atllbuild/objects/ICantBelieveItsNotFoundation.swift.o", ".atllbuild/objects/Package.swift.o", ".atllbuild/objects/Parser.swift.o", ".atllbuild/objects/Scanner.swift.o", ".atllbuild/objects/Tokenization.swift.o", ".atllbuild/objects/PathWithTrailingSlash.swift.o", ".atllbuild/objects/Substitutions.swift.o", ".atllbuild/objects/Task.swift.o"]
outputs: ["<atllbuild>", ".atllbuild/products/atpkg.a"]
args: ["/bin/sh","-c",rm -rf .atllbuild/products/atpkg.a; ar cr '.atllbuild/products/atpkg.a' '.atllbuild/objects/CollectSources.swift.o' '.atllbuild/objects/ExternalDependency.swift.o' '.atllbuild/objects/ICantBelieveItsNotFoundation.swift.o' '.atllbuild/objects/Package.swift.o' '.atllbuild/objects/Parser.swift.o' '.atllbuild/objects/Scanner.swift.o' '.atllbuild/objects/Tokenization.swift.o' '.atllbuild/objects/PathWithTrailingSlash.swift.o' '.atllbuild/objects/Task.swift.o']
args: ["/bin/sh","-c",rm -rf .atllbuild/products/atpkg.a; ar cr '.atllbuild/products/atpkg.a' '.atllbuild/objects/CollectSources.swift.o' '.atllbuild/objects/ExternalDependency.swift.o' '.atllbuild/objects/ICantBelieveItsNotFoundation.swift.o' '.atllbuild/objects/Package.swift.o' '.atllbuild/objects/Parser.swift.o' '.atllbuild/objects/Scanner.swift.o' '.atllbuild/objects/Tokenization.swift.o' '.atllbuild/objects/PathWithTrailingSlash.swift.o' '.atllbuild/objects/Substitutions.swift.o' '.atllbuild/objects/Task.swift.o']
description: "Linking Library: .atllbuild/products/atpkg.a"
\ No newline at end of file
;; This is the most basic of sample files.
(package
:name "collect_sources"
:version "0.1.0-dev"
:tasks {
:default {
:tool "nop"
:sources ["src/**.swift"]
}
:collect-sources {
:tool "shell"
:script "echo sources ${collect_sources:default}"
}
}
)
;; End of the sample.
\ No newline at end of file
// a
\ No newline at end of file
// b
\ No newline at end of file
......@@ -10,6 +10,15 @@ pwd
echo "****************SELF-HOSTING TEST**************"
$ATBUILD atbuild
echo "****************COLLECT SOURCES TEST**************"
cd $DIR/tests/fixtures/collect_sources
$ATBUILD collect-sources 2&> /tmp/sources.txt
if ! grep "sources src/a.swift src/b.swift" /tmp/sources.txt; then
echo "Unexpected sources $COLLECT_SOURCES"
exit 1
fi
echo "sources $COLLECT_SOURCES"
echo "****************DYNAMIC LIBRARY TEST**************"
cd $DIR/tests/fixtures/dynamic_library
$ATBUILD
......
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