]> granicus.if.org Git - clang/commitdiff
Driver: Add a --working-directory option which can be used to cause the compiler
authorDaniel Dunbar <daniel@zuster.org>
Fri, 23 Sep 2011 20:33:41 +0000 (20:33 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 23 Sep 2011 20:33:41 +0000 (20:33 +0000)
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

docs/tools/clang.pod
include/clang/Driver/Options.td
lib/Driver/Driver.cpp

index 704cc8743ba6fa00f394e6a1ed3d188468b294f0..abecd1c8ef500b2070e17c6688021f0a3cc87b61 100644 (file)
@@ -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
 
 
index 3f48b96d758367ff1f3fc5932c2eb3ac4163baf9..770b7d86f9fdadc34719a107990c777320359691 100644 (file)
@@ -855,6 +855,8 @@ def _verbose : Flag<"--verbose">, Alias<v>;
 def _version : Flag<"--version">;
 def _warn__EQ : Joined<"--warn-=">, Alias<W_Joined>;
 def _warn_ : Joined<"--warn-">, Alias<W_Joined>;
+def _working_directory : Separate<"--working-directory">,
+    HelpText<"Use the given argument as the effective working directory">;
 def _write_dependencies : Flag<"--write-dependencies">, Alias<MD>;
 def _write_user_dependencies : Flag<"--write-user-dependencies">, Alias<MMD>;
 def _ : Joined<"--">, Flags<[Unsupported]>;
index ec9295d6fb71eeaf590599a4d1f5f394f50a2528..d64eab5999bd17d7641822a00fd8ec1b0253e305 100644 (file)
@@ -323,6 +323,13 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> 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.