Commit b1fc7420 authored by Drew's avatar Drew

Add atbuild "user paths".

This patch adds a "user path" which is global to an entire buildchain
and allows tasks to progressively build up contents that are somewhat
arbitrary.

In particular, this is useful for AnarchyDispatch.  If we have
a/b/AnarchyDispatch, then AnarchyDispatch can install itself to the
ATBUILD_USER_PATH and be visible to both a and b.  Then we can inject
includeWithUser: ["AnarchyDispatch"] in an overlay and everything "just
works".
parent 43bf8b1a
Pipeline #944 passed with stage
......@@ -23,6 +23,7 @@ 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.") }
do {
let oldPath = NSFileManager.defaultManager().currentDirectoryPath
......
......@@ -13,6 +13,7 @@
// limitations under the License.
import atpkg
import Foundation
/** The builtin tools. */
let tools: [String:Tool] = [
......@@ -38,3 +39,18 @@ func toolByName(name: String) -> Tool {
guard let tool = tools[name] else { fatalError("Unknown build tool \(name)") }
return tool
}
private var userPathCreated = false
/**Returns the "user" path. This is a path that the user may use to store artifacts or for any other purposes. This path is shared for all tasks built as part of the same `atbuild` invocation.
- postcondition: The path exists at this absolute locaton on disk.
- warning: This path is cleared between atbuild invocations. */
func userPath() -> String {
let manager = NSFileManager.defaultManager()
let userPath = manager.currentDirectoryPath + "/user"
if !userPathCreated {
let _ = try? manager.removeItemAtPath(userPath)
try! manager.createDirectoryAtPath(userPath, withIntermediateDirectories: false, attributes: nil)
userPathCreated = true
}
return userPath
}
......@@ -199,7 +199,8 @@ final class ATllbuild : Tool {
"linkWithProduct",
"swiftCPath",
"xctestify",
"xctestStrict"]
"xctestStrict",
"includeWithUser"]
for key in task.allKeys {
if !knownOptions.contains(key) {
print("Warning: unknown option \(key) for task \(task.key)")
......@@ -246,6 +247,13 @@ final class ATllbuild : Tool {
compileOptions.append(os)
}
}
if let includePaths = task["includeWithUser"]?.vector {
for path_s in includePaths {
guard let path = path_s.string else { fatalError("Non-string path \(path_s)") }
compileOptions.append("-I")
compileOptions.append(userPath() + "/" + path)
}
}
var linkOptions: [String] = []
if let opts = task["linkOptions"]?.vector {
for o in opts {
......
......@@ -47,6 +47,9 @@ The `atllbuild` tool uses the [`swift-llbuild`](https://github.com/apple/swift-l
;; checking for API differences across XCTest
;; platforms
xctestStrict: false
;; Add a path in the $ATBUILD_USER_PATH as an include path
includeWithUser []
}
}
......
......@@ -13,3 +13,13 @@ The shell tool allows you to call a shell command.
:script "echo hello world"
}
```
# Environment variables
## `ATBUILD_USER_PATH`
The `ATBUILD_USER_PATH` contains the path to a "user" directory. You can use this directory however you like.
The directory is preserved across all tasks that are part of the same dependency chain, and is cleared between invocations to `atbuild`.
A common use of the `ATBUILD_USER_PATH` is to specify include information; see atllbuild's `includeWithUser` [documentation](/docs/atllbuild.md) for more information.
(package
:name "b"
:tasks {
:second {
:tool "shell"
:script "echo SECOND >> $ATBUILD_USER_PATH/test"
}
}
)
\ No newline at end of file
(package
:name "user_paths"
:import ["b/build.atpkg"]
:tasks {
:first {
:tool "shell"
:script "echo FIRST >> $ATBUILD_USER_PATH/test"
}
:third {
:tool "shell"
:script "echo THIRD >> $ATBUILD_USER_PATH/test"
:dependencies ["first" "b.second"]
}
:compiledep {
:tool "shell"
:script "mkdir $ATBUILD_USER_PATH/Foo && echo module Foo { } > $ATBUILD_USER_PATH/Foo/module.modulemap"
}
:compile {
:tool "atllbuild"
:source ["foo.swift"]
:includeWithUser ["Foo"]
:dependencies ["compiledep"]
:outputType "static-library"
:name "foo"
}
}
)
\ No newline at end of file
import Foo
\ No newline at end of file
......@@ -10,6 +10,22 @@ pwd
echo "****************SELF-HOSTING TEST**************"
$ATBUILD atbuild
echo "****************USER PATH TEST**************"
cd $DIR/tests/fixtures/user_paths
$ATBUILD third
RESULT=`cat user/test`
RESULT2="FIRST
SECOND
THIRD"
if [ "$RESULT" != "$RESULT2" ]; then
echo "Unusual user path concoction $RESULT $RESULT2"
exit 1
fi
$ATBUILD compile
echo "****************AGRESSIVE TEST**************"
cd $DIR/tests/fixtures/agressive
if $ATBUILD 2&> /tmp/warnings.txt; then
......
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