|
4 | 4 | import errno
|
5 | 5 | import json
|
6 | 6 | import os
|
| 7 | +import shutil |
7 | 8 | import subprocess
|
8 | 9 | import sys
|
9 | 10 | import tarfile
|
| 11 | +import tempfile |
10 | 12 | import time
|
11 | 13 | import warnings
|
12 | 14 |
|
|
22 | 24 | ALL_STATUSES = FINISHED_STATUSES + ["unscheduled", "pending", "running"]
|
23 | 25 | STATUS_VALUE = {"exception": 1, "failed": 2, "completed": 3}
|
24 | 26 |
|
| 27 | +GRCOV_INDEX = "gecko.cache.level-3.toolchains.v3.linux64-grcov.latest" |
| 28 | +GRCOV_ARTIFACT = "public/build/grcov.tar.xz" |
| 29 | + |
25 | 30 |
|
26 | 31 | def get_json(url, params=None, headers={}):
|
27 | 32 | if params is not None:
|
@@ -306,36 +311,42 @@ def generate_html_report(
|
306 | 311 |
|
307 | 312 |
|
308 | 313 | def download_grcov():
|
309 |
| - headers = {} |
310 |
| - if "GITHUB_ACCESS_TOKEN" in os.environ: |
311 |
| - headers["Authorization"] = "token {}".format(os.environ["GITHUB_ACCESS_TOKEN"]) |
| 314 | + local_path = "grcov" |
| 315 | + local_version = "grcov_ver" |
312 | 316 |
|
313 |
| - r = get_json( |
314 |
| - "https://api.github.com/repos/marco-c/grcov/releases/latest", headers=headers |
| 317 | + dest = tempfile.mkdtemp(suffix="grcov") |
| 318 | + archive = os.path.join(dest, "grcov.tar.xz") |
| 319 | + url = "https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/{index}/artifacts/{artifact}".format( |
| 320 | + index=GRCOV_INDEX, artifact=GRCOV_ARTIFACT |
315 | 321 | )
|
316 |
| - latest_tag = r["tag_name"] |
| 322 | + urlretrieve(url, archive) |
317 | 323 |
|
318 |
| - if os.path.exists("grcov") and os.path.exists("grcov_ver"): |
319 |
| - with open("grcov_ver", "r") as f: |
320 |
| - installed_ver = f.read() |
| 324 | + # Extract archive in temp |
| 325 | + tar = tarfile.open(archive, "r:xz") |
| 326 | + tar.extractall(dest) |
| 327 | + tar.close() |
| 328 | + os.remove(archive) |
321 | 329 |
|
322 |
| - if installed_ver == latest_tag: |
323 |
| - return |
| 330 | + # Get version from grcov binary |
| 331 | + grcov = os.path.join(dest, "grcov") |
| 332 | + assert os.path.exists(grcov), "Missing grcov binary" |
| 333 | + version = subprocess.check_output([grcov, "--version"]).decode("utf-8") |
324 | 334 |
|
325 |
| - urlretrieve( |
326 |
| - "https://github.com/marco-c/grcov/releases/download/%s/grcov-linux-x86_64.tar.bz2" |
327 |
| - % latest_tag, |
328 |
| - "grcov.tar.bz2", |
329 |
| - ) |
| 335 | + # Compare version with currently available |
| 336 | + if os.path.exists(local_path) and os.path.exists(local_version): |
| 337 | + with open(local_version, "r") as f: |
| 338 | + installed_ver = f.read() |
330 | 339 |
|
331 |
| - tar = tarfile.open("grcov.tar.bz2", "r:bz2") |
332 |
| - tar.extractall() |
333 |
| - tar.close() |
| 340 | + if installed_ver == version: |
| 341 | + return local_path |
334 | 342 |
|
335 |
| - os.remove("grcov.tar.bz2") |
| 343 | + # Promote downloaded version to installed one |
| 344 | + shutil.move(grcov, local_path) |
| 345 | + shutil.rmtree(dest) |
| 346 | + with open(local_version, "w") as f: |
| 347 | + f.write(version) |
336 | 348 |
|
337 |
| - with open("grcov_ver", "w") as f: |
338 |
| - f.write(latest_tag) |
| 349 | + return local_path |
339 | 350 |
|
340 | 351 |
|
341 | 352 | def download_genhtml():
|
@@ -442,8 +453,7 @@ def main():
|
442 | 453 | if args.grcov:
|
443 | 454 | grcov_path = args.grcov
|
444 | 455 | else:
|
445 |
| - download_grcov() |
446 |
| - grcov_path = "./grcov" |
| 456 | + grcov_path = download_grcov() |
447 | 457 |
|
448 | 458 | if args.stats:
|
449 | 459 | generate_report(grcov_path, "coveralls", "output.json", artifact_paths)
|
|
0 commit comments