Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for targets during build iteration #133

Merged
merged 4 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
61 changes: 32 additions & 29 deletions src/fuzzfetch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
branch: str,
build: Union[str, BuildTask],
flags: Union[Sequence[bool], BuildFlags],
targets: Sequence[str],
platform: Optional[Platform] = None,
nearest: Optional[BuildSearchOrder] = None,
) -> None:
Expand All @@ -73,6 +74,7 @@
self._branch = branch
self._flags = BuildFlags(*flags)
self._platform = platform or Platform()
self._targets = targets
self._task = None

if not isinstance(build, BuildTask):
Expand Down Expand Up @@ -197,6 +199,7 @@

try:
self._task = BuildTask(build, branch, self._flags, self._platform)
self.resolve_targets(self._targets)
except FetcherException:
if not nearest:
raise
Expand Down Expand Up @@ -245,30 +248,34 @@
# tried it directly
if search_build != build:
LOG.debug("trying %s", search_build)
try:
# iterate over all builds for the day, and take the next
# older/newer build available
build_tasks = BuildTask.iterall(
search_build, branch, self._flags, self._platform
# iterate over all builds for the day, and take the next
# older/newer build available
build_tasks = BuildTask.iterall(
search_build,
branch,
self._flags,
self._platform,
)
if not asc:
build_tasks = reversed(list(build_tasks))

for task in build_tasks:
task_date = timezone("EST").localize(
datetime.fromtimestamp(task.rank)
)
if not asc:
build_tasks = reversed(list(build_tasks))

for task in build_tasks:
task_date = timezone("EST").localize(
datetime.fromtimestamp(task.rank)
)
LOG.debug("got %s", task_date)
if (asc and task_date >= requested) or (
not asc and task_date <= requested
):
LOG.debug("got %s", task_date)
if (asc and task_date >= requested) or (
not asc and task_date <= requested
):
try:
self.resolve_targets(self._targets)
self._task = task
break
except FetcherException:
LOG.warning(
"Unable to find build for %s",
start.strftime("%Y-%m-%d"),
)
except FetcherException:
LOG.warning(

Check warning on line 275 in src/fuzzfetch/core.py

View check run for this annotation

Codecov / codecov/patch

src/fuzzfetch/core.py#L274-L275

Added lines #L274 - L275 were not covered by tests
"Unable to find build for %s",
start.strftime("%Y-%m-%d"),
)

if self._task is not None:
# a task was found
Expand Down Expand Up @@ -481,23 +488,19 @@
except FetcherException:
resolve_url(self.artifact_url(f"{target}.tests.zip"))

def extract_build(self, targets: Sequence[str], path: PathArg) -> None:
def extract_build(self, path: PathArg) -> None:
"""Download and extract the build and requested extra artifacts.

If an executable target is requested (js/firefox), coverage data
and/or symbols may be downloaded for the build.

Arguments:
targets: build artifacts to download
path: Path to extract downloaded artifacts.
"""
# sanity check all targets before downloading any
self.resolve_targets(targets)

path = Path(path)
path.mkdir(parents=True, exist_ok=True)

targets_remaining = set(targets)
targets_remaining = set(self._targets)

Check warning on line 503 in src/fuzzfetch/core.py

View check run for this annotation

Codecov / codecov/patch

src/fuzzfetch/core.py#L503

Added line #L503 was not covered by tests
have_exec = False

# warn if we don't have a fast decompressor for bz2
Expand Down Expand Up @@ -768,6 +771,7 @@
args.branch,
args.build,
flags,
args.target,
Platform(args.os, args.cpu),
args.nearest,
)
Expand All @@ -782,7 +786,6 @@
extract_options = {
"dry_run": args.dry_run,
"out": final_dir,
"targets": args.target,
}

return obj, extract_options
Expand Down Expand Up @@ -821,7 +824,7 @@

try:
assert isinstance(extract_args["targets"], list)
obj.extract_build(extract_args["targets"], out)
obj.extract_build(out)

Check warning on line 827 in src/fuzzfetch/core.py

View check run for this annotation

Codecov / codecov/patch

src/fuzzfetch/core.py#L827

Added line #L827 was not covered by tests
(out / "download").mkdir(parents=True)
with (out / "download" / "firefox-temp.txt").open("a") as dl_fd:
dl_fd.write(f"buildID={obj.id}{os.linesep}")
Expand Down
4 changes: 2 additions & 2 deletions src/fuzzfetch/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ class Platform:
"x86_64": "win64",
},
"Android": {
"arm": "android-api-16",
"arm": "android-arm",
"arm64": "android-aarch64",
"x86": "android-x86",
"x86_64": "android-x86_64",
Expand Down Expand Up @@ -376,7 +376,7 @@ def auto_name_prefix(self) -> str:
return ""
platform = {
"linux": "linux32",
"android-api-16": "android-arm",
"android-arm": "android-arm",
"android-aarch64": "android-arm64",
}.get(self.gecko_platform, self.gecko_platform)
return f"{platform}-"
9 changes: 8 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import os
from pathlib import Path
from unittest.mock import patch
from urllib.error import HTTPError
from urllib.request import Request, urlopen

Expand All @@ -25,7 +26,6 @@
"queue": "https://queue.taskcluster.net",
}


assert not BUILD_CACHE or str is not bytes, "BUILD_CACHE requires Python 3"


Expand Down Expand Up @@ -106,3 +106,10 @@ def requests_mock_cache():
requests_mock.ANY, requests_mock.ANY, content=_cache_requests
)
yield req_mock


@pytest.fixture
def fetcher_mock_resolve_targets():
"""mock Fetcher.resolve_targets to prevent downloading builds on init"""
with patch("fuzzfetch.core.Fetcher.resolve_targets") as mock:
yield mock

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"namespaces": [
{
"namespace": "gecko.v2.mozilla-central.pushdate.2022.12.31.20221231091949",
"name": "20221231091949",
"expires": "2024-01-03T00:00:00.000Z"
},
{
"namespace": "gecko.v2.mozilla-central.pushdate.2022.12.31.latest",
"name": "latest",
"expires": "2024-01-03T00:00:00.000Z"
}
]
}
Loading