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

Use conda.base.constants.KNOWN_SUBDIRS for setting up selectors #5009

Merged
merged 15 commits into from
Oct 16, 2023
Merged
35 changes: 22 additions & 13 deletions conda_build/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from conda_build.features import feature_list
from conda_build.license_family import ensure_valid_license_family
from conda_build.utils import (
DEFAULT_SUBDIRS,
HashableDict,
ensure_list,
expand_globs,
Expand All @@ -29,7 +30,7 @@
insert_variant_versions,
)

from .conda_interface import MatchSpec, envs_dirs, md5_file, non_x86_linux_machines
from .conda_interface import MatchSpec, envs_dirs, md5_file

try:
import yaml
Expand Down Expand Up @@ -121,25 +122,36 @@ def get_selectors(config: Config) -> dict[str, bool]:
# Remember to update the docs of any of this changes
plat = config.host_subdir
d = dict(
linux=plat.startswith("linux-"),
linux32=bool(plat == "linux-32"),
linux64=bool(plat == "linux-64"),
emscripten=plat.startswith("emscripten-"),
wasi=plat.startswith("wasi-"),
arm=plat.startswith("linux-arm"),
osx=plat.startswith("osx-"),
arm=plat.startswith(("linux-arm", "osx-arm", "win-arm")),
kenodegard marked this conversation as resolved.
Show resolved Hide resolved
unix=plat.startswith(("linux-", "osx-", "emscripten-")),
win=plat.startswith("win-"),
win32=bool(plat == "win-32"),
win64=bool(plat == "win-64"),
x86=plat.endswith(("-32", "-64")),
x86_64=plat.endswith("-64"),
wasm32=bool(plat.endswith("-wasm32")),
os=os,
environ=os.environ,
nomkl=bool(int(os.environ.get("FEATURE_NOMKL", False))),
)

# Add the current platform to the list of subdirs to enable conda-build
# to bootstrap new platforms without a new conda release.
subdirs = list(DEFAULT_SUBDIRS) + [plat]

# filter out noarch and other weird subdirs
subdirs = [subdir for subdir in subdirs if "-" in subdir]

subdir_oses = {subdir.split("-")[0] for subdir in subdirs}
subdir_archs = {subdir.split("-")[1] for subdir in subdirs}

for subdir_os in subdir_oses:
d[subdir_os] = plat.startswith(f"{subdir_os}-")

for arch in subdir_archs:
arch_full = ARCH_MAP.get(arch, arch)
d[arch_full] = plat.endswith(f"-{arch}")
if arch == "32":
d["x86"] = plat.endswith(("-32", "-64"))

defaults = variants.get_default_variant(config)
py = config.variant.get("python", defaults["python"])
# there are times when python comes in as a tuple
Expand Down Expand Up @@ -183,9 +195,6 @@ def get_selectors(config: Config) -> dict[str, bool]:
d["lua"] = lua
d["luajit"] = bool(lua[0] == "2")

for machine in non_x86_linux_machines:
d[machine] = bool(plat.endswith("-%s" % machine))

for feature, value in feature_list:
d[feature] = value
d.update(os.environ)
Expand Down
21 changes: 2 additions & 19 deletions conda_build/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
from glob import glob

from conda.api import PackageCacheData # noqa
from conda.base.constants import KNOWN_SUBDIRS

# NOQA because it is not used in this file.
from conda_build.conda_interface import rm_rf as _rm_rf # noqa
Expand Down Expand Up @@ -104,25 +105,7 @@
mmap_PROT_READ = 0 if on_win else mmap.PROT_READ
mmap_PROT_WRITE = 0 if on_win else mmap.PROT_WRITE

DEFAULT_SUBDIRS = {
"emscripten-wasm32",
"wasi-wasm32",
"linux-64",
"linux-32",
"linux-s390x",
"linux-ppc64",
"linux-ppc64le",
"linux-armv6l",
"linux-armv7l",
"linux-aarch64",
"win-64",
"win-32",
"win-arm64",
"osx-64",
"osx-arm64",
"zos-z",
"noarch",
}
DEFAULT_SUBDIRS = set(KNOWN_SUBDIRS)

RUN_EXPORTS_TYPES = {
"weak",
Expand Down
11 changes: 8 additions & 3 deletions docs/source/resources/define-metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1928,10 +1928,10 @@ variables are booleans.
* - osx
- True if the platform is macOS.
* - arm64
- True if the platform is macOS and the Python architecture
is arm64.
- True if the platform is either macOS or Windows and the
Python architecture is arm64.
* - unix
- True if the platform is either macOS or Linux.
- True if the platform is either macOS or Linux or emscripten.
* - win
- True if the platform is Windows.
* - win32
Expand Down Expand Up @@ -1965,6 +1965,11 @@ The use of the Python version selectors, `py27`, `py34`, etc. is discouraged in
favor of the more general comparison operators. Additional selectors in this
series will not be added to conda-build.

Note that for each subdir with OS and architecture that `conda` supports,
two preprocessing selectors are created for the OS and the architecture separately
except when the architecture is not a valid python expression (`*-32` and `*-64`
in particular).

Because the selector is any valid Python expression, complicated
logic is possible:

Expand Down
24 changes: 24 additions & 0 deletions news/5009-use-conda-known-subdirs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
### Enhancements

* Use subdirs known to conda for selector definitions. (#5009)
This allows conda_build to support new architectures with just
a new version of conda. For new OSes, there are more information
needed for conda_build to work properly, including whether the
new OS is a UNIX-like platform, the shared library prefix, and
the binary archive format for the platform.

### Bug fixes

* <news item>

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
11 changes: 7 additions & 4 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ def test_yamlize_versions():
"armv6l",
"armv7l",
"emscripten",
"freebsd",
"linux",
"linux32",
"linux64",
Expand All @@ -358,6 +359,8 @@ def test_yamlize_versions():
"win64",
"x86",
"x86_64",
"z",
"zos",
)


Expand All @@ -369,7 +372,7 @@ def test_yamlize_versions():
[
("emscripten-wasm32", {"unix", "emscripten", "wasm32"}),
("wasi-wasm32", {"wasi", "wasm32"}),
("freebsd-64", {"x86", "x86_64"}),
("freebsd-64", {"freebsd", "x86", "x86_64"}),
("linux-32", {"unix", "linux", "linux32", "x86"}),
("linux-64", {"unix", "linux", "linux64", "x86", "x86_64"}),
("linux-aarch64", {"unix", "linux", "aarch64"}),
Expand All @@ -380,11 +383,11 @@ def test_yamlize_versions():
("linux-riscv64", {"unix", "linux", "riscv64"}),
("linux-s390x", {"unix", "linux", "s390x"}),
("osx-64", {"unix", "osx", "x86", "x86_64"}),
("osx-arm64", {"unix", "osx", "arm64"}),
("osx-arm64", {"unix", "osx", "arm", "arm64"}),
kenodegard marked this conversation as resolved.
Show resolved Hide resolved
("win-32", {"win", "win32", "x86"}),
("win-64", {"win", "win64", "x86", "x86_64"}),
("win-arm64", {"win", "arm64"}),
("zos-z", {}),
("win-arm64", {"win", "arm", "arm64"}),
kenodegard marked this conversation as resolved.
Show resolved Hide resolved
("zos-z", {"zos", "z"}),
],
)
@pytest.mark.parametrize("nomkl", [0, 1])
Expand Down
Loading