Пример #1
0
def _BuildTargetUnitTestFailedResponse(_input_proto, output_proto, _config):
    """Add failed packages to a failed response."""
    packages = ['foo/bar', 'cat/pkg']
    failed_cpvs = [portage_util.SplitCPV(p, strict=False) for p in packages]
    for cpv in failed_cpvs:
        package_info = output_proto.failed_packages.add()
        controller_util.CPVToPackageInfo(cpv, package_info)
Пример #2
0
def List(input_proto: depgraph_pb2.ListRequest,
         output_proto: depgraph_pb2.ListResponse,
         _config: api_config.ApiConfig):
    """Get a list of package dependencies.

  Args:
    input_proto: The input arguments message.
    output_proto: The empty output message.
    _config: The API call config.
  """
    build_target = controller_util.ParseBuildTarget(
        input_proto.sysroot.build_target)
    sysroot_path = input_proto.sysroot.path
    src_paths = [src_path.path for src_path in input_proto.src_paths]
    packages = [
        controller_util.PackageInfoToCPV(x) for x in input_proto.packages
    ]

    package_deps = dependency.GetDependencies(sysroot_path,
                                              build_target=build_target,
                                              src_paths=src_paths,
                                              packages=packages)
    for package in package_deps:
        pkg_info = output_proto.package_deps.add()
        cpv = package_info.SplitCPV(package, strict=False)
        controller_util.CPVToPackageInfo(cpv, pkg_info)
Пример #3
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
Пример #4
0
    def _InputProto(self,
                    build_target=None,
                    sysroot_path=None,
                    build_source=False,
                    goma_dir=None,
                    goma_log_dir=None,
                    goma_stats_file=None,
                    goma_counterz_file=None,
                    package_indexes=None,
                    packages=None):
        """Helper to build an input proto instance."""
        instance = sysroot_pb2.InstallPackagesRequest()

        if build_target:
            instance.sysroot.build_target.name = build_target
        if sysroot_path:
            instance.sysroot.path = sysroot_path
        if build_source:
            instance.flags.build_source = build_source
        if goma_dir:
            instance.goma_config.goma_dir = goma_dir
        if goma_log_dir:
            instance.goma_config.log_dir.dir = goma_log_dir
        if goma_stats_file:
            instance.goma_config.stats_file = goma_stats_file
        if goma_counterz_file:
            instance.goma_config.counterz_file = goma_counterz_file
        if package_indexes:
            instance.package_indexes.extend(package_indexes)
        if packages:
            for pkg in packages:
                pkg_info = instance.packages.add()
                cpv = package_info.SplitCPV(pkg, strict=False)
                controller_util.CPVToPackageInfo(cpv, pkg_info)
        return instance
Пример #5
0
    def testPackageOnly(self):
        """Test handling when only given the package name."""
        pi = common_pb2.PackageInfo()
        cpv = portage_util.SplitCPV('pkg', strict=False)

        controller_util.CPVToPackageInfo(cpv, pi)
        self.assertEqual('', pi.category)
        self.assertEqual('pkg', pi.package_name)
        self.assertEqual('', pi.version)
Пример #6
0
    def testNoVersion(self):
        """Test handling when no version given."""
        pi = common_pb2.PackageInfo()
        cpv = portage_util.SplitCPV('cat/pkg', strict=False)

        controller_util.CPVToPackageInfo(cpv, pi)
        self.assertEqual('cat', pi.category)
        self.assertEqual('pkg', pi.package_name)
        self.assertEqual('', pi.version)
Пример #7
0
    def testAllFields(self):
        """Test handling when all fields present."""
        pi = common_pb2.PackageInfo()
        cpv = portage_util.SplitCPV('cat/pkg-2.0.0', strict=False)

        controller_util.CPVToPackageInfo(cpv, pi)
        self.assertEqual('cat', pi.category)
        self.assertEqual('pkg', pi.package_name)
        self.assertEqual('2.0.0', pi.version)
Пример #8
0
def BuildTargetUnitTest(input_proto, output_proto, _config):
    """Run a build target's ebuild unit tests."""
    # Required args.
    result_path = input_proto.result_path

    # Method flags.
    # An empty sysroot means build packages was not run. This is used for
    # certain boards that need to use prebuilts (e.g. grunt's unittest-only).
    was_built = not input_proto.flags.empty_sysroot

    # Packages to be tested.
    packages_package_info = input_proto.packages
    packages = []
    for package_info_msg in packages_package_info:
        packages.append(controller_util.PackageInfoToString(package_info_msg))

    # Skipped tests.
    # TODO: Remove blacklist when we fully switch to blocklist.
    blocklisted_package_info = (input_proto.package_blacklist
                                or input_proto.package_blocklist)
    blocklist = []
    for package_info_msg in blocklisted_package_info:
        blocklist.append(controller_util.PackageInfoToString(package_info_msg))

    # Allow call to succeed if no tests were found.
    testable_packages_optional = input_proto.flags.testable_packages_optional

    build_target = controller_util.ParseBuildTarget(input_proto.build_target)
    chroot = controller_util.ParseChroot(input_proto.chroot)

    code_coverage = input_proto.flags.code_coverage

    result = test.BuildTargetUnitTest(
        build_target,
        chroot,
        packages=packages,
        blocklist=blocklist,
        was_built=was_built,
        code_coverage=code_coverage,
        testable_packages_optional=testable_packages_optional)

    if not result.success:
        # Failed to run tests or some tests failed.
        # Record all failed packages.
        for cpv in result.failed_cpvs:
            package_info_msg = output_proto.failed_packages.add()
            controller_util.CPVToPackageInfo(cpv, package_info_msg)
        if result.failed_cpvs:
            return controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE
        else:
            return controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY

    sysroot = sysroot_lib.Sysroot(build_target.root)
    tarball = test.BuildTargetUnitTestTarball(chroot, sysroot, result_path)
    if tarball:
        output_proto.tarball_path = tarball
    deserialize_metrics_log(output_proto.events, prefix=build_target.name)
Пример #9
0
def GetBestVisible(input_proto, output_proto, _config):
  """Returns the best visible PackageInfo for the indicated atom."""
  build_target = None
  if input_proto.build_target.name:
    build_target = controller_util.ParseBuildTarget(input_proto.build_target)

  cpv = packages.get_best_visible(input_proto.atom, build_target=build_target)
  package_info = common_pb2.PackageInfo()
  controller_util.CPVToPackageInfo(cpv, package_info)
  output_proto.package_info.CopyFrom(package_info)
Пример #10
0
def InstallPackages(input_proto, output_proto, _config):
    """Install packages into a sysroot, building as necessary and permitted."""
    compile_source = input_proto.flags.compile_source
    event_file = input_proto.flags.event_file
    use_goma = input_proto.flags.use_goma

    target_sysroot = sysroot_lib.Sysroot(input_proto.sysroot.path)
    build_target = controller_util.ParseBuildTarget(
        input_proto.sysroot.build_target)
    packages = [
        controller_util.PackageInfoToString(x) for x in input_proto.packages
    ]

    if not target_sysroot.IsToolchainInstalled():
        cros_build_lib.Die('Toolchain must first be installed.')

    _LogBinhost(build_target.name)

    use_flags = [u.flag for u in input_proto.use_flags]
    build_packages_config = sysroot.BuildPackagesRunConfig(
        event_file=event_file,
        usepkg=not compile_source,
        install_debug_symbols=True,
        packages=packages,
        use_flags=use_flags,
        use_goma=use_goma)

    try:
        sysroot.BuildPackages(build_target, target_sysroot,
                              build_packages_config)
    except sysroot_lib.PackageInstallError as e:
        if not e.failed_packages:
            # No packages to report, so just exit with an error code.
            return controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY

        # We need to report the failed packages.
        for package in e.failed_packages:
            package_info = output_proto.failed_packages.add()
            controller_util.CPVToPackageInfo(package, package_info)

        return controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE

    # Read metric events log and pipe them into output_proto.events.
    deserialize_metrics_log(output_proto.events, prefix=build_target.name)
Пример #11
0
def BuildTargetUnitTest(input_proto, output_proto, _config):
    """Run a build target's ebuild unit tests."""
    # Required args.
    board = input_proto.build_target.name
    result_path = input_proto.result_path

    # Method flags.
    # An empty sysroot means build packages was not run. This is used for
    # certain boards that need to use prebuilts (e.g. grunt's unittest-only).
    was_built = not input_proto.flags.empty_sysroot

    # Skipped tests.
    blacklisted_package_info = input_proto.package_blacklist
    blacklist = []
    for package_info in blacklisted_package_info:
        blacklist.append(controller_util.PackageInfoToString(package_info))

    build_target = build_target_util.BuildTarget(board)
    chroot = controller_util.ParseChroot(input_proto.chroot)

    result = test.BuildTargetUnitTest(build_target,
                                      chroot,
                                      blacklist=blacklist,
                                      was_built=was_built)

    if not result.success:
        # Failed to run tests or some tests failed.
        # Record all failed packages.
        for cpv in result.failed_cpvs:
            package_info = output_proto.failed_packages.add()
            controller_util.CPVToPackageInfo(cpv, package_info)
        if result.failed_cpvs:
            return controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE
        else:
            return controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY

    sysroot = sysroot_lib.Sysroot(build_target.root)
    tarball = test.BuildTargetUnitTestTarball(chroot, sysroot, result_path)
    if tarball:
        output_proto.tarball_path = tarball
    deserialize_metrics_log(output_proto.events, prefix=build_target.name)
Пример #12
0
def InstallPackages(input_proto, output_proto, _config):
    """Install packages into a sysroot, building as necessary and permitted."""
    compile_source = (input_proto.flags.compile_source
                      or input_proto.flags.toolchain_changed)
    # Testing if Goma will support unknown compilers now.
    use_goma = input_proto.flags.use_goma

    target_sysroot = sysroot_lib.Sysroot(input_proto.sysroot.path)
    build_target = controller_util.ParseBuildTarget(
        input_proto.sysroot.build_target)

    # Get the package atom for each specified package. The field is optional, so
    # error only when we cannot parse an atom for each of the given packages.
    packages = [
        controller_util.PackageInfoToCPV(x).cp for x in input_proto.packages
    ]
    if input_proto.packages and not all(packages):
        cros_build_lib.Die(
            'Invalid package(s) specified. Unable to parse atom from all packages.'
        )

    package_indexes = [
        binpkg.PackageIndexInfo.from_protobuf(x)
        for x in input_proto.package_indexes
    ]

    if not target_sysroot.IsToolchainInstalled():
        cros_build_lib.Die('Toolchain must first be installed.')

    _LogBinhost(build_target.name)

    use_flags = [u.flag for u in input_proto.use_flags]
    build_packages_config = sysroot.BuildPackagesRunConfig(
        usepkg=not compile_source,
        install_debug_symbols=True,
        packages=packages,
        package_indexes=package_indexes,
        use_flags=use_flags,
        use_goma=use_goma,
        incremental_build=False)

    try:
        sysroot.BuildPackages(build_target, target_sysroot,
                              build_packages_config)
    except sysroot_lib.PackageInstallError as e:
        if not e.failed_packages:
            # No packages to report, so just exit with an error code.
            return controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY

        # We need to report the failed packages.
        for package in e.failed_packages:
            package_info = output_proto.failed_packages.add()
            controller_util.CPVToPackageInfo(package, package_info)

        return controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE

    # Copy goma logs to specified directory if there is a goma_config and
    # it contains a log_dir to store artifacts.
    if input_proto.goma_config.log_dir.dir:
        # Get the goma log directory based on the GLOG_log_dir env variable.
        # TODO(crbug.com/1045001): Replace environment variable with query to
        # goma object after goma refactoring allows this.
        log_source_dir = os.getenv('GLOG_log_dir')
        if not log_source_dir:
            cros_build_lib.Die('GLOG_log_dir must be defined.')
        archiver = goma_lib.LogsArchiver(
            log_source_dir,
            dest_dir=input_proto.goma_config.log_dir.dir,
            stats_file=input_proto.goma_config.stats_file,
            counterz_file=input_proto.goma_config.counterz_file)
        archiver_tuple = archiver.Archive()
        if archiver_tuple.stats_file:
            output_proto.goma_artifacts.stats_file = archiver_tuple.stats_file
        if archiver_tuple.counterz_file:
            output_proto.goma_artifacts.counterz_file = archiver_tuple.counterz_file
        output_proto.goma_artifacts.log_files[:] = archiver_tuple.log_files

    # Read metric events log and pipe them into output_proto.events.
    deserialize_metrics_log(output_proto.events, prefix=build_target.name)