def setUp(self): self.board = 'board' self.build_target = build_target_util.BuildTarget(self.board) self.chroot = chroot_lib.Chroot(path=self.tempdir) # Make the chroot's tmp directory, used for the parallel emerge status file. tempdir = os.path.join(self.tempdir, 'tmp') osutils.SafeMakedirs(tempdir)
def BundleAFDOGenerationArtifacts(input_proto, output_proto, _config): """Generic function for creating tarballs of both AFDO and orderfile. Args: input_proto (BundleChromeAFDORequest): The input proto. output_proto (BundleResponse): The output proto. _config (api_config.ApiConfig): The API call config. """ # Required args. build_target = build_target_util.BuildTarget(input_proto.build_target.name) chrome_root = input_proto.chroot.chrome_dir if not chrome_root: cros_build_lib.Die('chrome_root is not included in chroot') output_dir = input_proto.output_dir artifact_type = input_proto.artifact_type chroot = controller_util.ParseChroot(input_proto.chroot) try: is_orderfile = bool(artifact_type is toolchain_pb2.ORDERFILE) results = artifacts.BundleAFDOGenerationArtifacts( is_orderfile, chroot, chrome_root, build_target, output_dir) except artifacts.Error as e: cros_build_lib.Die('Error %s raised in BundleSimpleChromeArtifacts: %s', type(e), e) for file_name in results: output_proto.artifacts.add().path = file_name
def BundleSimpleChromeArtifacts(input_proto, output_proto, _config): """Create the simple chrome artifacts.""" # Required args. sysroot_path = input_proto.sysroot.path build_target_name = input_proto.sysroot.build_target.name output_dir = input_proto.output_dir # Optional args. chroot_path = input_proto.chroot.path or constants.DEFAULT_CHROOT_PATH cache_dir = input_proto.chroot.cache_dir # Build out the argument instances. build_target = build_target_util.BuildTarget(build_target_name) chroot = chroot_lib.Chroot(path=chroot_path, cache_dir=cache_dir) # Sysroot.path needs to be the fully qualified path, including the chroot. full_sysroot_path = os.path.join(chroot.path, sysroot_path.lstrip(os.sep)) sysroot = sysroot_lib.Sysroot(full_sysroot_path) # Quick sanity check that the sysroot exists before we go on. if not sysroot.Exists(): cros_build_lib.Die('The sysroot does not exist.') try: results = artifacts.BundleSimpleChromeArtifacts(chroot, sysroot, build_target, output_dir) except artifacts.Error as e: cros_build_lib.Die('Error %s raised in BundleSimpleChromeArtifacts: %s', type(e), e) for file_name in results: output_proto.artifacts.add().path = file_name
def setUp(self): self.PatchObject(cros_build_lib, 'IsInsideChroot', return_value=True) # A board we have a sysroot for already. self.board = 'board' self.sysroot_path = os.path.join(self.tempdir, 'build', self.board) self.build_target = build_target_util.BuildTarget( self.board, build_root=self.sysroot_path) self.sysroot = sysroot_lib.Sysroot(self.sysroot_path) # A board we don't have a sysroot for yet. self.unbuilt_board = 'board2' self.unbuilt_path = os.path.join(self.tempdir, 'build', self.unbuilt_board) self.unbuilt_target = build_target_util.BuildTarget( self.unbuilt_board, build_root=self.unbuilt_path) self.unbuilt_sysroot = sysroot_lib.Sysroot(self.unbuilt_path) osutils.SafeMakedirs(self.sysroot_path)
def GetBinhosts(input_proto, output_proto, _config): """Get a list of binhosts.""" build_target = build_target_util.BuildTarget(input_proto.build_target.name) binhosts = binhost.GetBinhosts(build_target) for current in binhosts: new_binhost = output_proto.binhosts.add() new_binhost.uri = current new_binhost.package_index = 'Packages'
def setUp(self): self.PatchObject(constants, 'SOURCE_ROOT', new=self.tempdir) self.chroot_path = os.path.join(self.tempdir, 'chroot') self.sysroot_path = '/build/foo' self.root = os.path.join(self.chroot_path, self.sysroot_path.lstrip('/'), 'packages') self.chroot = chroot_lib.Chroot(self.chroot_path) self.sysroot = sysroot_lib.Sysroot(self.sysroot_path) self.build_target = build_target_util.BuildTarget('foo') osutils.SafeMakedirs(self.root)
def setUp(self): # Avoid sudo password prompt for config writing. self.PatchObject(os, 'getuid', return_value=0) self.PatchObject(os, 'geteuid', return_value=0) # It has to be run inside the chroot. self.PatchObject(cros_build_lib, 'IsInsideChroot', return_value=True) # A board we have a sysroot for already. self.board = 'board' self.sysroot_path = os.path.join(self.tempdir, 'build', self.board) self.build_target = build_target_util.BuildTarget( self.board, build_root=self.sysroot_path) # A board we don't have a sysroot for yet. self.unbuilt_board = 'board2' self.unbuilt_path = os.path.join(self.tempdir, 'build', self.unbuilt_board) self.unbuilt_target = build_target_util.BuildTarget( self.unbuilt_board, build_root=self.unbuilt_path) # Create the sysroot. osutils.SafeMakedirs(self.sysroot_path)
def test_no_uprev(self): """Test no uprev handling.""" self.PatchObject(packages, '_parse_android_atom', return_value=None) build_targets = [build_target_util.BuildTarget(t) for t in ['foo', 'bar']] packages.uprev_android('refs/tracking-branch', 'android/package', 'refs/android-build-branch', Chroot(), build_targets=build_targets) self.assertCommandContains(['cros_mark_android_as_stable', '--boards=foo:bar']) self.assertCommandContains(['emerge-foo'], expected=False) self.assertCommandContains(['emerge-bar'], expected=False)
def PrepareBinhostUploads(input_proto, output_proto, config): """Return a list of files to upload to the binhost. See BinhostService documentation in api/proto/binhost.proto. Args: input_proto (PrepareBinhostUploadsRequest): The input proto. output_proto (PrepareBinhostUploadsResponse): The output proto. config (api_config.ApiConfig): The API call config. """ target_name = (input_proto.sysroot.build_target.name or input_proto.build_target.name) sysroot_path = input_proto.sysroot.path if not sysroot_path and not target_name: cros_build_lib.Die('Sysroot.path is required.') build_target = build_target_util.BuildTarget(target_name) chroot = controller_util.ParseChroot(input_proto.chroot) if not sysroot_path: # Very temporary, so not worried about this not calling the lib function. sysroot_path = build_target.root sysroot = sysroot_lib.Sysroot(sysroot_path) uri = input_proto.uri # For now, we enforce that all input URIs are Google Storage buckets. if not gs.PathIsGs(uri): raise ValueError('Upload URI %s must be Google Storage.' % uri) if config.validate_only: return controller.RETURN_CODE_VALID_INPUT parsed_uri = urllib.parse.urlparse(uri) upload_uri = gs.GetGsURL(parsed_uri.netloc, for_gsutil=True).rstrip('/') upload_path = parsed_uri.path.lstrip('/') # Read all packages and update the index. The index must be uploaded to the # binhost for Portage to use it, so include it in upload_targets. uploads_dir = binhost.GetPrebuiltsRoot(chroot, sysroot, build_target) index_path = binhost.UpdatePackageIndex(uploads_dir, upload_uri, upload_path, sudo=True) upload_targets = binhost.GetPrebuiltsFiles(uploads_dir) assert index_path.startswith(uploads_dir), ( 'expected index_path to start with uploads_dir') upload_targets.append(index_path[len(uploads_dir):]) output_proto.uploads_dir = uploads_dir for upload_target in upload_targets: output_proto.upload_targets.add().path = upload_target.strip('/')
def setUp(self): # Create the build target. self.build_target = build_target_util.BuildTarget('board') # Create the chroot. self.chroot_dir = os.path.join(self.tempdir, 'chroot') self.chroot_tmp = os.path.join(self.chroot_dir, 'tmp') osutils.SafeMakedirs(self.chroot_tmp) self.chroot = chroot_lib.Chroot(path=self.chroot_dir) # Create the output directory. self.output_dir = os.path.join(self.tempdir, 'output_dir') osutils.SafeMakedirs(self.output_dir)
def GetPrivatePrebuiltAclArgs(input_proto, output_proto, _config): """Get the ACL args from the files in the private overlays.""" build_target = build_target_util.BuildTarget(input_proto.build_target.name) try: args = binhost.GetPrebuiltAclArgs(build_target) except binhost.Error as e: cros_build_lib.Die(e) for arg, value in args: new_arg = output_proto.args.add() new_arg.arg = arg new_arg.value = value
def test_success(self): """Test successful run handling.""" self.PatchObject(packages, '_parse_android_atom', return_value='ANDROID_ATOM=android/android-1.0') build_targets = [build_target_util.BuildTarget(t) for t in ['foo', 'bar']] packages.uprev_android('refs/tracking-branch', 'android/package', 'refs/android-build-branch', Chroot(), build_targets=build_targets) self.assertCommandContains(['cros_mark_android_as_stable', '--boards=foo:bar']) self.assertCommandContains(['emerge-foo']) self.assertCommandContains(['emerge-bar'])
def testFullRun(self): """Test a regular full run. This method is basically just a sanity check that it's trying to create the sysroot and install the toolchain by default. """ target_sysroot = sysroot_lib.Sysroot('/build/board') create_mock = self.PatchObject(sysroot, 'Create', return_value=target_sysroot) install_toolchain_mock = self.PatchObject(sysroot, 'InstallToolchain') sysroot.SetupBoard(build_target_util.BuildTarget('board')) create_mock.assert_called_once() install_toolchain_mock.assert_called_once()
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()
def Uprev(input_proto, output_proto, _config): """Uprev all cros workon ebuilds that have changes.""" target_names = [t.name for t in input_proto.build_targets] build_targets = [build_target_util.BuildTarget(t) for t in target_names] overlay_type = _OVERLAY_TYPE_TO_NAME[input_proto.overlay_type] chroot = controller_util.ParseChroot(input_proto.chroot) output_dir = input_proto.output_dir or None try: uprevved = packages.uprev_build_targets(build_targets, overlay_type, chroot, output_dir) except packages.Error as e: # Handle module errors nicely, let everything else bubble up. cros_build_lib.Die(e) for path in uprevved: output_proto.modified_ebuilds.add().path = path
def setUp(self): # Currently just used to keep the parallel emerge status file from being # created in the chroot. This probably isn't strictly necessary, but since # we can otherwise run this test without a chroot existing at all and # without touching the chroot folder, it's better to keep it out of there # all together. self.PatchObject(cros_build_lib, 'IsInsideChroot', return_value=True) self.board = 'board' self.target = build_target_util.BuildTarget(self.board) self.sysroot_path = '/sysroot/path' self.sysroot = sysroot_lib.Sysroot(self.sysroot_path) self.build_packages = os.path.join(constants.CROSUTILS_DIR, 'build_packages') self.base_command = [self.build_packages, '--board', self.board, '--board_root', self.sysroot_path]
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)
def InstallToolchain(input_proto, output_proto, _config): """Install the toolchain into a sysroot.""" compile_source = input_proto.flags.compile_source sysroot_path = input_proto.sysroot.path build_target_name = input_proto.sysroot.build_target.name build_target = build_target_util.BuildTarget(name=build_target_name) 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
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
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_util.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
def setUp(self): self.build_target = build_target_util.BuildTarget('board')
def test_invalid_type_fails(self): """Test invalid type fails.""" with self.assertRaises(AssertionError): packages.uprev_build_targets([build_target_util.BuildTarget('foo')], 'invalid')
def test_none_type_fails(self): """Test None type fails.""" with self.assertRaises(AssertionError): packages.uprev_build_targets([build_target_util.BuildTarget('foo')], None)
def testGetPrebuiltsBadTarget(self): """GetPrebuiltsRoot dies on missing root (target probably not built.)""" with self.assertRaises(binhost.EmptyPrebuiltsRoot): binhost.GetPrebuiltsRoot(self.chroot, sysroot_lib.Sysroot('/build/bar'), build_target_util.BuildTarget('bar'))
def setUp(self): self.build_target = build_target_util.BuildTarget('board') self.acl_file = os.path.join(self.tempdir, 'googlestorage_acl.txt') osutils.WriteFile(self.acl_file, self._ACL_FILE)