Skip to content

Commit 8f53fac

Browse files
committed
IsShareable -> IsInStableDirectories
1 parent 274429a commit 8f53fac

File tree

5 files changed

+41
-37
lines changed

5 files changed

+41
-37
lines changed

clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ struct ModuleDeps {
120120
///
121121
/// External paths, as opposed to virtual file paths, are always used
122122
/// for computing this value.
123-
bool IsShareable;
123+
bool IsInStableDirectories;
124124

125125
/// The path to the modulemap file which defines this module.
126126
///
@@ -331,11 +331,12 @@ void resetBenignCodeGenOptions(frontend::ActionKind ProgramAction,
331331
const LangOptions &LangOpts,
332332
CodeGenOptions &CGOpts);
333333

334-
/// Determine if \c Input can be resolved within a shared location.
334+
/// Determine if \c Input can be resolved within a stable directory.
335335
///
336-
/// \param Directories Paths known to be in a shared location. e.g. Sysroot.
336+
/// \param Directories Paths known to be in a stable location. e.g. Sysroot.
337337
/// \param Input Path to evaluate.
338-
bool isPathInSharedDir(ArrayRef<StringRef> Directories, const StringRef Input);
338+
bool isPathInStableDir(const ArrayRef<StringRef> Directories,
339+
const StringRef Input);
339340

340341
} // end namespace dependencies
341342
} // end namespace tooling

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -158,25 +158,25 @@ static void optimizeCWD(CowCompilerInvocation &BuildInvocation, StringRef CWD) {
158158
}
159159

160160
/// Check a subset of invocation options to determine whether the current
161-
/// context can safely be considered as shareable.
162-
static bool areOptionsInSharedDir(CowCompilerInvocation &BuildInvocation,
163-
const ArrayRef<StringRef> SharedDirs) {
161+
/// context can safely be considered as stable.
162+
static bool areOptionsInStableDir(CowCompilerInvocation &BuildInvocation,
163+
const ArrayRef<StringRef> StableDirs) {
164164
const auto &HSOpts = BuildInvocation.getHeaderSearchOpts();
165-
assert(isPathInSharedDir(SharedDirs, HSOpts.Sysroot) &&
165+
assert(isPathInStableDir(StableDirs, HSOpts.Sysroot) &&
166166
"Sysroots differ between module dependencies and current TU");
167167

168-
assert(isPathInSharedDir(SharedDirs, HSOpts.ResourceDir) &&
168+
assert(isPathInStableDir(StableDirs, HSOpts.ResourceDir) &&
169169
"ResourceDirs differ between module dependencies and current TU");
170170

171171
for (const auto &Entry : HSOpts.UserEntries) {
172172
if (!Entry.IgnoreSysRoot)
173173
continue;
174-
if (!isPathInSharedDir(SharedDirs, Entry.Path))
174+
if (!isPathInStableDir(StableDirs, Entry.Path))
175175
return false;
176176
}
177177

178178
for (const auto &SysPrefix : HSOpts.SystemHeaderPrefixes) {
179-
if (!isPathInSharedDir(SharedDirs, SysPrefix.Prefix))
179+
if (!isPathInStableDir(StableDirs, SysPrefix.Prefix))
180180
return false;
181181
}
182182

@@ -238,7 +238,7 @@ void dependencies::resetBenignCodeGenOptions(frontend::ActionKind ProgramAction,
238238
}
239239
}
240240

241-
bool dependencies::isPathInSharedDir(ArrayRef<StringRef> Directories,
241+
bool dependencies::isPathInStableDir(const ArrayRef<StringRef> Directories,
242242
const StringRef Input) {
243243
auto PathStartsWith = [](StringRef Prefix, StringRef Path) {
244244
auto PrefixIt = llvm::sys::path::begin(Prefix),
@@ -747,12 +747,12 @@ ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
747747
// Start off with the assumption that this module is shareable when there
748748
// is a sysroot provided. As more dependencies are discovered, check if those
749749
// come from the provided shared directories.
750-
const llvm::SmallVector<StringRef> SharedDirs = {
750+
const llvm::SmallVector<StringRef> StableDirs = {
751751
MDC.ScanInstance.getHeaderSearchOpts().Sysroot,
752752
MDC.ScanInstance.getHeaderSearchOpts().ResourceDir};
753-
MD.IsShareable =
754-
!SharedDirs[0].empty() &&
755-
(llvm::sys::path::root_directory(SharedDirs[0]) != SharedDirs[0]);
753+
MD.IsInStableDirectories =
754+
!StableDirs[0].empty() &&
755+
(llvm::sys::path::root_directory(StableDirs[0]) != StableDirs[0]);
756756

757757
// For modules which use export_as link name, the linked product that of the
758758
// corresponding export_as-named module.
@@ -795,10 +795,11 @@ ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
795795
MDC.ScanInstance.getASTReader()->visitInputFileInfos(
796796
*MF, /*IncludeSystem=*/true,
797797
[&](const serialization::InputFileInfo &IFI, bool IsSystem) {
798-
if (MD.IsShareable) {
798+
if (MD.IsInStableDirectories) {
799799
auto FullFilePath = ASTReader::ResolveImportedPath(
800800
PathBuf, IFI.UnresolvedImportedFilename, MF->BaseDirectory);
801-
MD.IsShareable = isPathInSharedDir(SharedDirs, *FullFilePath);
801+
MD.IsInStableDirectories =
802+
isPathInStableDir(StableDirs, *FullFilePath);
802803
}
803804
if (!(IFI.TopLevel && IFI.ModuleMap))
804805
return;
@@ -841,9 +842,10 @@ ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
841842
}
842843
});
843844

844-
// Check provided input paths from the invocation for determining IsShareable.
845-
if (MD.IsShareable)
846-
MD.IsShareable = areOptionsInSharedDir(CI, SharedDirs);
845+
// Check provided input paths from the invocation for determining
846+
// IsInStableDirectories.
847+
if (MD.IsInStableDirectories)
848+
MD.IsInStableDirectories = areOptionsInStableDir(CI, StableDirs);
847849

848850
MDC.associateWithContextHash(CI, IgnoreCWD, MD);
849851

@@ -888,10 +890,10 @@ void ModuleDepCollectorPP::addModulePrebuiltDeps(
888890
if (MDC.isPrebuiltModule(Import->getTopLevelModule()))
889891
if (SeenSubmodules.insert(Import->getTopLevelModule()).second) {
890892
MD.PrebuiltModuleDeps.emplace_back(Import->getTopLevelModule());
891-
// Conservatively consider the module as not shareable,
892-
// as transitive dependencies from the prebuilt module have not been
893-
// determined.
894-
MD.IsShareable = false;
893+
// Conservatively consider the module as not coming from stable
894+
// directories, as transitive dependencies from the prebuilt module
895+
// have not been determined.
896+
MD.IsInStableDirectories = false;
895897
}
896898
}
897899

@@ -908,8 +910,8 @@ void ModuleDepCollectorPP::addAllSubmoduleDeps(
908910
void ModuleDepCollectorPP::addOneModuleDep(const Module *M, const ModuleID ID,
909911
ModuleDeps &MD) {
910912
MD.ClangModuleDeps.push_back(ID);
911-
if (MD.IsShareable)
912-
MD.IsShareable = MDC.ModularDeps[M]->IsShareable;
913+
if (MD.IsInStableDirectories)
914+
MD.IsInStableDirectories = MDC.ModularDeps[M]->IsInStableDirectories;
913915
}
914916

915917
void ModuleDepCollectorPP::addModuleDep(

clang/test/ClangScanDeps/modules-in-shared-dirs.c renamed to clang/test/ClangScanDeps/modules-in-stable-dirs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// This test verifies modules that are entirely comprised from shared directory inputs are captured in
1+
// This test verifies modules that are entirely comprised from stable directory inputs are captured in
22
// dependency information.
33

44
// The first compilation verifies that transitive dependencies on local input are captured.
55
// The second compilation verifies that external paths are resolved when a
6-
// vfsoverlay for determining is-shareable.
6+
// vfsoverlay for determining is-in-stable-directories.
77

88
// REQUIRES: shell
99
// RUN: rm -rf %t
@@ -16,11 +16,11 @@
1616

1717
// CHECK: "modules": [
1818
// CHECK-NEXT: {
19-
// CHECK: "is-shareable": true,
19+
// CHECK: "is-in-stable-directories": true,
2020
// CHECK: "name": "A"
2121

2222
// Verify that there are no more occurances of sysroot.
23-
// CHECK-NOT: "is-shareable"
23+
// CHECK-NOT: "is-in-stable-directories"
2424

2525
// CHECK: "name": "A"
2626
// CHECK: "USE_VFS"

clang/test/ClangScanDeps/prebuilt-modules-in-shared-dirs.c renamed to clang/test/ClangScanDeps/prebuilt-modules-in-stable-dirs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// This test validates that modules that depend on prebuilt modules resolve `is-shareable` as false.
1+
/// This test validates that modules that depend on prebuilt modules resolve `is-in-stable-directories` as false.
22

33
// REQUIRES: shell
44
// RUN: rm -rf %t
@@ -17,11 +17,11 @@
1717
// RUN: cat %t/deps_pch.db | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t --check-prefix PCH_DEP
1818
// RUN: cat %t/deps.db | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t
1919

20-
// PCH_DEP: "is-shareable": true
20+
// PCH_DEP: "is-in-stable-directories": true
2121
// PCH_DEP: "name": "A"
2222

23-
// Verify is-shareable is not in any module dependencies, as they all depend on prebuilt modules.
24-
// CHECK-NOT: "is-shareable"
23+
// Verify is-in-stable-directories is not in any module dependencies, as they all depend on prebuilt modules.
24+
// CHECK-NOT: "is-in-stable-directories"
2525

2626
//--- compile-pch.json.in
2727
[

clang/tools/clang-scan-deps/ClangScanDeps.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,9 @@ class FullDeps {
471471
for (auto &&ModID : ModuleIDs) {
472472
auto &MD = Modules[ModID];
473473
JOS.object([&] {
474-
if (MD.IsShareable)
475-
JOS.attribute("is-shareable", MD.IsShareable);
474+
if (MD.IsInStableDirectories)
475+
JOS.attribute("is-in-stable-directories",
476+
MD.IsInStableDirectories);
476477
JOS.attributeArray("clang-module-deps",
477478
toJSONSorted(JOS, MD.ClangModuleDeps));
478479
JOS.attribute("clang-modulemap-file",

0 commit comments

Comments
 (0)