Esempio n. 1
0
  def call_shell(clazz, command, script, env, shell_env = None, save_logs = None, execution_dir = None):
    command = execute.listify_command(command)
    command = [ part for part in command if part ]
    shell_env = shell_env or key_value_list()
    save_logs = save_logs or []
    check.check_key_value_list(shell_env)
    
    log.log_i('rebuild', 'call_shell(command=%s)' % (command))
    build_blurb.blurb_verbose('rebuild', 'call_shell(cmd=%s, shell_env=%s)' % (command, shell_env))

    env = clazz.create_command_env(script)

    env.update(shell_env)

    #clazz.env_dump(env, script.descriptor.name, 'PRE ENVIRONMENT')

    clazz._env_substitite(env)

    rogue_key = clazz._env_find_roque_dollar_sign(env)
    if rogue_key:
      raise RuntimeError('Rogue dollar sign (\"$\") found in %s: %s' % (rogue_key, env[rogue_key]))

    command = [ variable.substitute(part, env) for part in object_util.listify(command) ]

    # Check that no rogue dollar signs are in the command
    for part in command:
      if variable.has_rogue_dollar_signs(part):
        raise RuntimeError('Rogue dollar sign (\"$\") found in: %s' % (part))
      
    build_blurb.blurb('rebuild', '%s - %s' % (script.descriptor.name, ' '.join(command)))

#    file_util.mkdir(script.build_dir)
    retry_script = clazz._write_retry_script(command, env, script)

    #clazz.env_dump(env, script.descriptor.name, clazz.__name__ + ' : ' + 'POST ENVIRONMENT')

    for k,v in env.items():
      if string_util.is_quoted(v):
        env[k] = string_util.unquote(v)

    if execution_dir:
      cwd = path.join(script.build_dir, execution_dir)
    else:
      cwd = script.build_dir

    rv = execute.execute(command,
                         cwd = cwd,
                         env = env,
                         shell = True,
                         non_blocking = build_blurb.verbose,
                         stderr_to_stdout = build_blurb.verbose,
                         raise_error = False)
    message = rv.stdout
    if rv.stderr:
      message = message + '\n' + rv.stderr
    result = step_result(rv.exit_code == 0, message)
    clazz.save_build_dir_logs(script, save_logs)
    return result
 def __init__(self, filenames, build_target, env):
     # Load all the scripts
     self.scripts = {}
     for filename in filenames:
         build_blurb.blurb_verbose('rebuild', 'loading %s' % (filename))
         builder_scripts = self._load_scripts(filename, build_target, env)
         for script in builder_scripts:
             #print('%s: requirements=%s' % (script.descriptor.name, str(script.descriptor.requirements)))
             self.scripts[script.descriptor.name] = script
Esempio n. 3
0
 def _run_exe_test(clazz, exe_env_name, exe_default, config, test_source):
     context = clazz._make_test_context(config, test_source)
     build_blurb.blurb_verbose(
         'tester', '%s: running shell test %s' %
         (context.package_info.name, test_source))
     exe = clazz._determine_exe(exe_env_name, exe_default)
     cmd = '%s %s' % (exe, context.test_source_with_replacements)
     rv = execute.execute(cmd,
                          env=context.env,
                          non_blocking=build_blurb.verbose,
                          stderr_to_stdout=True,
                          raise_error=False)
     os.environ = context.saved_env
     if rv.exit_code != 0:
         return step_result(rv.exit_code == 0, rv.stdout)
     return step_result(True, None)
Esempio n. 4
0
 def _run_python_test(clazz, config, test_source):
     context = clazz._make_test_context(config, test_source)
     build_blurb.blurb_verbose(
         'tester', '%s: running python test %s' %
         (context.package_info.name, test_source))
     # FIXME: move this to context
     context.env['PYTHONPATH'] = context.package_manager.python_lib_dir
     # Run the test
     cmd = 'python2.7 %s' % (context.test_source_with_replacements)
     rv = execute.execute(cmd,
                          env=context.env,
                          non_blocking=build_blurb.verbose,
                          stderr_to_stdout=True,
                          raise_error=False)
     if rv.exit_code != 0:
         return step_result(rv.exit_code == 0, rv.stdout)
     return step_result(True, None)
Esempio n. 5
0
    def _run_c_test(clazz, config, test_source, compiler, extra_cflags):
        context = clazz._make_test_context(config, test_source)
        build_blurb.blurb_verbose(
            'tester', '%s: running c test %s with %s' %
            (context.package_info.name, path.relpath(test_source), compiler))
        package_names_for_pkg_config = [context.package_info.name]

        # FIXME: static is hardcoded here (depends on global static mode)
        cflags, libs = context.package_manager.compilation_flags(
            package_names_for_pkg_config, static=True)
        test_exe = path.join(context.test_dir, context.test_name + '.exe')
        cflags += extra_cflags
        cflags_flat = ' '.join(cflags)
        libs_flat = ' '.join(libs)
        compilation_cmd = '%s -o %s %s %s %s' % (
            compiler, test_exe, context.test_source_with_replacements,
            cflags_flat, libs_flat)
        build_blurb.blurb_verbose(
            'tester', '%s: compilation_cmd=\"%s\"' %
            (context.package_info.name, compilation_cmd))
        build_blurb.blurb_verbose(
            'tester', '%s: cflags=\"%s\" libs=\"%s\"' %
            (context.package_info.name, cflags_flat, libs_flat))

        # Build the test
        rv = execute.execute(compilation_cmd,
                             env=context.env,
                             non_blocking=build_blurb.verbose,
                             stderr_to_stdout=True,
                             raise_error=False)
        if rv.exit_code != 0:
            return step_result(rv.exit_code == 0, rv.stdout)
        # Run the test
        rv = execute.execute(test_exe,
                             env=context.env,
                             non_blocking=build_blurb.verbose,
                             stderr_to_stdout=True,
                             raise_error=False)

        # Restore the environment cause _make_test_context() hacks it
        os.environ = context.saved_env

        if rv.exit_code != 0:
            return step_result(rv.exit_code == 0, rv.stdout)

        return step_result(True, None)
Esempio n. 6
0
    def main(self):
        args = self.parser.parse_args()
        bt = self.build_target_resolve(args)
        args.verbose = bool(args.verbose)

        if args.change_dir:
            os.chdir(args.change_dir)

        target_packages = args.target_packages[0]

        available_packages = self.load_project_file(args.project_file)

        if args.filter:
            if path.isfile(args.filter[0]):
                target_packages_filter = file_util.read(
                    args.filter[0]).split('\n')
            else:
                target_packages_filter = args.filter[0].split(',')
            target_packages_filter = [p for p in target_packages_filter if p]
            available_packages = self._filter_target_packages(
                available_packages, target_packages_filter)

        args.system = build_system.parse_system(args.system)
        args.level = build_level.parse_level(args.level)
        args.arch = build_arch.parse_arch(args.arch, args.system, args.distro)

        build_blurb.set_process_name('rebuild')
        build_blurb.set_verbose(args.verbose)

        # Tests only run on desktop
        if not bt.is_desktop():
            args.skip_tests = True

        if args.download_only and args.no_network:
            build_blurb.blurb(
                'rebuild',
                'Only one of --download-only and --no-net can be given.')
            return 1

        config = builder_config()
        config.build_root = path.abspath(path.abspath(args.root))
        config.build_target = bt
        config.deps_only = args.deps_only
        config.recipes_only = args.recipes_only
        config.disabled = args.disabled
        config.keep_going = args.keep_going
        config.no_checksums = args.no_checksums
        config.no_network = args.no_network
        config.skip_tests = args.skip_tests
        config.skip_to_step = args.skip_to_step
        config.source_dir = args.source_dir
        config.source_pcloud = args.source_pcloud
        config.tools_only = args.tools_only
        config.source_git = args.source_git
        config.users = args.users
        config.verbose = args.verbose
        config.wipe = args.wipe
        config.scratch = args.scratch
        config.third_party_prefix = args.third_party_prefix
        if args.timestamp:
            config.timestamp = args.timestamp
        config.performance = args.performance
        config.download_only = args.download_only
        config.artifacts_dir = args.artifacts
        env = builder_env(config, available_packages)

        bldr = builder(env)

        resolved_args = bldr.check_and_resolve_cmd_line_args(target_packages)

        if args.targets:
            build_blurb.blurb('rebuild',
                              ' '.join(bldr.package_names()),
                              fit=True)
            return 1

        build_blurb.blurb(
            'rebuild',
            'target=%s; host=%s' % (config.build_target.build_path,
                                    config.host_build_target.build_path))
        build_blurb.blurb_verbose('rebuild',
                                  'command line: %s' % (' '.join(sys.argv)))

        if resolved_args.invalid_args:
            build_blurb.blurb(
                'rebuild',
                'Invalid targets: %s' % (' '.join(resolved_args.invalid_args)))
            build_blurb.blurb('rebuild', 'possible targets:')
            build_blurb.blurb('rebuild',
                              ' '.join(bldr.package_names()),
                              fit=True)
            return 1

        if config.recipes_only:
            return bldr.EXIT_CODE_SUCCESS

        return bldr.build_many_scripts(resolved_args.package_names)
Esempio n. 7
0
 def env_dump(clazz, env, package_name, label):
   for key, value in sorted(env.items()):
     build_blurb.blurb_verbose('rebuild', '%s(%s): %s=%s' % (label, package_name, key, value))