Skip to content

Commit

Permalink
Fix using ProjectDescription
Browse files Browse the repository at this point in the history
  • Loading branch information
fortmarek committed Nov 18, 2023
1 parent 981478c commit 48260d2
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 104 deletions.
9 changes: 0 additions & 9 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@
"version" : "0.6.7"
}
},
{
"identity" : "checksum",
"kind" : "remoteSourceControl",
"location" : "https://github.com/rnine/Checksum.git",
"state" : {
"revision" : "cd1ae53384dd578a84a0afef492a4f5d6202b068",
"version" : "1.0.2"
}
},
{
"identity" : "combineext",
"kind" : "remoteSourceControl",
Expand Down
3 changes: 0 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ var targets: [Target] = [
"TuistSupport",
"TuistGraph",
"XcodeProj",
"Checksum",
]
),
.target(
Expand Down Expand Up @@ -174,7 +173,6 @@ var targets: [Target] = [
"KeychainAccess",
swifterDependency,
"ZIPFoundation",
"Checksum",
"ProjectDescription",
]
),
Expand Down Expand Up @@ -653,7 +651,6 @@ let package = Package(
.package(url: "https://github.com/httpswift/swifter.git", revision: "1e4f51c92d7ca486242d8bf0722b99de2c3531aa"),
.package(url: "https://github.com/kishikawakatsumi/KeychainAccess", from: "4.2.2"),
.package(url: "https://github.com/krzyzanowskim/CryptoSwift", from: "1.8.0"),
.package(url: "https://github.com/rnine/Checksum", from: "1.0.2"),
.package(url: "https://github.com/stencilproject/Stencil", exact: "0.15.1"),
.package(url: "https://github.com/SwiftDocOrg/GraphViz", exact: "0.2.0"),
.package(url: "https://github.com/SwiftGen/StencilSwiftKit", exact: "2.10.1"),
Expand Down
20 changes: 16 additions & 4 deletions Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@ func targets() -> [Target] {
.external(name: "SystemPackage"),
.external(name: "GraphViz"),
.external(name: "ArgumentParser"),
]
],
settings: .settings(
base: [
"LD_RUNPATH_SEARCH_PATHS": "$(FRAMEWORK_SEARCH_PATHS)"
],
configurations: [
.debug(name: "Debug", settings: [:], xcconfig: nil),
.release(name: "Release", settings: [:], xcconfig: nil),
]
)
),
Target.target(
name: "tuistbenchmark",
Expand Down Expand Up @@ -81,7 +90,6 @@ func targets() -> [Target] {
.external(name: "XcodeProj"),
.external(name: "KeychainAccess"),
.external(name: "CombineExt"),
.external(name: "Checksum"),
.external(name: "Logging"),
.external(name: "ZIPFoundation"),
.external(name: "Swifter"),
Expand Down Expand Up @@ -190,7 +198,6 @@ func targets() -> [Target] {
.target(name: "TuistGraph"),
.external(name: "SwiftToolsSupport"),
.external(name: "SystemPackage"),
.external(name: "Checksum"),
.external(name: "XcodeProj"),
],
testDependencies: [
Expand Down Expand Up @@ -346,6 +353,7 @@ func targets() -> [Target] {
),
Target.module(
name: "ProjectDescription",
product: .framework,
hasTesting: false,
testDependencies: [
.target(name: "TuistSupportTesting"),
Expand All @@ -354,6 +362,7 @@ func targets() -> [Target] {
),
Target.module(
name: "ProjectAutomation",
product: .framework,
hasTests: false,
hasTesting: false,
dependencies: []
Expand Down Expand Up @@ -516,7 +525,10 @@ let acceptanceTests: [(target: Target, scheme: Scheme)] = ["Build", "GenerateOne
),
runAction: .runAction(
arguments: Arguments(
environmentVariables: ["TUIST_CONFIG_SRCROOT": "$(SRCROOT)"]
environmentVariables: [
"TUIST_CONFIG_SRCROOT": "$(SRCROOT)",
"TUIST_FRAMEWORK_SEARCH_PATHS": "$(FRAMEWORK_SEARCH_PATHS)",
]
)
)
)
Expand Down
15 changes: 11 additions & 4 deletions Sources/TuistAcceptanceTesting/TuistAcceptanceTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
import TSCBasic
import TuistCore
import TuistGraph
import TuistSupportTesting
import XCTest

@testable import TuistKit
@testable import TuistSupport
@testable import TuistSupportTesting

public enum Destination {
case simulator, device
}

open class TuistAcceptanceTestCase: TuistTestCase {
open class TuistAcceptanceTestCase: XCTestCase {
public var xcodeprojPath: AbsolutePath!
public var workspacePath: AbsolutePath!
public var fixturePath: AbsolutePath!
public var derivedDataPath: AbsolutePath!
public var environment: MockEnvironment!

private var sourceRootPath: AbsolutePath!

Expand All @@ -30,13 +31,19 @@ open class TuistAcceptanceTestCase: TuistTestCase {
"TUIST_CONFIG_SRCROOT"
]!
)

do {
// Environment
environment = try MockEnvironment()
Environment.shared = environment
} catch {
XCTFail("Failed to setup environment")
}
environment.tuistConfigVariables[
Constants.EnvironmentVariables.xcbeautifyBinaryPath
] = sourceRootPath
.appending(components: ["vendor", ".build", "debug", "xcbeautify"])
.pathString

DeveloperEnvironment.shared = DeveloperEnvironment()
}

override open func tearDown() async throws {
Expand Down
19 changes: 7 additions & 12 deletions Sources/TuistCore/ContentHashing/ContentHasher.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Checksum
import CryptoKit
import Foundation
import TSCBasic
import TuistSupport
Expand All @@ -17,18 +17,16 @@ public final class ContentHasher: ContentHashing {

// MARK: - ContentHashing

public func hash(_ data: Data) throws -> String {
guard let hash = data.checksum(algorithm: .md5) else {
throw ContentHashingError.dataHashingFailed
}
return hash
public func hash(_ data: Data) -> String {
Insecure.MD5.hash(data: data)
.compactMap { String(format: "%02x", $0) }.joined()
}

public func hash(_ string: String) throws -> String {
guard let hash = string.checksum(algorithm: .md5) else {
guard let data = string.data(using: .utf8) else {
throw ContentHashingError.stringHashingFailed(string)
}
return hash
return hash(data)
}

public func hash(_ strings: [String]) throws -> String {
Expand Down Expand Up @@ -64,10 +62,7 @@ public final class ContentHasher: ContentHashing {
guard let sourceData = try? fileHandler.readFile(filePath) else {
throw ContentHashingError.failedToReadFile(filePath)
}
guard let hash = sourceData.checksum(algorithm: .md5) else {
throw ContentHashingError.fileHashingFailed(filePath)
}

return hash
return hash(sourceData)
}
}
34 changes: 20 additions & 14 deletions Sources/TuistLoader/Utils/ResourceLocator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,26 @@ public final class ResourceLocator: ResourceLocating {
private func frameworkPath(_ name: String) throws -> AbsolutePath {
let frameworkNames = ["lib\(name).dylib", "\(name).framework", "PackageFrameworks/\(name).framework"]
let bundlePath = try AbsolutePath(validating: Bundle(for: ManifestLoader.self).bundleURL.path)
let paths = [
bundlePath,
bundlePath.parentDirectory,
/**
== Homebrew directory structure ==
x.y.z/
bin/
tuist
lib/
ProjectDescription.framework
ProjectDescription.framework.dSYM
*/
bundlePath.parentDirectory.appending(component: "lib"),
]

let paths: [AbsolutePath]
if let frameworkSearchPaths = ProcessEnv.vars["TUIST_FRAMEWORK_SEARCH_PATHS"]?.components(separatedBy: " ").filter { !$0.isEmpty } {

Check warning on line 48 in Sources/TuistLoader/Utils/ResourceLocator.swift

View workflow job for this annotation

GitHub Actions / Build with Xcode

trailing closure in this context is confusable with the body of the statement; pass as a parenthesized argument to silence this warning
paths = try frameworkSearchPaths.map { try AbsolutePath(validating: $0) }
} else {
paths = [
bundlePath,
bundlePath.parentDirectory,
/**
== Homebrew directory structure ==
x.y.z/
bin/
tuist
lib/
ProjectDescription.framework
ProjectDescription.framework.dSYM
*/
bundlePath.parentDirectory.appending(component: "lib"),
]
}
let candidates = try paths.flatMap { path in
try frameworkNames.map { path.appending(try RelativePath(validating: $0)) }
}
Expand Down
5 changes: 3 additions & 2 deletions Sources/TuistSupport/MachineEnvironment.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Checksum
import Foundation
import CryptoKit

public protocol MachineEnvironmentRetrieving {
var clientId: String { get }
Expand Down Expand Up @@ -28,7 +28,8 @@ public class MachineEnvironment: MachineEnvironmentRetrieving {
kCFAllocatorDefault,
0
).takeRetainedValue() as! String // swiftlint:disable:this force_cast
return uuid.checksum(algorithm: .md5)!
return Insecure.MD5.hash(data: uuid.data(using: .utf8)!)
.compactMap { String(format: "%02x", $0) }.joined()
}()

/// The `macOSVersion` of the machine running Tuist, in the format major.minor.path, e.g: "10.15.7"
Expand Down
32 changes: 32 additions & 0 deletions Sources/TuistSupportTesting/Extensions/XCTestCase+Extras.swift
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,36 @@ extension XCTestCase {
)
return collection[elementIndex] as? T
}

/// Asserts that a directory at given path contains expected elements.
/// It does not check the contents of a directory recursively.
/// - Throws: An error if the directory at given path does not exist.
public func XCTAssertDirectoryContentEqual(
_ directory: AbsolutePath,
_ expected: [String],
file: StaticString = #file,
line: UInt = #line
) throws {
let directoryContent = try FileHandler.shared
.contentsOfDirectory(directory)
.map(\.pathString)
.sorted()

let expectedContent = try expected
.map { directory.appending(try RelativePath(validating: $0)) }
.map(\.pathString)
.sorted()

let message = """
The directory content:
===========
\(directoryContent.isEmpty ? "<Empty>" : directoryContent.joined(separator: "\n"))
Doesn't equal to expected:
===========
\(expectedContent.isEmpty ? "<Empty>" : expectedContent.joined(separator: "\n"))
"""

XCTAssertEqual(directoryContent, expectedContent, message, file: file, line: line)
}
}
32 changes: 0 additions & 32 deletions Sources/TuistSupportTesting/TestCase/TuistTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,38 +225,6 @@ open class TuistTestCase: XCTestCase {
XCTAssertFalse(output.contains(notExpected), message, file: file, line: line)
}

/// Asserts that a directory at given path contains expected elements.
/// It does not check the contents of a directory recursively.
/// - Throws: An error if the directory at given path does not exist.
public func XCTAssertDirectoryContentEqual(
_ directory: AbsolutePath,
_ expected: [String],
file: StaticString = #file,
line: UInt = #line
) throws {
let directoryContent = try fileHandler
.contentsOfDirectory(directory)
.map(\.pathString)
.sorted()

let expectedContent = try expected
.map { directory.appending(try RelativePath(validating: $0)) }
.map(\.pathString)
.sorted()

let message = """
The directory content:
===========
\(directoryContent.isEmpty ? "<Empty>" : directoryContent.joined(separator: "\n"))
Doesn't equal to expected:
===========
\(expectedContent.isEmpty ? "<Empty>" : expectedContent.joined(separator: "\n"))
"""

XCTAssertEqual(directoryContent, expectedContent, message, file: file, line: line)
}

public func temporaryFixture(_ pathString: String) throws -> AbsolutePath {
let path = try RelativePath(validating: pathString)
let fixturePath = fixturePath(path: path)
Expand Down
10 changes: 5 additions & 5 deletions Tests/TuistBuildAcceptanceTests/BuildAcceptanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import XCTest

/// Build projects using Tuist build
final class BuildAcceptanceTestWithTemplates: TuistAcceptanceTestCase {
func test() async throws {
func test_with_templates() async throws {
try run(InitCommand.self, "--platform", "ios", "--name", "MyApp")
try await run(GenerateCommand.self)
try await run(BuildCommand.self)
Expand All @@ -16,7 +16,7 @@ final class BuildAcceptanceTestWithTemplates: TuistAcceptanceTestCase {
}

final class BuildAcceptanceTestAppWithFrameworkAndTests: TuistAcceptanceTestCase {
func test() async throws {
func test_with_framework_and_tests() async throws {
try setUpFixture("app_with_framework_and_tests")
try await run(GenerateCommand.self)
try await run(BuildCommand.self)
Expand All @@ -40,7 +40,7 @@ final class BuildAcceptanceTestAppWithFrameworkAndTests: TuistAcceptanceTestCase
// }

final class BuildAcceptanceTestiOSAppWithCustomConfigurationAndBuildToCustomDirectory: TuistAcceptanceTestCase {
func test() async throws {
func test_ios_app_with_custom_and_build_to_custom_directory() async throws {
try setUpFixture("ios_app_with_custom_configuration")
try await run(GenerateCommand.self)
try await run(
Expand Down Expand Up @@ -81,15 +81,15 @@ final class BuildAcceptanceTestiOSAppWithCustomConfigurationAndBuildToCustomDire
}

final class BuildAcceptanceTestFrameworkWithSwiftMacroIntegratedWithStandardMethod: TuistAcceptanceTestCase {
func test() async throws {
func test_framework_with_swift_macro_integrated_with_standard_method() async throws {
try setUpFixture("framework_with_swift_macro")
try await run(GenerateCommand.self)
try await run(BuildCommand.self, "Framework")
}
}

final class BuildAcceptanceTestFrameworkWithSwiftMacroIntegratedWithXcodeProjPrimitives: TuistAcceptanceTestCase {
func test() async throws {
func test_framework_with_swift_macro_integrated_with_xcode_proj_primitives() async throws {
try setUpFixture("framework_with_native_swift_macro")
try await run(FetchCommand.self)
try await run(BuildCommand.self, "Framework")
Expand Down
1 change: 0 additions & 1 deletion Tuist/Dependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ let dependencies = Dependencies(
"TSCUtility": .staticFramework,
"TSCclibc": .staticFramework,
"TSCLibc": .staticFramework,
"Checksum": .staticFramework,
]
),
platforms: [.macOS]
Expand Down
Loading

0 comments on commit 48260d2

Please sign in to comment.