aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiana Picus <diana.picus@linaro.org>2017-03-14 17:38:32 +0100
committerDiana Picus <diana.picus@linaro.org>2017-04-24 15:48:56 +0200
commit3d1a30130a581e68afdbc027c82c5b1cd662ea6e (patch)
tree261513090b45c402f25e0f44931fcfca6db082fb
parentb430760d782ac5a4e1270d49038d0f400a3506c0 (diff)
downloadlinaro-scripts-3d1a30130a581e68afdbc027c82c5b1cd662ea6e.tar.gz
Remove the need for LLVM_SRC in llvm.py
Add an extra parameter to llvm.py representing the environment that we want the command to refer to. We then compute the path to the LLVM source tree based on that and LLVM_ROOT (which is still an environment variable for the time being). The bash helper keeps its old interface and uses LLVM_SRC to compute the environment that it will pass down to llvm.py. We also perform a small number of drive-by fixes to this helper (e.g. replacing python with python3). Change-Id: Ie7a33103969622294e158f83be8b9f57832ef1dc
-rwxr-xr-xhelpers/llvm-projs9
-rw-r--r--scripts/llvm.py28
-rw-r--r--tests/cli/testllvmprojects.py126
3 files changed, 116 insertions, 47 deletions
diff --git a/helpers/llvm-projs b/helpers/llvm-projs
index 288fc8c..ae8ac22 100755
--- a/helpers/llvm-projs
+++ b/helpers/llvm-projs
@@ -43,11 +43,16 @@ need_all() {
llvmtool=$progdir/../scripts/llvm.py
+# Grab the environment name from $LLVM_SRC
+. llvm-common
+verify_env
+env=$(basename $(dirname $LLVM_SRC))
+
# No args, list
if [ "$1" = "" ]; then
echo "Use $prog -h for options"
echo
- python $llvmtool projects
+ safe_run python3 $llvmtool $env projects
exit
fi
@@ -205,4 +210,4 @@ if [ "$remove" != "" ]; then
remove="-r $remove"
fi
-python $llvmtool projects $add $remove
+safe_run python3 $llvmtool $env projects $add $remove
diff --git a/scripts/llvm.py b/scripts/llvm.py
index 706af11..13e5de6 100644
--- a/scripts/llvm.py
+++ b/scripts/llvm.py
@@ -19,17 +19,25 @@ def die(message, config_to_dump=None):
exit(1)
+
+def get_llvm_root():
+ """Get the path to the LLVM root, which contains the repos as well as all
+ the work environments."""
+ return os.environ["LLVM_ROOT"]
+
+
+def get_worktree_root(env):
+ """
+ Get the path to the LLVM worktree corresponding to env. The value will be
+ based on the LLVM root.
+ """
+ return os.path.join(get_llvm_root(), env, "llvm")
+
# Figure out the path to the LLVM repos
if "LLVM_ROOT" not in os.environ:
die("Please, define $LLVM_ROOT to point to the root\n"
"path where the worktree setup should be performed")
-llvm_repos_root = os.path.join(os.environ["LLVM_ROOT"], "repos")
-
-# Figure out the path to the current LLVM tree
-if "LLVM_SRC" not in os.environ:
- die("Please, define $LLVM_SRC to point to the current LLVM\n"
- "worktree directory, or run llvm-env to set it for you")
-llvm_worktree_root = os.environ["LLVM_SRC"]
+llvm_repos_root = os.path.join(get_llvm_root(), "repos")
def dump_config(config):
@@ -48,6 +56,8 @@ def projects(args):
"""Add/remove subprojects based on the values in args."""
proj = Proj()
+
+ llvm_worktree_root = get_worktree_root(args.env)
config = LLVMSourceConfig(proj, llvm_worktree_root)
if not args.add and not args.remove:
@@ -77,10 +87,12 @@ def projects(args):
valid_subprojects = list(LLVMSubproject.get_all_subprojects().keys())
options = ArgumentParser(formatter_class=RawTextHelpFormatter)
+options.add_argument('env', help="The environment to update.")
+
subcommands = options.add_subparsers()
# Subcommand for adding / removing subprojects
-projs = subcommands.add_parser("projects", help="Add/remove LLVM subprojects")
+projs = subcommands.add_parser("projects", help="Add/remove LLVM subprojects.")
projs.set_defaults(run_command=projects)
# TODO: Overwriting previous values is not necessarily what users expect (so for
diff --git a/tests/cli/testllvmprojects.py b/tests/cli/testllvmprojects.py
index e8bb860..8374aff 100644
--- a/tests/cli/testllvmprojects.py
+++ b/tests/cli/testllvmprojects.py
@@ -99,7 +99,8 @@ class Testllvmprojs(unittest.TestCase):
@classmethod
def setUp(cls):
- cls.llvm_src = os.path.join(cls.llvm_root, "src" + str(uuid4()))
+ cls.env = "src" + str(uuid4())
+ cls.llvm_src = os.path.join(cls.llvm_root, cls.env, "llvm")
# Create LLVM worktree
cls.branch = "br" + str(uuid4())
@@ -108,7 +109,6 @@ class Testllvmprojs(unittest.TestCase):
# Set up the environment variables
os.environ["LLVM_ROOT"] = cls.llvm_root
- os.environ["LLVM_SRC"] = cls.llvm_src
@classmethod
def tearDown(cls):
@@ -133,18 +133,19 @@ class Testllvmprojs(unittest.TestCase):
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.python, self.script, "projects"])
+ output = self.run_with_output(
+ [self.python, self.script, self.env, "projects"])
self.assertRegex(output, "Projects linked:.*\n.*none.*")
def test_add_remove_subprojects(self):
"""
Test that we can add and remove one or several subprojects.
"""
- output = self.run_with_output([self.python, self.script, "projects",
- "--add", "clang"])
+ output = self.run_with_output(
+ [self.python, self.script, self.env, "projects", "--add", "clang"])
self.assertRegex(output, "Projects linked:.*\n.*clang.*")
- output = self.run_with_output([self.python, self.script, "projects",
+ output = self.run_with_output([self.python, self.script, self.env, "projects",
"--add", "libcxx", "lldb"])
self.assertRegex(
output,
@@ -153,14 +154,14 @@ class Testllvmprojs(unittest.TestCase):
".*libcxx.*\n" +
".*lldb.*")
- output = self.run_with_output([self.python, self.script, "projects",
- "--remove", "libcxx"])
+ output = self.run_with_output(
+ [self.python, self.script, self.env, "projects", "--remove", "libcxx"])
self.assertRegex(output,
"Projects linked:.*\n" +
".*clang.*\n" +
".*lldb.*")
- output = self.run_with_output([self.python, self.script, "projects",
+ output = self.run_with_output([self.python, self.script, self.env, "projects",
"--remove", "clang", "lldb"])
self.assertRegex(output,
"Projects linked:.*\n" +
@@ -172,7 +173,7 @@ class Testllvmprojs(unittest.TestCase):
subprojects.
"""
with self.assertRaises(subprocess.CalledProcessError) as context:
- self.run_with_output([self.python, self.script, "projects",
+ self.run_with_output([self.python, self.script, self.env, "projects",
"--add", "inventedsubproject"])
self.assertRegex(
@@ -180,8 +181,12 @@ class Testllvmprojs(unittest.TestCase):
"(.*\n)*.*invalid choice:.*inventedsubproject(.*\n)*")
with self.assertRaises(subprocess.CalledProcessError) as context:
- self.run_with_output([self.python, self.script, "projects",
- "--remove", "inventedsubproject"])
+ self.run_with_output([self.python,
+ self.script,
+ self.env,
+ "projects",
+ "--remove",
+ "inventedsubproject"])
self.assertRegex(
str(context.exception.output),
@@ -192,14 +197,14 @@ class Testllvmprojs(unittest.TestCase):
Test that we don't crash when trying to add / remove the same subproject
twice with the same command.
"""
- output = self.run_with_output([self.python, self.script, "projects",
+ output = self.run_with_output([self.python, self.script, self.env, "projects",
"--add", "clang", "lld", "clang"])
self.assertRegex(output,
"Projects linked:.*\n" +
".*clang.*\n" +
".*lld.*")
- output = self.run_with_output([self.python, self.script, "projects",
+ output = self.run_with_output([self.python, self.script, self.env, "projects",
"--remove", "lld", "lld", "clang"])
self.assertRegex(output,
"Projects linked:.*\n" +
@@ -219,13 +224,13 @@ class Testllvmprojs(unittest.TestCase):
os.path.join(self.llvm_src, "projects", "compiler-rt"),
self.branch)
- output = self.run_with_output([self.python, self.script, "projects",
- "--add", "clang"])
+ output = self.run_with_output(
+ [self.python, self.script, self.env, "projects", "--add", "clang"])
self.assertRegex(output,
"Projects linked:.*\n" +
".*clang.*")
- output = self.run_with_output([self.python, self.script, "projects",
+ output = self.run_with_output([self.python, self.script, self.env, "projects",
"--add", "compiler-rt", "lld"])
self.assertRegex(
output,
@@ -234,8 +239,14 @@ class Testllvmprojs(unittest.TestCase):
".*compiler-rt.*\n" +
".*lld.*")
- output = self.run_with_output([self.python, self.script, "projects",
- "--remove", "lldb", "libcxx", "lld"])
+ output = self.run_with_output([self.python,
+ self.script,
+ self.env,
+ "projects",
+ "--remove",
+ "lldb",
+ "libcxx",
+ "lld"])
self.assertRegex(
output,
"Projects linked:.*\n" +
@@ -249,8 +260,14 @@ class Testllvmprojs(unittest.TestCase):
"""
# Try the really basic case and make sure we're not touching anything
with self.assertRaises(subprocess.CalledProcessError) as context:
- self.run_with_output([self.python, self.script, "projects",
- "--add", "clang", "--remove", "clang"])
+ self.run_with_output([self.python,
+ self.script,
+ self.env,
+ "projects",
+ "--add",
+ "clang",
+ "--remove",
+ "clang"])
self.assertRegex(
str(context.exception.output),
@@ -268,9 +285,17 @@ class Testllvmprojs(unittest.TestCase):
self.branch)
with self.assertRaises(subprocess.CalledProcessError) as context:
- self.run_with_output([self.python, self.script, "projects",
- "--add", "clang", "lld", "libcxx",
- "--remove", "lld", "libcxx"])
+ self.run_with_output([self.python,
+ self.script,
+ self.env,
+ "projects",
+ "--add",
+ "clang",
+ "lld",
+ "libcxx",
+ "--remove",
+ "lld",
+ "libcxx"])
self.assertRegex(
str(context.exception.output),
"(.*\n)*" +
@@ -292,30 +317,57 @@ class Testllvmprojs(unittest.TestCase):
Test that we can have multiple --add and --remove options in the same
command and that only the last one of each kind matters.
"""
- output = self.run_with_output([self.python, self.script, "projects",
- "--add", "libcxxabi",
- "--remove", "lld", "lldb",
- "--add", "clang", "libcxx",
- "--remove", "libunwind"])
+ output = self.run_with_output([self.python,
+ self.script,
+ self.env,
+ "projects",
+ "--add",
+ "libcxxabi",
+ "--remove",
+ "lld",
+ "lldb",
+ "--add",
+ "clang",
+ "libcxx",
+ "--remove",
+ "libunwind"])
self.assertRegex(output,
"Projects linked:.*\n" +
".*clang.*\n" +
".*libcxx.*\n")
- output = self.run_with_output([self.python, self.script, "projects",
- "--add", "libunwind", "libcxxabi",
- "--remove", "clang", "libcxx",
- "--add", "compiler-rt",
- "--remove", "libcxxabi"])
+ output = self.run_with_output([self.python,
+ self.script,
+ self.env,
+ "projects",
+ "--add",
+ "libunwind",
+ "libcxxabi",
+ "--remove",
+ "clang",
+ "libcxx",
+ "--add",
+ "compiler-rt",
+ "--remove",
+ "libcxxabi"])
self.assertRegex(output,
"Projects linked:.*\n" +
".*clang.*\n" +
".*compiler-rt.*\n" +
".*libcxx.*\n")
- output = self.run_with_output([self.python, self.script, "projects",
- "--add", "libcxx", "--remove", "lld",
- "--add", "lld", "--remove", "libcxx"])
+ output = self.run_with_output([self.python,
+ self.script,
+ self.env,
+ "projects",
+ "--add",
+ "libcxx",
+ "--remove",
+ "lld",
+ "--add",
+ "lld",
+ "--remove",
+ "libcxx"])
self.assertRegex(output,
"Projects linked:.*\n" +
".*clang.*\n" +