Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2c600a7

Browse files
Add Discovered Dependency File (yonaskolb#1012)
* Upgrade XCodeProj to 7.14.0 * Bump to XcodeProj to fork * Add script discoveredDependencyFile * Align cfbundle test * Add changelog mock * Update Documentation * Update SPM manifest * Change property name * Verify defult dependency file to nil * Add JSON encodable test * Add PR number Co-authored-by: Fernanda Geraissate <[email protected]>
1 parent 50aedc4 commit 2c600a7

File tree

8 files changed

+42
-7
lines changed

8 files changed

+42
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- More detailed error message with method arguments. [#990](https://github.com/yonaskolb/XcodeGen/pull/990) @bannzai
1010
- Added `basedOnDependencyAnalysis` to Project Spec Build Script to be able to choose not to skip the script. [#992](https://github.com/yonaskolb/XcodeGen/pull/992) @myihsan
1111
- Add `BuildRule.runOncePerArchitecture` to allow running build rules once per architecture. [#950](https://github.com/yonaskolb/XcodeGen/pull/950) @sascha
12+
- Adds discovered dependency file for a build script [#1012](https://github.com/yonaskolb/XcodeGen/pull/1012) @polac24 @fggeraissate
1213

1314
#### Changed
1415
- **Breaking**: Info.plists with custom prefixes are no longer added to the Copy Bundle Resources build phase [#945](https://github.com/yonaskolb/XcodeGen/pull/945) @anivaros

Docs/ProjectSpec.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ Each script can contain:
565565
- [ ] **showEnvVars**: **Bool** - whether the environment variables accessible to the script show be printed to the build log. Defaults to yes
566566
- [ ] **runOnlyWhenInstalling**: **Bool** - whether the script is only run when installing (`runOnlyForDeploymentPostprocessing`). Defaults to no
567567
- [ ] **basedOnDependencyAnalysis**: **Bool** - whether to skip the script if inputs, context, or outputs haven't changed. Defaults to yes
568+
- [ ] **discoveredDependencyFile**: **String** - discovered dependency .d file. Defaults to none
568569

569570
Either a **path** or **script** must be defined, the rest are optional.
570571

@@ -586,6 +587,7 @@ targets:
586587
- $(DERIVED_FILE_DIR)/file2
587588
outputFileLists:
588589
- $(SRCROOT)/outputFiles.xcfilelist
590+
discoveredDependencyFile: $(DERIVED_FILE_DIR)/target.d
589591
postCompileScripts:
590592
- script: swiftlint
591593
name: Swiftlint

Sources/ProjectSpec/BuildScript.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public struct BuildScript: Equatable {
1616
public var runOnlyWhenInstalling: Bool
1717
public let showEnvVars: Bool
1818
public let basedOnDependencyAnalysis: Bool
19+
public let discoveredDependencyFile: String?
1920

2021
public enum ScriptType: Equatable {
2122
case path(String)
@@ -32,7 +33,8 @@ public struct BuildScript: Equatable {
3233
shell: String? = nil,
3334
runOnlyWhenInstalling: Bool = runOnlyWhenInstallingDefault,
3435
showEnvVars: Bool = showEnvVarsDefault,
35-
basedOnDependencyAnalysis: Bool = basedOnDependencyAnalysisDefault
36+
basedOnDependencyAnalysis: Bool = basedOnDependencyAnalysisDefault,
37+
discoveredDependencyFile: String? = nil
3638
) {
3739
self.script = script
3840
self.name = name
@@ -44,6 +46,7 @@ public struct BuildScript: Equatable {
4446
self.runOnlyWhenInstalling = runOnlyWhenInstalling
4547
self.showEnvVars = showEnvVars
4648
self.basedOnDependencyAnalysis = basedOnDependencyAnalysis
49+
self.discoveredDependencyFile = discoveredDependencyFile
4750
}
4851
}
4952

@@ -66,6 +69,7 @@ extension BuildScript: JSONObjectConvertible {
6669
runOnlyWhenInstalling = jsonDictionary.json(atKeyPath: "runOnlyWhenInstalling") ?? BuildScript.runOnlyWhenInstallingDefault
6770
showEnvVars = jsonDictionary.json(atKeyPath: "showEnvVars") ?? BuildScript.showEnvVarsDefault
6871
basedOnDependencyAnalysis = jsonDictionary.json(atKeyPath: "basedOnDependencyAnalysis") ?? BuildScript.basedOnDependencyAnalysisDefault
72+
discoveredDependencyFile = jsonDictionary.json(atKeyPath: "discoveredDependencyFile")
6973
}
7074
}
7175

@@ -96,6 +100,10 @@ extension BuildScript: JSONEncodable {
96100
dict["script"] = string
97101
}
98102

103+
if let discoveredDependencyFile = discoveredDependencyFile {
104+
dict["discoveredDependencyFile"] = discoveredDependencyFile
105+
}
106+
99107
return dict
100108
}
101109
}

Sources/XcodeGenKit/PBXProjGenerator.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,8 @@ public class PBXProjGenerator {
479479
shellScript: shellScript,
480480
runOnlyForDeploymentPostprocessing: buildScript.runOnlyWhenInstalling,
481481
showEnvVarsInLog: buildScript.showEnvVars,
482-
alwaysOutOfDate: !buildScript.basedOnDependencyAnalysis
482+
alwaysOutOfDate: !buildScript.basedOnDependencyAnalysis,
483+
dependencyFile: buildScript.discoveredDependencyFile
483484
)
484485
return addObject(shellScriptPhase)
485486
}

Tests/Fixtures/TestProject/Project.xcodeproj/project.pbxproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2239,6 +2239,7 @@
22392239
CBE633966E8F3819F15270A3 /* MyScript */ = {
22402240
isa = PBXShellScriptBuildPhase;
22412241
buildActionMask = 2147483647;
2242+
dependencyFile = "$(DERIVED_FILE_DIR)/target.d";
22422243
files = (
22432244
);
22442245
inputFileListPaths = (
@@ -2254,7 +2255,7 @@
22542255
);
22552256
runOnlyForDeploymentPostprocessing = 0;
22562257
shellPath = /bin/sh;
2257-
shellScript = "echo \"You ran a script!\"\n";
2258+
shellScript = "echo \"You ran a script!\"\ntouch \"${DERIVED_FILE_DIR}/target.d\"\n";
22582259
};
22592260
CF3AABFD4A48983B322677DA /* MyScript */ = {
22602261
isa = PBXShellScriptBuildPhase;

Tests/Fixtures/TestProject/project.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,12 @@ targets:
149149
- name: MyScript
150150
script: |
151151
echo "You ran a script!"
152+
touch "${DERIVED_FILE_DIR}/target.d"
152153
inputFileLists:
153154
- App_iOS/inputList.xcfilelist
154155
outputFileLists:
155156
- App_iOS/outputList.xcfilelist
157+
discoveredDependencyFile: $(DERIVED_FILE_DIR)/target.d
156158

157159
EntitledApp:
158160
type: application

Tests/ProjectSpecTests/ProjectSpecTests.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,18 @@ class ProjectSpecTests: XCTestCase {
409409
shell: "/bin/bash",
410410
runOnlyWhenInstalling: true,
411411
showEnvVars: true,
412-
basedOnDependencyAnalysis: false)],
412+
basedOnDependencyAnalysis: false),
413+
BuildScript(script: .path("cmd.sh"),
414+
name: "Dependency script",
415+
inputFiles: ["foo"],
416+
outputFiles: ["bar"],
417+
inputFileLists: ["foo.xcfilelist"],
418+
outputFileLists: ["bar.xcfilelist"],
419+
shell: "/bin/bash",
420+
runOnlyWhenInstalling: true,
421+
showEnvVars: true,
422+
basedOnDependencyAnalysis: true,
423+
discoveredDependencyFile: "dep.d")],
413424
buildRules: [BuildRule(fileType: .pattern("*.xcassets"),
414425
action: .script("pre_process_swift.py"),
415426
name: "My Build Rule",

Tests/XcodeGenKitTests/ProjectGeneratorTests.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,20 +1145,29 @@ class ProjectGeneratorTests: XCTestCase {
11451145
var scriptSpec = project
11461146
scriptSpec.targets[0].preBuildScripts = [BuildScript(script: .script("script1"))]
11471147
scriptSpec.targets[0].postCompileScripts = [BuildScript(script: .script("script2"))]
1148-
scriptSpec.targets[0].postBuildScripts = [BuildScript(script: .script("script3"))]
1148+
scriptSpec.targets[0].postBuildScripts = [
1149+
BuildScript(script: .script("script3")),
1150+
BuildScript(script: .script("script4"), discoveredDependencyFile: "$(DERIVED_FILE_DIR)/target.d")
1151+
]
11491152
let pbxProject = try scriptSpec.generatePbxProj()
11501153

1151-
let nativeTarget = try unwrap(pbxProject.nativeTargets.first(where: { $0.buildPhases.count >= 3 }))
1154+
let nativeTarget = try unwrap(pbxProject.nativeTargets.first(where: { $0.buildPhases.count >= 4 }))
11521155
let buildPhases = nativeTarget.buildPhases
11531156

11541157
let scripts = pbxProject.shellScriptBuildPhases
1155-
try expect(scripts.count) == 3
1158+
try expect(scripts.count) == 4
11561159
let script1 = scripts.first { $0.shellScript == "script1" }!
11571160
let script2 = scripts.first { $0.shellScript == "script2" }!
11581161
let script3 = scripts.first { $0.shellScript == "script3" }!
1162+
let script4 = scripts.first { $0.shellScript == "script4" }!
11591163
try expect(buildPhases.contains(script1)) == true
11601164
try expect(buildPhases.contains(script2)) == true
11611165
try expect(buildPhases.contains(script3)) == true
1166+
try expect(buildPhases.contains(script4)) == true
1167+
try expect(script1.dependencyFile).beNil()
1168+
try expect(script2.dependencyFile).beNil()
1169+
try expect(script3.dependencyFile).beNil()
1170+
try expect(script4.dependencyFile) == "$(DERIVED_FILE_DIR)/target.d"
11621171
}
11631172

11641173
$0.it("generates targets with cylical dependencies") {

0 commit comments

Comments
 (0)