Commit 10824113 authored by Drew's avatar Drew

Proper path support for importing remote tasks

parent 9521092e
Pipeline #704 failed with stage
......@@ -17,13 +17,16 @@ import Foundation
* - parameter sourceDescriptions: a descriptions of sources such as ["src/**.swift"] */
* - returns: A list of resolved sources such as ["src/a.swift", "src/b.swift"]
*/
public func collectSources(sourceDescriptions: [String]) -> [String] {
public func collectSources(sourceDescriptions: [String], task: Task) -> [String] {
var sources : [String] = []
for description in sourceDescriptions {
for unPrefixedDescription in sourceDescriptions {
let description = task.importedPath + unPrefixedDescription
if description.hasSuffix("**.swift") {
let basepath = String(Array(description.characters)[0..<description.characters.count - 9])
let manager = NSFileManager.defaultManager()
let enumerator = manager.enumeratorAtPath(basepath)!
guard let enumerator = manager.enumeratorAtPath(basepath) else {
fatalError("Invalid path \(basepath)")
}
while let source = enumerator.nextObject() as? String {
if source.hasSuffix("swift") {
sources.append(basepath + "/" + source)
......
......@@ -17,16 +17,17 @@ final public class Task {
public var key: String = ""
public var dependencies: [String] = []
public var tool: String = "atllbuild"
public var importedPath: String ///the directory at which the task was imported. This includes a trailing /.
private var kvp: [String:ParseValue]
init?(value: ParseValue, name: String) {
init?(value: ParseValue, name: String, importedPath: String) {
guard let kvp = value.map else { return nil }
self.importedPath = importedPath.pathWithTrailingSlash
self.kvp = kvp
self.key = name
self.tool = kvp["tool"]?.string ?? self.tool
if let values = kvp["dependencies"]?.vector {
for value in values {
if let dep = value.string { self.dependencies.append(dep) }
......@@ -97,7 +98,7 @@ final public class Package {
if let parsedTasks = type.properties["tasks"]?.map {
for (key, value) in parsedTasks {
if let task = Task(value: value, name: key) {
if let task = Task(value: value, name: key, importedPath: pathOnDisk) {
self.tasks[key] = task
}
}
......@@ -135,11 +136,13 @@ final public class Package {
if let imports = type.properties["import"]?.vector {
for importFile in imports {
guard let importFileString = importFile.string else { fatalError("Non-string import \(importFile)")}
guard let remotePackage = Package(filepath: pathOnDisk + "/" + importFileString, configurations: configurations) else {
fatalError("Can't load remote package \(pathOnDisk + "/" + importFileString)")
let adjustedImportPath = (pathOnDisk.pathWithTrailingSlash + importFileString as NSString).stringByDeletingLastPathComponent.pathWithTrailingSlash
let adjustedFileName = (importFileString as NSString).lastPathComponent
guard let remotePackage = Package(filepath: adjustedImportPath + adjustedFileName, configurations: configurations) else {
fatalError("Can't load remote package \(adjustedImportPath + adjustedFileName)")
}
for task in remotePackage.tasks.keys {
remotePackage.tasks[task]!.importedPath = adjustedImportPath
self.tasks["\(remotePackage.name).\(task)"] = remotePackage.tasks[task]
}
}
......
// Copyright (c) 2016 Anarchy Tools Contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import Foundation
extension String {
var pathWithTrailingSlash: String {
if self.hasSuffix("/") { return self }
else if self.characters.count > 0 { return self + "/" }
else { return NSFileManager.defaultManager().currentDirectoryPath + "/" }
}
}
\ No newline at end of file
......@@ -52,15 +52,9 @@ class PackageTests: Test {
static func testImport() throws {
let filepath = "./tests/collateral/import_src.atpkg"
guard let parser = Parser(filepath: filepath) else {
print("error")
try test.assert(false); return
}
let result = try parser.parse()
guard let package = Package(type: result, configurations: [:], pathOnDisk: "./tests/collateral") else { print("error"); try test.assert(false); return }
guard let package = Package(filepath: filepath, configurations: [:]) else { print("error"); try test.assert(false); return }
try test.assert(package.tasks["import_dst.build"] != nil)
try test.assert(package.tasks["import_dst.build"]!.importedPath == "./tests/collateral")
}
}
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