def pre_build(self, env): imports = self.get_imports(env.spec) build_imports = [] for i in imports: import_steps = _build_project(i, env) if import_steps: build_imports += [ Script(import_steps, name='resolve {}'.format(i.name)) ] if build_imports: build_imports = [Script(build_imports, name='resolve imports')] deps = self.get_dependencies(env.spec) build_deps = [] for d in deps: dep_steps = _build_project(d, env) if dep_steps: build_deps += [ Script(dep_steps, name='build {}'.format(d.name)) ] if build_deps: build_deps = [Script(build_deps, name='build dependencies')] all_steps = build_imports + build_deps + \ env.config.get('pre_build_steps', []) if len(all_steps) == 0: return None all_steps = [ partial(_pushenv, self, 'pre_build_env'), *all_steps, _popenv ] return Script(all_steps, name='pre_build {}'.format(self.name))
def install(self, env): if self.installed: return config = env.config # Ensure additional compiler packages are installed packages = UniqueList(config.get('compiler_packages', [])) packages = [p for p in packages if not p.startswith('gcc')] Script([InstallPackages(packages)], name='Install compiler prereqs').run(env) installed_path, installed_version = Toolchain.find_compiler( env.spec.compiler, env.spec.compiler_version) if installed_path: print('Compiler {} {} already exists at {}'.format( env.spec.compiler, installed_version, installed_path)) self.installed = True return # It's ok to attempt to install packages redundantly, they won't hurt anything packages = UniqueList(config.get('compiler_packages', [])) Script([InstallPackages(packages)], name='install gcc').run(env) self.installed = True
def run_build(env): config = env.config print("Running build", env.spec.name, flush=True) def pre_build(env): return env.project.pre_build(env) def build(env): return env.project.build(env) def post_build(env): return env.project.post_build(env) def test(env): return env.project.test(env) def install(env): return env.project.install(env) def build_consumers(env): if env.spec.downstream: return env.project.build_consumers(env) build = Script([ pre_build, build, post_build, test, install, build_consumers, ], name='run_build {}'.format(env.project.name)) run_action(build, env)
def run_action(action, env): config = env.config # Set build environment from config env.shell.pushenv() for var, value in getattr(env, 'env', {}).items(): env.shell.setenv(var, value) if isinstance(action, str): action_cls = Scripts.find_action(action) if not action_cls: print('Action {} not found'.format(action)) sys.exit(13) action = action_cls() if action.is_main(): Scripts.run_action(action, env) else: Scripts.run_action( Script([ InstallCompiler(), InstallPackages(), DownloadDependencies(), action, ], name='main'), env) env.shell.popenv()
def build_consumers(self, env): build_consumers = [] consumers = self.get_consumers(env.spec) for c in consumers: build_consumers += _build_project(c, env) if len(build_consumers) == 0: return None return Script(build_consumers, name='build consumers of {}'.format(self.name))
def test(self, env): run_tests = env.config.get('run_tests', True) if not run_tests: return steps = env.config.get('test_steps', env.config.get('test', [])) if steps is None: steps = ['test'] if isinstance(steps, list): steps = _transform_steps(steps, env, self) test_project = steps if len(steps) == 0: return None steps = [partial(_pushenv, self, 'test_env'), *steps, _popenv] return Script(steps, name='test {}'.format(self.name))
def build(self, env): build_project = [] steps = self.config.get('build_steps', self.config.get('build', [])) if not steps: steps = ['build'] if isinstance(steps, list): steps = _transform_steps(steps, env, self) build_project = steps if len(build_project) == 0: return None build_project = [ partial(_pushenv, self, 'build_env'), *build_project, _popenv ] return Script(build_project, name='build project {}'.format(self.name))
def install_nvm_choco(self, env): sh = env.shell Script([InstallPackages(['nvm'], )]).run(env) env_script = r'{}\dump_env.bat'.format(self.install_dir) with open(env_script, 'w+') as script: script.writelines(['call refreshenv.cmd\n', 'set\n']) script.flush() result = sh.exec(env_script, check=True, quiet=True) lines = result.output.split('\n') vars = {} for line in lines: if '=' in line: key, value = line.split('=', 1) vars[key.upper()] = value # Update path and NVM_* env vars sh.setenv('PATH', vars['PATH']) for key, value in vars.items(): if key.startswith('NVM_'): sh.setenv(key, value) sh.exec('nvm', 'version', check=True)
def install(self, env): if self.installed: return sh = env.shell config = env.config installed_path, installed_version = Toolchain.find_compiler( env.spec.compiler, env.spec.compiler_version) if installed_path: print('Compiler {} {} already exists at {}'.format( env.spec.compiler, installed_version, installed_path)) self.installed = True return packages = UniqueList(config.get('compiler_packages', [])) compiler = env.spec.compiler version = env.spec.compiler_version Script([InstallPackages(packages)], name='install gcc').run(env) self.installed = True
def install(self, env): if self.installed: return config = env.config # Ensure compiler packages are installed packages = UniqueList(config.get('compiler_packages', [])) Script([InstallPackages(packages)], name='Install compiler prereqs').run(env) installed_path, installed_version = Toolchain.find_compiler( env.spec.compiler, env.spec.compiler_version) if installed_path: print('Compiler {} {} already exists at {}'.format( env.spec.compiler, installed_version, installed_path)) self.installed = True return raise EnvironmentError( 'MSVC does not support dynamic install, and {} {} could not be found' .format(env.spec.compiler, env.spec.compiler_version))
def install(self, env): if self.installed: return sh = env.shell config = env.config # Ensure compiler packages are installed packages = UniqueList(config.get('compiler_packages', [])) Script([InstallPackages(packages)], name='Install compiler prereqs').run(env) installed_path, installed_version = Toolchain.find_compiler( env.spec.compiler, env.spec.compiler_version) if installed_path: print('Compiler {} {} already exists at {}'.format( env.spec.compiler, installed_version, installed_path)) self.installed = True return sudo = env.config.get('sudo', current_os() == 'linux') sudo = ['sudo'] if sudo else [] # Strip minor version info version = env.toolchain.compiler_version.replace('\..+', '') script = tempfile.NamedTemporaryFile(delete=False) script_path = script.name script.write(LLVM_SH.encode()) script.close() # Make script executable os.chmod( script_path, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) sh.exec(*sudo, [script_path, version], check=True) self.installed = True
def post_build(self, env): steps = env.config.get('post_build_steps', []) if len(steps) == 0: return None steps = [partial(_pushenv, self, 'post_build_env'), *steps, _popenv] return Script(steps, name='post_build {}'.format(self.name))
def run(self, env): config = env.config sh = env.shell parser = argparse.ArgumentParser() parser.add_argument('--skip-install', action='store_true') args = parser.parse_known_args(env.args.args)[0] sudo = config.get('sudo', current_os() == 'linux') sudo = ['sudo'] if sudo else [] packages = self.packages if self.packages else config.get( 'packages', []) if packages: packages = UniqueList(packages) pkg_tool = package_tool() print('Installing packages via {}: {}'.format( pkg_tool.value, ', '.join(packages))) was_dryrun = sh.dryrun if args.skip_install: sh.dryrun = True if not InstallPackages.pkg_init_done: pkg_setup = UniqueList(config.get('pkg_setup', [])) if pkg_setup: for cmd in pkg_setup: if isinstance(cmd, str): cmd = cmd.split(' ') assert isinstance(cmd, list) sh.exec(*sudo, cmd, check=True, retries=3) pkg_update = config.get('pkg_update', None) if pkg_update: if not isinstance(pkg_update, list): pkg_update = pkg_update.split(' ') sh.exec(*sudo, pkg_update, check=True, retries=3) InstallPackages.pkg_init_done = True pkg_install = config['pkg_install'] if not isinstance(pkg_install, list): pkg_install = pkg_install.split(' ') pkg_install += packages sh.exec(*sudo, pkg_install, check=True, retries=3) if args.skip_install: sh.dryrun = was_dryrun setup_steps = env.config.get('setup_steps', []) if setup_steps: steps = [] for step in setup_steps: if not isinstance(step, list): step = step.split(' ') if step: steps.append([*sudo, *step]) if args.skip_install: return Script([ partial(set_dryrun, True), *steps, partial(set_dryrun, sh.dryrun) ], name='setup') return Script(steps, name='setup')