forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 339
[clang][depscan] Support prefix mappings when deciding modules that come from "stable" directories #10493
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
Open
cyndyishida
wants to merge
3
commits into
swiftlang:next
Choose a base branch
from
cyndyishida:eng/PR-148867037
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[clang][depscan] Support prefix mappings when deciding modules that come from "stable" directories #10493
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
clang/test/ClangScanDeps/modules-in-stable-dirs-prefix-mapping.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// This test verifies modules that are entirely comprised from stable directory inputs are captured in | ||
// dependency information when paths are prefix mapped. | ||
cyndyishida marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// REQUIRES: shell,ondisk_cas | ||
|
||
// RUN: rm -rf %t | ||
// RUN: split-file %s %t | ||
// RUN: sed -e "s|DIR|%/t|g" %t/overlay.json.template > %t/overlay.json | ||
// RUN: sed -e "s|DIR|%/t|g" %t/compile.json.in > %t/compile.json | ||
|
||
// RUN: clang-scan-deps -compilation-database %t/compile.json \ | ||
// RUN: -prefix-map=%t/modules=/^modules -prefix-map=%t=/^src -prefix-map-sdk=/^sdk -prefix-map-toolchain=/^tc \ | ||
// RUN: -cas-path %t/cas -module-files-dir %t/modules \ | ||
// RUN: -j 1 -format experimental-full > %t/deps.db | ||
|
||
// RUN: cat %t/deps.db | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t --check-prefix DEP | ||
|
||
// DEP: "is-in-stable-directories": true | ||
// DEP: "name": "A" | ||
|
||
// CHECK-NOT: "is-in-stable-directories": true | ||
// CHECK-NOT: warning: | ||
// CHECK-NOT: error: | ||
|
||
//--- compile.json.in | ||
[ | ||
{ | ||
"directory": "DIR", | ||
"command": "clang -x c -c DIR/client.c -isysroot DIR/MacOSX.sdk -IDIR/BuildDir -ivfsoverlay DIR/overlay.json -IDIR/MacOSX.sdk/usr/include -fmodules -fmodules-cache-path=DIR/module-cache -fimplicit-module-maps -o DIR/client.c.o", | ||
"file": "DIR/client.c" | ||
} | ||
] | ||
|
||
//--- overlay.json.template | ||
{ | ||
"version": 0, | ||
"case-sensitive": "false", | ||
"roots": [ | ||
{ | ||
"external-contents": "DIR/BuildDir/B_vfs.h", | ||
"name": "DIR/MacOSX.sdk/usr/include/B/B_vfs.h", | ||
"type": "file" | ||
} | ||
] | ||
} | ||
|
||
//--- MacOSX.sdk/usr/include/A/module.modulemap | ||
module A [system] { | ||
umbrella "." | ||
} | ||
|
||
//--- MacOSX.sdk/usr/include/A/A.h | ||
typedef int A_type; | ||
|
||
//--- MacOSX.sdk/usr/include/B/module.modulemap | ||
module B [system] { | ||
umbrella "." | ||
} | ||
|
||
//--- MacOSX.sdk/usr/include/B/B.h | ||
#include <B/B_vfs.h> | ||
|
||
//--- BuildDir/B_vfs.h | ||
typedef int local_t; | ||
|
||
//--- MacOSX.sdk/usr/include/sys/sys.h | ||
#include <A/A.h> | ||
typedef int sys_t_m; | ||
|
||
//--- MacOSX.sdk/usr/include/sys/module.modulemap | ||
module sys [system] { | ||
umbrella "." | ||
} | ||
|
||
//--- MacOSX.sdk/usr/include/B_transitive/B.h | ||
#include <B/B.h> | ||
|
||
//--- MacOSX.sdk/usr/include/B_transitive/module.modulemap | ||
module B_transitive [system] { | ||
umbrella "." | ||
} | ||
|
||
//--- MacOSX.sdk/usr/include/C/module.modulemap | ||
module C [system] { | ||
umbrella "." | ||
} | ||
|
||
//--- MacOSX.sdk/usr/include/C/C.h | ||
#include <B_transitive/B.h> | ||
|
||
|
||
//--- client.c | ||
#include <A/A.h> | ||
#include <C/C.h> // This dependency transitively depends on a local header. |
139 changes: 139 additions & 0 deletions
139
clang/test/ClangScanDeps/prebuilt-modules-in-stable-dirs-with-prefix-mapping.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/// This test validates that modules that depend on prebuilt modules | ||
/// resolve `is-in-stable-directories` correctly. | ||
|
||
// REQUIRES: shell,ondisk_cas | ||
|
||
/// The steps are: | ||
/// 1. Scan dependencies to build the PCH. One of the module's depend on header | ||
/// that is seemingly from the sysroot. However, it depends on a local header. | ||
/// 2. Build the PCH & dependency PCMs. | ||
/// 3. Scan a source file that transitively depends on the same modules as the pcm. | ||
|
||
// REQUIRES: shell | ||
// RUN: rm -rf %t | ||
// RUN: split-file %s %t | ||
// RUN: sed -e "s|DIR|%/t|g" %t/compile-pch.json.in > %t/compile-pch.json | ||
// RUN: sed -e "s|DIR|%/t|g" %t/compile-commands.json.in > %t/compile-commands.json | ||
|
||
// == Scan PCH | ||
// RUN: clang-scan-deps -compilation-database %t/compile-pch.json -format experimental-full \ | ||
// RUN: -cas-path %t/cas -module-files-dir %t/modules \ | ||
// RUN: -prefix-map=%t/modules=/^modules -prefix-map=%t=/^src -prefix-map-sdk=/^sdk -prefix-map-toolchain=/^tc \ | ||
// RUN: > %t/deps_pch.db | ||
|
||
// == Build Deps & PCH | ||
// RUN: %deps-to-rsp %t/deps_pch.db --module-name=A > %t/A.cc1.rsp | ||
// RUN: %deps-to-rsp %t/deps_pch.db --module-name=B > %t/B.cc1.rsp | ||
// RUN: %deps-to-rsp %t/deps_pch.db --module-name=B_transitive > %t/B_transitive.cc1.rsp | ||
// RUN: %deps-to-rsp %t/deps_pch.db --module-name=C > %t/C.cc1.rsp | ||
// RUN: %deps-to-rsp %t/deps_pch.db --tu-index 0 > %t/pch.cc1.rsp | ||
// RUN: %clang @%t/A.cc1.rsp | ||
// RUN: %clang @%t/B.cc1.rsp | ||
// RUN: %clang @%t/B_transitive.cc1.rsp | ||
// RUN: %clang @%t/C.cc1.rsp | ||
// Ensure we load pcms from action cache | ||
// RUN: rm -rf %t/modules | ||
// RUN: %clang @%t/pch.cc1.rsp | ||
|
||
// == Scan TU | ||
// RUN: clang-scan-deps -compilation-database %t/compile-commands.json -format experimental-full \ | ||
// RUN: -cas-path %t/cas -module-files-dir %t/modules \ | ||
// RUN: -prefix-map=%t/modules=/^modules -prefix-map=%t=/^src -prefix-map-sdk=/^sdk -prefix-map-toolchain=/^tc \ | ||
// RUN: > %t/deps.db | ||
|
||
// == Check Deps | ||
// RUN: cat %t/deps_pch.db | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t --check-prefix PCH_DEP | ||
// RUN: cat %t/deps.db | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t --check-prefix CLIENT | ||
|
||
// PCH_DEP: "is-in-stable-directories": true | ||
// PCH_DEP: "name": "A" | ||
|
||
// PCH_DEP-NOT: "is-in-stable-directories": true | ||
|
||
// Verify is-in-stable-directories is only assigned to the module that only depends on A. | ||
// CLIENT-NOT: "is-in-stable-directories": true | ||
|
||
// CLIENT: "name": "D" | ||
// CLIENT: "is-in-stable-directories": true | ||
// CLIENT: "name": "sys" | ||
|
||
// CLIENT-NOT: "is-in-stable-directories": true | ||
|
||
//--- compile-pch.json.in | ||
[ | ||
{ | ||
"directory": "DIR", | ||
"command": "clang -x c-header -c DIR/prebuild.h -isysroot DIR/MacOSX.sdk -IDIR/BuildDir -IDIR/MacOSX.sdk/usr/include -fmodules -fmodules-cache-path=DIR/module-cache -fimplicit-module-maps -o DIR/prebuild.pch", | ||
"file": "DIR/prebuild.h" | ||
} | ||
] | ||
|
||
//--- compile-commands.json.in | ||
[ | ||
{ | ||
"directory": "DIR", | ||
"command": "clang -c DIR/client.c -isysroot DIR/MacOSX.sdk -IDIR/BuildDir -IDIR/MacOSX.sdk/usr/include -fmodules -fmodules-cache-path=DIR/module-cache -fimplicit-module-maps -include-pch DIR/prebuild.pch", | ||
"file": "DIR/client.c" | ||
} | ||
] | ||
|
||
//--- MacOSX.sdk/usr/include/A/module.modulemap | ||
module A [system] { | ||
umbrella "." | ||
} | ||
|
||
//--- MacOSX.sdk/usr/include/A/A.h | ||
typedef int A_type; | ||
|
||
//--- MacOSX.sdk/usr/include/B/module.modulemap | ||
module B [system] { | ||
umbrella "." | ||
} | ||
|
||
//--- MacOSX.sdk/usr/include/B/B.h | ||
#include <Local/Local.h> | ||
|
||
//--- BuildDir/Local/Local.h | ||
typedef int local_t; | ||
|
||
//--- MacOSX.sdk/usr/include/sys/sys.h | ||
#include <A/A.h> | ||
typedef int sys_t_m; | ||
|
||
//--- MacOSX.sdk/usr/include/sys/module.modulemap | ||
module sys [system] { | ||
umbrella "." | ||
} | ||
|
||
//--- MacOSX.sdk/usr/include/B_transitive/B.h | ||
#include <B/B.h> | ||
|
||
//--- MacOSX.sdk/usr/include/B_transitive/module.modulemap | ||
module B_transitive [system] { | ||
umbrella "." | ||
} | ||
|
||
//--- MacOSX.sdk/usr/include/C/module.modulemap | ||
module C [system] { | ||
umbrella "." | ||
} | ||
|
||
//--- MacOSX.sdk/usr/include/C/C.h | ||
#include <B_transitive/B.h> | ||
|
||
|
||
//--- MacOSX.sdk/usr/include/D/module.modulemap | ||
module D [system] { | ||
umbrella "." | ||
} | ||
|
||
//--- MacOSX.sdk/usr/include/D/D.h | ||
#include <C/C.h> | ||
|
||
//--- prebuild.h | ||
#include <A/A.h> | ||
#include <C/C.h> // This dependency transitively depends on a local header. | ||
|
||
//--- client.c | ||
#include <sys/sys.h> | ||
#include <D/D.h> // This dependency transitively depends on a local header. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this change necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, a sysroot is always passed implicitly (through the lit testing configuration) and that doesn't match with the one passed in https://github.com/swiftlang/llvm-project/pull/10493/files#diff-aaa36845ad74ad6019adf78071e73c17d9e5db7080eb49de2605959a742d98faR100
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is that a problem now but wasn't before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertion was firing. I think the assertion should always hold unless a build is misconfigured, but I may be missing something.