def __check_duplicates(self, filename, files): if filename in files: print((('\t%-15s\t' % (self.name() + ':')) + error_str('ERROR') + ': Duplicate source files found! (' + filename + ')\n\t' + '\t\tPackage can only contain unique source filenames\n\t' + '\t\tOtherwise object files will collide')) return True else: files.add(filename) return False
def __check_duplicates(self, filename, files): if filename in files: print ((('\t%-15s\t' % (self.name() + ':')) + error_str('ERROR') + ': Duplicate source files found! (' + filename + ')\n\t' + '\t\tPackage can only contain unique source filenames\n\t' + '\t\tOtherwise object files will collide')) return True else: files.add(filename) return False
def _download_and_unzip(self, install_dir, unzip_path=None, retries=3): if not unzip_path: unzip_path = self.rootdir() try: if not os.path.exists(self.__zipname): curl_call = ["curl", "-L", "-o", self.__zipname, self.__url] if amigo_config.VERBOSE: print(' '.join(curl_call)) call(curl_call) if self.__zipname.endswith('.zip'): archive = zipfile.ZipFile(self.__zipname, "r") else: archive = tarfile.open(self.__zipname) else: if self.__zipname.endswith('.zip'): archive = zipfile.ZipFile(self.__zipname, "r") else: archive = tarfile.open(self.__zipname) if self.__zipname.endswith('.zip'): namelist = archive.namelist() else: namelist = archive.getnames() if len(namelist) > 0: path = namelist[0] if path.startswith('./'): path = path[2:] index = path.find("/") if index > 0: path = path[:index] path = os.path.join(unzip_path, path) if unzip_path == self.rootdir(): self.set_local_path(path) else: self.set_local_path(unzip_path) if os.path.exists(self.local_path()): shutil.rmtree(self.local_path()) archive.extractall(unzip_path) if amigo_config.VERBOSE: print("Project Path: " + self.local_path()) archive.close() except: if os.path.exists(self.__zipname): os.remove(self.__zipname) if retries > 0: print(('\t%-15s\t' % (self.name() + ':')) + warn_str('WARNING') + ': Could not download/unzip source. Retrying!') self._download_and_unzip(install_dir, unzip_path, retries - 1) else: print(('\t%-15s\t' % (self.name() + ':')) + error_str('ERROR') + ': Could not download/unzip source') sys.exit(1)
def _download_and_unzip(self, install_dir, unzip_path=None, retries=3): if not unzip_path: unzip_path = self.rootdir() try: if not os.path.exists(self.__zipname): curl_call = ["curl", "-L", "-o", self.__zipname, self.__url] if amigo_config.VERBOSE: print (' '.join(curl_call)) call(curl_call) if self.__zipname.endswith('.zip'): archive = zipfile.ZipFile(self.__zipname, "r") else: archive = tarfile.open(self.__zipname) else: if self.__zipname.endswith('.zip'): archive = zipfile.ZipFile(self.__zipname, "r") else: archive = tarfile.open(self.__zipname) if self.__zipname.endswith('.zip'): namelist = archive.namelist() else: namelist = archive.getnames() if len(namelist) > 0: path = namelist[0] if path.startswith('./'): path = path[2:] index = path.find("/") if index > 0: path = path[:index] path = os.path.join(unzip_path, path) if unzip_path == self.rootdir(): self.set_local_path(path) else: self.set_local_path(unzip_path) if os.path.exists(self.local_path()): shutil.rmtree(self.local_path()) archive.extractall(unzip_path) if amigo_config.VERBOSE: print ("Project Path: " + self.local_path()) archive.close() except: if os.path.exists(self.__zipname): os.remove(self.__zipname) if retries > 0: print (('\t%-15s\t' % (self.name() + ':')) + warn_str('WARNING') + ': Could not download/unzip source. Retrying!') self._download_and_unzip(install_dir, unzip_path, retries - 1) else: print (('\t%-15s\t' % (self.name() + ':')) + error_str('ERROR') + ': Could not download/unzip source') sys.exit(1)
def _link(self, platform): status = 0 cc = platform.flags('CXX') ar = platform.flags('AR') ldflags = platform.flags('LDFLAGS').split() obj_files = [] for (dirpath, dirnames, filenames) in os.walk(self.__obj_path): for filename in filenames: if (filename.startswith(self.name())): obj_files.append(os.path.join(dirpath, filename)) if self.__package_type == CPackage.STATIC_LIB: print(('\t%-15s\t' % (self.name() + ':')) + 'Preparing Static Library') output = os.path.join(self.__lib_path, self.__lib_prefix + self.name() + ".a") if not older(output, obj_files): return call_str = ar + " -r " + output + " " + (' '.join(obj_files)) if amigo_config.VERBOSE: print(call_str) status = call([call_str], env=platform.var_env(), shell=True) elif self.__package_type == CPackage.SHARED_LIB: print(('\t%-15s\t' % (self.name() + ':')) + 'Preparing Shared Library') self.__add_dep_lib(self.name(), self.__lib_path, True) output = os.path.join(self.__lib_path, self.__lib_prefix + self.name() + ".so") if not older(output, obj_files): return call_str = (cc + " -shared -o " + output + " " + (' '.join(obj_files)) + " " + (' '.join(ldflags))) if amigo_config.VERBOSE: print(call_str) status = call([call_str], env=platform.var_env(), shell=True) elif self.__package_type == CPackage.EXECUTABLE: print(('\t%-15s\t' % (self.name() + ':')) + 'Preparing Executable') output = os.path.join(self.__bin_path, self.name()) if not older(output, obj_files): return call_str = (cc + " -o " + output + " " + (' '.join(obj_files)) + " " + (' '.join(ldflags))) if amigo_config.VERBOSE: print(call_str) status = call([call_str], env=platform.var_env(), shell=True) if status != 0: print(('\t%-15s\t' % (self.name() + ':')) + error_str('ERROR') + ': Linking Failed!') sys.exit(1)
def _link(self, platform): status = 0 cc = platform.flags('CXX') ar = platform.flags('AR') ldflags = platform.flags('LDFLAGS').split() obj_files = [] for (dirpath, dirnames, filenames) in os.walk(self.__obj_path): for filename in filenames: if(filename.startswith(self.name())): obj_files.append(os.path.join(dirpath, filename)) if self.__package_type == CPackage.STATIC_LIB: print (('\t%-15s\t' % (self.name() + ':')) + 'Preparing Static Library') output = os.path.join(self.__lib_path, self.__lib_prefix + self.name() + ".a") if not older(output, obj_files): return call_str = ar + " -r " + output + " " + (' '.join(obj_files)) if amigo_config.VERBOSE: print (call_str) status = call([call_str], env=platform.var_env(), shell=True) elif self.__package_type == CPackage.SHARED_LIB: print (('\t%-15s\t' % (self.name() + ':')) + 'Preparing Shared Library') self.__add_dep_lib(self.name(), self.__lib_path, True) output = os.path.join(self.__lib_path, self.__lib_prefix + self.name() + ".so") if not older(output, obj_files): return call_str = (cc + " -shared -o " + output + " " + (' '.join(obj_files)) + " " + (' '.join(ldflags))) if amigo_config.VERBOSE: print (call_str) status = call([call_str], env=platform.var_env(), shell=True) elif self.__package_type == CPackage.EXECUTABLE: print (('\t%-15s\t' % (self.name() + ':')) + 'Preparing Executable') output = os.path.join(self.__bin_path, self.name()) if not older(output, obj_files): return call_str = (cc + " -o " + output + " " + (' '.join(obj_files)) + " " + (' '.join(ldflags))) if amigo_config.VERBOSE: print (call_str) status = call([call_str], env=platform.var_env(), shell=True) if status != 0: print (('\t%-15s\t' % (self.name() + ':')) + error_str('ERROR') + ': Linking Failed!') sys.exit(1)
def _build(self, platform, env_vars=None): if not env_vars: env_vars = self._env_vars self.__is_clean = False if self._build_finished: return del failed_files[:] self.__build_failed = False # Create output directories self.__lib_path = os.path.join(self.install_dir(platform), 'lib') self.__obj_path = os.path.join(self.install_dir(platform), 'obj') self.__bin_path = os.path.join(self.install_dir(platform), 'bin') if not os.path.exists(self.__lib_path): os.makedirs(self.__lib_path) if not os.path.exists(self.__obj_path): os.makedirs(self.__obj_path) if not os.path.exists(self.__bin_path): os.makedirs(self.__bin_path) self.__outdated_sources = None # Collect all source files and headers to be compiled print(('\t%-15s\t' % (self.name() + ':')) + 'Checking Files') src_filenames = set() self.__collect_files_by_extension(src_filenames) print(('\t%-15s\t' % (self.name() + ':')) + 'Building Dependencies') dep_install_dirs = [] for dep in self.deps(): install_dir = dep.install_dir(platform) if self.__should_build_deps: dep.build(platform) for dep_header in dep.headers(): self._headers.add(dep_header) if dep.__dep_libs: self.__dep_libs += dep.__dep_libs self.__dep_lib_to_path_map.update(dep.__dep_lib_to_path_map) elif not install_dir in dep_install_dirs: dep_install_dirs.insert(0, install_dir) dep_install_dirs = [ x for x in dep_install_dirs if os.path.join(x, 'lib') not in self.__dep_lib_to_path_map.values() ] # Crush dependency libs into one static lib for IOS if self.__should_build_deps: print(('\t%-15s\t' % (self.name() + ':')) + 'Crushing Deps') index = 1 for install_dir in dep_install_dirs: for (dirpath, dirnames, filenames) in os.walk(install_dir): for filename in filenames: if filename.startswith(self.__deps_prefix): os.remove(os.path.join(dirpath, filename)) if crush_deps(platform, install_dir, self.__deps_prefix + '_' + str(index), self.__crush_ldflags): index += 1 print(('\t%-15s\t' % (self.name() + ':')) + 'Initializing Source Maps') # Popuplate Source->Headers maps and Header->Sources maps self.__populate_src_maps() # Find Sources that require re-compilation self.__outdated_sources = self.__needs_recompile() if not self.__outdated_sources: print(('\t%-15s\t' % (self.name() + ':')) + 'No Changes Detected') return print(('\t%-15s\t' % (self.name() + ':')) + 'Configuring Platform') platform.configure(self.install_dir(platform), env_vars, None, self.deps()) # Add linking flags print(('\t%-15s\t' % (self.name() + ':')) + 'Configuring Dependency Linking') for dep_lib in self.__dep_libs: if dep_lib in self.__dep_lib_to_path_map: platform.append_flags( 'LDFLAGS', " -L" + self.__dep_lib_to_path_map[dep_lib]) platform.append_flags('LDFLAGS', " -l" + dep_lib) for install_dir in dep_install_dirs: lib_path = os.path.join(install_dir, "lib") dep_libs = set() match_found = False if os.path.exists(lib_path): for path in os.listdir(os.path.join(install_dir, "lib")): match = re.match(r'(' + self.__deps_prefix + '.*)\.so', path) if match: lib = match.group(1).strip()[3:] platform.append_flags('LDFLAGS', " -l" + lib) self.__add_dep_lib(lib, lib_path) match_found = True break else: match = re.match(r'lib(.*)\.so.*', path) if match: dep_libs.add(match.group(1).strip()) if not match_found: for dep_lib in dep_libs: self.__add_dep_lib(dep_lib, lib_path) platform.append_flags('LDFLAGS', " -l" + dep_lib) # Append custom flags try: app_flags = self._appended_flags.iteritems() except AttributeError: app_flags = self._appended_flags.items() for key, flags in app_flags: platform.append_flags(key, ' ' + flags) self._compile(platform) if self.__build_failed: print(('\t%-15s\t' % (self.name() + ':')) + error_str('ERROR') + ': Compilation Failed!') sys.exit(1) else: self._link(platform) if self.__should_install_headers: self.__inc_path = os.path.join(self.install_dir(platform), 'include') if not os.path.exists(self.__inc_path): os.makedirs(self.__inc_path) for header in self.headers(): shutil.copy(header, self.__inc_path)
def _build(self, platform, env_vars=None): if not env_vars: env_vars = self._env_vars self.__is_clean = False if self._build_finished: return del failed_files[:] self.__build_failed = False # Create output directories self.__lib_path = os.path.join(self.install_dir(platform), 'lib') self.__obj_path = os.path.join(self.install_dir(platform), 'obj') self.__bin_path = os.path.join(self.install_dir(platform), 'bin') if not os.path.exists(self.__lib_path): os.makedirs(self.__lib_path) if not os.path.exists(self.__obj_path): os.makedirs(self.__obj_path) if not os.path.exists(self.__bin_path): os.makedirs(self.__bin_path) self.__outdated_sources = None # Collect all source files and headers to be compiled print (('\t%-15s\t' % (self.name() + ':')) + 'Checking Files') src_filenames = set() self.__collect_files_by_extension(src_filenames) print (('\t%-15s\t' % (self.name() + ':')) + 'Building Dependencies') dep_install_dirs = [] for dep in self.deps(): install_dir = dep.install_dir(platform) if self.__should_build_deps: dep.build(platform) for dep_header in dep.headers(): self._headers.add(dep_header) if dep.__dep_libs: self.__dep_libs += dep.__dep_libs self.__dep_lib_to_path_map.update(dep.__dep_lib_to_path_map) elif not install_dir in dep_install_dirs: dep_install_dirs.insert(0, install_dir) dep_install_dirs = [x for x in dep_install_dirs if os.path.join(x, 'lib') not in self.__dep_lib_to_path_map.values()] # Crush dependency libs into one static lib for IOS if self.__should_build_deps: print (('\t%-15s\t' % (self.name() + ':')) + 'Crushing Deps') index = 1 for install_dir in dep_install_dirs: for (dirpath, dirnames, filenames) in os.walk(install_dir): for filename in filenames: if filename.startswith(self.__deps_prefix): os.remove(os.path.join(dirpath, filename)) if crush_deps(platform, install_dir, self.__deps_prefix + '_' + str(index), self.__crush_ldflags): index += 1 print (('\t%-15s\t' % (self.name() + ':')) + 'Initializing Source Maps') # Popuplate Source->Headers maps and Header->Sources maps self.__populate_src_maps() # Find Sources that require re-compilation self.__outdated_sources = self.__needs_recompile() if not self.__outdated_sources: print (('\t%-15s\t' % (self.name() + ':')) + 'No Changes Detected') return print (('\t%-15s\t' % (self.name() + ':')) + 'Configuring Platform') platform.configure(self.install_dir(platform), env_vars, None, self.deps()) # Add linking flags print (('\t%-15s\t' % (self.name() + ':')) + 'Configuring Dependency Linking') for dep_lib in self.__dep_libs: if dep_lib in self.__dep_lib_to_path_map: platform.append_flags('LDFLAGS', " -L" + self.__dep_lib_to_path_map[dep_lib]) platform.append_flags('LDFLAGS', " -l" + dep_lib) for install_dir in dep_install_dirs: lib_path = os.path.join(install_dir, "lib") dep_libs = set() match_found = False if os.path.exists(lib_path): for path in os.listdir(os.path.join(install_dir, "lib")): match = re.match(r'(' + self.__deps_prefix + '.*)\.so', path) if match: lib = match.group(1).strip()[3:] platform.append_flags('LDFLAGS', " -l" + lib) self.__add_dep_lib(lib, lib_path) match_found = True break else: match = re.match(r'lib(.*)\.so.*', path) if match: dep_libs.add(match.group(1).strip()) if not match_found: for dep_lib in dep_libs: self.__add_dep_lib(dep_lib, lib_path) platform.append_flags('LDFLAGS', " -l" + dep_lib) # Append custom flags try: app_flags = self._appended_flags.iteritems() except AttributeError: app_flags = self._appended_flags.items() for key, flags in app_flags: platform.append_flags(key, ' '+flags) self._compile(platform) if self.__build_failed: print (('\t%-15s\t' % (self.name() + ':')) + error_str('ERROR') + ': Compilation Failed!') sys.exit(1) else: self._link(platform) if self.__should_install_headers: self.__inc_path = os.path.join(self.install_dir(platform), 'include') if not os.path.exists(self.__inc_path): os.makedirs(self.__inc_path) for header in self.headers(): shutil.copy(header, self.__inc_path)