Skip to content

Add new manifest option to swift package init #2106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions Sources/Workspace/InitPackage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public final class InitPackage {
case library = "library"
case executable = "executable"
case systemModule = "system-module"
case manifest = "manifest"

public var description: String {
return rawValue
Expand Down Expand Up @@ -63,6 +64,11 @@ public final class InitPackage {
// FIXME: We should form everything we want to write, then validate that
// none of it exists, and then act.
try writeManifestFile()

if packageType == .manifest {
return
}

try writeREADMEFile()
try writeGitIgnore()
try writeSources()
Expand Down Expand Up @@ -96,7 +102,7 @@ public final class InitPackage {
name: "\(pkgname)"
""")

if packageType == .library {
if packageType == .library || packageType == .manifest {
pkgParams.append("""
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
Expand All @@ -114,7 +120,7 @@ public final class InitPackage {
]
""")

if packageType == .library || packageType == .executable {
if packageType == .library || packageType == .executable || packageType == .manifest {
pkgParams.append("""
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down Expand Up @@ -176,7 +182,7 @@ public final class InitPackage {
}

private func writeSources() throws {
if packageType == .systemModule {
if packageType == .systemModule || packageType == .manifest {
return
}
let sources = destinationPath.appending(component: "Sources")
Expand Down Expand Up @@ -210,7 +216,7 @@ public final class InitPackage {
print("Hello, world!")

"""
case .systemModule, .empty:
case .systemModule, .empty, .manifest:
fatalError("invalid")
}
}
Expand Down Expand Up @@ -249,7 +255,7 @@ public final class InitPackage {
try makeDirectories(tests)

switch packageType {
case .systemModule, .empty: break
case .systemModule, .empty, .manifest: break
case .library, .executable:
try writeLinuxMain(testsPath: tests)
try writeTestFileStubs(testsPath: tests)
Expand Down Expand Up @@ -356,7 +362,7 @@ public final class InitPackage {

let testClassFile = testModule.appending(RelativePath("\(moduleName)Tests.swift"))
switch packageType {
case .systemModule, .empty: break
case .systemModule, .empty, .manifest: break
case .library:
try writeLibraryTestsFile(testClassFile)
case .executable:
Expand Down
27 changes: 27 additions & 0 deletions Tests/WorkspaceTests/InitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,33 @@ class InitTests: XCTestCase {
XCTAssert(fs.exists(path.appending(component: "module.modulemap")))
}
}

func testInitManifest() throws {
mktmpdir { tmpPath in
let fs = localFileSystem
let path = tmpPath.appending(component: "Foo")
let name = path.basename
try fs.createDirectory(path)

// Create the package
let initPackage = try InitPackage(name: name, destinationPath: path, packageType: InitPackage.PackageType.manifest)
var progressMessages = [String]()
initPackage.progressReporter = { message in
progressMessages.append(message)
}
try initPackage.writePackageStructure()

// Not picky about the specific progress messages, just checking that we got some.
XCTAssert(progressMessages.count > 0)

// Verify basic file system content that we expect in the package
let manifest = path.appending(component: "Package.swift")
XCTAssertTrue(fs.exists(manifest))
let manifestContents = try localFileSystem.readFileContents(manifest).description
let version = "\(InitPackage.newPackageToolsVersion.major).\(InitPackage.newPackageToolsVersion.minor)"
XCTAssertTrue(manifestContents.hasPrefix("// swift-tools-version:\(version)\n"))
}
}

// MARK: Special case testing

Expand Down
1 change: 1 addition & 0 deletions Tests/WorkspaceTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extension InitTests {
// `swift test --generate-linuxmain`
// to regenerate.
static let __allTests__InitTests = [
("testInitManifest", testInitManifest),
("testInitPackageEmpty", testInitPackageEmpty),
("testInitPackageExecutable", testInitPackageExecutable),
("testInitPackageLibrary", testInitPackageLibrary),
Expand Down