Skip to content

Commit 0ddcd0f

Browse files
committed
[Documentation] Tidy up reference section.
1 parent 3392287 commit 0ddcd0f

File tree

1 file changed

+96
-70
lines changed

1 file changed

+96
-70
lines changed

Documentation/Reference.md

Lines changed: 96 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* [Source Layouts](#source-layouts)
1010
* [Other Rules](#other-rules)
1111
* [Package Manifest File Format Reference](#package-manifest-file-format-reference)
12+
* [Package Declaration](#package-declaration)
1213
* [Package](#package)
1314
* [Package Dependency](#package-dependency)
1415
* [Version](#version)
@@ -27,57 +28,82 @@
2728

2829
The modules that `swift build` creates are determined from the filesystem layout of your source files.
2930

30-
For example, if you created a directory with the following layout:
31+
For example, if you create a directory with the following layout:
3132

3233
example/
3334
example/Sources/bar.swift
3435
example/Sources/baz.swift
3536

36-
Running `swift build` within directory `example` would produce a single library target: `example/.build/debug/example.a`
37+
this defines a single module (named after the package name from `Package.swift).
3738

38-
To create multiple modules create multiple subdirectories:
39+
To create multiple modules, you can create multiple subdirectories:
3940

40-
example/Sources/foo/foo.swift
41-
example/Sources/bar/bar.swift
41+
example/Sources/Foo/Widget.swift
42+
example/Sources/Bar/Bazzer.swift
4243

43-
Running `swift build` would produce two library targets:
44-
45-
* `example/.build/debug/foo.a`
46-
* `example/.build/debug/bar.a`
44+
which would define two modules, `Foo` and `Bar`.
4745

4846
To generate an executable module (instead of a library module) add a `main.swift` file to that module’s subdirectory:
4947

5048
example/Sources/foo/main.swift
51-
example/Sources/bar/bar.swift
5249

53-
Running `swift build` would now produce:
50+
and `swift build` will now produce an:
5451

5552
* `example/.build/debug/foo`
56-
* `example/.build/debug/bar.a`
5753

58-
Where `foo` is an executable and `bar.a` a static library.
54+
executable output file.
55+
56+
### Test Suite Layouts
57+
58+
The package manager supports laying out test sources following a similar convention as primary sources:
59+
60+
example/Tests/FooTests/WidgetTests.swift
61+
62+
defined a `FooTests` test suite. By convention, when there is a sources module `Foo` and a matching tests module `FooTests`, the package manager will establish an implicit dependency between the test suite and the target it assumes it is trying to test.
63+
64+
On Linux, the `XCTest` testing framework does not support dynamic discovery of tests. Instead, packages which are intended for use on Linux should include a:
65+
66+
example/Tests/LinuxMain.swift
67+
68+
file which imports all of the individual test suites in the package, and then invokes `XCTest.XCTMain` passing it the list of all tests.
5969

6070
### Other Rules
6171

62-
* Sub directories of directory named `Tests` become test-modules and are executed by `swift test`. `Tests` or any subdirectory can be excluded via Manifest file. The package manager will add an implicit dependency between the test suite and the target it assumes it is trying to test when the sub directory in `Tests` and package *name* are the same.
63-
* Sub directories of a directory named `Sources`, `Source`, `srcs` or `src` become modules.
72+
* `Tests` or any other subdirectory can be excluded via Manifest file. The package manager will add an implicit dependency between the test suite and the target it assumes it is trying to test when the sub directory in `Tests` and package *name* are the same.
73+
* Subdirectories of a directory named `Sources`, `Source`, `srcs` or `src` become modules.
6474
* It is acceptable to have no `Sources` directory, in which case the root directory is treated as a single module (place your sources there) or sub directories of the root are considered modules. Use this layout convention for simple projects.
6575

6676
---
6777

6878
## Package Manifest File Format Reference
6979

70-
Instructions for how to build a package are provided by the `Package.swift` manifest file. `Package.swift` is a Swift file defining a single `Package` object. The Package is configured via the APIs used to form that object.
80+
Instructions for how to build a package are provided by the `Package.swift` manifest file. `Package.swift` is a Swift file defining a single `Package` object. This object is configured via the APIs defined in the `PackageDescription` Swift module supplied with the Swift Package Manager.
81+
82+
### Package Declaration
83+
84+
Every `Package.swift` file should follow the following format:
85+
86+
```swift
87+
import PackageDescription
88+
89+
/// The package description.
90+
let package = Package(/* ... */)
91+
92+
// ... subsequent package configuration APIs can be used here to further
93+
// configure the package ...
94+
```
95+
96+
Conceptually, the description defined by the `Package.swift` file is _combined_ with the information on the package derived from the filesystem conventions described previously.
7197

7298
### Package
7399

74100
```swift
75101
Package(
76-
name: String,
77-
pkgConfig: String? = nil,
78-
providers: [SystemPackageProvider]? = nil,
79-
targets: [Target] = [],
80-
dependencies: [Dependency] = [],
102+
name: String,
103+
pkgConfig: String? = nil,
104+
providers: [SystemPackageProvider]? = nil,
105+
targets: [Target] = [],
106+
dependencies: [Package.Dependency] = [],
81107
exclude: [String] = []
82108
)
83109
```
@@ -89,7 +115,9 @@ Package(
89115
\- [dependencies](#dependencies): Declare dependencies on external packages.
90116
\- [exclude](#exclude): Exclude files and directories from package sources.
91117

92-
### name
118+
Creates a new package instance. There should only be one package declared per manifest. The parameters here supply the package description and are documented in further detail below.
119+
120+
#### name
93121

94122
```swift
95123
import PackageDescription
@@ -99,31 +127,30 @@ let package = Package(
99127
)
100128
```
101129

102-
It is the minimal requirement for a manifest to be valid. When the sources are located directly under `Sources/` directory, there is only one module and the module name is same as the package name.
130+
This is the minimal requirement for a manifest to be valid. When the sources are located directly under `Sources/` directory, there is only one module and the module name will be the same as the package name.
103131

104-
### targets
132+
#### targets
105133

106-
Targets property is used when you have more than one module in your package and want to declare a dependency between them.
134+
The targets property is required when you have more than one module in your package and need to declare a dependency between them.
107135

108136
```swift
109137
import PackageDescription
110138

111139
let package = Package(
112140
name: "Hello",
113141
targets: [
114-
Target(name: "TestSupport"),
115142
Target(name: "Bar", dependencies: ["Foo"]),
116143
]
117144
)
118145
```
119146

120-
Here `Foo` and `Bar` are modules present under `Sources/` directory. `Foo` module will be built before `Bar` module and `Bar` can import `Foo` if `Foo` is a library.
147+
The name identifies which target (or module) the information is being associated with, and the list of dependencies specifies the names of other targets in the same package which must be built before that target. In the example here, `Foo` and `Bar` are modules present under `Sources/` directory, and a dependency is being establish on `Foo` from `Bar`. This will cause the `Foo` module to be built before `Bar` module so that it can be imported:
121148

122-
Note: It is also possible to declare target dependencies between a test and regular module.
149+
_NOTE: It is also possible to declare target dependencies between a test and regular module._
123150

124-
### dependencies
151+
#### dependencies
125152

126-
This is the list of packages that the current package depends on. You can specify a URL (or local path) to any valid Swift package.
153+
This is the list of packages that the current package depends on and information about the required versions. You can specify a URL (or local path) to any valid Swift package.
127154

128155
```swift
129156
import PackageDescription
@@ -138,9 +165,9 @@ let package = Package(
138165
)
139166
```
140167

141-
See [Package Dependency](#package-dependency).
168+
This is a list of `Package.Dependency` instances, see [Package Dependency](#package-dependency) for available options.
142169

143-
### exclude
170+
#### exclude
144171

145172
Use this property to exclude files and directories from the package sources.
146173

@@ -156,7 +183,7 @@ let package = Package(
156183
This is helpful when you want to place files like resources or fixtures that should not be considered by the convention system
157184
as possible sources.
158185

159-
### pkgConfig
186+
#### pkgConfig
160187

161188
This property should only be used for System Module Packages. It defines the name of the pkg-config (.pc) file
162189
that should be searched and read to get the additional flags like include search path, linker search path, system libraries
@@ -174,15 +201,14 @@ let package = Package(
174201
Here `gtk+-3.0.pc` will be searched in standard locations for the current system. Users can provide their own paths for location of pc files
175202
using the environment variable, `PKG_CONFIG_PATH`, which will be searched before the standard locations.
176203

177-
Note: This feature does not require pkg-config to be installed. However, if installed it will used to find additional platform specific pc file
178-
locations which might be unknown to SwiftPM.
204+
_NOTE: This feature does not require pkg-config to be installed. However, if installed it will used to find additional platform specific pc filelocations which might be unknown to SwiftPM._
179205

180-
### providers
206+
#### providers
181207

182208
This property should only be used for system module packages. It can be used to provide _hints_ for other users to install a System Module using
183209
a system package manager like homebrew, apt-get etc.
184210

185-
Note: SwiftPM will *never* execute the command and only suggest the users to run it.
211+
_NOTE: SwiftPM will *never* execute the command and only suggest the users to run it._
186212

187213
```swift
188214
import PackageDescription
@@ -202,70 +228,72 @@ the user is on i.e. macOS, Ubuntu, etc.
202228

203229
### Package Dependency
204230

205-
Package Dependency represents location and Version range of an external dependency.
231+
A `Package.Dependency` represents the location and and required version information of an external dependency. The version range controls what versions of a package dependency are expected to work with the current package. When the package manager is fetching the complete set of packages required to build a package, it considers all of the version range specifications from all of the packages in order to select appropriate versions.
206232

207233
```swift
208-
Dependency.Package(url: String, versions: Range<Version>)
234+
.Package(url: String, versions: Range<Version>)
209235
```
210-
\- url: URL or local path to a Package.
211-
\- versions: A range of [Version](#version).
236+
\- *url*: URL or local path to a Package.
237+
\- *versions*: The range of [versions](#version) which are required.
212238

213239
```swift
214-
Dependency.Package(url: String, versions: ClosedRange<Version>)
240+
.Package(url: String, versions: ClosedRange<Version>)
215241
```
216-
\- url: URL or local path to a Package.
217-
\- versions: A closed range of [Version](#version).
242+
\- *url*: URL or local path to a Package.
243+
\- *versions*: The closed range of [versions](#version) which are required.
218244

219245
```swift
220-
Dependency.Package(url: String, majorVersion: Int)
246+
.Package(url: String, majorVersion: Int)
221247
```
222-
\- url: URL or local path to a Package.
223-
\- majorVersion: Major version to consider. Latest available minor Version will be considered.
248+
\- *url*: URL or local path to a Package.
249+
\- *majorVersion*: The major version which is required.
224250

251+
This is a short-hand form for specifying a range including all versions of a major version, and is the recommended way for specifying a dependency following the [semantic versioning](http://semver.org) standard.
225252

226253
```swift
227-
Dependency.Package(url: String, majorVersion: Int, minor: Int)
254+
.Package(url: String, majorVersion: Int, minor: Int)
228255
```
229-
\- url: URL or local path to a Package.
230-
\- majorVersion: Major version to consider.
231-
\- minor: Minor version to consider.
256+
\- *url*: URL or local path to a Package.
257+
\- *majorVersion*: Major version to consider.
258+
\- *minor*: Minor version to consider.
259+
260+
As for the prior API, this is a short-hand form for specifying a range that inclues all versions of a major and minor version.
232261

233262
```swift
234-
Dependency.Package(url: String, _ version: Version)
263+
.Package(url: String, _ version: Version)
235264
```
236-
\- url: URL or local path to a Package.
237-
\- version: The specific [Version](#version) to consider.
238-
265+
\- *url*: URL or local path to a Package.
266+
\- *version*: The exact [Version](#version) which is required.
267+
239268
### Version
240269

241-
A struct representing [Semantic Versioning](http://semver.org).
270+
A struct representing a [semantic version](http://semver.org).
242271

243272
```swift
244273
Version(
245-
_ major: Int,
246-
_ minor: Int,
274+
_ major: Int,
275+
_ minor: Int,
247276
_ patch: Int,
248-
prereleaseIdentifiers: [String] = [],
277+
prereleaseIdentifiers: [String] = [],
249278
buildMetadataIdentifier: String? = nil
250279
)
251280
```
252281

253-
\- major: The major version, incremented when you make incompatible API changes.
254-
\- minor: The minor version, incremented when you add functionality in a backwards-compatible manner.
255-
\- patch: The patch version, incremented when you make backwards-compatible bug fixes.
256-
\- prereleaseIdentifiers: Used to denote a pre-released version for eg: alpha, beta, etc.
257-
\- buildMetadataIdentifier: Optional build meta data for eg: timestamp, hash, etc.
282+
\- *major*: The major version, incremented when you make incompatible API changes.
283+
\- *minor*: The minor version, incremented when you add functionality in a backwards-compatible manner.
284+
\- *patch*: The patch version, incremented when you make backwards-compatible bug fixes.
285+
\- *prereleaseIdentifiers*: Used to denote a pre-released version for eg: alpha, beta, etc.
286+
\- *buildMetadataIdentifier*: Optional build meta data for eg: timestamp, hash, etc.
258287

259-
Version can be initialized using a string literal in following format:
288+
A `Version` struct can be initialized using a string literal in following format:
260289

261290
``` "major.minor.patch[-prereleaseIdentifiers][+buildMetadata]" ```
262291

263-
prereleaseIdentifiers and buildMetadata are optional.
264-
Note: prereleaseIdentifiers are separated by dot (.)
292+
where `prereleaseIdentifiers` and `buildMetadata` are optional. _NOTE: prereleaseIdentifiers are separated by dot (.)._
265293

266294
### Customizing Builds
267295

268-
That the manifest is Swift allows for powerful customization, for example:
296+
Using Swift as the format for the manifest allows for powerful customization, for example:
269297

270298
```swift
271299
import PackageDescription
@@ -313,5 +341,3 @@ A C language target is build with following flags in release mode:
313341
### Depending on Apple Modules
314342

315343
At this time there is no explicit support for depending on Foundation, AppKit, etc, though importing these modules should work if they are present in the proper system location. We will add explicit support for system dependencies in the future. Note that at this time the Package Manager has no support for iOS, watchOS, or tvOS platforms.
316-
317-

0 commit comments

Comments
 (0)