Skip to content

Commit a12ea98

Browse files
Luni-4marco-c
authored andcommitted
Add a new command to compute metrics on ci systems
1 parent ff58260 commit a12ea98

1 file changed

Lines changed: 86 additions & 4 deletions

File tree

check-submodule.py

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
1414
NOTE: The compute-metrics subcommand MUST be run on a clean master branch!
1515
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+
1620
1721
To compare metrics and retrieve minimal tests:
1822
@@ -108,11 +112,16 @@ def run_subprocess(cmd: str, *args: T.Union[str, pathlib.Path]) -> None:
108112

109113
# Run rust-code-analysis on the chosen repository to compute metrics.
110114
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],
112119
) -> None:
113120
run_subprocess(
114121
"cargo",
115122
"run",
123+
"--manifest-path",
124+
manifest_path / "Cargo.toml" if manifest_path else "Cargo.toml",
116125
"--release",
117126
"--package",
118127
"rust-code-analysis-cli",
@@ -229,6 +238,54 @@ def save_diff_files(
229238
asyncio.run(json_diff.diff())
230239

231240

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+
232289
# Compute metrics before and after a tree-sitter-language update.
233290
def compute_metrics(args: argparse.Namespace) -> None:
234291

@@ -257,19 +314,19 @@ def compute_metrics(args: argparse.Namespace) -> None:
257314

258315
# Compute old metrics
259316
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])
261318

262319
# Create a new branch
263320
print("\nCreate a new branch called", args.language)
264321
run_subprocess("git", "checkout", "-B", args.language)
265322

266323
# Update tree-sitter-language submodule
267324
print("\nUpdate", args.language)
268-
run_subprocess("./update-sumbodules.sh", args.language)
325+
run_subprocess("./update-submodule.sh", args.language)
269326

270327
# Compute new metrics
271328
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])
273330

274331

275332
# Compare metrics and dump the differences whether there are some.
@@ -342,6 +399,31 @@ def main() -> None:
342399
)
343400
compute_metrics_cmd.set_defaults(func=compute_metrics)
344401

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+
345427
# Compare metrics command
346428
compare_metrics_cmd = commands.add_parser(
347429
"compare-metrics",

0 commit comments

Comments
 (0)