Skip to content

[Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory #90886

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 8 commits into from
May 14, 2024
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
3 changes: 3 additions & 0 deletions clang/include/clang/Driver/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,9 @@ class Driver {
/// option.
void setDriverMode(StringRef DriverModeValue);

/// Set the resource directory, depending on which driver is being used.
void setResourceDirectory();

/// Parse the \p Args list for LTO options and record the type of LTO
/// compilation based on which -f(no-)?lto(=.*)? option occurs last.
void setLTOMode(const llvm::opt::ArgList &Args);
Expand Down
5 changes: 4 additions & 1 deletion clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -5474,7 +5474,10 @@ def print_prog_name_EQ : Joined<["-", "--"], "print-prog-name=">,
Visibility<[ClangOption, CLOption]>;
def print_resource_dir : Flag<["-", "--"], "print-resource-dir">,
HelpText<"Print the resource directory pathname">,
Visibility<[ClangOption, CLOption]>;
HelpTextForVariants<[FlangOption],
"Print the resource directory pathname that contains lib and "
"include directories with the runtime libraries and MODULE files.">,
Visibility<[ClangOption, CLOption, FlangOption]>;
def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
HelpText<"Print the paths used for finding libraries and programs">,
Visibility<[ClangOption, CLOption]>;
Expand Down
22 changes: 19 additions & 3 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,6 @@ Driver::Driver(StringRef ClangExecutable, StringRef TargetTriple,
UserConfigDir = static_cast<std::string>(P);
}
#endif

// Compute the path to the resource directory.
ResourceDir = GetResourcesPath(ClangExecutable, CLANG_RESOURCE_DIR);
}

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

void Driver::setResourceDirectory() {
// Compute the path to the resource directory, depending on the driver mode.
switch (Mode) {
case GCCMode:
case GXXMode:
case CPPMode:
case CLMode:
case DXCMode:
ResourceDir = GetResourcesPath(ClangExecutable, CLANG_RESOURCE_DIR);
break;
case FlangMode:
SmallString<64> customResourcePathRelativeToDriver{".."};
ResourceDir =
GetResourcesPath(ClangExecutable, customResourcePathRelativeToDriver);
break;
}
}

InputArgList Driver::ParseArgStrings(ArrayRef<const char *> ArgStrings,
bool UseDriverMode, bool &ContainsError) {
llvm::PrettyStackTraceString CrashInfo("Command line argument parsing");
Expand Down Expand Up @@ -1202,6 +1217,7 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
if (!DriverMode.empty())
setDriverMode(DriverMode);

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

// Arguments specified in command line.
Expand Down
172 changes: 0 additions & 172 deletions flang/test/Driver/driver-help-hidden.f90

This file was deleted.

4 changes: 4 additions & 0 deletions flang/test/Driver/print-resource-dir.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
! DEFINE: %{resource_dir} = %S/Inputs/resource_dir
! RUN: %flang -print-resource-dir -resource-dir=%{resource_dir}.. \
! RUN: | FileCheck -check-prefix=PRINT-RESOURCE-DIR -DFILE=%{resource_dir} %s
! PRINT-RESOURCE-DIR: [[FILE]]
Loading