Skip to content

Commit

Permalink
Merge pull request #122 from polac24/20220418-derived
Browse files Browse the repository at this point in the history
Fix building target dependencies list with custom DERIVED_FILE_DIR
  • Loading branch information
polac24 authored Apr 19, 2022
2 parents fbb456b + 95f95be commit ef3a88c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
12 changes: 5 additions & 7 deletions Sources/XCRemoteCache/Dependencies/DependencyProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class DependencyProcessorImpl: DependencyProcessor {
return Dependency(url: file, type: .xcode)
} else if filePath.hasPrefix(intermediatePath) {
return Dependency(url: file, type: .intermediate)
} else if filePath.hasPrefix(derivedFilesPath) {
return Dependency(url: file, type: .derivedFile)
} else if let bundle = bundlePath, filePath.hasPrefix(bundle) {
// If a target produces a bundle, explicitly classify all
// of products to distinguish from other targets products
Expand All @@ -88,8 +90,6 @@ class DependencyProcessorImpl: DependencyProcessor {
return Dependency(url: file, type: .product)
} else if filePath.hasPrefix(sourcePath) {
return Dependency(url: file, type: .source)
} else if filePath.hasPrefix(derivedFilesPath) {
return Dependency(url: file, type: .derivedFile)
} else {
return Dependency(url: file, type: .unknown)
}
Expand All @@ -107,16 +107,14 @@ class DependencyProcessorImpl: DependencyProcessor {
return false
}

if dependency.type == .derivedFile && dependency.url.lastPathComponent.contains("-Swift.h") {
return false
}

// Skip:
// - A fingerprint generated includes Xcode version build number so no need to analyze prepackaged Xcode files
// - All files in `*/Interemediates/*` - this file are created on-fly for a given target
// - Some files may depend on its own product (e.g. .m may #include *-Swift.h) - we know products will match
// because in case of a hit, these will be taken from the artifact
let irrelevantDependenciesType: [Dependency.Kind] = [.xcode, .intermediate, .ownProduct]
// - Customized DERIVED_FILE_DIR may change a directory of
// derived files, which by default is under `*/Interemediates`
let irrelevantDependenciesType: [Dependency.Kind] = [.xcode, .intermediate, .ownProduct, .derivedFile]
return !irrelevantDependenciesType.contains(dependency.type)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ class DependencyProcessorImplTests: FileXCTestCase {
XCTAssertEqual(dependencies, [])
}

func testFiltersOutDerivedFile() throws {
let dependencies = processor.process([
"/DerivedFiles/output.h",
])

XCTAssertEqual(dependencies, [])
}

func testFiltersOutProductModulemap() throws {
let dependencies = processor.process([
"/Product/some.modulemap",
Expand Down Expand Up @@ -202,4 +210,21 @@ class DependencyProcessorImplTests: FileXCTestCase {

return sourceDir.appendingPathComponent(filename)
}

func testSkipsCustomizedDerivedDirFileUnderSources() {
let derivedFile: URL = "/DerivedFiles/Module-Swift.h"
let processor = DependencyProcessorImpl(
xcode: "/Xcode",
product: "/",
source: "/",
intermediate: "/Intermediate",
derivedFiles: "/DerivedFiles",
bundle: nil
)

XCTAssertEqual(
processor.process([derivedFile]),
[]
)
}
}

0 comments on commit ef3a88c

Please sign in to comment.