Skip to content

Commit 5040f9e

Browse files
committed
Merge pull request #174 from mxcl/xcodeproj
Xcode Project Generation
2 parents ecf03f0 + c82fd09 commit 5040f9e

38 files changed

+856
-888
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ xcuserdata
55
*~
66
*.xcscmblueprint
77
/default.profraw
8+
*.xcodeproj

Package.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ let package = Package(
2525
/** Base types for the package-engine */
2626
name: "PackageType",
2727
dependencies: ["PackageDescription", "Utility"]), //FIXME dependency on PackageDescription sucks
28-
Target( //FIXME Carpet is too general, we only need `Path`
28+
Target( //FIXME Utility is too general, we only need `Path`
2929
name: "ManifestParser",
3030
dependencies: ["PackageDescription", "PackageType"]),
3131
Target(
@@ -35,7 +35,7 @@ let package = Package(
3535
Target(
3636
/** Fetches Packages and their dependencies */
3737
name: "Get",
38-
dependencies: ["ManifestParser"]),
38+
dependencies: ["PackageDescription", "PackageType"]),
3939
Target(
4040
/** Builds Modules and Products */
4141
name: "Build",
@@ -44,9 +44,12 @@ let package = Package(
4444
/** Common components of both executables */
4545
name: "Multitool",
4646
dependencies: ["PackageType"]),
47+
Target(
48+
name: "Xcodeproj",
49+
dependencies: ["PackageType"]),
4750
Target(
4851
name: "swift-build",
49-
dependencies: ["Get", "Transmute", "Build", "Multitool"]),
52+
dependencies: ["ManifestParser", "Get", "Transmute", "Build", "Multitool", "Xcodeproj"]),
5053
Target(
5154
name: "swift-test",
5255
dependencies: ["Multitool"]),

Sources/Build/describe().swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
import func POSIX.getenv
1212
import func POSIX.mkdir
13-
import PackageType
14-
import Utility
1513
import func POSIX.fopen
1614
import func libc.fclose
15+
import PackageType
16+
import Utility
1717

1818
/**
1919
- Returns: path to generated YAML for consumption by the llbuild based swift-build-tool
@@ -41,7 +41,7 @@ public func describe(prefix: String, _ conf: Configuration, _ modules: [Module],
4141
}
4242

4343
var mkdirs = Set<String>()
44-
let swiftcArgs = Xcc + Xswiftc
44+
let swiftcArgs = Xcc + Xswiftc + verbosity.ccArgs
4545

4646
for case let module as SwiftModule in modules {
4747

@@ -53,7 +53,7 @@ public func describe(prefix: String, _ conf: Configuration, _ modules: [Module],
5353
args.append("-enable-testing")
5454

5555
#if os(OSX)
56-
if let platformPath = Resources.path.platformPath {
56+
if let platformPath = Toolchain.platformPath {
5757
let path = Path.join(platformPath, "Developer/Library/Frameworks")
5858
args += ["-F", path]
5959
} else {
@@ -65,7 +65,7 @@ public func describe(prefix: String, _ conf: Configuration, _ modules: [Module],
6565
let swiftc = SwiftcTool(
6666
inputs: node.inputs,
6767
outputs: node.outputs,
68-
executable: Resources.path.swiftc,
68+
executable: Toolchain.swiftc,
6969
moduleName: module.c99name,
7070
moduleOutputPath: node.moduleOutputPath,
7171
importPaths: prefix,
@@ -96,7 +96,7 @@ public func describe(prefix: String, _ conf: Configuration, _ modules: [Module],
9696
description: "Compiling \(module.name)",
9797
inputs: inputs,
9898
outputs: [productPath, module.targetName],
99-
args: [Resources.path.swiftc, "-o", productPath] + args + module.sources.paths + otherArgs)
99+
args: [Toolchain.swiftc, "-o", productPath] + args + module.sources.paths + otherArgs)
100100

101101
let command = Command(name: module.targetName, tool: shell)
102102
append(command, buildable: module)
@@ -121,7 +121,7 @@ public func describe(prefix: String, _ conf: Configuration, _ modules: [Module],
121121
objects = product.buildables.flatMap{ return IncrementalNode(module: $0, prefix: prefix).objectPaths }
122122
}
123123

124-
var args = [Resources.path.swiftc] + swiftcArgs
124+
var args = [Toolchain.swiftc] + swiftcArgs
125125

126126
switch product.type {
127127
case .Library(.Static):
@@ -130,7 +130,7 @@ public func describe(prefix: String, _ conf: Configuration, _ modules: [Module],
130130
#if os(OSX)
131131
args += ["-Xlinker", "-bundle"]
132132

133-
if let platformPath = Resources.path.platformPath {
133+
if let platformPath = Toolchain.platformPath {
134134
let path = Path.join(platformPath, "Developer/Library/Frameworks")
135135
args += ["-F", path]
136136
} else {

Sources/Build/misc.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import Utility
1515
func platformArgs() -> [String] {
1616
var args = [String]()
1717

18-
#if os(OSX)
19-
args += ["-target", "x86_64-apple-macosx10.10"]
18+
#if os(OSX)
19+
args += ["-target", "x86_64-apple-macosx10.10"]
2020

21-
if let sysroot = Resources.path.sysroot {
22-
args += ["-sdk", sysroot]
23-
}
24-
#endif
21+
if let sysroot = Toolchain.sysroot {
22+
args += ["-sdk", sysroot]
23+
}
24+
#endif
2525

2626
return args
2727
}

Sources/Get/Package.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
*/
1010

1111
import struct PackageDescription.Version
12-
import ManifestParser
1312
import PackageType
1413
import Utility
1514

1615
extension Package {
1716
// FIXME we *always* have a manifest, don't reparse it
1817

19-
static func make(repo repo: Git.Repo) throws -> Package? {
18+
static func make(repo repo: Git.Repo, manifestParser: (path: String, url: String) throws -> Manifest) throws -> Package? {
2019
guard let origin = repo.origin else { throw Error.NoOrigin(repo.path) }
21-
let manifest = try Manifest(path: repo.path, baseURL: origin)
20+
let manifest = try manifestParser(path: repo.path, url: origin)
2221
let pkg = Package(manifest: manifest, url: origin)
2322
guard Version(pkg.versionString) != nil else { return nil }
2423
return pkg

Sources/Get/PackagesDirectory.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import struct PackageDescription.Version
1212
import func POSIX.mkdir
1313
import func POSIX.rename
14-
import ManifestParser
1514
import PackageType
1615
import Utility
1716

@@ -20,9 +19,11 @@ import Utility
2019
*/
2120
class PackagesDirectory {
2221
let prefix: String
22+
let manifestParser: (path: String, url: String) throws -> Manifest
2323

24-
init(prefix: String) {
24+
init(prefix: String, manifestParser: (path: String, url: String) throws -> Manifest) {
2525
self.prefix = prefix
26+
self.manifestParser = manifestParser
2627
}
2728
}
2829

@@ -33,7 +34,7 @@ extension PackagesDirectory: Fetcher {
3334
for prefix in walk(self.prefix, recursively: false) {
3435
guard let repo = Git.Repo(path: prefix) else { continue } //TODO warn user
3536
guard repo.origin == url else { continue }
36-
return try Package.make(repo: repo)
37+
return try Package.make(repo: repo, manifestParser: manifestParser)
3738
}
3839
return nil
3940
}
@@ -42,13 +43,13 @@ extension PackagesDirectory: Fetcher {
4243
let dstdir = Path.join(prefix, Package.nameForURL(url))
4344
if let repo = Git.Repo(path: dstdir) where repo.origin == url {
4445
//TODO need to canonicalize the URL need URL struct
45-
return try RawClone(path: dstdir)
46+
return try RawClone(path: dstdir, manifestParser: manifestParser)
4647
}
4748

4849
// fetch as well, clone does not fetch all tags, only tags on the master branch
4950
try Git.clone(url, to: dstdir).fetch()
5051

51-
return try RawClone(path: dstdir)
52+
return try RawClone(path: dstdir, manifestParser: manifestParser)
5253
}
5354

5455
func finalize(fetchable: Fetchable) throws -> Package {
@@ -57,7 +58,8 @@ extension PackagesDirectory: Fetcher {
5758
let prefix = Path.join(self.prefix, clone.finalName)
5859
try mkdir(prefix.parentDirectory)
5960
try rename(old: clone.path, new: prefix)
60-
return try Package.make(repo: Git.Repo(path: prefix)!)!
61+
//TODO don't reparse the manifest!
62+
return try Package.make(repo: Git.Repo(path: prefix)!, manifestParser: manifestParser)!
6163
case let pkg as Package:
6264
return pkg
6365
default:

Sources/Get/RawClone.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010

1111
import struct PackageDescription.Version
12-
import ManifestParser
1312
import PackageType
1413
import Utility
1514
import libc
@@ -23,21 +22,23 @@ import libc
2322
*/
2423
class RawClone: Fetchable {
2524
let path: String
25+
let manifestParser: (path: String, url: String) throws -> Manifest
2626

2727
// lazy because the tip of the default branch does not have to be a valid package
2828
//FIXME we should error gracefully if a selected version does not however
2929
var manifest: Manifest! {
3030
if let manifest = _manifest {
3131
return manifest
3232
} else {
33-
_manifest = try? Manifest(path: path, baseURL: repo.origin!)
33+
_manifest = try? manifestParser(path: path, url: repo.origin!)
3434
return _manifest
3535
}
3636
}
3737
private var _manifest: Manifest?
3838

39-
init(path: String) throws {
39+
init(path: String, manifestParser: (path: String, url: String) throws -> Manifest) throws {
4040
self.path = path
41+
self.manifestParser = manifestParser
4142
if !repo.hasVersion {
4243
throw Error.Unversioned(path)
4344
}

Sources/Get/get().swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import Utility
1717
- Throws: Error.InvalidDependencyGraph
1818
- Returns: The modules that this manifest requires building
1919
*/
20-
public func get(manifest: Manifest) throws -> [Package] {
20+
public func get(manifest: Manifest, manifestParser: (path: String, url: String) throws -> Manifest) throws -> [Package] {
2121
let dir = Path.join(manifest.path.parentDirectory, "Packages")
22-
let box = PackagesDirectory(prefix: dir)
22+
let box = PackagesDirectory(prefix: dir, manifestParser: manifestParser)
2323

2424
//TODO don't lose the dependency information during the Fetcher process!
2525

Sources/ManifestParser/Error.swift

Lines changed: 0 additions & 13 deletions
This file was deleted.

Sources/ManifestParser/Manifest+parse.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11-
import struct PackageType.Manifest
1211
import func POSIX.realpath
1312
import PackageDescription
13+
import PackageType
1414
import Utility
1515
import func POSIX.fopen
1616
import func libc.fileno
1717
import func libc.unlink
1818
import func libc.fclose
1919

2020
extension Manifest {
21-
public init(path pathComponents: String..., baseURL: String) throws {
21+
public init(path pathComponents: String..., baseURL: String, swiftc: String, libdir: String) throws {
2222

2323
guard baseURL.chuzzle() != nil else { fatalError() } //TODO
2424

@@ -36,32 +36,31 @@ extension Manifest {
3636
path = joinedPath
3737
}
3838

39-
guard path.isFile else { throw Error.NoManifest(path) }
39+
guard path.isFile else { throw PackageType.Package.Error.NoManifest(path) }
4040

41-
if let toml = try parse(path) {
41+
if let toml = try parse(path: path, swiftc: swiftc, libdir: libdir) {
4242
let toml = try TOMLItem.parse(toml)
4343
let package = PackageDescription.Package.fromTOML(toml, baseURL: baseURL)
4444
let products = PackageDescription.Product.fromTOML(toml)
4545

4646
self.init(path: path, package: package, products: products)
4747
} else {
4848
// As a special case, we accept an empty file as an unnamed package.
49-
self.init(path: path, package: Package(), products: [Product]())
49+
self.init(path: path, package: PackageDescription.Package(), products: [])
5050
}
5151
}
5252
}
5353

54-
private func parse(manifestPath: String) throws -> String? {
54+
private func parse(path manifestPath: String, swiftc: String, libdir: String) throws -> String? {
5555

5656
// For now, we load the manifest by having Swift interpret it directly.
5757
// Eventually, we should have two loading processes, one that loads only
5858
// the the declarative package specification using the Swift compiler
5959
// directly and validates it.
6060

61-
let libdir = Resources.runtimeLibPath
62-
63-
var cmd = [Resources.path.swiftc]
61+
var cmd = [swiftc]
6462
cmd += ["--driver-mode=swift"]
63+
cmd += verbosity.ccArgs
6564
cmd += ["-I", libdir]
6665
cmd += ["-L", libdir, "-lPackageDescription"]
6766
#if os(OSX)

Sources/Multitool/build().swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,23 @@
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11+
import func POSIX.getenv
1112
import Utility
1213

1314
public func build(YAMLPath YAMLPath: String, target: String) throws {
14-
var args = [Resources.path.swift_build_tool, "-f", YAMLPath, target]
15+
var args = [swift_build_tool(), "-f", YAMLPath, target]
1516
if verbosity != .Concise { args.append("-v") }
1617
try system(args)
1718
}
19+
20+
private func swift_build_tool() -> String {
21+
if let tool = getenv("SWIFT_BUILD_TOOL") { //FIXME remove and if people complain, make it a flag
22+
return tool
23+
} else if let path = try? Path.join(exepath, "..", "swift-build-tool").abspath() where path.isFile {
24+
return path
25+
} else {
26+
return "swift-build-tool"
27+
}
28+
}
29+
30+
private let exepath: String = try! Process.arguments.first!.abspath()

Sources/POSIX/system.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ public func system() {}
4545

4646
/// Convenience wrapper for posix_spawn.
4747
func posix_spawnp(path: String, args: [String], environment: [String: String] = [:], fileActions: posix_spawn_file_actions_t? = nil) throws -> pid_t {
48-
var environment = environment
4948
let argv = args.map{ $0.withCString(strdup) }
5049
defer { for arg in argv { free(arg) } }
5150

51+
var environment = environment
5252
for key in ["PATH", "SDKROOT", "TOOLCHAINS", "HOME", "SWIFT_EXEC",
5353
// FIXME these
5454
"SPM_INSTALL_PATH", "SWIFT_BUILD_TOOL"] {
55-
environment[key] = POSIX.getenv(key)
55+
if environment[key] == nil {
56+
environment[key] = POSIX.getenv(key)
57+
}
5658
}
5759

5860
let env = environment.map{ "\($0.0)=\($0.1)".withCString(strdup) }

Sources/Transmute/transmute().swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ public func transmute(packages: [Package], rootdir: String) throws -> ([Module],
4242
// depend upon 'Utility', and hope that no users define
4343
// test modules named 'Functional'.
4444
testModule.dependencies = modules.filter{ $0.name == "Utility" }
45+
} else if testModule.basename == "Transmute" {
46+
// FIXME: Turns out TransmuteTests violate encapsulation :(
47+
testModule.dependencies = modules.filter{
48+
switch $0.name {
49+
case "Get", "Transmute", "ManifestParser":
50+
return true
51+
default:
52+
return false
53+
}
54+
}
4555
} else {
4656
// Normally, test modules are only dependent upon modules with
4757
// the same basename. For example, a test module in

0 commit comments

Comments
 (0)