Skip to content

[DependencyScan] Fix and cleanup CAS Depscanner #67133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 31 additions & 21 deletions lib/DependencyScan/ScanDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,35 @@ static llvm::Error resolveExplicitModuleInputs(
if (auto ID = resolvingDepInfo.getClangIncludeTree())
includeTrees.push_back(*ID);

auto addBridgingHeaderDeps =
[&](const ModuleDependencyInfo &depInfo) -> llvm::Error {
auto sourceDepDetails = depInfo.getAsSwiftSourceModule();
if (!sourceDepDetails)
return llvm::Error::success();

if (sourceDepDetails->textualModuleDetails
.CASBridgingHeaderIncludeTreeRootID.empty()) {
if (!sourceDepDetails->textualModuleDetails.bridgingSourceFiles.empty()) {
if (auto tracker =
cache.getScanService().createSwiftDependencyTracker()) {
tracker->startTracking();
for (auto &file :
sourceDepDetails->textualModuleDetails.bridgingSourceFiles)
tracker->trackFile(file);
auto bridgeRoot = tracker->createTreeFromDependencies();
if (!bridgeRoot)
return bridgeRoot.takeError();
rootIDs.push_back(bridgeRoot->getID().toString());
}
}
} else
includeTrees.push_back(sourceDepDetails->textualModuleDetails
.CASBridgingHeaderIncludeTreeRootID);
return llvm::Error::success();
};
if (auto E = addBridgingHeaderDeps(resolvingDepInfo))
return E;

std::vector<std::string> commandLine = resolvingDepInfo.getCommandline();
for (const auto &depModuleID : dependencies) {
const auto optionalDepInfo =
Expand Down Expand Up @@ -386,27 +415,8 @@ static llvm::Error resolveExplicitModuleInputs(
includeTrees.push_back(*ID);
} break;
case swift::ModuleDependencyKind::SwiftSource: {
auto sourceDepDetails = depInfo->getAsSwiftSourceModule();
assert(sourceDepDetails && "Expected source dependency");
if (sourceDepDetails->textualModuleDetails
.CASBridgingHeaderIncludeTreeRootID.empty()) {
if (!sourceDepDetails->textualModuleDetails.bridgingSourceFiles
.empty()) {
if (auto tracker =
cache.getScanService().createSwiftDependencyTracker()) {
tracker->startTracking();
for (auto &file :
sourceDepDetails->textualModuleDetails.bridgingSourceFiles)
tracker->trackFile(file);
auto bridgeRoot = tracker->createTreeFromDependencies();
if (!bridgeRoot)
return bridgeRoot.takeError();
rootIDs.push_back(bridgeRoot->getID().toString());
}
}
} else
includeTrees.push_back(sourceDepDetails->textualModuleDetails
.CASBridgingHeaderIncludeTreeRootID);
if (auto E = addBridgingHeaderDeps(*depInfo))
return E;
break;
}
default:
Expand Down
4 changes: 1 addition & 3 deletions lib/Frontend/CachingUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,7 @@ createCASFileSystem(ObjectStore &CAS, ArrayRef<std::string> FSRoots,
auto ID = CAS.parseID(FSRoots.front());
if (!ID)
return ID.takeError();
auto Ref = CAS.getReference(*ID);
if (!Ref)
return createCASObjectNotFoundError(*ID);
return createCASFileSystem(CAS, *ID);
}

auto NewRoot = mergeCASFileSystem(CAS, FSRoots);
Expand Down
4 changes: 2 additions & 2 deletions test/CAS/Inputs/SwiftDepsExtractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
continue

if key in detail.keys():
print(detail[key])
json.dump(detail[key], sys.stdout, indent=2)
break

print(detail['details'][mode][key])
json.dump(detail['details'][mode][key], sys.stdout, indent=2)
break
8 changes: 4 additions & 4 deletions test/CAS/cas-explicit-module-map.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@
// RUN: echo "[{" > %/t/map.json
// RUN: echo "\"moduleName\": \"A\"," >> %/t/map.json
// RUN: echo "\"modulePath\": \"A.swiftmodule\"," >> %/t/map.json
// RUN: echo -n "\"moduleCacheKey\": \"" >> %/t/map.json
// RUN: echo -n "\"moduleCacheKey\": " >> %/t/map.json
// RUN: cat %t/A.key >> %/t/map.json
// RUN: echo "\"," >> %/t/map.json
// RUN: echo "," >> %/t/map.json
// RUN: echo "\"isFramework\": false" >> %/t/map.json
// RUN: echo "}," >> %/t/map.json
// RUN: echo "{" >> %/t/map.json
// RUN: echo "\"moduleName\": \"B\"," >> %/t/map.json
// RUN: echo "\"modulePath\": \"B.swiftmodule\"," >> %/t/map.json
// RUN: echo -n "\"moduleCacheKey\": \"" >> %/t/map.json
// RUN: echo -n "\"moduleCacheKey\": " >> %/t/map.json
// RUN: cat %t/B.key >> %/t/map.json
// RUN: echo "\"," >> %/t/map.json
// RUN: echo "," >> %/t/map.json
// RUN: echo "\"isFramework\": false" >> %/t/map.json
// RUN: echo "}," >> %/t/map.json
// RUN: echo "{" >> %/t/map.json
Expand Down
4 changes: 4 additions & 0 deletions test/CAS/module_deps.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
// RUN: %S/Inputs/SwiftDepsExtractor.py %t/deps.json clang:F casFSRootID > %t/F_fs.casid
// RUN: llvm-cas --cas %t/cas --ls-tree-recursive @%t/F_fs.casid | %FileCheck %s -check-prefix FS_ROOT_F

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

// FS_ROOT_E-DAG: E.swiftinterface
// FS_ROOT_E-DAG: SDKSettings.json

Expand Down
4 changes: 4 additions & 0 deletions test/CAS/module_deps_include_tree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
// RUN: %S/Inputs/SwiftDepsExtractor.py %t/deps.json clang:F clangIncludeTree > %t/F_tree.casid
// RUN: clang-cas-test --cas %t/cas --print-include-tree @%t/F_tree.casid | %FileCheck %s -check-prefix INCLUDE_TREE_F

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

// FS_ROOT_E-DAG: E.swiftinterface
// FS_ROOT_E-DAG: SDKSettings.json

Expand Down