Skip to content

Commit 401367b

Browse files
Linux (#156)
* refactor name common linux+mac instances * update project to linux - swift-package * update ci: add linux supports fix ci remove invalid workflows
1 parent 32dc546 commit 401367b

23 files changed

+179
-101
lines changed

Diff for: .github/workflows/deploy-docs.yml

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ jobs:
1111

1212
steps:
1313
- uses: actions/checkout@v2
14+
- name: Switch Xcode version
15+
run: sudo xcode-select -s /Applications/Xcode_11.4.1.app/Contents/Developer
1416
- name: Generate microsite
1517
run: |
1618
brew install nef

Diff for: .github/workflows/homebrew.yml

-17
This file was deleted.

Diff for: .github/workflows/nef-compile.yml

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ jobs:
99

1010
steps:
1111
- uses: actions/checkout@v2
12+
- name: Switch Xcode version
13+
run: sudo xcode-select -s /Applications/Xcode_11.4.1.app/Contents/Developer
1214
- name: Compile documentation
1315
run: |
1416
brew install nef

Diff for: .github/workflows/swift.yml

+34-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,42 @@ name: Compile and test
33
on: [pull_request]
44

55
jobs:
6-
build:
7-
6+
macos:
7+
name: macos
88
runs-on: macos-latest
99

1010
steps:
1111
- uses: actions/checkout@v2
12+
- name: Switch Xcode version
13+
run: sudo xcode-select -s /Applications/Xcode_11.4.1.app/Contents/Developer
14+
- name: Run tests
15+
run: swift test
16+
- name: Generate linux tests
17+
run: swift test --generate-linuxmain
18+
- name: Cached auto-generate linux tests
19+
uses: actions/upload-artifact@v1
20+
with:
21+
name: generate-linuxmain
22+
path: project/Tests
23+
24+
linux:
25+
name: linux
26+
needs: macos
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- uses: actions/checkout@v2
31+
- name: Clean Tests
32+
run: rm -rf project/Tests
33+
- name: Get auto-generate linux tests
34+
uses: actions/download-artifact@v1
35+
with:
36+
name: generate-linuxmain
37+
path: project/Tests
38+
- name: Remove generated artifact
39+
uses: geekyeggo/delete-artifact@v1
40+
with:
41+
name: generate-linuxmain
42+
failOnError: false
1243
- name: Run tests
13-
run: swift test --disable-sandbox --package-path project --configuration debug | xcpretty -c
44+
run: swift test

Diff for: .github/workflows/xcode.yml

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ jobs:
99

1010
steps:
1111
- uses: actions/checkout@v2
12+
- name: Switch Xcode version
13+
run: sudo xcode-select -s /Applications/Xcode_11.4.1.app/Contents/Developer
1214
- name: Compile project
1315
run: |
1416
set -o pipefail

Diff for: .gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ vendor/
3939
/Documentation.app/nef
4040
/Documentation.app/Contents/MacOS/Pods
4141
/Documentation.app/Contents/MacOS/Podfile.lock
42+
43+
## linux
44+
**/LinuxMain.swift
45+
**/XCTestManifests.swift

Diff for: Documentation.app/Contents/MacOS/Documentation.xcodeproj/project.pbxproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
7F7243B8107DB49E06C28E62 /* Pods-Documentation.debug.xcconfig */,
7171
B1BAA2B7041D48F5D67DC6E8 /* Pods-Documentation.release.xcconfig */,
7272
);
73-
name = Pods;
7473
path = Pods;
7574
sourceTree = "<group>";
7675
};
@@ -222,6 +221,7 @@
222221
DEBUG_INFORMATION_FORMAT = dwarf;
223222
ENABLE_STRICT_OBJC_MSGSEND = YES;
224223
ENABLE_TESTABILITY = YES;
224+
ENABLE_TESTING_SEARCH_PATHS = YES;
225225
GCC_C_LANGUAGE_STANDARD = gnu11;
226226
GCC_DYNAMIC_NO_PIC = NO;
227227
GCC_NO_COMMON_BLOCKS = YES;
@@ -283,6 +283,7 @@
283283
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
284284
ENABLE_NS_ASSERTIONS = NO;
285285
ENABLE_STRICT_OBJC_MSGSEND = YES;
286+
ENABLE_TESTING_SEARCH_PATHS = YES;
286287
GCC_C_LANGUAGE_STANDARD = gnu11;
287288
GCC_NO_COMMON_BLOCKS = YES;
288289
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;

Diff for: Package.swift

+94-37
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// swift-tools-version:5.2
22
import PackageDescription
33

4-
// MARK: - Dependencies
4+
// MARK: - Target.Dependencies
55
extension Target.Dependency {
66
static var bow: Target.Dependency {
77
.product(name: "Bow", package: "Bow")
@@ -18,10 +18,6 @@ extension Target.Dependency {
1818
static var swiftLine: Target.Dependency {
1919
.product(name: "Swiftline", package: "Swiftline")
2020
}
21-
22-
static var argumentParser: Target.Dependency {
23-
.product(name: "ArgumentParser", package: "swift-argument-parser")
24-
}
2521
}
2622

2723
extension Target {
@@ -33,7 +29,18 @@ extension Target {
3329
// MARK: - Libraries
3430
extension Target {
3531
static var modules: [Target] {
36-
[
32+
#if os(Linux)
33+
return [
34+
.nefModels,
35+
.nefCommon,
36+
.nefCore,
37+
.nefRender,
38+
.nefMarkdown,
39+
.nefJekyll,
40+
.nefPlaygroundBook,
41+
]
42+
#else
43+
return [
3744
.nefModels,
3845
.nefCommon,
3946
.nefCore,
@@ -46,14 +53,24 @@ extension Target {
4653
.nefPlayground,
4754
.nefPlaygroundBook,
4855
]
56+
#endif
4957
}
5058

5159
static var nefModels: Target {
52-
.target(name: "NefModels",
53-
dependencies: [.bow,
54-
.bowEffects,
55-
.bowOptics],
56-
path: "project/Component/NefModels")
60+
#if os(Linux)
61+
return .target(name: "NefModels",
62+
dependencies: [.bow,
63+
.bowEffects,
64+
.bowOptics],
65+
path: "project/Component/NefModels",
66+
exclude: ["CarbonView.swift"])
67+
#else
68+
return .target(name: "NefModels",
69+
dependencies: [.bow,
70+
.bowEffects,
71+
.bowOptics],
72+
path: "project/Component/NefModels")
73+
#endif
5774
}
5875

5976
static var nefCommon: Target {
@@ -119,9 +136,21 @@ extension Target {
119136

120137
extension Target {
121138
static var nef: Target {
122-
.target(name: "nef",
123-
dependencies: [.swiftLine] + Target.modules.map { $0.asDependency },
124-
path: "project/Component/nef")
139+
#if os(Linux)
140+
return .target(name: "nef",
141+
dependencies: [.swiftLine] + Target.modules.map { $0.asDependency },
142+
path: "project/Component/nef",
143+
exclude: ["CleanAPI.swift",
144+
"CompilerAPI.swift",
145+
"CarbonAPI.swift",
146+
"PlaygroundAPI.swift",
147+
"Instances/MacCompilerShell.swift",
148+
"Instances/MacNefPlaygroundSystem.swift"])
149+
#else
150+
return .target(name: "nef",
151+
dependencies: [.swiftLine] + Target.modules.map { $0.asDependency },
152+
path: "project/Component/nef")
153+
#endif
125154
}
126155
}
127156

@@ -161,7 +190,7 @@ extension Target {
161190

162191
static var cliKit: Target {
163192
.target(name: "CLIKit",
164-
dependencies: [.argumentParser,
193+
dependencies: [.product(name: "ArgumentParser", package: "swift-argument-parser"),
165194
Target.nef.asDependency],
166195
path: "project/UI",
167196
exclude: ["Nef/main.swift",
@@ -290,29 +319,57 @@ extension Product {
290319
}
291320
}
292321

322+
// MARK: - Package
323+
extension Package.Dependency {
324+
static var dependencies: [Package.Dependency] {
325+
#if os(Linux)
326+
return [
327+
.package(name: "Bow", url: "https://github.com/bow-swift/bow.git", .branch("master")),
328+
.package(url: "https://github.com/bow-swift/Swiftline.git", .exact("0.5.5")),
329+
]
330+
#else
331+
return [
332+
.package(name: "Bow", url: "https://github.com/bow-swift/bow.git", .branch("master")),
333+
.package(url: "https://github.com/bow-swift/Swiftline.git", .exact("0.5.5")),
334+
.package(url: "https://github.com/apple/swift-argument-parser", .exact("0.0.5")),
335+
]
336+
#endif
337+
}
338+
}
339+
340+
extension Target {
341+
static var targets: [Target] {
342+
#if os(Linux)
343+
return [
344+
Target.modules,
345+
Target.tests,
346+
[Target.nef],
347+
].flatMap { $0 }
348+
#else
349+
return [
350+
Target.modules,
351+
Target.tests,
352+
Target.ui,
353+
[Target.nef],
354+
].flatMap { $0 }
355+
#endif
356+
}
357+
}
358+
359+
extension Product {
360+
static var products: [Product] {
361+
#if os(Linux)
362+
return [Product.nef]
363+
#else
364+
return [Product.nef] + Product.cli
365+
#endif
366+
}
367+
}
293368

294369
let package = Package(
295370
name: "nef",
296-
297-
platforms: [
298-
.macOS(.v10_14),
299-
],
300-
301-
products: [
302-
[Product.nef],
303-
Product.cli,
304-
].flatMap { $0 },
305-
306-
dependencies: [
307-
.package(name: "Bow", url: "https://github.com/bow-swift/bow.git", .branch("master")),
308-
.package(url: "https://github.com/bow-swift/Swiftline.git", .exact("0.5.5")),
309-
.package(url: "https://github.com/apple/swift-argument-parser", .exact("0.0.5")),
310-
],
311-
312-
targets: [
313-
Target.modules,
314-
Target.tests,
315-
Target.ui,
316-
[Target.nef],
317-
].flatMap { $0 }
371+
platforms: [.macOS(.v10_14)],
372+
products: Product.products,
373+
dependencies: Package.Dependency.dependencies,
374+
targets: Target.targets
318375
)

Diff for: project/Component/nef/CarbonAPI.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,9 @@ public enum Carbon: CarbonAPI {
301301
private static func environment(progressReport: ProgressReport, style: CarbonStyle) -> NefCarbon.Carbon.Environment {
302302
NefCarbon.Carbon.Environment(
303303
progressReport: progressReport,
304-
fileSystem: MacFileSystem(),
304+
fileSystem: UnixFileSystem(),
305305
persistence: .init(),
306-
xcodePlaygroundSystem: MacXcodePlaygroundSystem(),
306+
xcodePlaygroundSystem: UnixPlaygroundSystem(),
307307
style: style,
308308
carbonPrinter: CoreRender.carbon.render)
309309
}

Diff for: project/Component/nef/CleanAPI.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public enum Clean: CleanAPI {
2525
.contramap { progressReport in
2626
CleanEnvironment(
2727
progressReport: progressReport,
28-
fileSystem: MacFileSystem(),
28+
fileSystem: UnixFileSystem(),
2929
shell: MacNefPlaygroundSystem()) }
3030
.mapError { e in nef.Error.compiler(info: "clean: \(e)") }
3131
}

Diff for: project/Component/nef/CompilerAPI.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ public enum Compiler: CompilerAPI {
7171
private static func environment(progressReport: ProgressReport) -> NefCompiler.Compiler.Environment {
7272
.init(
7373
progressReport: progressReport,
74-
fileSystem: MacFileSystem(),
74+
fileSystem: UnixFileSystem(),
7575
compilerShell: MacCompilerShell(),
7676
nefPlaygroundSystem: MacNefPlaygroundSystem(),
77-
xcodePlaygroundSystem: MacXcodePlaygroundSystem(),
77+
xcodePlaygroundSystem: UnixPlaygroundSystem(),
7878
codePrinter: CoreRender.code.render)
7979
}
8080
}

Diff for: project/Component/nef/Instances/MacCompilerShell.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import Swiftline
77
import Bow
88
import BowEffects
99

10-
11-
class MacCompilerShell: CompilerShell {
10+
final class MacCompilerShell: CompilerShell {
1211

1312
func podinstall(project: URL, platform: Platform, cached: Bool) -> IO<CompilerShellError, Void> {
1413
IO.invoke {

Diff for: project/Component/nef/Instances/MacNefPlaygroundSystem.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Bow
77
import BowEffects
88
import Swiftline
99

10-
class MacNefPlaygroundSystem: NefPlaygroundSystem {
10+
final class MacNefPlaygroundSystem: NefPlaygroundSystem {
1111

1212
func installTemplate(into output: URL, name: String, platform: Platform) -> EnvIO<FileSystem, NefPlaygroundSystemError, NefPlaygroundURL> {
1313
func existPlayground(at output: URL, name: String) -> EnvIO<FileSystem, NefPlaygroundSystemError, Void> {
@@ -366,7 +366,7 @@ class MacNefPlaygroundSystem: NefPlaygroundSystem {
366366
}
367367
}
368368

369-
func createCocoaPodsWorkspace(playground: NefPlaygroundURL) -> EnvIO<FileSystem, NefPlaygroundSystemError, Void> {
369+
private func createCocoaPodsWorkspace(playground: NefPlaygroundURL) -> EnvIO<FileSystem, NefPlaygroundSystemError, Void> {
370370
EnvIO.invoke { _ in
371371
let result = run("pod", args: ["install", "--project-directory=\(playground.appending(.contentFiles).path)"])
372372
guard result.exitStatus == 0 else {

Diff for: project/Component/nef/Instances/MacFileSytem.swift renamed to project/Component/nef/Instances/UnixFileSystem.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import NefCommon
55
import Bow
66
import BowEffects
77

8-
class MacFileSystem: NefCommon.FileSystem {
8+
final class UnixFileSystem: NefCommon.FileSystem {
99

1010
func createDirectory(atPath path: String) -> IO<FileSystemError, ()> {
1111
FileManager.default.createDirectoryIO(atPath: path, withIntermediateDirectories: true)

Diff for: project/Component/nef/Instances/MacPackageShell.swift renamed to project/Component/nef/Instances/UnixPackageShell.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import NefSwiftPlayground
55
import BowEffects
66
import Swiftline
77

8-
class MacPackageShell: PackageShell {
8+
final class UnixPackageShell: PackageShell {
99

1010
func resolve(packagePath: String, buildPath: String) -> IO<PackageShellError, Void> {
1111
IO.invoke {

Diff for: project/Component/nef/Instances/MacXcodePlaygroundSystem.swift renamed to project/Component/nef/Instances/UnixPlaygroundSystem.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import NefCommon
55
import Bow
66
import BowEffects
77

8-
class MacXcodePlaygroundSystem: XcodePlaygroundSystem {
8+
final class UnixPlaygroundSystem: XcodePlaygroundSystem {
99

1010
func xcodeprojs(at folder: URL) -> EnvIO<FileSystem, XcodePlaygroundSystemError, NEA<URL>> {
1111
func nea(from xcodeprojs: [URL], inFolder folder: URL) -> IO<XcodePlaygroundSystemError, NEA<URL>> {

0 commit comments

Comments
 (0)