Skip to content

Commit

Permalink
modify build_all.py to use rattler-build
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra committed Jul 18, 2024
1 parent e26076d commit 8f87e11
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions .ci_support/build_all.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import conda.base.context
import conda.core.index
import conda.resolve
Expand Down Expand Up @@ -44,17 +45,32 @@ def build_all(recipes_dir, arch):
script_dir = os.path.dirname(os.path.realpath(__file__))
variant_config_file = os.path.join(script_dir, "{}.yaml".format(get_config_name(arch)))

has_meta_yaml = False
has_recipe_yaml = False

found_cuda = False
found_centos7 = False
for folder in folders:
meta_yaml = os.path.join(recipes_dir, folder, "meta.yaml")
if os.path.exists(meta_yaml):
has_meta_yaml = True
with(open(meta_yaml, "r", encoding="utf-8")) as f:
text = ''.join(f.readlines())
if 'cuda' in text:
found_cuda = True
if 'sysroot_linux-64' in text:
found_centos7 = True

recipe_yaml = os.path.join(recipes_dir, folder, "recipe.yaml")
if os.path.exists(recipe_yaml):
has_recipe_yaml = True
with(open(recipe_yaml, "r", encoding="utf-8")) as f:
text = ''.join(f.readlines())
if 'cuda' in text:
found_cuda = True
if 'sysroot_linux-64' in text:
found_centos7 = True

cbc = os.path.join(recipes_dir, folder, "conda_build_config.yaml")
if os.path.exists(cbc):
with open(cbc, "r") as f:
Expand All @@ -72,6 +88,11 @@ def build_all(recipes_dir, arch):
print(f"Found c_stdlib_version for linux: {version=}")
found_centos7 |= version == (2, 17)

if has_meta_yaml and has_recipe_yaml:
raise ValueError('Mixing meta.yaml and recipe.yaml recipes is not supported')
if not has_meta_yaml and not has_recipe_yaml:
raise ValueError('Neither a meta.yaml or a recipe.yaml recipes was found')

if found_cuda:
print('##vso[task.setvariable variable=NEED_CUDA;isOutput=true]1')
if found_centos7:
Expand Down Expand Up @@ -147,8 +168,13 @@ def build_all(recipes_dir, arch):

if 'conda-forge' not in channel_urls:
raise ValueError('conda-forge needs to be part of channel_sources')
print("Building {} with {}".format(','.join(folders), ','.join(channel_urls)))
build_folders(recipes_dir, folders, arch, channel_urls)

if has_meta_yaml:
print("Building {} with {} using conda-build".format(','.join(folders), ','.join(channel_urls)))
build_folders(recipes_dir, folders, arch, channel_urls)
elif has_recipe_yaml:
print("Building {} with {} using rattler-build".format(','.join(folders), ','.join(channel_urls)))
build_folders_rattler_build(recipes_dir, folders, platform, arch, channel_urls)


def get_config(arch, channel_urls):
Expand Down Expand Up @@ -207,6 +233,19 @@ def build_folders(recipes_dir, folders, arch, channel_urls):
conda_build.api.build([recipe], config=get_config(arch, channel_urls))


def build_folders_rattler_build(recipes_dir, folders, platform, arch, channel_urls):
args = [
"rattler-build",
"build",
"--recipe-dir", recipes_dir,
"--target-platform", f"{platform}-{arch}",
]
for channel_url in channel_urls:
args.extend(["-c", channel_url])

subprocess.run(args, check=True)


def check_recipes_in_correct_dir(root_dir, correct_dir):
from pathlib import Path
for path in Path(root_dir).rglob('meta.yaml'):
Expand Down

0 comments on commit 8f87e11

Please sign in to comment.