Skip to content

Commit 3271c19

Browse files
authored
[Dependency Scanning] Remove Unnecessary Code that Computes Module Output Path (#79752)
#79297 implemented current working directory pruning but left some unnecessary code that computes Swift interface module output path prematurely. This PR removes the code that computes the output path too early. The `ExplicitModuleDependencyResolver` now adds the path to the command line after it can correctly compute it. Context: https://github.com/swiftlang/swift/pull/79297/files#r1955314542
1 parent c169f88 commit 3271c19

File tree

6 files changed

+15
-36
lines changed

6 files changed

+15
-36
lines changed

lib/DependencyScan/ScanDependencies.cpp

+4-11
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class ExplicitModuleDependencyResolver {
172172
SwiftInterfaceModuleOutputPathResolution::ResultTy swiftInterfaceOutputPath;
173173
if (resolvingDepInfo.isSwiftInterfaceModule()) {
174174
pruneUnusedVFSOverlay(swiftInterfaceOutputPath);
175-
updateSwiftInterfaceModuleOutputPath(swiftInterfaceOutputPath);
175+
addSwiftInterfaceModuleOutputPathToCommandLine(swiftInterfaceOutputPath);
176176
}
177177

178178
// Update the dependency in the cache with the modified command-line.
@@ -455,19 +455,12 @@ class ExplicitModuleDependencyResolver {
455455
return;
456456
}
457457

458-
void updateSwiftInterfaceModuleOutputPath(
458+
void addSwiftInterfaceModuleOutputPathToCommandLine(
459459
const SwiftInterfaceModuleOutputPathResolution::ResultTy &outputPath) {
460460
StringRef outputName = outputPath.outputPath.str();
461461

462-
bool isOutputPath = false;
463-
for (auto &A : commandline) {
464-
if (isOutputPath) {
465-
A = outputName.str();
466-
break;
467-
} else if (A == "-o") {
468-
isOutputPath = true;
469-
}
470-
}
462+
commandline.push_back("-o");
463+
commandline.push_back(outputName.str());
471464

472465
return;
473466
}

lib/Serialization/ScanningLoaders.cpp

-14
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,6 @@ SwiftModuleScanner::scanInterfaceFile(Twine moduleInterfacePath,
205205
Args.push_back(candidate);
206206
}
207207

208-
// Compute the output path and add it to the command line
209-
SmallString<128> outputPathBase(moduleOutputPath);
210-
llvm::sys::path::append(
211-
outputPathBase,
212-
moduleName.str() + "-" + Hash + "." +
213-
file_types::getExtension(file_types::TY_SwiftModuleFile));
214-
Args.push_back("-o");
215-
Args.push_back(outputPathBase.str().str());
216-
217208
// Open the interface file.
218209
auto &fs = *Ctx.SourceMgr.getFileSystem();
219210
auto interfaceBuf = fs.getBufferForFile(moduleInterfacePath);
@@ -251,11 +242,6 @@ SwiftModuleScanner::scanInterfaceFile(Twine moduleInterfacePath,
251242
InPath, compiledCandidatesRefs, ArgsRefs, {}, {}, linkLibraries,
252243
isFramework, isStatic, {}, /*module-cache-key*/ "", UserModVer);
253244

254-
// We do NOT need the code below to set output path in the dependency
255-
// info because it will be calculated again later. We do not want to
256-
// create output paths that do not exist in the end.
257-
// Result->setOutputPathAndHash(outputPathBase.str().str(), Hash);
258-
259245
if (Ctx.CASOpts.EnableCaching) {
260246
std::vector<std::string> clangDependencyFiles;
261247
auto clangImporter =

test/ScanDependencies/FilterClangSearchPaths.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import C
2828
// CHECK-NEXT: "moduleInterfacePath": "{{.*}}{{/|\\}}Inputs{{/|\\}}Swift{{/|\\}}A.swiftinterface",
2929
// CHECK: "commandLine": [
3030
// CHECK: "-fobjc-disable-direct-methods-for-testing"
31-
// CHECK: "-o",
32-
// CHECK-NEXT: "{{.*}}{{/|\\}}A-{{.*}}.swiftmodule",
3331
// CHECK-NOT: "/tmp/foo"
3432
// CHECK-NOT: "-I/tmp/bar"
33+
// CHECK: "-o",
34+
// CHECK-NEXT: "{{.*}}{{/|\\}}A-{{.*}}.swiftmodule"
3535
// CHECK: ]

test/ScanDependencies/ObjCStrict.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import C
2929
// CHECK: "commandLine": [
3030
// CHECK: "-fobjc-disable-direct-methods-for-testing"
3131
// CHECK: "-o",
32-
// CHECK-NEXT: "{{.*}}{{/|\\}}A-{{.*}}.swiftmodule",
32+
// CHECK-NEXT: "{{.*}}{{/|\\}}A-{{.*}}.swiftmodule"
3333

3434

3535

test/ScanDependencies/eliminate_unused_vfs.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -79,30 +79,30 @@ import F
7979
// MOD-HASH-NEXT: "swift": {
8080
// MOD-HASH-NEXT: "moduleInterfacePath": "{{.*}}{{/|\\}}F.swiftinterface",
8181
// MOD-HASH: "commandLine": [
82-
// MOD-HASH: "-o",
83-
// MOD-HASH-NEXT: "{{.*}}{{/|\\}}F-[[FHASH:.*]].swiftmodule",
8482
// MOD-HASH: "-swift-module-file=Swift={{.*}}{{/|\\}}Swift-[[SHASH:.*]].swiftmodule",
8583
// MOD-HASH: "-swift-module-file=SwiftOnoneSupport={{.*}}{{/|\\}}SwiftOnoneSupport-[[SOSHASH:.*]].swiftmodule",
84+
// MOD-HASH: "-o",
85+
// MOD-HASH-NEXT: "{{.*}}{{/|\\}}F-[[FHASH:.*]].swiftmodule"
8686
// MOD-HASH: ],
8787
// MOD-HASH: "mainModuleName": "deps1",
8888
// MOD-HASH: "linkLibraries": [],
8989
// MOD-HASH: "details": {
9090
// MOD-HASH-NEXT: "swift": {
9191
// MOD-HASH-NEXT: "moduleInterfacePath": "{{.*}}{{/|\\}}F.swiftinterface",
9292
// MOD-HASH: "commandLine": [
93-
// MOD-HASH: "-o",
94-
// MOD-HASH-NEXT: "{{.*}}{{/|\\}}F-[[FHASH]].swiftmodule",
9593
// MOD-HASH: "-swift-module-file=Swift={{.*}}{{/|\\}}Swift-[[SHASH]].swiftmodule",
9694
// MOD-HASH: "-swift-module-file=SwiftOnoneSupport={{.*}}{{/|\\}}SwiftOnoneSupport-[[SOSHASH]].swiftmodule",
95+
// MOD-HASH: "-o",
96+
// MOD-HASH-NEXT: "{{.*}}{{/|\\}}F-[[FHASH]].swiftmodule"
9797
// MOD-HASH: ],
9898
// MOD-HASH: "mainModuleName": "deps2",
9999
// MOD-HASH: "linkLibraries": [],
100100
// MOD-HASH: "details": {
101101
// MOD-HASH-NEXT: "swift": {
102102
// MOD-HASH-NEXT: "moduleInterfacePath": "{{.*}}{{/|\\}}F.swiftinterface",
103103
// MOD-HASH: "commandLine": [
104-
// MOD-HASH: "-o",
105-
// MOD-HASH-NEXT: "{{.*}}{{/|\\}}F-[[FHASH]].swiftmodule",
106104
// MOD-HASH: "-swift-module-file=Swift={{.*}}{{/|\\}}Swift-[[SHASH]].swiftmodule",
107105
// MOD-HASH: "-swift-module-file=SwiftOnoneSupport={{.*}}{{/|\\}}SwiftOnoneSupport-[[SOSHASH]].swiftmodule",
106+
// MOD-HASH: "-o",
107+
// MOD-HASH-NEXT: "{{.*}}{{/|\\}}F-[[FHASH]].swiftmodule"
108108
// MOD-HASH: ],

test/ScanDependencies/explicit-swift-dependencies.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ import F
4747
// CHECK-NEXT: "-fno-implicit-modules",
4848
// CHECK-NEXT: "-Xcc",
4949
// CHECK-NEXT: "-fno-implicit-module-maps",
50-
// CHECK-NEXT: "-o",
51-
// CHECK-NEXT: "{{.*}}{{/|\\}}F-{{.*}}.swiftmodule"
5250
// CHECK-DAG: "-swift-module-file=Swift={{.*}}{{/|\\}}Swift-{{.*}}.swiftmodule"
5351
// CHECK-DAG: "-swift-module-file=SwiftOnoneSupport={{.*}}{{/|\\}}SwiftOnoneSupport-{{.*}}.swiftmodule"
5452
// CHECK-DAG: "-fmodule-file=F={{.*}}{{/|\\}}F-{{.*}}.pcm"
5553
// CHECK-DAG: "-fmodule-file=SwiftShims={{.*}}{{/|\\}}SwiftShims-{{.*}}.pcm"
54+
// CHECK-NEXT: "-o",
55+
// CHECK-NEXT: "{{.*}}{{/|\\}}F-{{.*}}.swiftmodule"

0 commit comments

Comments
 (0)