Replace --env with --source-dir

Remove the --env argument, which was compulsory for all subcommands, and
replace it with a --source-dir argument, only for those subcommands that
need it.

We do this for 2 reasons:
* Not all subcommands care about the source directory (e.g. llvm.py
  build won't need it)
* llvm.py should not have any knowledge about environments - that
  concept only makes sense for the helper scripts. llvm.py should
  instead receive very specific info about where the source and build
  directories are.

Change-Id: Iffaeef95559e8923bd883d5c51fed8c306287280
diff --git a/tests/cli/testllvmprojects.py b/tests/cli/testllvmprojects.py
index ac1cd23..32cead4 100644
--- a/tests/cli/testllvmprojects.py
+++ b/tests/cli/testllvmprojects.py
@@ -79,28 +79,36 @@
         """
         with self.assertRaises(subprocess.CalledProcessError) as context:
             self.run_with_output(
-                self.llvm_projects("--add", "clang"))
+                self.llvm_projects(
+                    "--source-dir",
+                    self.llvm_src,
+                    "--add",
+                    "clang"))
 
         self.assertRegex(
             str(context.exception.output),
             "(.*\n)*.*When adding a subproject you must also pass the --repos argument(.*\n)*")
 
         # These should not raise.
-        self.run_with_output(self.llvm_projects())
+        self.run_with_output(self.llvm_projects("--source-dir", self.llvm_src))
         self.run_with_output(
-            self.llvm_projects("--remove", "clang"))
+            self.llvm_projects(
+                "--source-dir",
+                self.llvm_src,
+                "--remove",
+                "clang"))
 
-    def test_env_arg_is_compulsory(self):
+    def test_source_dir_is_compulsory(self):
         """
-        Test that we must pass in the environment for various combinations of
+        Test that we must pass in the source dir for various combinations of
         input args.
         """
         with self.assertRaises(subprocess.CalledProcessError) as context:
-            self.run_with_output(self.llvm_projects(env=None))
+            self.run_with_output(self.llvm_projects())
 
         self.assertRegex(
             str(context.exception.output),
-            "(.*\n)*.*the following arguments are required:(.*)--env(.*\n)*")
+            "(.*\n)*.*the following arguments are required:(.*)--source-dir(.*\n)*")
 
         with self.assertRaises(subprocess.CalledProcessError) as context:
             self.run_with_output(
@@ -110,7 +118,7 @@
 
         self.assertRegex(
             str(context.exception.output),
-            "(.*\n)*.*the following arguments are required:(.*)--env(.*\n)*")
+            "(.*\n)*.*the following arguments are required:(.*)--source-dir(.*\n)*")
 
         with self.assertRaises(subprocess.CalledProcessError) as context:
             self.run_with_output(
@@ -119,14 +127,15 @@
 
         self.assertRegex(
             str(context.exception.output),
-            "(.*\n)*.*the following arguments are required:(.*)--env(.*\n)*")
+            "(.*\n)*.*the following arguments are required:(.*)--source-dir(.*\n)*")
 
     def test_dump_empty_config(self):
         """
         Test that we're correctly dumping an empty configuration (i.e. no
         projects linked) when running llvmprojs without arguments.
         """
-        output = self.run_with_output(self.llvm_projects())
+        output = self.run_with_output(
+            self.llvm_projects("--source-dir", self.llvm_src))
         self.assertRegex(output, "Projects linked:.*\n.*none.*")
 
     def test_add_remove_subprojects(self):
@@ -134,12 +143,14 @@
         Test that we can add and remove one or several subprojects.
         """
         output = self.run_with_output(self.llvm_projects(
+            "--source-dir", self.llvm_src,
             "--repos", self.repos,
             "--add", "clang"))
         self.assertRegex(output, "Projects linked:.*\n.*clang.*")
 
         output = self.run_with_output(
             self.llvm_projects(
+                "--source-dir", self.llvm_src,
                 "--repos", self.repos,
                 "--add", "libcxx", "lldb"))
         self.assertRegex(
@@ -149,7 +160,12 @@
             ".*libcxx.*\n" +
             ".*lldb.*")
 
-        output = self.run_with_output(self.llvm_projects("--remove", "libcxx"))
+        output = self.run_with_output(
+            self.llvm_projects(
+                "--source-dir",
+                self.llvm_src,
+                "--remove",
+                "libcxx"))
         self.assertRegex(output,
                          "Projects linked:.*\n" +
                          ".*clang.*\n" +
@@ -157,6 +173,7 @@
 
         output = self.run_with_output(
             self.llvm_projects(
+                "--source-dir", self.llvm_src,
                 "--remove", "clang", "lldb"))
         self.assertRegex(output,
                          "Projects linked:.*\n" +
@@ -170,6 +187,7 @@
         with self.assertRaises(subprocess.CalledProcessError) as context:
             self.run_with_output(
                 self.llvm_projects(
+                    "--source-dir", self.llvm_src,
                     "--repos", self.repos,
                     "--add", "inventedsubproject"))
 
@@ -180,6 +198,7 @@
         with self.assertRaises(subprocess.CalledProcessError) as context:
             self.run_with_output(
                 self.llvm_projects(
+                    "--source-dir", self.llvm_src,
                     "--remove",
                     "inventedsubproject"))
 
@@ -194,6 +213,7 @@
         """
         output = self.run_with_output(
             self.llvm_projects(
+                "--source-dir", self.llvm_src,
                 "--repos", self.repos,
                 "--add", "clang", "lld", "clang"))
         self.assertRegex(output,
@@ -203,6 +223,7 @@
 
         output = self.run_with_output(
             self.llvm_projects(
+                "--source-dir", self.llvm_src,
                 "--remove", "lld", "lld", "clang"))
         self.assertRegex(output,
                          "Projects linked:.*\n" +
@@ -223,6 +244,7 @@
             self.branch)
 
         output = self.run_with_output(self.llvm_projects(
+            "--source-dir", self.llvm_src,
             "--repos", self.repos,
             "--add", "clang"))
         self.assertRegex(output,
@@ -231,6 +253,7 @@
 
         output = self.run_with_output(
             self.llvm_projects(
+                "--source-dir", self.llvm_src,
                 "--repos", self.repos,
                 "--add", "compiler-rt", "lld"))
         self.assertRegex(
@@ -242,6 +265,7 @@
 
         output = self.run_with_output(
             self.llvm_projects(
+                "--source-dir", self.llvm_src,
                 "--remove", "lldb", "libcxx", "lld"))
         self.assertRegex(
             output,
@@ -258,6 +282,8 @@
         with self.assertRaises(subprocess.CalledProcessError) as context:
             self.run_with_output(
                 self.llvm_projects(
+                    "--source-dir",
+                    self.llvm_src,
                     "--repos",
                     self.repos,
                     "--add",
@@ -283,6 +309,8 @@
         with self.assertRaises(subprocess.CalledProcessError) as context:
             self.run_with_output(
                 self.llvm_projects(
+                    "--source-dir",
+                    self.llvm_src,
                     "--repos",
                     self.repos,
                     "--add",
@@ -315,6 +343,8 @@
         """
         output = self.run_with_output(
             self.llvm_projects(
+                "--source-dir",
+                self.llvm_src,
                 "--repos",
                 self.repos,
                 "--add",
@@ -334,6 +364,8 @@
 
         output = self.run_with_output(
             self.llvm_projects(
+                "--source-dir",
+                self.llvm_src,
                 "--repos",
                 self.repos,
                 "--add",
@@ -354,6 +386,8 @@
 
         output = self.run_with_output(
             self.llvm_projects(
+                "--source-dir",
+                self.llvm_src,
                 "--repos",
                 self.repos,
                 "--add",
@@ -377,49 +411,62 @@
         """
         # Create a separate environment
         new_env = mkdtemp()
+        new_llvm_src = os.path.join(new_env, "llvm")
         new_branch = "br" + str(uuid4())
-        self.add_worktree(self.get_subproj_repo("llvm"),
-                          os.path.join(new_env, "llvm"), new_branch)
+        self.add_worktree(
+            self.get_subproj_repo("llvm"),
+            new_llvm_src,
+            new_branch)
 
         # Check that we start with a clean slate in both the new environment and
         # the one that's already set up
-        output = self.run_with_output(self.llvm_projects())
+        output = self.run_with_output(self.llvm_projects("--source-dir",
+                                                         self.llvm_src))
         self.assertRegex(output, "Projects linked:.*\n.*none.*")
 
-        output = self.run_with_output(self.llvm_projects(env=new_env))
+        output = self.run_with_output(self.llvm_projects("--source-dir",
+                                                         new_llvm_src))
         self.assertRegex(output, "Projects linked:.*\n.*none.*")
 
         # Make sure that adding projects works
         output = self.run_with_output(
             self.llvm_projects(
+                "--source-dir", self.llvm_src,
                 "--repos", self.repos,
                 "--add", "clang", "lld"))
         self.assertRegex(output, "Projects linked:.*\n.*clang.*\n.*lld.*\n")
 
         output = self.run_with_output(
             self.llvm_projects(
+                "--source-dir",
+                new_llvm_src,
                 "--repos",
                 self.repos,
                 "--add",
                 "libcxx",
-                "libcxxabi",
-                env=new_env))
+                "libcxxabi"))
         self.assertRegex(output,
                          "Projects linked:.*\n.*libcxx.*\n.*libcxxabi.*\n.*")
 
-        output = self.run_with_output(self.llvm_projects())
+        output = self.run_with_output(
+            self.llvm_projects("--source-dir", self.llvm_src))
         self.assertRegex(output, "Projects linked:.*\n.*clang.*\n.*lld.*\n")
 
         # Make sure that removing projects works
-        output = self.run_with_output(self.llvm_projects("--remove", "lld"))
+        output = self.run_with_output(
+            self.llvm_projects(
+                "--source-dir", self.llvm_src,
+                "--remove", "lld"))
         self.assertRegex(output, "Projects linked:.*\n.*clang.*\n")
 
         output = self.run_with_output(self.llvm_projects("--remove", "libcxx",
-                                                         env=new_env))
+                                                         "--source-dir",
+                                                         new_llvm_src))
         self.assertRegex(output,
                          "Projects linked:.*\n.*libcxxabi.*\n.*")
 
-        output = self.run_with_output(self.llvm_projects())
+        output = self.run_with_output(
+            self.llvm_projects("--source-dir", self.llvm_src))
         self.assertRegex(output, "Projects linked:.*\n.*clang.*\n")
 
         shutil.rmtree(new_env)