def find_lib(link): from conda_build.build import prefix_files files = prefix_files() if link.startswith(config.build_prefix): link = link[len(config.build_prefix) + 1:] if link not in files: sys.exit("Error: Could not find %s" % link) return link if link.startswith('/'): # but doesn't start with the build prefix return if link.startswith('@rpath/'): # Assume the rpath already points to lib, so there is no need to # change it. return if '/' not in link or link.startswith('@executable_path/'): link = basename(link) file_names = defaultdict(list) for f in files: file_names[basename(f)].append(f) if link not in file_names: sys.exit("Error: Could not find %s" % link) if len(file_names[link]) > 1: sys.exit("Error: Found multiple instances of %s: %s" % (link, file_names[link])) return file_names[link][0] print("Don't know how to find %s, skipping" % link)
def find_lib(link): from conda_build.build import prefix_files files = prefix_files() if link.startswith(config.build_prefix): link = link[len(config.build_prefix) + 1:] if link not in files: sys.exit("Error: Could not find %s" % link) return link if link.startswith('/'): # but doesn't start with the build prefix return if link.startswith('@rpath/'): # Assume the rpath already points to lib, so there is no need to # change it. return if '/' not in link or link.startswith('@executable_path/'): link = basename(link) file_names = defaultdict(list) for f in files: file_names[basename(f)].append(f) if link not in file_names: sys.exit("Error: Could not find %s" % link) if len(file_names[link]) > 1: sys.exit("Error: Found multiple instances of %s: %s" % (link, file_names[link])) return file_names[link][0] print("Don't know how to find %s, skipping" % link)
def find_lib(link, path=None): from conda_build.build import prefix_files files = prefix_files() if link.startswith(config.build_prefix): link = link[len(config.build_prefix) + 1:] if link not in files: sys.exit("Error: Could not find %s" % link) return link if link.startswith('/'): # but doesn't start with the build prefix return if link.startswith('@rpath/'): # Assume the rpath already points to lib, so there is no need to # change it. return if '/' not in link or link.startswith('@executable_path/'): link = basename(link) file_names = defaultdict(list) for f in files: file_names[basename(f)].append(f) if link not in file_names: sys.exit("Error: Could not find %s" % link) if len(file_names[link]) > 1: if path and basename(path) == link: # The link is for the file itself, just use it return path # Allow for the possibility of the same library appearing in # multiple places. md5s = set() for f in file_names[link]: md5s.add(md5_file(join(config.build_prefix, f))) if len(md5s) > 1: sys.exit("Error: Found multiple instances of %s: %s" % (link, file_names[link])) else: file_names[link].sort() print("Found multiple instances of %s (%s). " "Choosing the first one." % (link, file_names[link])) return file_names[link][0] print("Don't know how to find %s, skipping" % link)
def find_lib(link, path=None): from conda_build.build import prefix_files files = prefix_files() if link.startswith(config.build_prefix): link = link[len(config.build_prefix) + 1:] if link not in files: sys.exit("Error: Could not find %s" % link) return link if link.startswith('/'): # but doesn't start with the build prefix return if link.startswith('@rpath/'): # Assume the rpath already points to lib, so there is no need to # change it. return if '/' not in link or link.startswith('@executable_path/'): link = basename(link) file_names = defaultdict(list) for f in files: file_names[basename(f)].append(f) if link not in file_names: sys.exit("Error: Could not find %s" % link) if len(file_names[link]) > 1: if path and basename(path) == link: # The link is for the file itself, just use it return path # Allow for the possibility of the same library appearing in # multiple places. md5s = set() for f in file_names[link]: md5s.add(md5_file(join(config.build_prefix, f))) if len(md5s) > 1: sys.exit("Error: Found multiple instances of %s: %s" % (link, file_names[link])) else: file_names[link].sort() print("Found multiple instances of %s (%s). " "Choosing the first one." % (link, file_names[link])) return file_names[link][0] print("Don't know how to find %s, skipping" % link)
def build(m, verbose=True, channel_urls=(), override_channels=False, wheel_dir="./build"): ''' Build the package with the specified metadata. :param m: Package metadata :type m: Metadata ''' if (m.get_value('build/detect_binary_files_with_prefix') or m.binary_has_prefix_files()): # We must use a long prefix here as the package will only be # installable into prefixes shorter than this one. config.use_long_build_prefix = True else: # In case there are multiple builds in the same process config.use_long_build_prefix = False if m.skip(): print("Skipped: The %s recipe defines build/skip for this " "configuration." % m.dist()) return print("Removing old build environment") if on_win: if isdir(config.short_build_prefix): move_to_trash(config.short_build_prefix, '') if isdir(config.long_build_prefix): move_to_trash(config.long_build_prefix, '') else: rm_rf(config.short_build_prefix) rm_rf(config.long_build_prefix) print("Removing old work directory") if on_win: if isdir(source.WORK_DIR): move_to_trash(source.WORK_DIR, '') else: rm_rf(source.WORK_DIR) # Display the name only # Version number could be missing due to dependency on source info. print("BUILD START:", m.dist()) create_env(config.build_prefix, [ms.spec for ms in m.ms_depends('build')], verbose=verbose, channel_urls=channel_urls, override_channels=override_channels) if m.name() in [i.rsplit('-', 2)[0] for i in linked(config.build_prefix)]: print("%s is installed as a build dependency. Removing." % m.name()) index = get_build_index(clear_cache=False, channel_urls=channel_urls, override_channels=override_channels) actions = plan.remove_actions(config.build_prefix, [m.name()], index=index) assert not plan.nothing_to_do(actions), actions plan.display_actions(actions, index) plan.execute_actions(actions, index) # downlaod source code... source.provide(m.path, m.get_section('source')) # Parse our metadata again because we did not initialize the source # information before. m.parse_again() print("Package:", m.dist()) assert isdir(source.WORK_DIR) src_dir = source.get_dir() contents = os.listdir(src_dir) if contents: print("source tree in:", src_dir) else: print("no source") rm_rf(config.info_dir) files1 = prefix_files() for pat in m.always_include_files(): has_matches = False for f in set(files1): if fnmatch.fnmatch(f, pat): print("Including in package existing file", f) files1.discard(f) has_matches = True if not has_matches: sys.exit("Error: Glob %s from always_include_files does not match any files" % pat) # Save this for later with open(join(config.croot, 'prefix_files.txt'), 'w') as f: f.write(u'\n'.join(sorted(list(files1)))) f.write(u'\n') print("Source dir: %s" % src_dir) if sys.platform == 'win32': windows_build(m) else: env = environ.get_dict(m) build_file = join(m.path, 'build_wheel.sh') if not isfile(build_file): print("Using plain 'python setup.py bdist_wheel' as build script") build_file = join(src_dir, 'build_wheel.sh') with open(build_file, 'w') as fo: fo.write('\n') fo.write('# Autogenerated build command:\n') fo.write('python setup.py bdist_wheel\n') fo.write('\n') cmd = [shell_path, '-x', '-e', build_file] _check_call(cmd, env=env, cwd=src_dir) all_wheels = glob(join(src_dir, "dist", '*.whl')) if len(all_wheels) == 0: print("No wheels produced!") else: if len(all_wheels) == 1: print("More than one wheel produced!") try: os.makedirs(wheel_dir) print("Created wheel dir: %s:" % wheel_dir) except OSError: if not isdir(wheel_dir): raise print("Copying to %s:" % wheel_dir) for wheel in all_wheels: shutil.copy(wheel, wheel_dir) print(" %s" % basename(wheel))
def build(m, verbose=True, channel_urls=(), override_channels=False, wheel_dir="./build"): ''' Build the package with the specified metadata. :param m: Package metadata :type m: Metadata ''' if (m.get_value('build/detect_binary_files_with_prefix') or m.binary_has_prefix_files()): # We must use a long prefix here as the package will only be # installable into prefixes shorter than this one. config.use_long_build_prefix = True else: # In case there are multiple builds in the same process config.use_long_build_prefix = False if m.skip(): print("Skipped: The %s recipe defines build/skip for this " "configuration." % m.dist()) return print("Removing old build environment") if on_win: if isdir(config.short_build_prefix): move_to_trash(config.short_build_prefix, '') if isdir(config.long_build_prefix): move_to_trash(config.long_build_prefix, '') else: rm_rf(config.short_build_prefix) rm_rf(config.long_build_prefix) print("Removing old work directory") if on_win: if isdir(source.WORK_DIR): move_to_trash(source.WORK_DIR, '') else: rm_rf(source.WORK_DIR) # Display the name only # Version number could be missing due to dependency on source info. print("BUILD START:", m.dist()) create_env(config.build_prefix, [ms.spec for ms in m.ms_depends('build')], verbose=verbose, channel_urls=channel_urls, override_channels=override_channels) if m.name() in [i.rsplit('-', 2)[0] for i in linked(config.build_prefix)]: print("%s is installed as a build dependency. Removing." % m.name()) index = get_build_index(clear_cache=False, channel_urls=channel_urls, override_channels=override_channels) actions = plan.remove_actions(config.build_prefix, [m.name()], index=index) assert not plan.nothing_to_do(actions), actions plan.display_actions(actions, index) plan.execute_actions(actions, index) # downlaod source code... source.provide(m.path, m.get_section('source')) # Parse our metadata again because we did not initialize the source # information before. m.parse_again() print("Package:", m.dist()) assert isdir(source.WORK_DIR) src_dir = source.get_dir() contents = os.listdir(src_dir) if contents: print("source tree in:", src_dir) else: print("no source") rm_rf(config.info_dir) files1 = prefix_files() for pat in m.always_include_files(): has_matches = False for f in set(files1): if fnmatch.fnmatch(f, pat): print("Including in package existing file", f) files1.discard(f) has_matches = True if not has_matches: sys.exit( "Error: Glob %s from always_include_files does not match any files" % pat) # Save this for later with open(join(config.croot, 'prefix_files.txt'), 'w') as f: f.write(u'\n'.join(sorted(list(files1)))) f.write(u'\n') print("Source dir: %s" % src_dir) if sys.platform == 'win32': windows_build(m) else: env = environ.get_dict(m) build_file = join(m.path, 'build_wheel.sh') if not isfile(build_file): print("Using plain 'python setup.py bdist_wheel' as build script") build_file = join(src_dir, 'build_wheel.sh') with open(build_file, 'w') as fo: fo.write('\n') fo.write('# Autogenerated build command:\n') fo.write('python setup.py bdist_wheel\n') fo.write('\n') cmd = [shell_path, '-x', '-e', build_file] _check_call(cmd, env=env, cwd=src_dir) all_wheels = glob(join(src_dir, "dist", '*.whl')) if len(all_wheels) == 0: print("No wheels produced!") else: if len(all_wheels) == 1: print("More than one wheel produced!") try: os.makedirs(wheel_dir) print("Created wheel dir: %s:" % wheel_dir) except OSError: if not isdir(wheel_dir): raise print("Copying to %s:" % wheel_dir) for wheel in all_wheels: shutil.copy(wheel, wheel_dir) print(" %s" % basename(wheel))