Skip to content
This repository was archived by the owner on Aug 26, 2019. It is now read-only.
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CONDA_PYTHON=$(conda info --root)/bin/python
${CONDA_PYTHON} ${RECIPE_DIR}/download-extra-sources.py

ls -l $(realpath $PWD/..)
117 changes: 104 additions & 13 deletions download-extra-sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
source:
fn: llvm-3.8.0.src.tar.xz
url: http://llvm.org/releases/3.8.0/llvm-3.8.0.src.tar.xz
md5: 07a7a74f3c6bd65de4702bf941b511a0
md5: 07a7a74f3c6bd65de4702bf941b511a0

extra:
sources:
cfe:
Expand All @@ -36,26 +36,117 @@

# ... build commands go here ...
"""
from __future__ import print_function

import os
from conda_build import source
from conda_build import config
from conda_build.metadata import MetaData

class SpecialConfig(config.Config):
"""Allow overriding the work_dir property."""

@property
def work_dir(self):
return self._work_dir


def split_path(path):
bits = []
while path != '/':
path, tail = os.path.split(path)
bits.append(tail)
bits.append(path)
bits.reverse()
return bits


def has_only_one_dir(path):
"""
Conda has this weird thing where if the workdir is only a single directory,
it'll change into it and use that as the workdir.
"""
lst = [fn for fn in os.listdir(path) if not fn.startswith('.')]
if len(lst) != 1:
return ''
dir_path = os.path.join(path, lst[0])
if not os.path.isdir(dir_path):
return ''
return dir_path


def main():
print()
print("Getting extra source packages.")
# Force verbose mode
config.verbose = True
cwd = os.getcwd()

# Get the metadata for the recipe
recipe_dir = os.environ["RECIPE_DIR"]
src_dir = os.environ["SRC_DIR"]
main_work_dir = source.WORK_DIR

metadata = MetaData(recipe_dir)
print(metadata.name())
print("-"*75)
print(' cwd:', cwd)

# Figure out the work_dir
# Look upwards for a directory with the name 'work'.
# FIXME: Why does metadata.config.work_dir not return the correct
# directory?
bits = split_path(cwd)
dirname = []
while bits and bits[-1] != 'work':
dirname.insert(0, bits.pop(-1))
dirname = os.path.join(*dirname, '')

work_dir = bits.pop(-1)
assert work_dir == 'work'

build_id = bits.pop(-1)
croot = os.path.join(*bits)

work_dir = os.path.join(croot, build_id, 'work')
if has_only_one_dir(work_dir):
real_work_dir = work_dir
else:
real_work_dir = os.path.join(croot, build_id)

print(' work dir:', real_work_dir)
print('conda root:', croot)
print(' build id:', build_id)
print(' src dir:', dirname)

extra_sources_sections = metadata.get_section('extra')['sources']

for name, source_section in extra_sources_sections.items():
# Override the location to clone into
source.WORK_DIR = main_work_dir + '/' + name
os.makedirs(source.WORK_DIR)

# Download source
source.provide(recipe_dir, source_section)

print()
print("Extra source: %s" % name)
print("-"*75)
# Create a fake metadata which contains the extra source_section.
newmetadata = metadata.copy()
newmetadata.meta['source'] = source_section

if has_only_one_dir(work_dir):
extra_work_dir = real_work_dir
else:
extra_work_dir = os.path.join(real_work_dir, name)

newmetadata.config.__class__ = SpecialConfig
newmetadata.config._work_dir = extra_work_dir
print("Work Directory:", newmetadata.config.work_dir)

# Download+extract source.
source.provide(newmetadata, newmetadata.config)

print("-"*75)

print()
print("Extra source packages download and extracted!")
print()
print("Work Directory contents (%s)" % real_work_dir)
print("-"*75)
print(os.listdir(real_work_dir))
print()


if __name__ == "__main__":
main()