Skip to content

Commit bb98759

Browse files
committed
Merge branch 'master' into hd/tests/string_utils
# Conflicts: # Tests/Utility/FileTests.swift
2 parents 8f6cf43 + 7661b27 commit bb98759

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+904
-587
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import PackageDescription
2+
3+
let package = Package(
4+
name: "Bar",
5+
dependencies: [
6+
.Package(url: "../Foo", majorVersion: 1)
7+
]
8+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <Foo/Foo.h>
2+
3+
void cool() {
4+
foo();
5+
}

Fixtures/DependencyResolution/External/CUsingCDep2/Bar/Sources/SeaLover/include/Sea.h

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module SeaLover {
2+
header "Sea/Sea.h"
3+
link "SeaLover"
4+
export *
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Foo
2+
3+
foo()

Fixtures/DependencyResolution/External/CUsingCDep2/Foo/Package.swift

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
void foo() {
2+
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void foo();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Foo {
2+
header "Foo/Foo.h"
3+
link "Foo"
4+
export *
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public class Foo {
2+
var bar: Int = 0
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import PackageDescription
2+
3+
let package = Package(name: "Foo")
4+
5+
let archive = Product(name: "Bar", type: .Library(.Static), modules: "Foo")
6+
7+
products.append(archive)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import PackageDescription
2+
3+
let package = Package(
4+
name: "CExecutable"
5+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
int a = 5;
5+
printf("hello %d", a);
6+
}

README.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,31 @@ Additionally, it is important to note that the Swift language syntax is not stab
2323

2424
## Installing
2525

26-
The package manager is bundled with the [developer snapshots available at swift.org](https://swift.org/download/).
27-
**Please note the package manager does not come with the 2.2 release snapshots, ensure you download a
28-
developer snapshot.**
26+
The package manager is bundled with the [**Trunk Development** Snapshots available at swift.org](https://swift.org/download/). Following installation you will need to do one of the following to use the package manager on the command line:
2927

30-
If you want to verify you already have the package manager installed, enter the following in a terminal:
28+
* Xcode 7.3:
29+
30+
export TOOLCHAINS=swift
31+
32+
* Xcode 7.2:
33+
34+
export PATH=/Library/Toolchains/swift-latest.xctoolchain/usr/bin:$PATH
35+
36+
* Linux:
37+
38+
export PATH=path/to/toolchain/usr/bin:$PATH
39+
40+
You can verify your installation by typing `swift build --version` in a terminal:
3141

3242
```sh
33-
swift build --help
43+
$ swift build --version
44+
Apple Swift Package Manager
3445
```
3546

36-
If you get usage output, it is installed, otherwise you will see an error such as:
47+
The following indicates you have not installed a snapshot successfully:
3748

3849
<unknown>:0: error: no such file or directory: 'build'
3950

40-
After installing a downloadable toolchain on OS X, by default you will probably see this error.
41-
To execute the swift from your download you either need to put that `swift` first in your `PATH`,
42-
or you need to set the `TOOLCHAINS` environment variable: see the next section.
43-
44-
4551
### Managing Swift Environments
4652

4753
The `TOOLCHAINS` environment variable on OS X can be used to control which
@@ -66,7 +72,7 @@ your `TOOLCHAINS` enivonment variable.
6672
To use a specific toolchain you can set `TOOLCHAINS` to the `CFBundleIdentifier`
6773
in an `.xctoolchain`’s Info.plist.
6874

69-
Please note, this feature may by a little flakey with Xcode prior to 7.3.
75+
This feature requires Xcode 7.3.
7076

7177

7278
## Development

Sources/Build/Buildable.swift

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright 2015 - 2016 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import PackageType
12+
13+
protocol Buildable {
14+
var targetName: String { get }
15+
var isTest: Bool { get }
16+
}
17+
18+
extension Module: Buildable {
19+
var isTest: Bool {
20+
return self is TestModule
21+
}
22+
23+
var Xcc: [String] {
24+
return recursiveDependencies.flatMap { module -> [String] in
25+
if let module = module as? CModule {
26+
return ["-Xcc", "-fmodule-map-file=\(module.moduleMapPath)"]
27+
} else {
28+
return []
29+
}
30+
}
31+
}
32+
33+
var targetName: String {
34+
return "<\(name).module>"
35+
}
36+
}
37+
38+
extension Product: Buildable {
39+
var isTest: Bool {
40+
if case .Test = type {
41+
return true
42+
}
43+
return false
44+
}
45+
46+
var targetName: String {
47+
switch type {
48+
case .Library(.Dynamic):
49+
return "<\(name).dylib>"
50+
case .Test:
51+
return "<\(name).test>"
52+
case .Library(.Static):
53+
return "<\(name).a>"
54+
case .Executable:
55+
return "<\(name).exe>"
56+
}
57+
}
58+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright 2015 - 2016 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import PackageType
12+
import Utility
13+
import POSIX
14+
15+
//FIXME: Incremental builds
16+
17+
extension Command {
18+
static func compile(clangModule module: ClangModule, externalModules: Set<Module>, configuration conf: Configuration, prefix: String) -> (Command, Command) {
19+
20+
let wd = Path.join(prefix, "\(module.c99name).build")
21+
let mkdir = Command.createDirectory(wd)
22+
23+
let inputs = module.dependencies.map{ $0.targetName } + module.sources.paths + [mkdir.node]
24+
let productPath = Path.join(prefix, module.type == .Library ? "lib\(module.c99name).so" : module.c99name)
25+
26+
var args: [String] = []
27+
#if os(Linux)
28+
args += ["-fPIC"]
29+
#endif
30+
args += ["-fmodules", "-fmodule-name=\(module.name)"]
31+
args += ["-L\(prefix)"]
32+
33+
for case let dep as ClangModule in module.dependencies {
34+
let includeFlag: String
35+
//add `-iquote` argument to the include directory of every target in the package in the
36+
//transitive closure of the target being built allowing the use of `#include "..."`
37+
//add `-I` argument to the include directory of every target outside the package in the
38+
//transitive closure of the target being built allowing the use of `#include <...>`
39+
40+
includeFlag = externalModules.contains(dep) ? "-I" : "-iquote"
41+
args += [includeFlag, dep.path]
42+
args += ["-l\(dep.c99name)"] //FIXME: giving path to other module's -fmodule-map-file is not linking that module
43+
}
44+
45+
switch conf {
46+
case .Debug:
47+
args += ["-g", "-O0"]
48+
case .Release:
49+
args += ["-O2"]
50+
}
51+
52+
args += module.sources.paths
53+
54+
if module.type == .Library {
55+
args += ["-shared"]
56+
}
57+
58+
args += ["-o", productPath]
59+
60+
let clang = ShellTool(
61+
description: "Compiling \(module.name)",
62+
inputs: inputs,
63+
outputs: [productPath, module.targetName],
64+
args: [Toolchain.clang] + args)
65+
66+
let command = Command(node: module.targetName, tool: clang)
67+
68+
return (command, mkdir)
69+
}
70+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright 2015 - 2016 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import PackageType
12+
import Utility
13+
14+
extension Command {
15+
static func compile(swiftModule module: SwiftModule, configuration conf: Configuration, prefix: String, otherArgs: [String]) throws -> (Command, [Command]) {
16+
17+
let otherArgs = otherArgs + module.Xcc
18+
19+
func cmd(tool: ToolProtocol) -> Command {
20+
return Command(node: module.targetName, tool: tool)
21+
}
22+
23+
switch conf {
24+
case .Debug:
25+
var args = ["-j8","-Onone","-g","-D","SWIFT_PACKAGE", "-enable-testing"]
26+
27+
#if os(OSX)
28+
if let platformPath = Toolchain.platformPath {
29+
let path = Path.join(platformPath, "Developer/Library/Frameworks")
30+
args += ["-F", path]
31+
} else {
32+
throw Error.InvalidPlatformPath
33+
}
34+
#endif
35+
let tool = SwiftcTool(module: module, prefix: prefix, otherArgs: args + otherArgs)
36+
let mkdirs = Set(tool.objects.map{ $0.parentDirectory }).map(Command.createDirectory)
37+
return (cmd(tool), mkdirs)
38+
39+
case .Release:
40+
let inputs = module.dependencies.map{ $0.targetName } + module.sources.paths
41+
var args = ["-c", "-emit-module", "-D", "SWIFT_PACKAGE", "-O", "-whole-module-optimization", "-I", prefix] + otherArgs
42+
let productPath = Path.join(prefix, "\(module.c99name).o")
43+
44+
if module.type == .Library {
45+
args += ["-parse-as-library"]
46+
}
47+
48+
let tool = ShellTool(
49+
description: "Compiling \(module.name)",
50+
inputs: inputs,
51+
outputs: [productPath, module.targetName],
52+
args: [Toolchain.swiftc, "-o", productPath] + args + module.sources.paths + otherArgs)
53+
54+
return (cmd(tool), [])
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)