Commit ea762196 authored by Drew's avatar Drew

Merge pull request #46 from AnarchyTools/atbuild_user

Add atbuild "user paths".
parents 61e7e2a7 9f98f7f0
Pipeline #1079 failed 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
}
......@@ -194,6 +194,7 @@ final class ATllbuild : Tool {
case SwiftCPath = "swiftc-path"
case XCTestify = "xctestify"
case XCTestStrict = "xctest-strict"
case IncludeWithUser = "include-with-user"
case PublishProduct = "publish-product"
static var allOptions : [Options] {
......@@ -212,6 +213,7 @@ final class ATllbuild : Tool {
SwiftCPath,
XCTestify,
XCTestStrict,
IncludeWithUser,
PublishProduct
]
}
......@@ -266,6 +268,13 @@ final class ATllbuild : Tool {
compileOptions.append(os)
}
}
if let includePaths = task[Options.IncludeWithUser.rawValue]?.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[Options.LinkOptions.rawValue]?.vector {
for o in opts {
......
(package
:name "b"
:tasks {
:second {
:tool "shell"
:script "echo SECOND >> $ATBUILD_USER_PATH/test"
}
}
)
\ No newline at end of file
import Foo
\ No newline at end of file
(package
:name "user_paths"
:import-packages ["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"
:sources ["bar.swift"]
:include-with-user ["Foo"]
:dependencies ["compiledep"]
:output-type "static-library"
:name "bar"
}
}
)
\ 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 "****************PUBLISHPRODUCT TEST**************"
cd $DIR/tests/fixtures/publish_product
$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