Skip to content

Commit 82768db

Browse files
authored
Support scie-jump binaries linked against glibc. (#187)
1 parent 80f49a4 commit 82768db

File tree

9 files changed

+71
-35
lines changed

9 files changed

+71
-35
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Release Notes
22

3+
## 0.17.0
4+
5+
This release adds support for `scie-jump` binaries linked against glibc for Linux aarch64 and
6+
x86_64.
7+
38
## 0.16.0
49

510
This release adds support for musl Linux on aarch64 and upgrades the `science` internal Python

science/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
from packaging.version import Version
55

6-
__version__ = "0.16.0"
6+
__version__ = "0.17.0"
77

88
VERSION = Version(__version__)

science/a_scie.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,25 @@
1414
from science.fetcher import FetchResult, fetch_and_verify
1515
from science.hashing import Digest, Fingerprint
1616
from science.model import Ptex, ScieJump, Url
17-
from science.platform import CURRENT_PLATFORM, Platform
17+
from science.platform import CURRENT_PLATFORM, CURRENT_PLATFORM_SPEC, Platform, PlatformSpec
18+
19+
20+
def qualify_binary_name(
21+
binary_name: str,
22+
version: Version | None = None,
23+
platform_spec: PlatformSpec = CURRENT_PLATFORM_SPEC,
24+
) -> str:
25+
# N.B.: The scie-jump added support for `-{gnu,musl}-linux-{aarch,x86_}64` suffixes in the
26+
# 1.9.0 release.
27+
if (
28+
platform_spec.libc
29+
and binary_name == "scie-jump"
30+
and platform_spec.platform in (Platform.Linux_aarch64, Platform.Linux_x86_64)
31+
and (not version or version >= Version("1.9.0"))
32+
):
33+
return platform_spec.qualified_binary_name(binary_name, gnu_prefix=True)
34+
35+
return platform_spec.platform.qualified_binary_name(binary_name)
1836

1937

2038
@dataclass(frozen=True)
@@ -28,10 +46,12 @@ def load_project_release(
2846
binary_name: str,
2947
version: Version | None = None,
3048
fingerprint: Digest | Fingerprint | None = None,
31-
platform: Platform = CURRENT_PLATFORM,
49+
platform_spec: PlatformSpec = CURRENT_PLATFORM_SPEC,
3250
base_url: Url | None = None,
3351
) -> LoadResult:
34-
qualified_binary_name = platform.qualified_binary_name(binary_name)
52+
qualified_binary_name = qualify_binary_name(
53+
binary_name, version=version, platform_spec=platform_spec
54+
)
3555
root_url = (base_url or f"https://github.com/a-scie/{project_name}/releases").rstrip("/")
3656
if version:
3757
version_path = f"download/v{version}"
@@ -51,7 +71,7 @@ def load_project_release(
5171

5272

5373
def jump(
54-
specification: ScieJump | None = None, platform: Platform = CURRENT_PLATFORM
74+
specification: ScieJump | None = None, platform_spec: PlatformSpec = CURRENT_PLATFORM_SPEC
5575
) -> LoadResult:
5676
version = specification.version if specification else None
5777
fingerprint = specification.digest if specification and specification.digest else None
@@ -61,7 +81,7 @@ def jump(
6181
binary_name="scie-jump",
6282
version=version,
6383
fingerprint=fingerprint,
64-
platform=platform,
84+
platform_spec=platform_spec,
6585
base_url=base_url,
6686
)
6787

@@ -77,7 +97,9 @@ def custom_jump(repo_path: Path) -> LoadResult:
7797
return LoadResult(path=path, digest=Digest.hash(path), binary_name=qualified_binary_name)
7898

7999

80-
def ptex(specification: Ptex | None = None, platform: Platform = CURRENT_PLATFORM) -> LoadResult:
100+
def ptex(
101+
specification: Ptex | None = None, platform_spec: PlatformSpec = CURRENT_PLATFORM_SPEC
102+
) -> LoadResult:
81103
version = specification.version if specification else None
82104
fingerprint = specification.digest if specification and specification.digest else None
83105
base_url = specification.base_url if specification else None
@@ -86,6 +108,6 @@ def ptex(specification: Ptex | None = None, platform: Platform = CURRENT_PLATFOR
86108
binary_name="ptex",
87109
version=version,
88110
fingerprint=fingerprint,
89-
platform=platform,
111+
platform_spec=platform_spec,
90112
base_url=base_url,
91113
)

science/commands/download.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from science.errors import InputError
1515
from science.fetcher import fetch_and_verify
1616
from science.model import Fetch, Identifier
17-
from science.platform import Platform, PlatformSpec
17+
from science.platform import PlatformSpec
1818
from science.providers import ProviderInfo
1919

2020
logger = logging.getLogger(__name__)
@@ -24,7 +24,7 @@ def download_a_scie_executables(
2424
project_name: str,
2525
binary_name: str,
2626
versions: Iterable[Version | None],
27-
platforms: Iterable[Platform],
27+
platform_specs: Iterable[PlatformSpec],
2828
dest_dir: Path,
2929
) -> None:
3030
for version in versions or [None]:
@@ -33,17 +33,20 @@ def download_a_scie_executables(
3333
else:
3434
dest = dest_dir / project_name / "latest" / "download"
3535
dest.mkdir(parents=True, exist_ok=True)
36-
for platform in platforms:
37-
binary = dest / platform.qualified_binary_name(binary_name)
36+
for platform_spec in platform_specs:
37+
binary = dest / a_scie.qualify_binary_name(
38+
binary_name, version=version, platform_spec=platform_spec
39+
)
3840
click.echo(
39-
f"Downloading {binary_name} {version or 'latest'} for {platform} to {binary}...",
41+
f"Downloading {binary_name} {version or 'latest'} for {platform_spec} to "
42+
f"{binary}...",
4043
err=True,
4144
)
4245
result = a_scie.load_project_release(
4346
project_name=project_name,
4447
binary_name=binary_name,
4548
version=version,
46-
platform=platform,
49+
platform_spec=platform_spec,
4750
)
4851
shutil.copy(result.path, binary)
4952
binary.with_name(f"{binary.name}.sha256").write_text(

science/commands/lift.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def maybe_invert_lazy(file: File) -> File:
159159
isinstance(file.source, Fetch) and file.source.lazy for file in requested_files
160160
)
161161
if application.ptex or fetches_present:
162-
ptex = a_scie.ptex(specification=application.ptex, platform=platform_spec.platform)
162+
ptex = a_scie.ptex(specification=application.ptex, platform_spec=platform_spec)
163163
(chroot / ptex.binary_name).symlink_to(ptex.path)
164164
ptex_key = application.ptex.id if application.ptex and application.ptex.id else "ptex"
165165
ptex_file = File(
@@ -248,7 +248,7 @@ def maybe_invert_lazy(file: File) -> File:
248248
load_result = (
249249
a_scie.custom_jump(repo_path=use_jump)
250250
if use_jump
251-
else a_scie.jump(specification=application.scie_jump, platform=platform_spec.platform)
251+
else a_scie.jump(specification=application.scie_jump, platform_spec=platform_spec)
252252
)
253253
if load_result.version:
254254
scie_jump = ScieJump(version=load_result.version, digest=load_result.digest)

science/exe.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,7 @@ def _download_ptex(
412412
project_name="ptex",
413413
binary_name="ptex",
414414
versions=versions,
415-
platforms=dict.fromkeys(
416-
platform_spec.platform for platform_spec in download_config.platform_specs
417-
),
415+
platform_specs=dict.fromkeys(download_config.platform_specs),
418416
dest_dir=dest_dir,
419417
)
420418

@@ -431,9 +429,7 @@ def _download_scie_jump(
431429
project_name="jump",
432430
binary_name="scie-jump",
433431
versions=versions,
434-
platforms=dict.fromkeys(
435-
platform_spec.platform for platform_spec in download_config.platform_specs
436-
),
432+
platform_specs=dict.fromkeys(download_config.platform_specs),
437433
dest_dir=dest_dir,
438434
)
439435

science/platform.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ class PlatformSpec:
207207
def binary_name(self, binary_name: str) -> str:
208208
return self.platform.binary_name(binary_name)
209209

210-
def qualified_binary_name(self, binary_name: str) -> str:
211-
if LibC.MUSL is self.libc:
210+
def qualified_binary_name(self, binary_name: str, gnu_prefix: bool = False) -> str:
211+
if LibC.MUSL is self.libc or (LibC.GLIBC is self.libc and gnu_prefix):
212212
return self.platform.qualified_binary_name(binary_name, self.libc.value)
213213
return self.platform.qualified_binary_name(binary_name)
214214

tests/conftest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from click.globals import pop_context, push_context
1212

1313
from science.context import ScienceConfig
14-
from science.platform import CURRENT_PLATFORM, Platform
14+
from science.platform import CURRENT_PLATFORM, CURRENT_PLATFORM_SPEC, Platform, PlatformSpec
1515

1616

1717
def pytest_sessionstart(session: pytest.Session) -> None:
@@ -47,3 +47,8 @@ def cache_dir(tmp_path: Path) -> Iterator[Path]:
4747
@pytest.fixture
4848
def current_platform() -> Platform:
4949
return CURRENT_PLATFORM
50+
51+
52+
@pytest.fixture
53+
def current_platform_spec() -> PlatformSpec:
54+
return CURRENT_PLATFORM_SPEC

tests/test_download.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
import pytest
1616
from pytest import MonkeyPatch
1717

18+
from science import a_scie
1819
from science.hashing import Digest
19-
from science.platform import CURRENT_PLATFORM_SPEC, Platform
20+
from science.platform import CURRENT_PLATFORM_SPEC, Platform, PlatformSpec
2021
from science.providers import PyPy
2122

2223

@@ -71,13 +72,15 @@ def read_data():
7172

7273

7374
def assert_download_mirror(
74-
tmp_path: Path, current_platform: Platform, *, download_dir: Path, download_url: str
75+
tmp_path: Path, current_platform_spec: PlatformSpec, *, download_dir: Path, download_url: str
7576
) -> None:
7677
subprocess.run(args=["science", "download", "ptex", download_dir], check=True)
7778
subprocess.run(args=["science", "download", "scie-jump", download_dir], check=True)
7879

7980
lift_manifest = tmp_path / "lift.toml"
80-
scie_jump_qualified_binary_name = current_platform.qualified_binary_name("scie-jump")
81+
scie_jump_qualified_binary_name = a_scie.qualify_binary_name(
82+
"scie-jump", platform_spec=current_platform_spec
83+
)
8184
lift_manifest.write_text(
8285
dedent(
8386
f"""\
@@ -99,31 +102,33 @@ def assert_download_mirror(
99102
)
100103
subprocess.run(args=["science", "lift", "build", lift_manifest], cwd=tmp_path, check=True)
101104

102-
scie = tmp_path / current_platform.binary_name("mirror")
105+
scie = tmp_path / current_platform_spec.binary_name("mirror")
103106
split_dir = tmp_path / "split"
104107
subprocess.run(args=[scie, split_dir], env={**os.environ, "SCIE": "split"}, check=True)
105108
subprocess.run(args=[scie], cwd=tmp_path, check=True)
106109

107110
assert Digest.hash(tmp_path / scie_jump_qualified_binary_name) == Digest.hash(
108-
split_dir / current_platform.binary_name("scie-jump")
111+
split_dir / current_platform_spec.binary_name("scie-jump")
109112
)
110113

111114

112-
def test_download_http_mirror(tmp_path: Path, current_platform: Platform, server: Server) -> None:
115+
def test_download_http_mirror(
116+
tmp_path: Path, current_platform_spec: PlatformSpec, server: Server
117+
) -> None:
113118
assert_download_mirror(
114-
tmp_path, current_platform, download_dir=server.root, download_url=server.url
119+
tmp_path, current_platform_spec, download_dir=server.root, download_url=server.url
115120
)
116121

117122

118-
def test_download_file_mirror(tmp_path: Path, current_platform: Platform) -> None:
123+
def test_download_file_mirror(tmp_path: Path, current_platform_spec: PlatformSpec) -> None:
119124
download_dir = tmp_path / "download-dir"
120125
download_dir_url = (
121126
f"file:///{download_dir.as_posix()}"
122-
if current_platform.is_windows
127+
if current_platform_spec.is_windows
123128
else f"file://{download_dir}"
124129
)
125130
assert_download_mirror(
126-
tmp_path, current_platform, download_dir=download_dir, download_url=download_dir_url
131+
tmp_path, current_platform_spec, download_dir=download_dir, download_url=download_dir_url
127132
)
128133

129134

0 commit comments

Comments
 (0)