Exemplo n.º 1
0
  def testUpdateChroot(self):
    """Test the update_chroot related handling."""
    # Prevent it from doing anything else for this test.
    self.PatchObject(sysroot, '_CreateSysrootSkeleton')
    self.PatchObject(sysroot, '_InstallConfigs')
    self.PatchObject(sysroot, '_InstallPortageConfigs')

    # Make sure we have a board we haven't setup to avoid triggering the
    # existing sysroot logic. That is entirely unrelated to the chroot update.
    target = self.unbuilt_target

    # Test no update case.
    config = sysroot.SetupBoardRunConfig(upgrade_chroot=False)
    get_args_patch = self.PatchObject(config, 'GetUpdateChrootArgs')

    sysroot.Create(target, config, None)

    # The update chroot args not being fetched is a
    # strong enough signal that the update wasn't run.
    get_args_patch.assert_not_called()

    # Test update case.
    script_loc = os.path.join(constants.CROSUTILS_DIR, 'update_chroot')
    config = sysroot.SetupBoardRunConfig(upgrade_chroot=True)

    sysroot.Create(target, config, None)

    self.assertCommandContains([script_loc])
Exemplo n.º 2
0
    def testGetUpdateChrootArgs(self):
        """Test the update chroot args conversion method."""
        # False/0/None tests.
        instance = sysroot.SetupBoardRunConfig(usepkg=False,
                                               jobs=None,
                                               update_toolchain=False)
        args = instance.GetUpdateChrootArgs()
        self.assertIn('--nousepkg', args)
        self.assertIn('--skip_toolchain_update', args)
        self.assertNotIn('--usepkg', args)
        self.assertNotIn('--jobs', args)

        instance.jobs = 0
        args = instance.GetUpdateChrootArgs()
        self.assertNotIn('--jobs', args)

        # True/set values tests.
        instance = sysroot.SetupBoardRunConfig(usepkg=True,
                                               jobs=1,
                                               update_toolchain=True)
        args = instance.GetUpdateChrootArgs()
        self.assertIn('--usepkg', args)
        self.assertIn('--jobs', args)
        self.assertNotIn('--nousepkg', args)
        self.assertNotIn('--skip_toolchain_update', args)
Exemplo n.º 3
0
  def testForce(self):
    """Test the force flag."""
    # Prevent it from doing anything else for this test.
    self.PatchObject(sysroot, '_CreateSysrootSkeleton')
    self.PatchObject(sysroot, '_InstallConfigs')
    self.PatchObject(sysroot, '_InstallPortageConfigs')

    delete_patch = self.PatchObject(sysroot_lib.Sysroot, 'Delete')

    config = sysroot.SetupBoardRunConfig(force=False)
    sysroot.Create(self.build_target, config, None)
    delete_patch.assert_not_called()

    config = sysroot.SetupBoardRunConfig(force=True)
    sysroot.Create(self.build_target, config, None)
    delete_patch.assert_called_once()
Exemplo n.º 4
0
def Create(input_proto, output_proto, _config):
    """Create or replace a sysroot."""
    update_chroot = not input_proto.flags.chroot_current
    replace_sysroot = input_proto.flags.replace

    build_target = controller_util.ParseBuildTarget(input_proto.build_target,
                                                    input_proto.profile)
    package_indexes = [
        binpkg.PackageIndexInfo.from_protobuf(x)
        for x in input_proto.package_indexes
    ]
    run_configs = sysroot.SetupBoardRunConfig(force=replace_sysroot,
                                              upgrade_chroot=update_chroot,
                                              package_indexes=package_indexes)

    try:
        created = sysroot.Create(build_target,
                                 run_configs,
                                 accept_licenses=_ACCEPTED_LICENSES)
    except sysroot.Error as e:
        cros_build_lib.Die(e)

    output_proto.sysroot.path = created.path
    output_proto.sysroot.build_target.name = build_target.name

    return controller.RETURN_CODE_SUCCESS
Exemplo n.º 5
0
def InstallToolchain(input_proto, output_proto, _config):
    """Install the toolchain into a sysroot."""
    compile_source = (input_proto.flags.compile_source
                      or input_proto.flags.toolchain_changed)

    sysroot_path = input_proto.sysroot.path

    build_target = controller_util.ParseBuildTarget(
        input_proto.sysroot.build_target)
    target_sysroot = sysroot_lib.Sysroot(sysroot_path)
    run_configs = sysroot.SetupBoardRunConfig(usepkg=not compile_source)

    _LogBinhost(build_target.name)

    try:
        sysroot.InstallToolchain(build_target, target_sysroot, run_configs)
    except sysroot_lib.ToolchainInstallError as e:
        # Error installing - populate the failed package info.
        for package in e.failed_toolchain_info:
            package_info = output_proto.failed_packages.add()
            controller_util.CPVToPackageInfo(package, package_info)

        return controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE

    return controller.RETURN_CODE_SUCCESS
Exemplo n.º 6
0
  def testLocalBuild(self):
    """Test the local build logic."""
    update_patch = self.PatchObject(self.sysroot, 'UpdateToolchain')

    # Test False.
    config = sysroot.SetupBoardRunConfig(usepkg=False, local_build=False)
    sysroot.InstallToolchain(self.build_target, self.sysroot, config)
    update_patch.assert_called_with(self.board, local_init=False)

    # Test usepkg True.
    update_patch.reset_mock()
    config = sysroot.SetupBoardRunConfig(usepkg=True, local_build=False)
    sysroot.InstallToolchain(self.build_target, self.sysroot, config)
    update_patch.assert_called_with(self.board, local_init=True)

    # Test local_build True.
    update_patch.reset_mock()
    config = sysroot.SetupBoardRunConfig(usepkg=False, local_build=True)
    sysroot.InstallToolchain(self.build_target, self.sysroot, config)
    update_patch.assert_called_with(self.board, local_init=True)
Exemplo n.º 7
0
  def testRegenConfigs(self):
    """Test the regen configs install prevention."""
    target_sysroot = sysroot_lib.Sysroot('/build/board')
    create_mock = self.PatchObject(sysroot, 'Create',
                                   return_value=target_sysroot)
    install_toolchain_mock = self.PatchObject(sysroot, 'InstallToolchain')

    target = build_target_util.BuildTarget('board')
    configs = sysroot.SetupBoardRunConfig(regen_configs=True)

    sysroot.SetupBoard(target, run_configs=configs)

    # Should still try to create the sysroot, but should not try to install
    # the toolchain.
    create_mock.assert_called_once()
    install_toolchain_mock.assert_not_called()
Exemplo n.º 8
0
def Create(input_proto, output_proto, _config):
    """Create or replace a sysroot."""
    update_chroot = not input_proto.flags.chroot_current
    replace_sysroot = input_proto.flags.replace

    build_target_name = input_proto.build_target.name
    profile = input_proto.profile.name or None

    build_target = build_target_util.BuildTarget(name=build_target_name,
                                                 profile=profile)
    run_configs = sysroot.SetupBoardRunConfig(force=replace_sysroot,
                                              upgrade_chroot=update_chroot)

    try:
        created = sysroot.Create(build_target,
                                 run_configs,
                                 accept_licenses=_ACCEPTED_LICENSES)
    except sysroot.Error as e:
        cros_build_lib.Die(e)

    output_proto.sysroot.path = created.path
    output_proto.sysroot.build_target.name = build_target_name

    return controller.RETURN_CODE_SUCCESS
Exemplo n.º 9
0
def _ParseArgs(args):
    """Parse and validate arguments."""
    parser = GetParser()
    opts = parser.parse_args(args)

    # Translate raw options to config objects.
    name = '%s_%s' % (opts.board, opts.variant) if opts.variant else opts.board
    opts.build_target = build_target_lib.BuildTarget(
        name, build_root=opts.board_root, profile=opts.profile)

    opts.run_config = sysroot.SetupBoardRunConfig(
        set_default=opts.default,
        force=opts.force,
        usepkg=opts.usepkg,
        jobs=opts.jobs,
        regen_configs=opts.regen_configs,
        quiet=opts.quiet,
        update_toolchain=not opts.skip_toolchain_update,
        upgrade_chroot=not opts.skip_chroot_upgrade,
        init_board_pkgs=not opts.skip_board_pkg_init,
        local_build=opts.reuse_local)

    opts.Freeze()
    return opts
Exemplo n.º 10
0
 def testNoSysroot(self):
   """Test handling of no sysroot."""
   with self.assertRaises(ValueError):
     sysroot.InstallToolchain(self.unbuilt_target, self.unbuilt_sysroot,
                              sysroot.SetupBoardRunConfig())