Skip to content

Commit 768dc93

Browse files
authored
Download grcov from Taskcluster index, fixes #243. (#387)
1 parent 5ca01a1 commit 768dc93

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

report/firefox_code_coverage/codecoverage.py

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
import errno
55
import json
66
import os
7+
import shutil
78
import subprocess
89
import sys
910
import tarfile
11+
import tempfile
1012
import time
1113
import warnings
1214

@@ -22,6 +24,9 @@
2224
ALL_STATUSES = FINISHED_STATUSES + ["unscheduled", "pending", "running"]
2325
STATUS_VALUE = {"exception": 1, "failed": 2, "completed": 3}
2426

27+
GRCOV_INDEX = "gecko.cache.level-3.toolchains.v3.linux64-grcov.latest"
28+
GRCOV_ARTIFACT = "public/build/grcov.tar.xz"
29+
2530

2631
def get_json(url, params=None, headers={}):
2732
if params is not None:
@@ -306,36 +311,42 @@ def generate_html_report(
306311

307312

308313
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"
312316

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
315321
)
316-
latest_tag = r["tag_name"]
322+
urlretrieve(url, archive)
317323

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)
321329

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")
324334

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()
330339

331-
tar = tarfile.open("grcov.tar.bz2", "r:bz2")
332-
tar.extractall()
333-
tar.close()
340+
if installed_ver == version:
341+
return local_path
334342

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)
336348

337-
with open("grcov_ver", "w") as f:
338-
f.write(latest_tag)
349+
return local_path
339350

340351

341352
def download_genhtml():
@@ -442,8 +453,7 @@ def main():
442453
if args.grcov:
443454
grcov_path = args.grcov
444455
else:
445-
download_grcov()
446-
grcov_path = "./grcov"
456+
grcov_path = download_grcov()
447457

448458
if args.stats:
449459
generate_report(grcov_path, "coveralls", "output.json", artifact_paths)

0 commit comments

Comments
 (0)