Create mac framework for fixture, Only link Package.Resolved if it contains a remote package, swiftformat .

This commit is contained in:
Oliver Atkinson 2019-09-24 09:06:28 +01:00
parent 8412134ef4
commit 5c20d859ef
22 changed files with 116 additions and 52 deletions

View File

@ -43,6 +43,14 @@ public protocol FileHandling: AnyObject {
/// - Returns: True if there's a folder or file at the given path.
func exists(_ path: AbsolutePath, followSymlink: Bool) -> Bool
/// Move a file from a location to another location
///
/// - Parameters:
/// - from: File/Folder to be moved.
/// - to: Path where the file/folder will be moved.
/// - Throws: An error if from doesn't exist or to does.
func move(from: AbsolutePath, to: AbsolutePath) throws
/// It copies a file or folder to another path.
///
/// - Parameters:
@ -167,6 +175,16 @@ public final class FileHandler: FileHandling {
try fileManager.copyItem(atPath: from.pathString, toPath: to.pathString)
}
/// Move a file from a location to another location
///
/// - Parameters:
/// - from: File/Folder to be moved.
/// - to: Path where the file/folder will be moved.
/// - Throws: An error if from doesn't exist or to does.
public func move(from: AbsolutePath, to: AbsolutePath) throws {
try fileManager.moveItem(atPath: from.pathString, toPath: to.pathString)
}
/// Reads a text file at the given path and returns it.
///
/// - Parameter at: Path to the text file.

View File

@ -2,7 +2,6 @@ import Basic
import Foundation
public protocol Systeming {
/// System environment.
var env: [String: String] { get }
@ -163,7 +162,6 @@ public enum SystemError: FatalError {
public var verbose = false
public final class System: Systeming {
/// Regex expression used to get the Swift version from the output of the 'swift --version' command.
// swiftlint:disable:next force_try
private static var swiftVersionRegex = try! NSRegularExpression(pattern: "Apple Swift version\\s(.+)\\s\\(.+\\)", options: [])
@ -405,13 +403,11 @@ public final class System: Systeming {
}
private func printing(_ result: ProcessResult) throws -> ProcessResult {
if verbose {
print(try result.utf8Output().yellow())
print(try result.utf8stderrOutput().red())
}
return result
}
}

View File

@ -44,6 +44,10 @@ public final class MockFileHandler: FileHandling {
try fileHandler.linkFile(atPath: atPath, toPath: toPath)
}
public func move(from: AbsolutePath, to: AbsolutePath) throws {
try fileHandler.move(from: from, to: to)
}
public func copy(from: AbsolutePath, to: AbsolutePath) throws {
try fileHandler.copy(from: from, to: to)
}

View File

@ -133,28 +133,43 @@ final class WorkspaceGenerator: WorkspaceGenerating {
return workspacePath
}
private func generatePackageDependencyManager(at path: AbsolutePath,
private func generatePackageDependencyManager(
at path: AbsolutePath,
workspace _: Workspace,
workspaceName: String,
graph: Graphing) throws {
let hasPackages: Bool = try !graph.targets.flatMap { try graph.packages(path: $0.path, name: $0.name) }.isEmpty
guard hasPackages else { return }
graph: Graphing
) throws {
let packageResolvedPath = path.appending(component: ".package.resolved")
let packages = try graph.targets.flatMap { try graph.packages(path: $0.path, name: $0.name) }
let hasPackages = !packages.isEmpty
guard hasPackages else {
return
}
let hasRemotePackage = packages.first(where: { package in
switch package.packageType {
case .remote: return true
case .local: return false
}
}) != nil
let packageResolvedPath = path.appending(component: "Package.resolved")
let packagePath = path.appending(RelativePath("\(workspaceName)/xcshareddata/swiftpm/Package.resolved"))
if !fileHandler.exists(packageResolvedPath) {
let workspacePath = path.appending(component: workspaceName)
// -list parameter is a workaround to resolve package dependencies for given workspace without specifying scheme
try system.run(["xcodebuild", "-resolvePackageDependencies", "-workspace", workspacePath.pathString, "-list"])
try fileHandler.linkFile(atPath: packagePath, toPath: packageResolvedPath)
} else {
// Just in case Package.resolved was created by user before hard linking
if fileHandler.exists(packagePath) {
try system.runAndPrint(["xcodebuild", "-resolvePackageDependencies", "-workspace", workspacePath.pathString, "-list"])
if hasRemotePackage {
if fileHandler.exists(packageResolvedPath) {
try fileHandler.delete(packagePath)
} else {
try fileHandler.move(from: packagePath, to: packageResolvedPath)
}
try fileHandler.linkFile(atPath: packageResolvedPath, toPath: packagePath)
}
}
private func write(xcworkspace: XCWorkspace, to: AbsolutePath) throws {

View File

@ -66,7 +66,6 @@ class GenerateCommand: NSObject, Command {
}
func run(with arguments: ArgumentParser.Result) throws {
TuistCore.verbose = arguments.get(verboseArgument) ?? false
let timer = clock.startTimer()

View File

@ -191,6 +191,5 @@ class GraphManifestLoader: GraphManifestLoading {
}
return data
}
}

View File

@ -26,7 +26,7 @@ final class InfoPlistContentProviderTests: XCTestCase {
"UISupportedInterfaceOrientations": [
"UIInterfaceOrientationPortrait",
"UIInterfaceOrientationLandscapeLeft",
"UIInterfaceOrientationLandscapeRight"
"UIInterfaceOrientationLandscapeRight",
],
"CFBundleShortVersionString": "1.0",
"UIMainStoryboardFile": "Main",
@ -38,12 +38,12 @@ final class InfoPlistContentProviderTests: XCTestCase {
"UIInterfaceOrientationPortrait",
"UIInterfaceOrientationPortraitUpsideDown",
"UIInterfaceOrientationLandscapeLeft",
"UIInterfaceOrientationLandscapeRight"
"UIInterfaceOrientationLandscapeRight",
],
"CFBundleVersion": "1",
"ExtraAttribute": "Value",
"CFBundleExecutable": "$(EXECUTABLE_NAME)",
"CFBundleInfoDictionaryVersion": "6.0"
"CFBundleInfoDictionaryVersion": "6.0",
])
}
@ -69,7 +69,7 @@ final class InfoPlistContentProviderTests: XCTestCase {
"CFBundleExecutable": "$(EXECUTABLE_NAME)",
"CFBundleIdentifier": "$(PRODUCT_BUNDLE_IDENTIFIER)",
"ExtraAttribute": "Value",
"LSMinimumSystemVersion": "$(MACOSX_DEPLOYMENT_TARGET)"
"LSMinimumSystemVersion": "$(MACOSX_DEPLOYMENT_TARGET)",
])
}

View File

@ -12,11 +12,11 @@ Then(/I should be able to (.+) for (iOS|macOS|tvOS|watchOS) the scheme (.+)/) do
"-derivedDataPath", @derived_data_path
]
if action == "test" and platform == "iOS"
if action == "test" && platform == "iOS"
args << "-destination\ \'name=iPhone 11\'"
end
if action == "build" and platform == "iOS"
if action == "build" && platform == "iOS"
args << "-sdk\ iphoneos"
end

View File

@ -4,8 +4,8 @@ require "open3"
module System
def system(*args)
puts args.join " "
_, err, status = Open3.capture3(args.join " ")
puts args.join(" ")
_, err, status = Open3.capture3(args.join(" "))
assert(status.success?, err)
end

View File

@ -0,0 +1,16 @@
{
"object": {
"pins": [
{
"package": "RxSwift",
"repositoryURL": "https://github.com/ReactiveX/RxSwift",
"state": {
"branch": null,
"revision": "b3e888b4972d9bc76495dd74d30a8c7fad4b9395",
"version": "5.0.1"
}
}
]
},
"version": 1
}

View File

@ -1,4 +1,4 @@
// Generated by Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)
// Generated by Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgcc-compat"
@ -110,6 +110,15 @@ typedef unsigned int swift_uint4 __attribute__((__ext_vector_type__(4)));
# define SWIFT_CLASS_NAMED(SWIFT_NAME) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA
# endif
#endif
#if !defined(SWIFT_RESILIENT_CLASS)
# if __has_attribute(objc_class_stub)
# define SWIFT_RESILIENT_CLASS(SWIFT_NAME) SWIFT_CLASS(SWIFT_NAME) __attribute__((objc_class_stub))
# define SWIFT_RESILIENT_CLASS_NAMED(SWIFT_NAME) __attribute__((objc_class_stub)) SWIFT_CLASS_NAMED(SWIFT_NAME)
# else
# define SWIFT_RESILIENT_CLASS(SWIFT_NAME) SWIFT_CLASS(SWIFT_NAME)
# define SWIFT_RESILIENT_CLASS_NAMED(SWIFT_NAME) SWIFT_CLASS_NAMED(SWIFT_NAME)
# endif
#endif
#if !defined(SWIFT_PROTOCOL)
# define SWIFT_PROTOCOL(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA
@ -151,6 +160,9 @@ typedef unsigned int swift_uint4 __attribute__((__ext_vector_type__(4)));
#if !defined(SWIFT_AVAILABILITY)
# define SWIFT_AVAILABILITY(plat, ...) __attribute__((availability(plat, __VA_ARGS__)))
#endif
#if !defined(SWIFT_WEAK_IMPORT)
# define SWIFT_WEAK_IMPORT __attribute__((weak_import))
#endif
#if !defined(SWIFT_DEPRECATED)
# define SWIFT_DEPRECATED __attribute__((deprecated))
#endif
@ -162,6 +174,9 @@ typedef unsigned int swift_uint4 __attribute__((__ext_vector_type__(4)));
#else
# define SWIFT_DEPRECATED_OBJC(Msg) SWIFT_DEPRECATED_MSG(Msg)
#endif
#if !defined(IBSegueAction)
# define IBSegueAction
#endif
#if __has_feature(modules)
#if __has_warning("-Watimport-in-framework-header")
#pragma clang diagnostic ignored "-Watimport-in-framework-header"

View File

@ -27,17 +27,19 @@
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>10E1001</string>
<string>11A420a</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>18E219</string>
<string>19A547</string>
<key>DTSDKName</key>
<string>macosx10.14</string>
<string>macosx10.15</string>
<key>DTXcode</key>
<string>1020</string>
<string>1100</string>
<key>DTXcodeBuild</key>
<string>10E1001</string>
<string>11A420a</string>
<key>LSMinimumSystemVersion</key>
<string>10.15</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright Tuist©. All rights reserved.</string>
</dict>