def testGetTargetVersionsWithPackagesSet(self): """Verify packages pass through and basic return values.""" # TODO(crbug.com/1124393): Migrate this test to use portage_testables # rather than mocking the boundary to portage calls such as # packages_service.builds). builds_mock = self.PatchObject(packages_service, 'builds', return_value=True) # Mock that chrome is built and set the chrome_version. chrome_version = '76.0.1.2' self.PatchObject(packages_service, 'determine_chrome_version', return_value=chrome_version) android_version = 'android_test_version' self.PatchObject(packages_service, 'determine_android_version', return_value=android_version) android_branch = 'android_test_branch' self.PatchObject(packages_service, 'determine_android_branch', return_value=android_branch) android_target = 'android_test_target' self.PatchObject(packages_service, 'determine_android_target', return_value=android_target) platform_version = '12345.1.2' self.PatchObject(packages_service, 'determine_platform_version', return_value=platform_version) milestone_version = '79' self.PatchObject(packages_service, 'determine_milestone_version', return_value=milestone_version) full_version = 'R79-12345.1.2' self.PatchObject(packages_service, 'determine_full_version', return_value=full_version) request = self._GetRequest(board='betty') # Add optional packages to the request. cpv_package_list = [] package = request.packages.add() package.package_name = 'test' package.category = 'chromeos-base' package.version = '0.0.1-r1' cpv_package_list.append(controller_util.PackageInfoToCPV(package)) package = request.packages.add() package.package_name = 'target-fuzzers' package.category = 'virtual' cpv_package_list.append(controller_util.PackageInfoToCPV(package)) packages_controller.GetTargetVersions(request, self.response, self.api_config) self.assertEqual(self.response.android_version, android_version) self.assertEqual(self.response.android_branch_version, android_branch) self.assertEqual(self.response.android_target_version, android_target) self.assertEqual(self.response.chrome_version, chrome_version) self.assertEqual(self.response.platform_version, platform_version) self.assertEqual(self.response.milestone_version, milestone_version) # Verify call to packages.builds passes the package list. builds_mock.assert_called_with(constants.CHROME_CP, mock.ANY, # Match the build target object packages=cpv_package_list)
def UprevVersionedPackage(input_proto, output_proto, _config): """Uprev a versioned package. See go/pupr-generator for details about this endpoint. """ chroot = controller_util.ParseChroot(input_proto.chroot) build_targets = controller_util.ParseBuildTargets(input_proto.build_targets) package = controller_util.PackageInfoToCPV(input_proto.package_info) refs = [] for ref in input_proto.versions: refs.append(GitRef(path=ref.repository, ref=ref.ref, revision=ref.revision)) try: result = packages.uprev_versioned_package(package, build_targets, refs, chroot) except packages.Error as e: # Handle module errors nicely, let everything else bubble up. cros_build_lib.Die(e) if not result.uprevved: # No uprevs executed, skip the output population. return for modified in result.modified: uprev_response = output_proto.responses.add() uprev_response.version = modified.new_version for path in modified.files: uprev_response.modified_ebuilds.add().path = path
def testNoPackageName(self): """Test no package name given.""" pi = common_pb2.PackageInfo() pi.category = 'cat' pi.version = '2.0.0' self.assertIsNone(controller_util.PackageInfoToCPV(pi))
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)
def testListResponse(self): """Test calls helper method with correct args.""" mock_get_deps = self.PatchObject( dependency_service, 'GetDependencies', return_value=['foo/bar-1.2.3']) sysroot = sysroot_pb2.Sysroot( path=self.sysroot, build_target=self.build_target) path = '/path' package = common_pb2.PackageInfo(category='foo', package_name='bar') input_proto = depgraph_pb2.ListRequest( sysroot=sysroot, src_paths=[ depgraph_pb2.SourcePath(path='/path'), ], packages=[package]) dependency.List(input_proto, self.response, self.api_config) mock_get_deps.assert_called_once_with( self.sysroot, build_target=controller_util.ParseBuildTarget(self.build_target), src_paths=[path], packages=[controller_util.PackageInfoToCPV(package)]) expected_deps = [ common_pb2.PackageInfo( category='foo', package_name='bar', version='1.2.3') ] self.assertCountEqual(expected_deps, self.response.package_deps)
def testAllFields(self): """Quick sanity check it's working properly.""" pi = common_pb2.PackageInfo() pi.package_name = 'pkg' pi.category = 'cat' pi.version = '2.0.0' cpv = controller_util.PackageInfoToCPV(pi) self.assertEqual('pkg', cpv.package) self.assertEqual('cat', cpv.category) self.assertEqual('2.0.0', cpv.version)
def testBuildsChromeWithPackages(self): """Test successful call with packages handling.""" patch = self.PatchObject(packages_service, 'builds', return_value=True) package = common_pb2.PackageInfo( category='category', package_name='name', version='1.01', ) request = self._GetRequest(board='foo', packages=[package]) packages_controller.BuildsChrome(request, self.response, self.api_config) self.assertTrue(self.response.builds_chrome) patch.assert_called_once_with(constants.CHROME_CP, build_target_lib.BuildTarget('foo'), [controller_util.PackageInfoToCPV(package)])
def GetBuildDependencyGraph(input_proto, output_proto, _config): """Create the build dependency graph. Args: input_proto (GetBuildDependencyGraphRequest): The input arguments message. output_proto (GetBuildDependencyGraphResponse): The empty output message. _config (api_config.ApiConfig): The API call config. """ if input_proto.HasField('sysroot'): board = input_proto.sysroot.build_target.name sysroot_path = input_proto.sysroot.path else: # TODO(crbug/1081828): stop using build_target and drop it from the proto. board = input_proto.build_target.name sysroot_path = cros_build_lib.GetSysroot(board or None) packages = tuple( controller_util.PackageInfoToCPV(x) for x in input_proto.packages) json_map, sdk_json_map = dependency.GetBuildDependency( sysroot_path, board, packages) AugmentDepGraphProtoFromJsonMap(json_map, output_proto.dep_graph) AugmentDepGraphProtoFromJsonMap(sdk_json_map, output_proto.sdk_dep_graph)
def BuildsChrome(input_proto, output_proto, _config): """Check if the board builds chrome.""" build_target = controller_util.ParseBuildTarget(input_proto.build_target) cpvs = [controller_util.PackageInfoToCPV(pi) for pi in input_proto.packages] builds_chrome = packages.builds(constants.CHROME_CP, build_target, cpvs) output_proto.builds_chrome = builds_chrome
def testNoPackageInfo(self): """Test no package info given.""" self.assertIsNone(controller_util.PackageInfoToCPV(None))
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)