Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 1 | """Command line interface tests for llvmprojs.py |
| 2 | |
| 3 | Note that although this uses the unittest framework, it does *not* contain unit |
| 4 | tests. |
| 5 | |
| 6 | """ |
| 7 | |
| 8 | import shutil |
| 9 | import os |
| 10 | import subprocess |
| 11 | import unittest |
| 12 | |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 13 | from tempfile import mkdtemp |
| 14 | from uuid import uuid4 |
| 15 | |
| 16 | from linaropy.cd import cd |
Diana Picus | 3601bea | 2017-05-29 11:26:18 +0200 | [diff] [blame] | 17 | from llvmtestcase import LLVMTestCase |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 18 | |
| 19 | |
Diana Picus | 3601bea | 2017-05-29 11:26:18 +0200 | [diff] [blame] | 20 | class Testllvmprojs(LLVMTestCase): |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 21 | |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 22 | @classmethod |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 23 | def llvm_projects(cls, *args, **kwargs): |
Diana Picus | 3601bea | 2017-05-29 11:26:18 +0200 | [diff] [blame] | 24 | return cls.command_with_defaults("projects", *args, **kwargs) |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 25 | |
| 26 | @classmethod |
Diana Picus | efc7bda | 2017-06-09 19:14:08 +0200 | [diff] [blame] | 27 | def get_subproj_repo(cls, subproj): |
| 28 | return os.path.join(cls.repos, subproj) |
| 29 | |
| 30 | @classmethod |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 31 | def setUpClass(cls): |
| 32 | """Create the file structure and environment that llvmprojs expects""" |
| 33 | cls.llvm_root = mkdtemp() |
| 34 | cls.repos = os.path.join(cls.llvm_root, "repos") |
| 35 | |
| 36 | cls.all_repos = ("llvm", "clang", "compiler-rt", "lld", "lldb", |
| 37 | "libcxx", "libcxxabi", "libunwind", "test-suite") |
| 38 | |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 39 | # Create dummy repos |
| 40 | for reponame in cls.all_repos: |
Diana Picus | 3601bea | 2017-05-29 11:26:18 +0200 | [diff] [blame] | 41 | cls.create_dummy_repo(cls.get_subproj_repo(reponame)) |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 42 | |
| 43 | @classmethod |
| 44 | def tearDownClass(cls): |
| 45 | shutil.rmtree(cls.llvm_root) |
| 46 | |
| 47 | @classmethod |
| 48 | def setUp(cls): |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 49 | cls.env = os.path.join(cls.llvm_root, "env" + str(uuid4())) |
| 50 | cls.llvm_src = os.path.join(cls.env, "llvm") |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 51 | |
| 52 | # Create LLVM worktree |
| 53 | cls.branch = "br" + str(uuid4()) |
Diana Picus | 3601bea | 2017-05-29 11:26:18 +0200 | [diff] [blame] | 54 | cls.add_worktree(cls.get_subproj_repo("llvm"), cls.llvm_src, |
| 55 | cls.branch) |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 56 | |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 57 | @classmethod |
| 58 | def tearDown(cls): |
| 59 | # Clean up the directories where we might have added subprojects. |
| 60 | # This isn't 100% clean, because we don't clean up the repos between |
| 61 | # tests (so any branches will remain), but it's good enough for the |
| 62 | # current tests. |
| 63 | for subprojdir in (os.path.join(cls.llvm_src, "projects"), |
| 64 | os.path.join(cls.llvm_src, "tools")): |
| 65 | if os.path.isdir(subprojdir): |
| 66 | shutil.rmtree(subprojdir) |
| 67 | os.makedirs(subprojdir) |
| 68 | |
| 69 | # Run prune on the original repos, to remove any dangling worktrees. |
| 70 | for reponame in cls.all_repos: |
Diana Picus | 3601bea | 2017-05-29 11:26:18 +0200 | [diff] [blame] | 71 | repopath = cls.get_subproj_repo(reponame) |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 72 | with cd(repopath): |
| 73 | cls.run_quietly(["git", "worktree", "prune"]) |
| 74 | |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 75 | def test_repos_arg_is_compulsory_for_add(self): |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 76 | """ |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 77 | Test that we must pass in the repos when adding a subproject, but not |
| 78 | for other combinations of arguments. |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 79 | """ |
| 80 | with self.assertRaises(subprocess.CalledProcessError) as context: |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 81 | self.run_with_output( |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 82 | self.llvm_projects( |
| 83 | "--source-dir", |
| 84 | self.llvm_src, |
| 85 | "--add", |
| 86 | "clang")) |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 87 | |
| 88 | self.assertRegex( |
| 89 | str(context.exception.output), |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 90 | "(.*\n)*.*When adding a subproject you must also pass the --repos argument(.*\n)*") |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 91 | |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 92 | # These should not raise. |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 93 | self.run_with_output(self.llvm_projects("--source-dir", self.llvm_src)) |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 94 | self.run_with_output( |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 95 | self.llvm_projects( |
| 96 | "--source-dir", |
| 97 | self.llvm_src, |
| 98 | "--remove", |
| 99 | "clang")) |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 100 | |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 101 | def test_source_dir_is_compulsory(self): |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 102 | """ |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 103 | Test that we must pass in the source dir for various combinations of |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 104 | input args. |
| 105 | """ |
| 106 | with self.assertRaises(subprocess.CalledProcessError) as context: |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 107 | self.run_with_output(self.llvm_projects()) |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 108 | |
| 109 | self.assertRegex( |
| 110 | str(context.exception.output), |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 111 | "(.*\n)*.*the following arguments are required:(.*)--source-dir(.*\n)*") |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 112 | |
| 113 | with self.assertRaises(subprocess.CalledProcessError) as context: |
| 114 | self.run_with_output( |
| 115 | self.llvm_projects( |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 116 | "--repos", self.repos, |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 117 | "--add", "clang", env=None)) |
| 118 | |
| 119 | self.assertRegex( |
| 120 | str(context.exception.output), |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 121 | "(.*\n)*.*the following arguments are required:(.*)--source-dir(.*\n)*") |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 122 | |
| 123 | with self.assertRaises(subprocess.CalledProcessError) as context: |
| 124 | self.run_with_output( |
| 125 | self.llvm_projects( |
| 126 | "--remove", "clang", env=None)) |
| 127 | |
| 128 | self.assertRegex( |
| 129 | str(context.exception.output), |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 130 | "(.*\n)*.*the following arguments are required:(.*)--source-dir(.*\n)*") |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 131 | |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 132 | def test_dump_empty_config(self): |
| 133 | """ |
| 134 | Test that we're correctly dumping an empty configuration (i.e. no |
| 135 | projects linked) when running llvmprojs without arguments. |
| 136 | """ |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 137 | output = self.run_with_output( |
| 138 | self.llvm_projects("--source-dir", self.llvm_src)) |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 139 | self.assertRegex(output, "Projects linked:.*\n.*none.*") |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 140 | |
| 141 | def test_add_remove_subprojects(self): |
| 142 | """ |
| 143 | Test that we can add and remove one or several subprojects. |
| 144 | """ |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 145 | output = self.run_with_output(self.llvm_projects( |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 146 | "--source-dir", self.llvm_src, |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 147 | "--repos", self.repos, |
| 148 | "--add", "clang")) |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 149 | self.assertRegex(output, "Projects linked:.*\n.*clang.*") |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 150 | |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 151 | output = self.run_with_output( |
| 152 | self.llvm_projects( |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 153 | "--source-dir", self.llvm_src, |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 154 | "--repos", self.repos, |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 155 | "--add", "libcxx", "lldb")) |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 156 | self.assertRegex( |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 157 | output, |
| 158 | "Projects linked:.*\n" + |
| 159 | ".*clang.*\n" + |
| 160 | ".*libcxx.*\n" + |
| 161 | ".*lldb.*") |
| 162 | |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 163 | output = self.run_with_output( |
| 164 | self.llvm_projects( |
| 165 | "--source-dir", |
| 166 | self.llvm_src, |
| 167 | "--remove", |
| 168 | "libcxx")) |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 169 | self.assertRegex(output, |
| 170 | "Projects linked:.*\n" + |
| 171 | ".*clang.*\n" + |
| 172 | ".*lldb.*") |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 173 | |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 174 | output = self.run_with_output( |
| 175 | self.llvm_projects( |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 176 | "--source-dir", self.llvm_src, |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 177 | "--remove", "clang", "lldb")) |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 178 | self.assertRegex(output, |
| 179 | "Projects linked:.*\n" + |
| 180 | ".*none.*") |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 181 | |
| 182 | def test_add_remove_invalid_subprojects(self): |
| 183 | """ |
| 184 | Test that we error out nicely when trying to add/remove invalid |
| 185 | subprojects. |
| 186 | """ |
| 187 | with self.assertRaises(subprocess.CalledProcessError) as context: |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 188 | self.run_with_output( |
| 189 | self.llvm_projects( |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 190 | "--source-dir", self.llvm_src, |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 191 | "--repos", self.repos, |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 192 | "--add", "inventedsubproject")) |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 193 | |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 194 | self.assertRegex( |
| 195 | str(context.exception.output), |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 196 | "(.*\n)*.*invalid choice:.*inventedsubproject(.*\n)*") |
| 197 | |
| 198 | with self.assertRaises(subprocess.CalledProcessError) as context: |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 199 | self.run_with_output( |
| 200 | self.llvm_projects( |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 201 | "--source-dir", self.llvm_src, |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 202 | "--remove", |
| 203 | "inventedsubproject")) |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 204 | |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 205 | self.assertRegex( |
| 206 | str(context.exception.output), |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 207 | "(.*\n)*.*invalid choice:.*inventedsubproject(.*\n)*") |
| 208 | |
| 209 | def test_duplicate_add_remove(self): |
| 210 | """ |
| 211 | Test that we don't crash when trying to add / remove the same subproject |
| 212 | twice with the same command. |
| 213 | """ |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 214 | output = self.run_with_output( |
| 215 | self.llvm_projects( |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 216 | "--source-dir", self.llvm_src, |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 217 | "--repos", self.repos, |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 218 | "--add", "clang", "lld", "clang")) |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 219 | self.assertRegex(output, |
| 220 | "Projects linked:.*\n" + |
| 221 | ".*clang.*\n" + |
| 222 | ".*lld.*") |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 223 | |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 224 | output = self.run_with_output( |
| 225 | self.llvm_projects( |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 226 | "--source-dir", self.llvm_src, |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 227 | "--remove", "lld", "lld", "clang")) |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 228 | self.assertRegex(output, |
| 229 | "Projects linked:.*\n" + |
| 230 | ".*none.*") |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 231 | |
| 232 | def test_redundant_add_remove(self): |
| 233 | """ |
| 234 | Test that we can add a subproject that already exists (either because it |
| 235 | was added by our script or manually) or remove a subproject that doesn't |
| 236 | exist. |
| 237 | """ |
Diana Picus | 3601bea | 2017-05-29 11:26:18 +0200 | [diff] [blame] | 238 | self.add_worktree(self.get_subproj_repo("clang"), |
| 239 | os.path.join(self.llvm_src, "tools", "clang"), |
| 240 | self.branch) |
| 241 | self.add_worktree( |
| 242 | self.get_subproj_repo("compiler-rt"), |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 243 | os.path.join(self.llvm_src, "projects", "compiler-rt"), |
| 244 | self.branch) |
| 245 | |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 246 | output = self.run_with_output(self.llvm_projects( |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 247 | "--source-dir", self.llvm_src, |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 248 | "--repos", self.repos, |
| 249 | "--add", "clang")) |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 250 | self.assertRegex(output, |
| 251 | "Projects linked:.*\n" + |
| 252 | ".*clang.*") |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 253 | |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 254 | output = self.run_with_output( |
| 255 | self.llvm_projects( |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 256 | "--source-dir", self.llvm_src, |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 257 | "--repos", self.repos, |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 258 | "--add", "compiler-rt", "lld")) |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 259 | self.assertRegex( |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 260 | output, |
| 261 | "Projects linked:.*\n" + |
| 262 | ".*clang.*\n" + |
| 263 | ".*compiler-rt.*\n" + |
| 264 | ".*lld.*") |
| 265 | |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 266 | output = self.run_with_output( |
| 267 | self.llvm_projects( |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 268 | "--source-dir", self.llvm_src, |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 269 | "--remove", "lldb", "libcxx", "lld")) |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 270 | self.assertRegex( |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 271 | output, |
| 272 | "Projects linked:.*\n" + |
| 273 | ".*clang.*\n" + |
| 274 | ".*compiler-rt.*") |
| 275 | |
| 276 | def test_simultaneous_add_remove(self): |
| 277 | """ |
| 278 | Test that we error out when someone is trying to add and remove the same |
| 279 | project with the same command. |
| 280 | """ |
| 281 | # Try the really basic case and make sure we're not touching anything |
| 282 | with self.assertRaises(subprocess.CalledProcessError) as context: |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 283 | self.run_with_output( |
| 284 | self.llvm_projects( |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 285 | "--source-dir", |
| 286 | self.llvm_src, |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 287 | "--repos", |
| 288 | self.repos, |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 289 | "--add", |
| 290 | "clang", |
| 291 | "--remove", |
| 292 | "clang")) |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 293 | |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 294 | self.assertRegex( |
| 295 | str(context.exception.output), |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 296 | "(.*\n)*.*Can't add and remove clang at the same time(.*\n)*") |
| 297 | |
| 298 | self.assertFalse( |
| 299 | os.path.exists( |
| 300 | os.path.join(self.llvm_src, "tools", "clang"))) |
| 301 | |
| 302 | # Try something a bit more complicated and make sure we're not touching |
| 303 | # anything |
Diana Picus | 3601bea | 2017-05-29 11:26:18 +0200 | [diff] [blame] | 304 | self.add_worktree( |
| 305 | self.get_subproj_repo("lld"), |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 306 | os.path.join(self.llvm_src, "tools", "lld"), |
| 307 | self.branch) |
| 308 | |
| 309 | with self.assertRaises(subprocess.CalledProcessError) as context: |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 310 | self.run_with_output( |
| 311 | self.llvm_projects( |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 312 | "--source-dir", |
| 313 | self.llvm_src, |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 314 | "--repos", |
| 315 | self.repos, |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 316 | "--add", |
| 317 | "clang", |
| 318 | "lld", |
| 319 | "libcxx", |
| 320 | "--remove", |
| 321 | "lld", |
| 322 | "libcxx")) |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 323 | self.assertRegex( |
| 324 | str(context.exception.output), |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 325 | "(.*\n)*" + |
| 326 | ".*Can't add and remove (lld|libcxx) at the same time(.*\n)*") |
| 327 | |
| 328 | # Make sure we didn't touch anything |
| 329 | self.assertFalse( |
| 330 | os.path.exists( |
| 331 | os.path.join(self.llvm_src, "tools", "clang"))) |
| 332 | self.assertTrue( |
| 333 | os.path.exists( |
| 334 | os.path.join(self.llvm_src, "tools", "lld"))) |
| 335 | self.assertFalse( |
| 336 | os.path.exists( |
| 337 | os.path.join(self.llvm_src, "projects", "libcxx"))) |
| 338 | |
| 339 | def test_multiple_adds_removes(self): |
| 340 | """ |
| 341 | Test that we can have multiple --add and --remove options in the same |
| 342 | command and that only the last one of each kind matters. |
| 343 | """ |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 344 | output = self.run_with_output( |
| 345 | self.llvm_projects( |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 346 | "--source-dir", |
| 347 | self.llvm_src, |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 348 | "--repos", |
| 349 | self.repos, |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 350 | "--add", |
| 351 | "libcxxabi", |
| 352 | "--remove", |
| 353 | "lld", |
| 354 | "lldb", |
| 355 | "--add", |
| 356 | "clang", |
| 357 | "libcxx", |
| 358 | "--remove", |
| 359 | "libunwind")) |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 360 | self.assertRegex(output, |
| 361 | "Projects linked:.*\n" + |
| 362 | ".*clang.*\n" + |
| 363 | ".*libcxx.*\n") |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 364 | |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 365 | output = self.run_with_output( |
| 366 | self.llvm_projects( |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 367 | "--source-dir", |
| 368 | self.llvm_src, |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 369 | "--repos", |
| 370 | self.repos, |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 371 | "--add", |
| 372 | "libunwind", |
| 373 | "libcxxabi", |
| 374 | "--remove", |
| 375 | "clang", |
| 376 | "libcxx", |
| 377 | "--add", |
| 378 | "compiler-rt", |
| 379 | "--remove", |
| 380 | "libcxxabi")) |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 381 | self.assertRegex(output, |
| 382 | "Projects linked:.*\n" + |
| 383 | ".*clang.*\n" + |
| 384 | ".*compiler-rt.*\n" + |
| 385 | ".*libcxx.*\n") |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 386 | |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 387 | output = self.run_with_output( |
| 388 | self.llvm_projects( |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 389 | "--source-dir", |
| 390 | self.llvm_src, |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 391 | "--repos", |
| 392 | self.repos, |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 393 | "--add", |
| 394 | "libcxx", |
| 395 | "--remove", |
| 396 | "lld", |
| 397 | "--add", |
| 398 | "lld", |
| 399 | "--remove", |
| 400 | "libcxx")) |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 401 | self.assertRegex(output, |
| 402 | "Projects linked:.*\n" + |
| 403 | ".*clang.*\n" + |
| 404 | ".*compiler-rt.*\n" + |
| 405 | ".*lld.*\n") |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 406 | |
| 407 | def test_different_env(self): |
| 408 | """ |
| 409 | Test that we can have different environments in completely different |
| 410 | paths and they don't interfere when we try to add/remove projects. |
| 411 | """ |
| 412 | # Create a separate environment |
| 413 | new_env = mkdtemp() |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 414 | new_llvm_src = os.path.join(new_env, "llvm") |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 415 | new_branch = "br" + str(uuid4()) |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 416 | self.add_worktree( |
| 417 | self.get_subproj_repo("llvm"), |
| 418 | new_llvm_src, |
| 419 | new_branch) |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 420 | |
| 421 | # Check that we start with a clean slate in both the new environment and |
| 422 | # the one that's already set up |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 423 | output = self.run_with_output(self.llvm_projects("--source-dir", |
| 424 | self.llvm_src)) |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 425 | self.assertRegex(output, "Projects linked:.*\n.*none.*") |
| 426 | |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 427 | output = self.run_with_output(self.llvm_projects("--source-dir", |
| 428 | new_llvm_src)) |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 429 | self.assertRegex(output, "Projects linked:.*\n.*none.*") |
| 430 | |
| 431 | # Make sure that adding projects works |
| 432 | output = self.run_with_output( |
| 433 | self.llvm_projects( |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 434 | "--source-dir", self.llvm_src, |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 435 | "--repos", self.repos, |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 436 | "--add", "clang", "lld")) |
| 437 | self.assertRegex(output, "Projects linked:.*\n.*clang.*\n.*lld.*\n") |
| 438 | |
| 439 | output = self.run_with_output( |
| 440 | self.llvm_projects( |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 441 | "--source-dir", |
| 442 | new_llvm_src, |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 443 | "--repos", |
| 444 | self.repos, |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 445 | "--add", |
| 446 | "libcxx", |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 447 | "libcxxabi")) |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 448 | self.assertRegex(output, |
| 449 | "Projects linked:.*\n.*libcxx.*\n.*libcxxabi.*\n.*") |
| 450 | |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 451 | output = self.run_with_output( |
| 452 | self.llvm_projects("--source-dir", self.llvm_src)) |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 453 | self.assertRegex(output, "Projects linked:.*\n.*clang.*\n.*lld.*\n") |
| 454 | |
| 455 | # Make sure that removing projects works |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 456 | output = self.run_with_output( |
| 457 | self.llvm_projects( |
| 458 | "--source-dir", self.llvm_src, |
| 459 | "--remove", "lld")) |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 460 | self.assertRegex(output, "Projects linked:.*\n.*clang.*\n") |
| 461 | |
| 462 | output = self.run_with_output(self.llvm_projects("--remove", "libcxx", |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 463 | "--source-dir", |
| 464 | new_llvm_src)) |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 465 | self.assertRegex(output, |
| 466 | "Projects linked:.*\n.*libcxxabi.*\n.*") |
| 467 | |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 468 | output = self.run_with_output( |
| 469 | self.llvm_projects("--source-dir", self.llvm_src)) |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 470 | self.assertRegex(output, "Projects linked:.*\n.*clang.*\n") |
| 471 | |
| 472 | shutil.rmtree(new_env) |