Skip to content

Commit 2df06e4

Browse files
authored
[Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (#90886)
This should be a NFC change for all drivers, but Flang.
1 parent c441aa5 commit 2df06e4

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

clang/include/clang/Driver/Driver.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,9 @@ class Driver {
747747
/// option.
748748
void setDriverMode(StringRef DriverModeValue);
749749

750+
/// Set the resource directory, depending on which driver is being used.
751+
void setResourceDirectory();
752+
750753
/// Parse the \p Args list for LTO options and record the type of LTO
751754
/// compilation based on which -f(no-)?lto(=.*)? option occurs last.
752755
void setLTOMode(const llvm::opt::ArgList &Args);

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5491,7 +5491,10 @@ def print_prog_name_EQ : Joined<["-", "--"], "print-prog-name=">,
54915491
Visibility<[ClangOption, CLOption]>;
54925492
def print_resource_dir : Flag<["-", "--"], "print-resource-dir">,
54935493
HelpText<"Print the resource directory pathname">,
5494-
Visibility<[ClangOption, CLOption]>;
5494+
HelpTextForVariants<[FlangOption],
5495+
"Print the resource directory pathname that contains lib and "
5496+
"include directories with the runtime libraries and MODULE files.">,
5497+
Visibility<[ClangOption, CLOption, FlangOption]>;
54955498
def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
54965499
HelpText<"Print the paths used for finding libraries and programs">,
54975500
Visibility<[ClangOption, CLOption]>;

clang/lib/Driver/Driver.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,6 @@ Driver::Driver(StringRef ClangExecutable, StringRef TargetTriple,
229229
UserConfigDir = static_cast<std::string>(P);
230230
}
231231
#endif
232-
233-
// Compute the path to the resource directory.
234-
ResourceDir = GetResourcesPath(ClangExecutable, CLANG_RESOURCE_DIR);
235232
}
236233

237234
void Driver::setDriverMode(StringRef Value) {
@@ -250,6 +247,24 @@ void Driver::setDriverMode(StringRef Value) {
250247
Diag(diag::err_drv_unsupported_option_argument) << OptName << Value;
251248
}
252249

250+
void Driver::setResourceDirectory() {
251+
// Compute the path to the resource directory, depending on the driver mode.
252+
switch (Mode) {
253+
case GCCMode:
254+
case GXXMode:
255+
case CPPMode:
256+
case CLMode:
257+
case DXCMode:
258+
ResourceDir = GetResourcesPath(ClangExecutable, CLANG_RESOURCE_DIR);
259+
break;
260+
case FlangMode:
261+
SmallString<64> customResourcePathRelativeToDriver{".."};
262+
ResourceDir =
263+
GetResourcesPath(ClangExecutable, customResourcePathRelativeToDriver);
264+
break;
265+
}
266+
}
267+
253268
InputArgList Driver::ParseArgStrings(ArrayRef<const char *> ArgStrings,
254269
bool UseDriverMode, bool &ContainsError) {
255270
llvm::PrettyStackTraceString CrashInfo("Command line argument parsing");
@@ -1202,6 +1217,7 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
12021217
if (!DriverMode.empty())
12031218
setDriverMode(DriverMode);
12041219

1220+
setResourceDirectory();
12051221
// FIXME: What are we going to do with -V and -b?
12061222

12071223
// Arguments specified in command line.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
! DEFINE: %{resource_dir} = %S/Inputs/resource_dir
2+
! RUN: %flang -print-resource-dir -resource-dir=%{resource_dir}.. \
3+
! RUN: | FileCheck -check-prefix=PRINT-RESOURCE-DIR -DFILE=%{resource_dir} %s
4+
! PRINT-RESOURCE-DIR: [[FILE]]

0 commit comments

Comments
 (0)