|
13 | 13 |
|
14 | 14 | NOTE: The compute-metrics subcommand MUST be run on a clean master branch! |
15 | 15 |
|
| 16 | +To compute metrics on a continuous integration system: |
| 17 | +
|
| 18 | +./check-submodule.py compute-ci-metrics -p LOCAL_DIR -l TREE_SITTER_LANGUAGE |
| 19 | +
|
16 | 20 |
|
17 | 21 | To compare metrics and retrieve minimal tests: |
18 | 22 |
|
@@ -108,11 +112,16 @@ def run_subprocess(cmd: str, *args: T.Union[str, pathlib.Path]) -> None: |
108 | 112 |
|
109 | 113 | # Run rust-code-analysis on the chosen repository to compute metrics. |
110 | 114 | def run_rca( |
111 | | - repo_dir: pathlib.Path, output_dir: pathlib.Path, include_languages: T.List[str] |
| 115 | + repo_dir: pathlib.Path, |
| 116 | + output_dir: pathlib.Path, |
| 117 | + manifest_path: T.Optional[pathlib.Path], |
| 118 | + include_languages: T.List[str], |
112 | 119 | ) -> None: |
113 | 120 | run_subprocess( |
114 | 121 | "cargo", |
115 | 122 | "run", |
| 123 | + "--manifest-path", |
| 124 | + manifest_path / "Cargo.toml" if manifest_path else "Cargo.toml", |
116 | 125 | "--release", |
117 | 126 | "--package", |
118 | 127 | "rust-code-analysis-cli", |
@@ -229,6 +238,54 @@ def save_diff_files( |
229 | 238 | asyncio.run(json_diff.diff()) |
230 | 239 |
|
231 | 240 |
|
| 241 | +# Compute continuous integration metrics before and after a |
| 242 | +# tree-sitter-language update. |
| 243 | +def compute_ci_metrics(args: argparse.Namespace) -> None: |
| 244 | + |
| 245 | + if args.language not in EXTENSIONS.keys(): |
| 246 | + print(args.language, "is not a valid tree-sitter-language") |
| 247 | + sys.exit(1) |
| 248 | + |
| 249 | + # Repository passed as input |
| 250 | + repo_dir = pathlib.Path(args.path) |
| 251 | + |
| 252 | + # Create rust-code-analysis repository path |
| 253 | + rca_path = WORKDIR / "rust-code-analysis" |
| 254 | + |
| 255 | + # Old metrics directory |
| 256 | + old_dir = WORKDIR / (args.language + OLD_SUFFIX) |
| 257 | + # New metrics directory |
| 258 | + new_dir = WORKDIR / (args.language + NEW_SUFFIX) |
| 259 | + |
| 260 | + # Create output directories |
| 261 | + old_dir.mkdir(parents=True, exist_ok=True) |
| 262 | + new_dir.mkdir(parents=True, exist_ok=True) |
| 263 | + |
| 264 | + # Git clone rust-code-analysis master branch repository |
| 265 | + print(f"Cloning rust-code-analysis master branch into /tmp") |
| 266 | + run_subprocess( |
| 267 | + "git", |
| 268 | + "clone", |
| 269 | + "--depth=1", |
| 270 | + "--recurse-submodules", |
| 271 | + "-j8", |
| 272 | + "https://github.com/mozilla/rust-code-analysis", |
| 273 | + rca_path, |
| 274 | + ) |
| 275 | + |
| 276 | + # Compute old metrics |
| 277 | + print("\nComputing metrics before the update and saving them in", old_dir) |
| 278 | + run_rca(repo_dir, old_dir, rca_path, EXTENSIONS[args.language]) |
| 279 | + |
| 280 | + # Update tree-sitter-language submodule |
| 281 | + print("\nUpdate", args.language) |
| 282 | + run_subprocess("./update-language-bindings.sh") |
| 283 | + |
| 284 | + # Compute new metrics |
| 285 | + print("\nComputing metrics after the update and saving them in", new_dir) |
| 286 | + run_rca(repo_dir, new_dir, None, EXTENSIONS[args.language]) |
| 287 | + |
| 288 | + |
232 | 289 | # Compute metrics before and after a tree-sitter-language update. |
233 | 290 | def compute_metrics(args: argparse.Namespace) -> None: |
234 | 291 |
|
@@ -257,19 +314,19 @@ def compute_metrics(args: argparse.Namespace) -> None: |
257 | 314 |
|
258 | 315 | # Compute old metrics |
259 | 316 | print("\nComputing metrics before the update and saving them in", old_dir) |
260 | | - run_rca(repo_dir, old_dir, EXTENSIONS[args.language]) |
| 317 | + run_rca(repo_dir, old_dir, None, EXTENSIONS[args.language]) |
261 | 318 |
|
262 | 319 | # Create a new branch |
263 | 320 | print("\nCreate a new branch called", args.language) |
264 | 321 | run_subprocess("git", "checkout", "-B", args.language) |
265 | 322 |
|
266 | 323 | # Update tree-sitter-language submodule |
267 | 324 | print("\nUpdate", args.language) |
268 | | - run_subprocess("./update-sumbodules.sh", args.language) |
| 325 | + run_subprocess("./update-submodule.sh", args.language) |
269 | 326 |
|
270 | 327 | # Compute new metrics |
271 | 328 | print("\nComputing metrics after the update and saving them in", new_dir) |
272 | | - run_rca(repo_dir, new_dir, EXTENSIONS[args.language]) |
| 329 | + run_rca(repo_dir, new_dir, None, EXTENSIONS[args.language]) |
273 | 330 |
|
274 | 331 |
|
275 | 332 | # Compare metrics and dump the differences whether there are some. |
@@ -342,6 +399,31 @@ def main() -> None: |
342 | 399 | ) |
343 | 400 | compute_metrics_cmd.set_defaults(func=compute_metrics) |
344 | 401 |
|
| 402 | + # Compute continuous integration metrics command |
| 403 | + compute_ci_metrics_cmd = commands.add_parser( |
| 404 | + "compute-ci-metrics", |
| 405 | + help="Computes the metrics of a chosen repository before and after " |
| 406 | + "a tree-sitter-language update on a continuous integration system.", |
| 407 | + ) |
| 408 | + |
| 409 | + compute_ci_metrics_cmd.add_argument( |
| 410 | + "-p", |
| 411 | + "--path", |
| 412 | + type=str, |
| 413 | + required=True, |
| 414 | + help="Path where the rust-code-analysis repository is saved on the " |
| 415 | + "continuous integration system", |
| 416 | + ) |
| 417 | + compute_ci_metrics_cmd.add_argument( |
| 418 | + "-l", |
| 419 | + "--language", |
| 420 | + type=str, |
| 421 | + required=True, |
| 422 | + help="tree-sitter-language to be updated", |
| 423 | + ) |
| 424 | + |
| 425 | + compute_ci_metrics_cmd.set_defaults(func=compute_ci_metrics) |
| 426 | + |
345 | 427 | # Compare metrics command |
346 | 428 | compare_metrics_cmd = commands.add_parser( |
347 | 429 | "compare-metrics", |
|
0 commit comments