From 9ec7bba8d029b29ed4387a0d59a92382aa2ade70 Mon Sep 17 00:00:00 2001 From: Meador Inge <meadori@codesourcery.com> Date: Tue, 4 Apr 2017 21:46:50 +0000 Subject: [PATCH] [Driver] Add option to print the resource directory This patch adds the option -print-resource-dir. It simply prints the resource directory. This information will eventually be used in compiler-rt to setup COMPILER_RT_LIBRARY_INSTALL_DIR. Patch by Catherine Moore! Differential Revision: https://reviews.llvm.org/D31447 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@299473 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Options.td | 2 ++ lib/Driver/Driver.cpp | 5 +++++ test/Driver/immediate-options.c | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 12b7ca21fc6..da1dd361ede 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -2091,6 +2091,8 @@ def print_multi_os_directory : Flag<["-", "--"], "print-multi-os-directory">, Flags<[Unsupported]>; def print_prog_name_EQ : Joined<["-", "--"], "print-prog-name=">, HelpText<"Print the full program path of <name>">, MetaVarName<"<name>">; +def print_resource_dir : Flag<["-", "--"], "print-resource-dir">, + HelpText<"Print the resource directory pathname">; def print_search_dirs : Flag<["-", "--"], "print-search-dirs">, HelpText<"Print the paths used for finding libraries and programs">; def private__bundle : Flag<["-"], "private_bundle">; diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 1633082fb07..adba98a93ed 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -1169,6 +1169,11 @@ bool Driver::HandleImmediateArgs(const Compilation &C) { if (C.getArgs().hasArg(options::OPT_v)) TC.printVerboseInfo(llvm::errs()); + if (C.getArgs().hasArg(options::OPT_print_resource_dir)) { + llvm::outs() << ResourceDir; + return false; + } + if (C.getArgs().hasArg(options::OPT_print_search_dirs)) { llvm::outs() << "programs: ="; bool separator = false; diff --git a/test/Driver/immediate-options.c b/test/Driver/immediate-options.c index f50ccae6421..935c948321f 100644 --- a/test/Driver/immediate-options.c +++ b/test/Driver/immediate-options.c @@ -12,3 +12,8 @@ // RUN: %clang -print-search-dirs | FileCheck %s -check-prefix=PRINT-SEARCH-DIRS // PRINT-SEARCH-DIRS: programs: ={{.*}} // PRINT-SEARCH-DIRS: libraries: ={{.*}} + +// Test if the -print-resource-dir option is accepted without error. +// Allow unspecified output because the value of CLANG_RESOURCE_DIR is unknown. +// RUN: %clang -print-resource-dir | FileCheck %s -check-prefix=PRINT-RESOURCE-DIR +// PRINT-RESOURCE-DIR: {{.+}} -- GitLab