Ejemplo n.º 1
0
def _run_cros_config_host(build_target, args, log_output=True):
    """Run the cros_config_host tool.

  Args:
    build_target (build_target_lib.BuildTarget): The build target.
    args: List of arguments to pass.
    log_output: Whether to log the output of the cros_config_host.

  Returns:
    Output of the tool
  """
    cros_build_lib.AssertInsideChroot()
    tool = '/usr/bin/cros_config_host'
    if not os.path.isfile(tool):
        return None

    config_fname = build_target.full_path(
        'usr/share/chromeos-config/yaml/config.yaml')

    result = cros_build_lib.run([tool, '-c', config_fname] + args,
                                capture_output=True,
                                encoding='utf-8',
                                log_output=log_output,
                                check=False)
    if result.returncode:
        # Show the output for debugging purposes.
        if 'No such file or directory' not in result.error:
            logging.error('cros_config_host failed: %s\n', result.error)
        return None
    return result.output.strip().splitlines()
def main(argv: List[str]) -> None:
  cros_build_lib.AssertInsideChroot()
  parser = get_parser()
  opts = parser.parse_args(argv)
  opts.Freeze()

  only_files = {Path(f).resolve() for f in opts.file}

  git_repo_base = opts.git_repo_base
  if git_repo_base:
    git_repo_base = Path(opts.git_repo_base)
    if not (git_repo_base / '.git').exists():
      # This script doesn't strictly care if there's a .git dir there; more of
      # a smoke check.
      parser.error(f'Given git repo base ({git_repo_base}) has no .git dir')

  package_ebuilds = [
      portage_util.EBuild(x)
      for x in resolve_package_ebuilds(opts.board, opts.package)
  ]

  setup_tidy(opts.board, package_ebuilds)
  lints = filter_tidy_lints(
      only_files,
      git_repo_base,
      diags=run_tidy(opts.board, package_ebuilds, opts.keep_lint_dirs,
                     opts.nonfatal_parse_errors))

  osutils.WriteFile(
      opts.output,
      json.dumps({'tidy_diagnostics': [x.to_dict() for x in lints]}),
      atomic=True)
Ejemplo n.º 3
0
def BuildPackages(target, sysroot, run_configs):
  """Build and install packages into a sysroot.

  Args:
    target (build_target_lib.BuildTarget): The target whose packages are being
      installed.
    sysroot (sysroot_lib.Sysroot): The sysroot where the packages are being
      installed.
    run_configs (BuildPackagesRunConfig): The run configs.
  """
  cros_build_lib.AssertInsideChroot()

  cmd = [os.path.join(constants.CROSUTILS_DIR, 'build_packages'),
         '--board', target.name, '--board_root', sysroot.path]
  cmd += run_configs.GetBuildPackagesArgs()

  extra_env = run_configs.GetEnv()
  extra_env['USE_NEW_PARALLEL_EMERGE'] = '1'
  with osutils.TempDir() as tempdir:
    extra_env[constants.CROS_METRICS_DIR_ENVVAR] = tempdir

    try:
      # REVIEW: discuss which dimensions to flatten into the metric
      # name other than target.name...
      with metrics.timer('service.sysroot.BuildPackages.RunCommand'):
        cros_build_lib.run(cmd, extra_env=extra_env)
    except cros_build_lib.RunCommandError as e:
      failed_pkgs = portage_util.ParseDieHookStatusFile(tempdir)
      raise sysroot_lib.PackageInstallError(
          str(e), e.result, exception=e, packages=failed_pkgs)
Ejemplo n.º 4
0
def main(argv):
  """Generate the delta sysroot

  Create a tarball containing a sysroot that can be patched over extracted
  prebuilt package contents to create a complete sysroot.

  1. Unpack all packages for a board into an unpack_only sysroot directory.
  2. Emerge all packages for a board into a build sysroot directory.
  3. Create a batch file using:
    rsync -rplgoDc --delete --write-batch=<batch> <build_sys> <unpackonly_sys>
  4. Put the batch file inside a tarball.
  """
  options = _ParseCommandLine(argv)
  FinishParsing(options)

  cros_build_lib.AssertInsideChroot()

  with osutils.TempDir(set_global=False, sudo_rm=True) as tmp_dir:
    build_sysroot = os.path.join(tmp_dir, 'build-sys')
    unpackonly_sysroot = os.path.join(tmp_dir, 'tmp-sys')
    batch_filename = options.out_batch

    GenerateSysroot(unpackonly_sysroot, options.board, options.build_tests,
                    unpack_only=True)
    GenerateSysroot(build_sysroot, options.board, options.build_tests,
                    unpack_only=False)

    # Finally create batch file.
    CreateBatchFile(build_sysroot, unpackonly_sysroot,
                    os.path.join(tmp_dir, batch_filename))

    cros_build_lib.CreateTarball(
        os.path.join(options.out_dir, options.out_file), tmp_dir, sudo=True,
        inputs=[batch_filename])
Ejemplo n.º 5
0
def get_all_firmware_versions(build_target):
    """Extract firmware version for all models present.

  Args:
    build_target (build_target_lib.BuildTarget): The build target.

  Returns:
    A dict of FirmwareVersions namedtuple instances by model.
    Each element will be populated based on whether it was present in the
    command output.
  """
    cros_build_lib.AssertInsideChroot()
    result = {}
    # Note that example output for _get_firmware_version_cmd_result is available
    # in the packages_unittest.py for testing get_all_firmware_versions.
    cmd_result = _get_firmware_version_cmd_result(build_target)

    # There is a blank line between the version info for each model.
    firmware_version_payloads = cmd_result.split('\n\n')
    for firmware_version_payload in firmware_version_payloads:
        if 'BIOS' in firmware_version_payload:
            firmware_version = _find_firmware_versions(
                firmware_version_payload)
            result[firmware_version.model] = firmware_version
    return result
Ejemplo n.º 6
0
def main(argv):
    """Parses arguments and executes a command.

  Args:
    argv: The prorgram arguments.

  Returns:
    0 on success. Non-zero on failure.
  """
    cros_build_lib.AssertInsideChroot()
    options = ParseArgs(argv)
    if options.board is None:
        logging.error('Please specify "--board" or set ".default_board".')
        return 1

    SysrootPath.SetPathToSysroot(options.board)

    InstallBaseDependencies(options)

    if options.command == 'cleanup':
        ExecuteCleanupCommand()
    elif options.command == 'coverage':
        ExecuteCoverageCommand(options)
    elif options.command == 'setup':
        ExecuteSetupCommand()
    elif options.command == 'download':
        ExecuteDownloadCommand(options)
    elif options.command == 'reproduce':
        ExecuteReproduceCommand(options)
    elif options.command == 'shell':
        return ExecuteShellCommand()

    return 0
Ejemplo n.º 7
0
def main(argv):
    cros_build_lib.AssertInsideChroot()
    opts = _ParseArguments(argv)

    site_config = config_lib.GetConfig()

    logging.info('Generating board configs. This takes about 2m...')
    for key in sorted(binhost.GetChromePrebuiltConfigs(site_config)):
        binhost.GenConfigsForBoard(key.board,
                                   regen=opts.regen,
                                   error_code_ok=True)

    # Fetch all compat IDs.
    fetcher = binhost.CompatIdFetcher()
    keys = binhost.GetChromePrebuiltConfigs(site_config).keys()
    compat_ids = fetcher.FetchCompatIds(keys)

    # Save the PFQ configs.
    pfq_configs = binhost.PrebuiltMapping.Get(keys, compat_ids)
    filename_internal = binhost.PrebuiltMapping.GetFilename(
        opts.buildroot, 'chrome')
    pfq_configs.Dump(filename_internal)
    git.AddPath(filename_internal)
    git.Commit(os.path.dirname(filename_internal),
               'Update PFQ config dump',
               allow_empty=True)

    filename_external = binhost.PrebuiltMapping.GetFilename(opts.buildroot,
                                                            'chromium',
                                                            internal=False)
    pfq_configs.Dump(filename_external, internal=False)
    git.AddPath(filename_external)
    git.Commit(os.path.dirname(filename_external),
               'Update PFQ config dump',
               allow_empty=True)
Ejemplo n.º 8
0
def builds(atom, build_target, packages=None):
    """Check if |build_target| builds |atom| (has it in its depgraph)."""
    cros_build_lib.AssertInsideChroot()

    graph, _sdk_graph = dependency.GetBuildDependency(build_target.name,
                                                      packages)
    return any(atom in package for package in graph['package_deps'])
Ejemplo n.º 9
0
def main(argv):
    opts = _ParseArguments(argv)
    cros_build_lib.AssertInsideChroot()

    board = opts.build_target_name
    bests = {}
    for cpv in opts.packages:
        bests[cpv.atom] = portage_util.PortageqBestVisible(cpv.atom,
                                                           board=board)

    # Emerge args:
    #   g: use binpkgs (needed to find if we have one)
    #   u: update packages to latest version (want updates to invalidate binpkgs)
    #   D: deep -- consider full tree rather that just immediate deps
    #     (changes in dependencies and transitive deps can invalidate a binpkg)
    #   N: Packages with changed use flags should be considered
    #     (changes in dependencies and transitive deps can invalidate a binpkg)
    #   q: quiet (simplifies output)
    #   p: pretend (don't actually install it)
    args = ['-guDNqp', '--with-bdeps=y', '--color=n']
    if board:
        args.append('--board=%s' % board)
    args.extend('=%s' % best.cpf for best in bests.values())

    generator = depgraph.DepGraphGenerator()
    generator.Initialize(args)

    results = {}
    for atom, best in bests.items():
        results[atom] = generator.HasPrebuilt(best.cpf)

    osutils.WriteFile(opts.output, json.dumps(results))
Ejemplo n.º 10
0
def InstallToolchain(target, sysroot, run_configs):
  """Update the toolchain to a sysroot.

  This entry point just installs the target's toolchain into the sysroot.
  Everything else must have been done already for this to be successful.

  Args:
    target (build_target_lib.BuildTarget): The target whose toolchain is being
      installed.
    sysroot (sysroot_lib.Sysroot): The sysroot where the toolchain is being
      installed.
    run_configs (SetupBoardRunConfig): The run configs.
  """
  cros_build_lib.AssertInsideChroot()
  if not sysroot.Exists():
    # Sanity check before we try installing anything.
    raise ValueError('The sysroot must exist, run Create first.')

  # Step 4: Install toolchain and packages.
  # Dependencies: Portage configs and wrappers have been installed.
  if run_configs.init_board_pkgs:
    logging.info('Updating toolchain.')
    # Use the local packages if we're doing a local only build or usepkg is set.
    local_init = run_configs.usepkg or run_configs.local_build
    _InstallToolchain(sysroot, target, local_init=local_init)
Ejemplo n.º 11
0
def main(argv):
    parser = GetParser()
    options = parser.parse_args(argv)
    options.Freeze()

    if options.command == 'list-all':
        board_to_packages = workon_helper.ListAllWorkedOnAtoms()
        color = terminal.Color()
        for board in sorted(board_to_packages):
            print(color.Start(color.GREEN) + board + ':' + color.Stop())
            for package in board_to_packages[board]:
                print('    ' + package)
            print('')
        return 0

    # TODO(wiley): Assert that we're not running as root.
    cros_build_lib.AssertInsideChroot()

    if options.host:
        friendly_name = 'host'
        sysroot = '/'
    elif options.board:
        friendly_name = options.board
        sysroot = cros_build_lib.GetSysroot(board=options.board)
    else:
        cros_build_lib.Die('You must specify either --host, --board')

    helper = workon_helper.WorkonHelper(sysroot, friendly_name)
    try:
        if options.command == 'start':
            helper.StartWorkingOnPackages(options.packages,
                                          use_all=options.all,
                                          use_workon_only=options.workon_only)
        elif options.command == 'stop':
            helper.StopWorkingOnPackages(options.packages,
                                         use_all=options.all,
                                         use_workon_only=options.workon_only)
        elif options.command == 'info':
            triples = helper.GetPackageInfo(
                options.packages,
                use_all=options.all,
                use_workon_only=options.workon_only)
            for package, repos, paths in triples:
                print(package, ','.join(repos), ','.join(paths))
        elif options.command == 'list':
            packages = helper.ListAtoms(use_all=options.all,
                                        use_workon_only=options.workon_only)
            if packages:
                print('\n'.join(packages))
        elif options.command == 'iterate':
            helper.RunCommandInPackages(options.packages,
                                        options.iterate_command,
                                        use_all=options.all,
                                        use_workon_only=options.workon_only)
    except workon_helper.WorkonError as e:
        cros_build_lib.Die(e)

    return 0
def main(argv):
  parser = GetParser()
  options = parser.parse_args(argv)
  options.Freeze()

  # Figure out what we're supposed to do and reject conflicting options.
  conflicting_options = (
      options.cfg_name,
      options.show_packages,
      options.create_packages,
  )
  if sum(bool(x) for x in conflicting_options) > 1:
    parser.error('conflicting options: create-packages & show-packages & '
                 'show-board-cfg')

  targets_wanted = set(options.targets.split(','))
  boards_wanted = (set(options.include_boards.split(','))
                   if options.include_boards else set())

  if options.cfg_name:
    ShowConfig(options.cfg_name)
  elif options.show_packages is not None:
    cros_build_lib.AssertInsideChroot()
    target = options.show_packages
    Crossdev.Load(False)
    for package in GetTargetPackages(target):
      print(GetPortagePackage(target, package))
  elif options.create_packages:
    cros_build_lib.AssertInsideChroot()
    Crossdev.Load(False)
    CreatePackages(targets_wanted, options.output_dir)
  else:
    cros_build_lib.AssertInsideChroot()
    # This has to be always run as root.
    if os.geteuid() != 0:
      cros_build_lib.Die('this script must be run as root')

    Crossdev.Load(options.reconfig)
    root = options.sysroot or '/'
    UpdateToolchains(options.usepkg, options.deleteold, options.hostonly,
                     options.reconfig, targets_wanted, boards_wanted,
                     root=root)
    Crossdev.Save()

  return 0
Ejemplo n.º 13
0
def builds(atom, build_target, packages=None):
    """Check if |build_target| builds |atom| (has it in its depgraph)."""
    cros_build_lib.AssertInsideChroot()

    pkgs = tuple(packages) if packages else None
    # TODO(crbug/1081828): Receive and use sysroot.
    graph, _sdk_graph = dependency.GetBuildDependency(build_target.root,
                                                      build_target.name, pkgs)
    return any(atom in package for package in graph['package_deps'])
Ejemplo n.º 14
0
def main(argv):
    cros_build_lib.AssertInsideChroot()
    opts = _ParseArguments(argv)
    filename = binhost.PrebuiltMapping.GetFilename(opts.buildroot,
                                                   opts.prebuilt_type)
    pfq_configs = binhost.PrebuiltMapping.Load(filename)
    extra_useflags = os.environ.get('USE', '').split()
    compat_id = binhost.CalculateCompatId(opts.board, extra_useflags)
    for key in pfq_configs.GetPrebuilts(compat_id):
        print(key.board)
def main(argv):
  cros_build_lib.AssertInsideChroot()

  opts = _ParseArgs(argv)
  try:
    toolchain.InstallToolchain(sysroot=opts.sysroot,
                               toolchain=opts.toolchain,
                               force=opts.force, configure=opts.configure)
  except (toolchain.Error, cros_build_lib.RunCommandError, ValueError) as e:
    cros_build_lib.Die(e)
Ejemplo n.º 16
0
def _CheckSaneArguments(command, options):
    """Checks to make sure the flags are sane.  Dies if arguments are not sane."""
    if not command in COMMAND_DICTIONARY.keys():
        _PrintUsageAndDie('%s is not a valid command' % command)
    if not options.packages and command == 'commit' and not options.all:
        _PrintUsageAndDie('Please specify at least one package')
    if options.boards:
        cros_build_lib.AssertInsideChroot()
    if not os.path.isdir(options.srcroot):
        _PrintUsageAndDie('srcroot is not a valid path')
    options.srcroot = os.path.abspath(options.srcroot)
Ejemplo n.º 17
0
def main(argv):
    opts = ParseArgs(argv)

    cros_build_lib.AssertInsideChroot()

    sysroot = opts.sysroot or cros_build_lib.GetSysroot(opts.board)
    package_blacklist = portage_util.UNITTEST_PACKAGE_BLACKLIST
    if opts.package_blacklist:
        package_blacklist |= set(opts.package_blacklist.split())

    packages = set()
    # The list of packages to test can be passed as a file containing a
    # space-separated list of package names.
    # This is used by the builder to test only the packages that were upreved.
    if opts.package_file and os.path.exists(opts.package_file):
        packages = set(osutils.ReadFile(opts.package_file).split())

    if opts.packages:
        packages |= set(opts.packages.split())

    # If no packages were specified, use all testable packages.
    if not (opts.packages or opts.package_file):
        workon = workon_helper.WorkonHelper(sysroot)
        packages = (workon.InstalledWorkonAtoms()
                    if opts.installed else workon.ListAtoms(use_all=True))

    for cp in packages & package_blacklist:
        logging.info('Skipping blacklisted package %s.', cp)

    packages = packages - package_blacklist
    pkg_with_test = portage_util.PackagesWithTest(sysroot, packages)

    if packages - pkg_with_test:
        logging.warning('The following packages do not have tests:')
        logging.warning('\n'.join(sorted(packages - pkg_with_test)))

    if opts.pretend:
        print('\n'.join(sorted(pkg_with_test)))
        return

    env = None
    if opts.nowithdebug:
        use_flags = os.environ.get('USE', '')
        use_flags += ' -cros-debug'
        env = {'USE': use_flags}

    try:
        chroot_util.RunUnittests(sysroot,
                                 pkg_with_test,
                                 extra_env=env,
                                 jobs=min(10, multiprocessing.cpu_count()))
    except cros_build_lib.RunCommandError:
        logging.error('Unittests failed.')
        raise
Ejemplo n.º 18
0
def main(argv):
  cros_build_lib.AssertInsideChroot()
  opts = _ParseArgs(argv)
  try:
    success = image_lib.SecurityTest(board=opts.board, image=opts.image,
                                     baselines=opts.baselines,
                                     vboot_hash=opts.vboot_hash)
  except image_lib.Error as e:
    cros_build_lib.Die(e)
  else:
    return 0 if success else 1
Ejemplo n.º 19
0
def main(argv):
    cros_build_lib.AssertInsideChroot()

    args = ParseArguments(argv)

    if os.geteuid() != 0:
        try:
            cros_build_lib.SudoRunCommand([sys.executable] + sys.argv)
        except cros_build_lib.RunCommandError:
            return 1
        return 0

    if not args.board:
        print 'No board specified. Aborting.'
        return 1

    manifest = git.ManifestCheckout.Cached(constants.SOURCE_ROOT)
    source_path = manifest.GetProjectPath(AUTOTEST_PROJECT_NAME, absolute=True)
    source_path = os.path.join(source_path, '')

    script_path = os.path.dirname(__file__)
    include_pattern_file = os.path.join(script_path, INCLUDE_PATTERNS_FILENAME)

    # TODO: Determine the following string programatically.
    sysroot_path = os.path.join('/build', args.board, '')
    sysroot_autotest_path = os.path.join(sysroot_path, 'usr', 'local',
                                         'autotest', '')

    rsync_output = RsyncQuickmerge(source_path, sysroot_autotest_path,
                                   include_pattern_file, args.pretend,
                                   args.overwrite)

    if args.verbose:
        logging.info(rsync_output.output)

    change_report = ItemizeChangesFromRsyncOutput(rsync_output.output,
                                                  sysroot_autotest_path)

    if not args.pretend:
        UpdatePackageContents(change_report, AUTOTEST_EBUILD, sysroot_path)
        for ebuild in DOWNGRADE_EBUILDS:
            if not DowngradePackageVersion(sysroot_path, ebuild):
                logging.warning(
                    'Unable to downgrade package %s version number.', ebuild)
        RemoveBzipPackages(sysroot_autotest_path)

    if args.pretend:
        logging.info('The following message is pretend only. No filesystem '
                     'changes made.')
    logging.info(
        'Quickmerge complete. Created or modified %s files.',
        len(change_report.new_files) + len(change_report.modified_files))

    return 0
Ejemplo n.º 20
0
def main(argv):
    options = ParseCommandLine(argv)
    FinishParsing(options)

    cros_build_lib.AssertInsideChroot()

    with sudo.SudoKeepAlive(ttyless_sudo=False):
        with osutils.TempDir(set_global=True, sudo_rm=True) as tempdir:
            sysroot = os.path.join(tempdir, SYSROOT)
            os.mkdir(sysroot)
            GenerateSysroot(sysroot, options).Perform()
Ejemplo n.º 21
0
def Emerge(packages,
           sysroot,
           with_deps=True,
           rebuild_deps=True,
           use_binary=True,
           jobs=None,
           debug_output=False):
    """Emerge the specified |packages|.

  Args:
    packages: List of packages to emerge.
    sysroot: Path to the sysroot in which to emerge.
    with_deps: Whether to include dependencies.
    rebuild_deps: Whether to rebuild dependencies.
    use_binary: Whether to use binary packages.
    jobs: Number of jobs to run in parallel.
    debug_output: Emit debug level output.

  Raises:
    cros_build_lib.RunCommandError: If emerge returns an error.
  """
    cros_build_lib.AssertInsideChroot()
    if not packages:
        raise ValueError('No packages provided')

    cmd = GetEmergeCommand(sysroot)
    cmd.append('-uNv')

    modified_packages = workon.ListModifiedWorkonPackages(
        sysroot_lib.Sysroot(sysroot))
    if modified_packages:
        mod_pkg_list = ' '.join(modified_packages)
        cmd += [
            '--reinstall-atoms=' + mod_pkg_list,
            '--usepkg-exclude=' + mod_pkg_list
        ]

    cmd.append('--deep' if with_deps else '--nodeps')
    if use_binary:
        cmd += ['-g', '--with-bdeps=y']
        if sysroot == '/':
            # Only update toolchains in the chroot when binpkgs are available. The
            # toolchain rollout process only takes place when the chromiumos sdk
            # builder finishes a successful build and pushes out binpkgs.
            cmd += ['--useoldpkg-atoms=%s' % ' '.join(_GetToolchainPackages())]

    if rebuild_deps:
        cmd.append('--rebuild-if-unbuilt')
    if jobs:
        cmd.append('--jobs=%d' % jobs)
    if debug_output:
        cmd.append('--show-output')

    cros_build_lib.SudoRunCommand(cmd + packages)
Ejemplo n.º 22
0
def main(argv):
  options = ParseCommandLine(argv)
  FinishParsing(options)

  cros_build_lib.AssertInsideChroot()

  with sudo.SudoKeepAlive(ttyless_sudo=False):
    with osutils.TempDir(set_global=True, sudo_rm=True) as tempdir:
      warnings_dir = os.path.join(tempdir, TIDY_WARNINGS)
      os.mkdir(warnings_dir)
      GenerateTidyWarnings(warnings_dir, options).Perform()
def main(argv):
    """Main function."""
    cros_build_lib.AssertInsideChroot()

    opts = _ParseArgs(argv)

    if opts.init_latest:
        cros_sdk_lib.InitLatestVersion()
    else:
        try:
            cros_sdk_lib.RunChrootVersionHooks()
        except cros_sdk_lib.Error as e:
            cros_build_lib.Die(e)
Ejemplo n.º 24
0
def main(argv):
    cros_build_lib.AssertInsideChroot()

    opts = ParseArguments(argv)

    if opts.config:
        config_content = osutils.ReadFile(opts.config)
    else:
        config_content = GetConfigContent(opts)

    logging.info('Using config: %s', config_content)

    if opts.dump_config:
        print(config_content)

    PrepareImage(opts.image, config_content, opts.enrollment_domain)
Ejemplo n.º 25
0
def main(argv):
    cros_build_lib.AssertInsideChroot()
    options = GetOptions(argv)

    if options.action == ACTION_GET_ENTRY:
        db = user_db.UserDB(options.sysroot)
        if options.database == USER_DB:
            print(db.GetUserEntry(options.name, skip_lock=options.nolock))
        else:
            print(db.GetGroupEntry(options.name, skip_lock=options.nolock))
        return 0

    overlays = sysroot_lib.Sysroot(options.sysroot).GetStandardField(
        sysroot_lib.STANDARD_FIELD_PORTDIR_OVERLAY).split()

    # TODO(wiley) This process could be optimized to avoid reparsing these
    #             overlay databases each time.
    account_db = accounts_lib.AccountDatabase()
    for overlay_path in overlays:
        database_path = os.path.join(overlay_path, ACCOUNT_DB_FILENAME)
        if os.path.exists(database_path):
            account_db.AddAccountsFromDatabase(database_path)

    installed_users = user_db.UserDB(options.sysroot)

    if options.action == ACTION_INSTALL_USER:
        account_db.InstallUser(options.name,
                               installed_users,
                               uid=options.uid,
                               shell=options.shell,
                               homedir=options.home,
                               primary_group=options.primary_group)

        homedir = account_db.users[options.name].home
        homedir_path = os.path.join(options.sysroot, homedir)

        if homedir != '/dev/null' and not os.path.exists(homedir_path):
            osutils.SafeMakedirs(homedir_path, sudo=True)
            uid = account_db.users[options.name].uid
            cros_build_lib.sudo_run(
                ['chown', '%d:%d' % (uid, uid), homedir_path], print_cmd=False)

    elif options.action == ACTION_INSTALL_GROUP:
        account_db.InstallGroup(options.name, installed_users, gid=options.gid)
    else:
        cros_build_lib.Die('Unsupported account type: %s' %
                           options.account_type)
Ejemplo n.º 26
0
def main(argv):
    cros_build_lib.AssertInsideChroot()

    parser = commandline.ArgumentParser(description=__doc__)
    parser.add_argument('--output',
                        required=True,
                        help='File to write results to')
    parser.add_argument('board', nargs='+')
    opts = parser.parse_args(argv)

    output = opts.output
    if output == '-':
        output = '/dev/stdout'

    results = {x: get_all_package_objects(x) for x in opts.board}
    with open(output, 'w') as f:
        json.dump(results, f)
Ejemplo n.º 27
0
def get_firmware_versions(build_target):
    """Extract version information from the firmware updater, if one exists.

  Args:
    build_target (build_target_lib.BuildTarget): The build target.

  Returns:
    A FirmwareVersions namedtuple instance.
    Each element will either be set to the string output by the firmware
    updater shellball, or None if there is no firmware updater.
  """
    cros_build_lib.AssertInsideChroot()
    cmd_result = _get_firmware_version_cmd_result(build_target)
    if cmd_result:
        return _find_firmware_versions(cmd_result)
    else:
        return FirmwareVersions(None, None, None, None, None)
Ejemplo n.º 28
0
def Update(arguments):
    """Update the chroot.

  Args:
    arguments (UpdateArguments): The various arguments for updating a chroot.

  Returns:
    int - The version of the chroot after the update.
  """
    # TODO: This should be able to be run either in or out of the chroot.
    cros_build_lib.AssertInsideChroot()

    cmd = [os.path.join(constants.CROSUTILS_DIR, 'update_chroot')]
    cmd.extend(arguments.GetArgList())

    cros_build_lib.run(cmd)

    return GetChrootVersion()
Ejemplo n.º 29
0
def find_fingerprints(build_target):
    """Returns a list of fingerprints for this build.

  Args:
    build_target (build_target_lib.BuildTarget): The build target.

  Returns:
    list[str] - List of fingerprint strings.
  """
    cros_build_lib.AssertInsideChroot()
    fp_file = 'cheets-fingerprint.txt'
    fp_path = os.path.join(image_lib.GetLatestImageLink(build_target.name),
                           fp_file)
    if not os.path.isfile(fp_path):
        logging.info('Fingerprint file not found: %s', fp_path)
        return []
    logging.info('Reading fingerprint file: %s', fp_path)
    fingerprints = osutils.ReadFile(fp_path).splitlines()
    return fingerprints
Ejemplo n.º 30
0
def main(argv):
    parser = commandline.ArgumentParser(description=__doc__)
    parser.add_argument(
        '--sysroot',
        type='path',
        help='The sysroot to use for brick metadata validation.')
    parser.add_argument('appc_pod_manifest_path',
                        type='path',
                        help='path to appc pod manifest')
    parser.add_argument('sandbox_spec_path',
                        type='path',
                        help='path to file to write resulting SandboxSpec to. '
                        'Must not exist.')
    options = parser.parse_args(argv)
    options.Freeze()

    cros_build_lib.AssertInsideChroot()

    generator = sandbox_spec_generator.SandboxSpecGenerator(options.sysroot)
    generator.WriteSandboxSpec(options.appc_pod_manifest_path,
                               options.sandbox_spec_path)
    return 0