Skip to content
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

[platform][feature] Use swift CLI instead of Commandant #117

Merged
merged 8 commits into from
Apr 21, 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
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,18 @@ jobs:
- store_test_results:
path: << parameters.test-results-dir >>

generate_linux_main:
generate_linuxmain:
executor: mac
steps:
- checkout
- attach
- run: make update_build_number
- run: swift test --package-path Tests --generate-linuxmain
- run: make linuxmain
- persist_to_workspace:
root: .
paths:
- Tests/LinuxMain.swift
- Tests/FinchAppTests/XCTestManifests.swift
- LinuxMain.swift
- Tests/XCTestManifests.swift

test_linux:
executor: linux
Expand Down Expand Up @@ -233,9 +233,9 @@ workflows:
ignore: /.*/
tags:
only: /.*/
- generate_linux_main:
- generate_linuxmain:
requires:
- resolve
- test_linux:
requires:
- generate_linux_main
- generate_linuxmain
16 changes: 10 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ ORG_IDENTIFIER=org.$(APP_NAME_LOWERCASE).$(APP_NAME_LOWERCASE)
OUTPUT_PACKAGE=$(APP_NAME).pkg
PIPEFAIL=set -o pipefail
SWIFT_BUILD_FLAGS=--configuration release
TEST=FINCH_TESTS=1 swift test
UNAME=$(shell uname)
VERSION_FILE=./Sources/$(APP_NAME)/App/Version.swift
VERSION_STRING=$(shell cat $(VERSION_FILE) | grep appVersion | sed -n -e 's/^.*(//p' | tr -d ") " | tr "," ".")
Expand All @@ -29,7 +30,7 @@ VERSION_STRING=$(shell cat $(VERSION_FILE) | grep appVersion | sed -n -e 's/^.*(
RM_SAFELY := bash -c '[[ ! $${1:?} =~ "^[[:space:]]+\$$" ]] && [[ $${1:A} != "/" ]] && [[ $${\#} == "1" ]] && set -o noglob && rm -rf $${1:A}' --


.PHONY: all build build_with_disable_sandbox config_template install lint package prefix_install xcodeproj publish symlink test update_build_number update_version
.PHONY: all build build_with_disable_sandbox config_template install lint linuxmain package prefix_install project publish symlink test update_build_number update_version

all: install

Expand All @@ -44,7 +45,7 @@ config_template:
$(MKDIR) $(INSTALL_DIR)
$(CP) Resources/$(CONFIG_TEMPLATE) $(INSTALL_DIR)/

docs: xcodeproj
docs: project
$(JAZZY) --config .jazzy/FinchApp.yml -o $(DOCS)/FinchApp
$(JAZZY) --config .jazzy/FinchCore.yml -o $(DOCS)/FinchCore

Expand All @@ -55,6 +56,9 @@ install: build symlink config_template
lint:
swift run --package-path .devtools swiftlint --strict

linuxmain:
$(TEST) --generate-linuxmain

package: build
$(MKDIR) $(APP_TMP)
$(CP) $(APP_EXECUTABLE) $(APP_TMP)
Expand Down Expand Up @@ -107,9 +111,9 @@ symlink: build
test: update_build_number
@$(RM_SAFELY) ./.build/debug/$(APP_NAME)PackageTests.xctest
ifeq ($(UNAME), Darwin)
$(PIPEFAIL) && swift test --package-path Tests 2>&1 | xcpretty -r junit --output build/reports/test/junit.xml
$(PIPEFAIL) && $(TEST) 2>&1 | xcpretty -r junit --output build/reports/test/junit.xml
else
swift test --package-path Tests
$(TEST)
endif

update_build_number:
Expand All @@ -126,8 +130,8 @@ ifdef NEW_VERSION
@echo "import Version\n\nlet appVersion: Version = .init($(MAJOR), $(MINOR), $(PATCH))" > $(VERSION_FILE)
endif

xcodeproj:
swift package generate-xcodeproj --enable-code-coverage
project:
FINCH_TESTS=1 swift package generate-xcodeproj --enable-code-coverage

%:
@:
35 changes: 4 additions & 31 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,12 @@
"object": {
"pins": [
{
"package": "Commandant",
"repositoryURL": "https://github.com/Carthage/Commandant.git",
"package": "SwiftCLI",
"repositoryURL": "https://github.com/jakeheis/SwiftCLI",
"state": {
"branch": null,
"revision": "ab68611013dec67413628ac87c1f29e8427bc8e4",
"version": "0.17.0"
}
},
{
"package": "Curry",
"repositoryURL": "https://github.com/thoughtbot/Curry.git",
"state": {
"branch": null,
"revision": "4331dd50bc1db007db664a23f32e6f3df93d4e1a",
"version": "4.0.2"
}
},
{
"package": "Nimble",
"repositoryURL": "https://github.com/Quick/Nimble.git",
"state": {
"branch": null,
"revision": "43304bf2b1579fd555f2fdd51742771c1e4f2b98",
"version": "8.0.1"
}
},
{
"package": "Quick",
"repositoryURL": "https://github.com/Quick/Quick.git",
"state": {
"branch": null,
"revision": "94df9b449508344667e5afc7e80f8bcbff1e4c37",
"version": "2.1.0"
"revision": "5318c37d3cacc8780f50b87a8840a6774320ebdf",
"version": "5.2.2"
}
},
{
Expand Down
59 changes: 34 additions & 25 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,41 +1,50 @@
// swift-tools-version:4.2

import Foundation
import PackageDescription

var dependencies: [Package.Dependency] = [
.package(url: "https://github.com/Carthage/Commandant.git", from: "0.16.0"),
.package(url: "https://github.com/thoughtbot/Curry.git", from: "4.0.0"),
.package(url: "https://github.com/jpsim/Yams.git", from: "2.0.0"),
.package(url: "https://github.com/mxcl/Version.git", from: "1.0.0")
.package(url: "https://github.com/jakeheis/SwiftCLI", from: "5.0.0"),
.package(url: "https://github.com/jpsim/Yams.git", from: "2.0.0"),
.package(url: "https://github.com/mxcl/Version.git", from: "1.0.0")
]

var finchDependencies: [Target.Dependency] = ["FinchCore", "Commandant", "Curry", "Version"]
var finchDependencies: [Target.Dependency] = ["FinchCore", "SwiftCLI", "Version"]

#if swift(>=5.0)
dependencies.append(.package(url: "https://github.com/antitypical/Result.git", from:"4.1.0"))
finchDependencies.append("Result")
#endif
var targets: [Target] = [
.target(
name: "Finch",
dependencies: ["FinchApp"]),
.target(
name: "FinchApp",
dependencies: finchDependencies),
.target(
name: "FinchCore",
dependencies: ["FinchUtilities"]),
.target(
name: "FinchUtilities",
dependencies: ["Yams"])
]

if ProcessInfo.processInfo.environment["FINCH_TESTS"] != nil {
targets.append(
.testTarget(
name: "FinchAppTests",
dependencies: ["FinchApp", "SnapshotTesting", "Yams"],
path: "Tests"
)
)
dependencies.append(
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.1.0")
)
}

let package = Package(
name: "Finch",
products: [
.executable(name: "finch", targets: ["Finch"]),
.library(name: "FinchApp", targets: ["FinchApp"])
.executable(name: "finch", targets: ["Finch"])
],
dependencies: dependencies,
targets: [
.target(
name: "Finch",
dependencies: ["FinchApp"]),
.target(
name: "FinchApp",
dependencies: finchDependencies),
.target(
name: "FinchCore",
dependencies: ["FinchUtilities"]),
.target(
name: "FinchUtilities",
dependencies: ["Yams"])
],
targets: targets,
swiftLanguageVersions: [.v4, .v4_2, .version("5")]
)
10 changes: 5 additions & 5 deletions Sources/Finch/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import FinchApp
import Foundation

let processInfo: ProcessInfo = .processInfo

let meta: App.Meta = .init(
buildNumber: appBuildNumber,
name: appName,
version: appVersion
)

AppRunner(
environment: processInfo.environment,
let result = AppRunner(
environment: ProcessInfo.processInfo.environment,
meta: meta
).run(arguments: processInfo.arguments)
).run(with: CommandLine.arguments)

exit(result)
54 changes: 13 additions & 41 deletions Sources/FinchApp/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// Copyright © 2019 DHL. All rights reserved.
//

import Commandant
import struct FinchCore.Configuration
import FinchUtilities
import Version
Expand All @@ -33,63 +32,36 @@ public struct App {
}
}

/// Abstract base class of app options received from the commandline.
class Options {
enum Key: String {
case configPath = "config"
case projectDir = "project-dir"
case verbose = "verbose"
}

/// Path to config
var configPath: String?

/// The project directory if it is not the current working directory.
var projectDir: String?

/// Execute with verbose output.
var verbose: Bool

init(configPath: String?, projectDir: String?, verbose: Bool) {
self.configPath = configPath
self.projectDir = projectDir
self.verbose = verbose
}
}

/// The app's derived configuration.
let configuration: Configuration

/// The app's current environment
let environment: Environment

/// The app's meta-information.
let meta: Meta

/// The app's options derived from the commandline.
let options: Options
/// Output should be verbose
let verbose: Bool

/// The current print destination for the app,
private let output: OutputType

/// :nodoc:
init(configuration: Configuration, meta: Meta, options: Options, output: OutputType = Output.instance) {
init(configuration: Configuration,
environment: Environment = [:],
meta: Meta,
verbose: Bool = false,
output: OutputType = Output.instance) {
self.configuration = configuration
self.environment = environment
self.meta = meta
self.options = options
self.output = output
self.verbose = verbose
}

/// Prints to the app's output.
func print(_ value: String, kind: Output.Kind = .default) {
output.print(value, kind: kind, verbose: options.verbose)
}
}

/// :nodoc:
extension App.Options {
static var blank: App.Options {
return .init(
configPath: nil,
projectDir: nil,
verbose: false
)
output.print(value, kind: kind, verbose: verbose)
}
}
Loading