diff --git a/conda_build/metadata.py b/conda_build/metadata.py index 1160c1e9fe..d2d87912bf 100644 --- a/conda_build/metadata.py +++ b/conda_build/metadata.py @@ -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, @@ -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 @@ -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-"), 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 @@ -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) diff --git a/conda_build/utils.py b/conda_build/utils.py index af5678247e..06a5c79c6d 100644 --- a/conda_build/utils.py +++ b/conda_build/utils.py @@ -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 @@ -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", diff --git a/docs/source/resources/define-metadata.rst b/docs/source/resources/define-metadata.rst index d314349b2b..c9e1ddd32b 100644 --- a/docs/source/resources/define-metadata.rst +++ b/docs/source/resources/define-metadata.rst @@ -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 @@ -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: diff --git a/news/5009-use-conda-known-subdirs b/news/5009-use-conda-known-subdirs new file mode 100644 index 0000000000..a9423202f4 --- /dev/null +++ b/news/5009-use-conda-known-subdirs @@ -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 + +* + +### Deprecations + +* + +### Docs + +* + +### Other + +* diff --git a/tests/test_metadata.py b/tests/test_metadata.py index 9c2ab7bd30..37319f0de4 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -342,6 +342,7 @@ def test_yamlize_versions(): "armv6l", "armv7l", "emscripten", + "freebsd", "linux", "linux32", "linux64", @@ -358,6 +359,8 @@ def test_yamlize_versions(): "win64", "x86", "x86_64", + "z", + "zos", ) @@ -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"}), @@ -384,7 +387,7 @@ def test_yamlize_versions(): ("win-32", {"win", "win32", "x86"}), ("win-64", {"win", "win64", "x86", "x86_64"}), ("win-arm64", {"win", "arm64"}), - ("zos-z", {}), + ("zos-z", {"zos", "z"}), ], ) @pytest.mark.parametrize("nomkl", [0, 1])