Skip to content

Commit 06d7403

Browse files
Merge pull request #67133 from cachemeifyoucan/eng/PR-cas-deps-fixups
[DependencyScan] Fix and cleanup CAS Depscanner
2 parents 089df84 + 96e0965 commit 06d7403

File tree

6 files changed

+46
-30
lines changed

6 files changed

+46
-30
lines changed

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,35 @@ static llvm::Error resolveExplicitModuleInputs(
310310
if (auto ID = resolvingDepInfo.getClangIncludeTree())
311311
includeTrees.push_back(*ID);
312312

313+
auto addBridgingHeaderDeps =
314+
[&](const ModuleDependencyInfo &depInfo) -> llvm::Error {
315+
auto sourceDepDetails = depInfo.getAsSwiftSourceModule();
316+
if (!sourceDepDetails)
317+
return llvm::Error::success();
318+
319+
if (sourceDepDetails->textualModuleDetails
320+
.CASBridgingHeaderIncludeTreeRootID.empty()) {
321+
if (!sourceDepDetails->textualModuleDetails.bridgingSourceFiles.empty()) {
322+
if (auto tracker =
323+
cache.getScanService().createSwiftDependencyTracker()) {
324+
tracker->startTracking();
325+
for (auto &file :
326+
sourceDepDetails->textualModuleDetails.bridgingSourceFiles)
327+
tracker->trackFile(file);
328+
auto bridgeRoot = tracker->createTreeFromDependencies();
329+
if (!bridgeRoot)
330+
return bridgeRoot.takeError();
331+
rootIDs.push_back(bridgeRoot->getID().toString());
332+
}
333+
}
334+
} else
335+
includeTrees.push_back(sourceDepDetails->textualModuleDetails
336+
.CASBridgingHeaderIncludeTreeRootID);
337+
return llvm::Error::success();
338+
};
339+
if (auto E = addBridgingHeaderDeps(resolvingDepInfo))
340+
return E;
341+
313342
std::vector<std::string> commandLine = resolvingDepInfo.getCommandline();
314343
for (const auto &depModuleID : dependencies) {
315344
const auto optionalDepInfo =
@@ -386,27 +415,8 @@ static llvm::Error resolveExplicitModuleInputs(
386415
includeTrees.push_back(*ID);
387416
} break;
388417
case swift::ModuleDependencyKind::SwiftSource: {
389-
auto sourceDepDetails = depInfo->getAsSwiftSourceModule();
390-
assert(sourceDepDetails && "Expected source dependency");
391-
if (sourceDepDetails->textualModuleDetails
392-
.CASBridgingHeaderIncludeTreeRootID.empty()) {
393-
if (!sourceDepDetails->textualModuleDetails.bridgingSourceFiles
394-
.empty()) {
395-
if (auto tracker =
396-
cache.getScanService().createSwiftDependencyTracker()) {
397-
tracker->startTracking();
398-
for (auto &file :
399-
sourceDepDetails->textualModuleDetails.bridgingSourceFiles)
400-
tracker->trackFile(file);
401-
auto bridgeRoot = tracker->createTreeFromDependencies();
402-
if (!bridgeRoot)
403-
return bridgeRoot.takeError();
404-
rootIDs.push_back(bridgeRoot->getID().toString());
405-
}
406-
}
407-
} else
408-
includeTrees.push_back(sourceDepDetails->textualModuleDetails
409-
.CASBridgingHeaderIncludeTreeRootID);
418+
if (auto E = addBridgingHeaderDeps(*depInfo))
419+
return E;
410420
break;
411421
}
412422
default:

lib/Frontend/CachingUtils.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,7 @@ createCASFileSystem(ObjectStore &CAS, ArrayRef<std::string> FSRoots,
384384
auto ID = CAS.parseID(FSRoots.front());
385385
if (!ID)
386386
return ID.takeError();
387-
auto Ref = CAS.getReference(*ID);
388-
if (!Ref)
389-
return createCASObjectNotFoundError(*ID);
387+
return createCASFileSystem(CAS, *ID);
390388
}
391389

392390
auto NewRoot = mergeCASFileSystem(CAS, FSRoots);

test/CAS/Inputs/SwiftDepsExtractor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
continue
2828

2929
if key in detail.keys():
30-
print(detail[key])
30+
json.dump(detail[key], sys.stdout, indent=2)
3131
break
3232

33-
print(detail['details'][mode][key])
33+
json.dump(detail['details'][mode][key], sys.stdout, indent=2)
3434
break

test/CAS/cas-explicit-module-map.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@
4343
// RUN: echo "[{" > %/t/map.json
4444
// RUN: echo "\"moduleName\": \"A\"," >> %/t/map.json
4545
// RUN: echo "\"modulePath\": \"A.swiftmodule\"," >> %/t/map.json
46-
// RUN: echo -n "\"moduleCacheKey\": \"" >> %/t/map.json
46+
// RUN: echo -n "\"moduleCacheKey\": " >> %/t/map.json
4747
// RUN: cat %t/A.key >> %/t/map.json
48-
// RUN: echo "\"," >> %/t/map.json
48+
// RUN: echo "," >> %/t/map.json
4949
// RUN: echo "\"isFramework\": false" >> %/t/map.json
5050
// RUN: echo "}," >> %/t/map.json
5151
// RUN: echo "{" >> %/t/map.json
5252
// RUN: echo "\"moduleName\": \"B\"," >> %/t/map.json
5353
// RUN: echo "\"modulePath\": \"B.swiftmodule\"," >> %/t/map.json
54-
// RUN: echo -n "\"moduleCacheKey\": \"" >> %/t/map.json
54+
// RUN: echo -n "\"moduleCacheKey\": " >> %/t/map.json
5555
// RUN: cat %t/B.key >> %/t/map.json
56-
// RUN: echo "\"," >> %/t/map.json
56+
// RUN: echo "," >> %/t/map.json
5757
// RUN: echo "\"isFramework\": false" >> %/t/map.json
5858
// RUN: echo "}," >> %/t/map.json
5959
// RUN: echo "{" >> %/t/map.json

test/CAS/module_deps.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
// RUN: %S/Inputs/SwiftDepsExtractor.py %t/deps.json clang:F casFSRootID > %t/F_fs.casid
2929
// RUN: llvm-cas --cas %t/cas --ls-tree-recursive @%t/F_fs.casid | %FileCheck %s -check-prefix FS_ROOT_F
3030

31+
/// make sure the number of CASFS is correct. 10 entries with 2 line each + 1 extra bracket
32+
// RUN: NUM_CMDS=$(%S/Inputs/SwiftDepsExtractor.py %t/deps.json deps commandLine | wc -l)
33+
// RUN: if [ ! $NUM_CMDS -eq 21 ]; then echo "wrong number of CASFS from scanning"; exit 1; fi
34+
3135
// FS_ROOT_E-DAG: E.swiftinterface
3236
// FS_ROOT_E-DAG: SDKSettings.json
3337

test/CAS/module_deps_include_tree.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
// RUN: %S/Inputs/SwiftDepsExtractor.py %t/deps.json clang:F clangIncludeTree > %t/F_tree.casid
3030
// RUN: clang-cas-test --cas %t/cas --print-include-tree @%t/F_tree.casid | %FileCheck %s -check-prefix INCLUDE_TREE_F
3131

32+
/// make sure the number of CASFS is correct. 10 entries with 2 line each + 1 extra bracket
33+
// RUN: NUM_CMDS=$(%S/Inputs/SwiftDepsExtractor.py %t/deps.json deps commandLine | wc -l)
34+
// RUN: if [ ! $NUM_CMDS -eq 21 ]; then echo "wrong number of CASFS from scanning"; exit 1; fi
35+
3236
// FS_ROOT_E-DAG: E.swiftinterface
3337
// FS_ROOT_E-DAG: SDKSettings.json
3438

0 commit comments

Comments
 (0)