From: Daniel Dunbar Date: Fri, 23 Sep 2011 20:33:41 +0000 (+0000) Subject: Driver: Add a --working-directory option which can be used to cause the compiler X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=63bc59bf22b8f2e672fcf3904fe33993f69e006f;p=clang Driver: Add a --working-directory option which can be used to cause the compiler to operate "as if" in a certain working directory. - For now, we just implement this by changing the actual working directory, but eventually we would want to handle this transparently. This is useful to avoid an extra exec() pair in some situations, and will be something we would want to support for more flexibility in using the Clang libraries. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140409 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/tools/clang.pod b/docs/tools/clang.pod index 704cc8743b..abecd1c8ef 100644 --- a/docs/tools/clang.pod +++ b/docs/tools/clang.pod @@ -407,6 +407,13 @@ Print timing summary of each stage of compilation. Show commands to run and use verbose output. +=item B<--working-directory> + +Use the given argument as the effective working directory to run the compiler +in. This is useful for running the compiler as if in a specific working +directory without the overhead of having to change directory using an auxiliary +process. + =back diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 3f48b96d75..770b7d86f9 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -855,6 +855,8 @@ def _verbose : Flag<"--verbose">, Alias; def _version : Flag<"--version">; def _warn__EQ : Joined<"--warn-=">, Alias; def _warn_ : Joined<"--warn-">, Alias; +def _working_directory : Separate<"--working-directory">, + HelpText<"Use the given argument as the effective working directory">; def _write_dependencies : Flag<"--write-dependencies">, Alias; def _write_user_dependencies : Flag<"--write-user-dependencies">, Alias; def _ : Joined<"--">, Flags<[Unsupported]>; diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index ec9295d6fb..d64eab5999 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -323,6 +323,13 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { if (Args->hasArg(options::OPT_nostdlib)) UseStdLib = false; + // Honor --working-directory. Eventually we want to handle this completely + // internally to support good use as a library, but for now we just change our + // working directory. + if (const Arg *A = Args->getLastArg(options::OPT__working_directory)) { + ::chdir(A->getValue(*Args)); + } + Host = GetHostInfo(DefaultHostTriple.c_str()); // Perform the default argument translations.