def Install(self, cpv, url): """Install the debug symbols for |cpv|. This will install the debug symbols tarball in PKGDIR so that it can be used later. Args: cpv: the cpv of the package to build. This assumes that the cpv is installed in the sysroot. url: url of the debug symbols archive. This could be a Google Storage url or a local path. """ archive = os.path.join(self._vartree.settings['PKGDIR'], cpv + DEBUG_SYMS_EXT) # GsContext does not understand file:// scheme so we need to extract the # path ourselves. parsed_url = urllib.parse.urlsplit(url) if not parsed_url.scheme or parsed_url.scheme == 'file': url = parsed_url.path if not os.path.isfile(archive): self._gs_context.Copy(url, archive, debug_level=logging.DEBUG) with osutils.TempDir(sudo_rm=True) as tempdir: cros_build_lib.sudo_run( ['tar', '-I', 'bzip2 -q', '-xf', archive, '-C', tempdir], quiet=True) with open(self._vartree.getpath(cpv, filename='CONTENTS'), 'a') as content_file: # Merge the content of the temporary dir into the sysroot. # pylint: disable=protected-access link = self._vartree.dbapi._dblink(cpv) link.mergeme(tempdir, self._sysroot, content_file, None, '', {}, None)
def Run(self): """Perform the command.""" # Get the sudo password immediately. cros_build_lib.sudo_run(['echo']) image_filepath = None if self.options.image: logging.notice('Getting sizes for image: %s', self.options.image) image_filepath = self.options.image else: if self.options.local_path: image_filepath = self.options.local_path logging.notice('Getting sizes for: %s', self.options.version) image_filepath = fetch_image( board=self.options.board, version=self.options.version, local_path=image_filepath) required_paths = [] if self.options.spreadsheet: required_paths = WATCHED_PATHS logging.notice('Analyzing disk usage of locally-mounted image: %s', image_filepath) sizes = get_image_sizes( image_filepath=image_filepath, required_paths=required_paths, min_size=self.options.minsize) write_sizes( sizes=sizes, required_paths=required_paths, human_readable=self.options.human_readable, output_format=self.options.format, output_path=self.options.output)
def PrepareImage(path, content, domain=None): """Prepares a recovery image for OOBE autoconfiguration. Args: path: Path to the recovery image. content: The content of the OOBE autoconfiguration. domain: Which domain to enroll to. """ with osutils.TempDir() as tmp, \ image_lib.LoopbackPartitions(path, tmp) as image: stateful_mnt = image.Mount((constants.CROS_PART_STATEFUL, ), mount_opts=('rw', ))[0] # /stateful/unencrypted may not exist at this point in time on the # recovery image, so create it root-owned here. unencrypted = os.path.join(stateful_mnt, 'unencrypted') osutils.SafeMakedirs(unencrypted, mode=0o755, sudo=True) # The OOBE autoconfig directory must be owned by the chronos user so # that we can delete the config file from it from Chrome. oobe_autoconf = os.path.join(unencrypted, _OOBE_DIRECTORY) osutils.SafeMakedirsNonRoot(oobe_autoconf, user='******') # Create the config file to be owned by the chronos user, and write the # given data into it. config = os.path.join(oobe_autoconf, _CONFIG_PATH) osutils.WriteFile(config, content, sudo=True) cros_build_lib.sudo_run(['chown', 'chronos:chronos', config]) # If we have a plaintext domain name, write it. if domain: domain_path = os.path.join(oobe_autoconf, _DOMAIN_PATH) osutils.WriteFile(domain_path, SanitizeDomain(domain), sudo=True) cros_build_lib.sudo_run(['chown', 'chronos:chronos', domain_path])
def WriteLsbRelease(sysroot, fields): """Writes out the /etc/lsb-release file into the given sysroot. Args: sysroot: The sysroot to write the lsb-release file to. fields: A dictionary of all the fields and values to write. """ content = '\n'.join('%s=%s' % (k, v) for k, v in fields.items()) + '\n' path = os.path.join(sysroot, constants.LSB_RELEASE_PATH.lstrip('/')) if os.path.exists(path): # The file has already been pre-populated with some fields. Since # osutils.WriteFile(..) doesn't support appending with sudo, read in the # content and prepend it to the new content to write. # TODO(stevefung): Remove this appending, once all writing to the # /etc/lsb-release file has been removed from ebuilds and consolidated # to the buid tools. content = osutils.ReadFile(path) + content osutils.WriteFile(path, content, mode='w', makedirs=True, sudo=True) cros_build_lib.sudo_run([ 'setfattr', '-n', 'security.selinux', '-v', 'u:object_r:cros_conf_file:s0', path ])
def UpdateStatefulPartitionVblock(image, keyset): """Update the SSD install-able vblock file on stateful partition. This is deprecated because all new images should have a SSD boot-able kernel in partition 4. However, the signer needs to be able to sign new & old images (crbug.com/449450#c13) so we will probably never remove this. Args: image: image_lib.LoopbackPartitions() for the image. keyset: Keyset to use for signing """ with tempfile.NamedTemporaryFile(dir=image.destination) as tmpfile: loop_kern = image.GetPartitionDevName('KERN-B') ret = _GetKernelCmdLine(loop_kern, check=False) if not ret: logging.info( 'Building vmlinuz_hd.vblock from legacy image partition 2.') loop_kern = image.GetPartitionDevName(2) kernel_key = keyset.keys['kernel_data_key'] cros_build_lib.sudo_run([ 'vbutil_kernel', '--repack', tmpfile.name, '--keyblock', kernel_key.keyblock, '--signprivate', kernel_key.private, '--oldblob', loop_kern, '--vblockonly' ]) state_dir = image.Mount(('STATE', ), mount_opts=('rw', ))[0] cros_build_lib.sudo_run( ['cp', tmpfile.name, os.path.join(state_dir, 'vmlinuz_hd.vblock')]) image.Unmount(('STATE', ))
def CreateTarball(source_root, tarball_path, exclude_paths=None): """Packs |source_root| into |tarball_path|. Args: source_root: Path to the directory we want to package. tarball_path: Path of the tarball that should be created. exclude_paths: Subdirectories to exclude. """ # TODO(zbehan): We cannot use xz from the chroot unless it's # statically linked. extra_args = None if exclude_paths is not None: extra_args = ['--anchored'] extra_args.extend('--exclude=./%s/*' % x for x in exclude_paths) # Options for maximum compression. extra_env = {'XZ_OPT': '-e9'} cros_build_lib.CreateTarball( tarball_path, source_root, sudo=True, extra_args=extra_args, debug_level=logging.INFO, extra_env=extra_env) # Make sure the regular user has the permission to read. cmd = ['chmod', 'a+r', tarball_path] cros_build_lib.sudo_run(cmd)
def _GetFd(self): if self.world_writable: create = True try: create = stat.S_IMODE(os.stat(self.path).st_mode) != 0o666 except OSError as e: if e.errno != errno.ENOENT: raise if create: osutils.SafeMakedirs(os.path.dirname(self.path), sudo=True) cros_build_lib.sudo_run(['touch', self.path], print_cmd=False) cros_build_lib.sudo_run(['chmod', '666', self.path], print_cmd=False) # If we're on py3.4 and this attribute is exposed, use it to close # the threading race between open and fcntl setting; this is # extremely paranoid code, but might as well. cloexec = getattr(os, 'O_CLOEXEC', 0) # There exist race conditions where the lock may be created by # root, thus denying subsequent accesses from others. To prevent # this, we create the lock with mode 0o666. try: value = os.umask(000) fd = os.open(self.path, os.W_OK | os.O_CREAT | cloexec, 0o666) finally: os.umask(value) return fd
def _ArchiveTestResults(self, results_dir): """Try to find the results dropped during testing and archive them. Args: results_dir: Path to a directory used for creating result files. """ results_reldir = 'moblab_vm_test_results' cros_build_lib.sudo_run(['chmod', '-R', 'a+rw', results_dir], print_cmd=False) archive_dir = os.path.join(self.archive_path, results_reldir) osutils.RmDir(archive_dir, ignore_missing=True) def _ShouldIgnore(dirname, file_list): # gsutil hangs on broken symlinks. return [ x for x in file_list if os.path.islink(os.path.join(dirname, x)) ] shutil.copytree(results_dir, archive_dir, symlinks=False, ignore=_ShouldIgnore) self._Upload(results_reldir) self._PrintDetailedLogLinks(results_reldir)
def WipePayloadCache(cls, devserver_bin='start_devserver', static_dir=None): """Cleans up devserver cache of payloads. This isn't necessary for chrome checkouts. Args: devserver_bin: path to the devserver binary. static_dir: path to use as the static directory of the devserver instance. """ if path_util.DetermineCheckout( ).type == path_util.CHECKOUT_TYPE_GCLIENT: return logging.info('Cleaning up previously generated payloads.') cmd = [devserver_bin, '--clear_cache', '--exit'] if static_dir: cmd.append('--static_dir=%s' % path_util.ToChrootPath(static_dir)) cros_build_lib.sudo_run(cmd, enter_chroot=True, print_cmd=False, stderr=subprocess.STDOUT, stdout=True, cwd=constants.SOURCE_ROOT)
def ArchiveTestResults(results_path, archive_dir): """Archives the test results to |archive_dir|. Args: results_path: Path to test results. archive_dir: Local directory to archive to. """ cros_build_lib.sudo_run(['chmod', '-R', 'a+rw', results_path], print_cmd=False) if os.path.exists(archive_dir): osutils.RmDir(archive_dir) def _ShouldIgnore(dirname, file_list): # Note: We exclude VM disk and memory images. Instead, they are # archived via ArchiveVMFiles. Also skip any symlinks. gsutil # hangs on broken symlinks. return [ x for x in file_list if x.startswith(constants.VM_DISK_PREFIX) or x.startswith(constants.VM_MEM_PREFIX) or os.path.islink(os.path.join(dirname, x)) ] shutil.copytree(results_path, archive_dir, symlinks=False, ignore=_ShouldIgnore)
def GetFileSystemDebug(path: str, run_ps: bool = True) -> FileSystemDebugInfo: """Collect filesystem debugging information. Dump some information to help find processes that may still be sing files. Running ps auxf can also be done to see what processes are still running. Args: path: Full path for directory we want information on. run_ps: When true, show processes running. Returns: FileSystemDebugInfo with debug info. """ cmd_kwargs = { 'check': False, 'capture_output': True, 'encoding': 'utf-8', 'errors': 'replace' } fuser = cros_build_lib.sudo_run(['fuser', path], **cmd_kwargs) lsof = cros_build_lib.sudo_run(['lsof', path], **cmd_kwargs) if run_ps: ps = cros_build_lib.run(['ps', 'auxf'], **cmd_kwargs) ps_stdout = ps.stdout else: ps_stdout = None return FileSystemDebugInfo(fuser.stdout, lsof.stdout, ps_stdout)
def PerformStage(self): new_chroot_dir = 'new-sdk-chroot' tarball_location = os.path.join(self._build_root, SDK_TARBALL_NAME) new_chroot_args = ['--chroot', new_chroot_dir] if self._run.options.chrome_root: new_chroot_args += ['--chrome_root', self._run.options.chrome_root] # Build a new SDK using the provided tarball. chroot_args = new_chroot_args + [ '--download', '--replace', '--nousepkg', '--url', 'file://' + tarball_location ] cros_build_lib.run(['true'], cwd=self._build_root, enter_chroot=True, chroot_args=chroot_args, extra_env=self._portage_extra_env) # Inject the toolchain binpkgs from the previous sdk build. On end user # systems, they'd be fetched from the binpkg mirror, but we don't have one # set up for this local build. pkgdir = os.path.join('var', 'lib', 'portage', 'pkgs') old_pkgdir = os.path.join(self._build_root, constants.DEFAULT_CHROOT_DIR, pkgdir) new_pkgdir = os.path.join(self._build_root, new_chroot_dir, pkgdir) osutils.SafeMakedirs(new_pkgdir, sudo=True) cros_build_lib.sudo_run(['cp', '-r'] + glob.glob(os.path.join(old_pkgdir, '*')) + [new_pkgdir]) # Now install those toolchains in the new chroot. We skip the chroot # upgrade below which means we need to install the toolchain manually. cmd = [ 'cros_setup_toolchains', '--targets=boards', '--include-boards=%s' % ','.join(self._boards) ] commands.RunBuildScript(self._build_root, cmd, chromite_cmd=True, enter_chroot=True, sudo=True, chroot_args=new_chroot_args, extra_env=self._portage_extra_env) # Build all the boards with the new sdk. for board in self._boards: logging.PrintBuildbotStepText(board) commands.SetupBoard(self._build_root, board, usepkg=True, chroot_upgrade=False, extra_env=self._portage_extra_env, chroot_args=new_chroot_args) commands.Build(self._build_root, board, build_autotest=True, usepkg=False, extra_env=self._portage_extra_env, chroot_args=new_chroot_args, disable_revdep_logic=True)
def close(self): if self.dev: for part in list(self._mounted): self._Unmount(part) # We still need to remove some directories, since _Unmount did not. for link in self._symlinks: osutils.SafeUnlink(link) self._symlinks = set() for path in self._to_be_rmdir: retry_util.RetryException(cros_build_lib.RunCommandError, 60, osutils.RmDir, path, sudo=True, sleep=1) self._to_be_rmdir = set() cmd = ['partx', '-d', self.dev] cros_build_lib.sudo_run(cmd, quiet=True, error_code_ok=True) cros_build_lib.sudo_run(['losetup', '--detach', self.dev]) self.dev = None self.parts = {} self._gpt_table = None if self._destination_created: self.destination = None self._destination_created = False
def CopyTempContentsToBuildDir(self): """Copy the temp files to the build directory using sudo.""" src = self.temp_root.tempdir.rstrip('/') + '/.' dst = self.install_root_dir logging.info( 'Copy files from temporary directory (%s) to build directory (%s).', src, dst) cros_build_lib.sudo_run(['cp', '-dR', src, dst])
def _RunIgnoringErrors(cmd): """Runs the given command, ignores errors but warns user.""" try: cros_build_lib.sudo_run(cmd, quiet=True) except cros_build_lib.RunCommandError as e: logging.error('Cleanup operation failed. Please run "%s" manually.', ' '.join(cmd)) logging.debug('Encountered error: %s', e)
def _PingDD(self, dd_pid): """Send USR1 signal to dd to get status update.""" try: cmd = ['kill', '-USR1', str(dd_pid)] cros_build_lib.sudo_run(cmd, print_cmd=False) except cros_build_lib.RunCommandError: # Here we assume that dd finished in the background. return
def _Emerge(self, *args, **kwargs): """Emerge the given packages using parallel_emerge.""" cmd = [ self.PARALLEL_EMERGE, '--board=%s' % self.options.board, '--usepkgonly', '--noreplace' ] + list(args) kwargs.setdefault('extra_env', self.extra_env) cros_build_lib.sudo_run(cmd, **kwargs)
def UpdateRootfsHash(image, loop_kern, keyset, keyA_prefix): """Update the root filesystem hash. Args: image: image_lib.LoopbackPartitions instance for this image. loop_kern: Device file name for the kernel partition to hash. keyset: Kernel_cmdline.Keyset to use. keyA_prefix: Prefix for kernA key (e.g., 'recovery_'). """ logging.info( 'Updating rootfs hash and updating cmdline for kernel partitions') logging.info('%s (in %s) keyset=%s keyA_prefix=%s', loop_kern, image.path, keyset.key_dir, keyA_prefix) cmd_line = _GetKernelCmdLine(loop_kern, check=False) if cmd_line: dm_config = cmd_line.GetDmConfig() if not cmd_line or not dm_config: logging.error("Couldn't get dm_config from kernel %s", loop_kern) logging.error(' (cmdline: %s)', cmd_line) raise SignImageError('Could not get dm_config from kernel') loop_rootfs = image.GetPartitionDevName('ROOT-A') image.DisableRwMount('ROOT-A') rootfs_hash = CalculateRootfsHash(image, cmd_line) fsinfo = cros_build_lib.sudo_run( ['tune2fs', '-l', image.GetPartitionDevName('ROOT-A')], capture_output=True, encoding='utf-8').stdout rootfs_blocks = int( re.search(r'^Block count: *([0-9]+)$', fsinfo, flags=re.MULTILINE).group(1)) rootfs_sectors = 8 * rootfs_blocks # Overwrite the appended hashes in the rootfs. cros_build_lib.sudo_run([ 'dd', 'if=%s' % rootfs_hash.hashtree_filename, 'of=%s' % loop_rootfs, 'bs=512', 'seek=%d' % rootfs_sectors, 'conv=notrunc' ], redirect_stderr=True) # Update kernel command lines. for kern in ('KERN-A', 'KERN-B'): loop_kern = image.GetPartitionDevName(kern) new_cmd_line = _GetKernelCmdLine(loop_kern, check=False) if not new_cmd_line and kern == 'KERN-B': logging.info('Skipping empty KERN-B partition (legacy images).') continue new_cmd_line.SetDmConfig(rootfs_hash.calculated_dm_config) logging.info('New cmdline for %s partition is: %s', kern, new_cmd_line) if kern == 'KERN-A': key = keyset.keys['%skernel_data_key' % keyA_prefix] else: key = keyset.keys['kernel_data_key'] _UpdateKernelConfig(loop_kern, new_cmd_line, key)
def SquashOwnerships(self, path): """Squash the owernships & permissions for files. Args: path: (str) path that contains all files to be processed. """ cros_build_lib.sudo_run(['chown', '-R', '0:0', path]) cros_build_lib.sudo_run([ 'find', path, '-exec', 'touch', '-h', '-t', '197001010000.00', '{}', '+' ])
def IsExt4Image(image): """Returns true if the image is detected to be ext2/ext3/ext4.""" try: # -l: Listing the content of the superblock structure. cros_build_lib.sudo_run( ['tune2fs', '-l', path_util.ToChrootPath(image)], stdout=True, enter_chroot=True) return True except cros_build_lib.RunCommandError: return False
def _StartVM(image_path, ssh_port, max_port, tap_dev, tap_mac_addr, is_moblab, disk_path=None, chroot_path=None): """Starts a VM instance. Args: image_path: Path to the OS image to use. ssh_port: (int) port to use for SSH. max_port: (int) ports upto this are available. tap_dev: Name of the tap device to use for secondary network. tap_mac_addr: The MAC address of the secondary network device. is_moblab: Whether we're starting a moblab VM. disk_path: Moblab disk. chroot_path: Location of chroot on disk to pass to cros_vm. """ cmd = [ './cros_vm', '--start', '--image-path=%s' % image_path, '--ssh-port=%d' % ssh_port, '--qemu-m', '32G', '--qemu-args', '-net nic,macaddr=%s' % tap_mac_addr, '--qemu-args', '-net tap,ifname=%s' % tap_dev ] if chroot_path: cmd.extend(['--chroot-path', chroot_path]) if is_moblab: moblab_monitoring_port = ssh_port + 1 afe_port = ssh_port + 2 dev_server_port = ssh_port + 3 assert dev_server_port < max_port, 'Exceeded maximum available ports.' cmd += [ # Moblab monitoring port. '--qemu-hostfwd', 'tcp:127.0.0.1:%d-:9991' % moblab_monitoring_port, # AFE port. '--qemu-hostfwd', 'tcp:127.0.0.1:%d-:80' % afe_port, # DevServer port. '--qemu-hostfwd', 'tcp:127.0.0.1:%d-:8080' % dev_server_port, # Create a dedicated scsi controller for the external disk, and attach # the disk to that bus. This separates us from any scsi controllers that # may be created for the boot disk. '--qemu-args', '-drive id=moblabdisk,if=none,file=%s,format=raw' % disk_path, '--qemu-args', '-device virtio-scsi-pci,id=scsiext', '--qemu-args', '-device scsi-hd,bus=scsiext.0,drive=moblabdisk', ] cros_build_lib.sudo_run(cmd, cwd=constants.CHROMITE_BIN_DIR)
def _CleanUpRepoManifest(self, directory): """Clean up the manifest and repo dirs under the '.repo' dir. Args: directory: The directory where stores repo and manifest dirs. """ paths = [ os.path.join(directory, '.repo', x) for x in ('manifest.xml', 'manifests.git', 'manifests', 'repo') ] cros_build_lib.sudo_run(['rm', '-rf'] + paths)
def testSafeMakedirsMode(self): """Test that mode is honored.""" path = os.path.join(self.tempdir, 'a', 'b', 'c', 'd', 'e') self.assertTrue(osutils.SafeMakedirs(path, mode=0o775)) self.assertEqual(0o775, stat.S_IMODE(os.stat(path).st_mode)) self.assertFalse(osutils.SafeMakedirs(path, mode=0o777)) self.assertEqual(0o777, stat.S_IMODE(os.stat(path).st_mode)) cros_build_lib.sudo_run(['chown', 'root:root', path], print_cmd=False) # Tries, but fails to change the mode. self.assertFalse(osutils.SafeMakedirs(path, 0o755)) self.assertEqual(0o777, stat.S_IMODE(os.stat(path).st_mode))
def Check(self): logging.debug('Checking LOAS credentials for %s', self.user) cmd = ['runloas', '/usr/bin/loas_check'] # Error message to print when loas credential check fails. This usually # is the result of production credentials expiring for accessing # Keystore for the unwrapping private key. loas_error = 'loas_check for %s failed! Did you run: %s' % ( self.user, self.enroll_msg) try: cros_build_lib.sudo_run(cmd, user=self.user) except cros_build_lib.RunCommandError as e: raise LoasError('%s\n%s' % (e.msg, loas_error))
def f(dirname, sudo=False): dirname = os.path.join(self.tempdir, dirname) path = os.path.join(dirname, 'foon') os.makedirs(dirname) open(path, 'w').close() self.assertExists(path) if sudo: cros_build_lib.sudo_run( ['chown', 'root:root', '-R', '--', dirname], print_cmd=False) self.assertRaises(EnvironmentError, os.unlink, path) self.assertTrue(osutils.SafeUnlink(path, sudo=sudo)) self.assertNotExists(path) self.assertFalse(osutils.SafeUnlink(path)) self.assertNotExists(path)
def _CreateWrapper(wrapper_path, template, **kwargs): """Creates a wrapper from a given template. Args: wrapper_path: path to the wrapper. template: wrapper template. kwargs: fields to be set in the template. """ osutils.WriteFile(wrapper_path, template.format(**kwargs), makedirs=True, sudo=True) cros_build_lib.sudo_run(['chmod', '+x', wrapper_path], print_cmd=False, stderr=True)
def WipePayloadCache(cls, devserver_bin='start_devserver', static_dir=None): """Cleans up devserver cache of payloads. Args: devserver_bin: path to the devserver binary. static_dir: path to use as the static directory of the devserver instance. """ logging.info('Cleaning up previously generated payloads.') cmd = [devserver_bin, '--clear_cache', '--exit'] if static_dir: cmd.append('--static_dir=%s' % path_util.ToChrootPath(static_dir)) cros_build_lib.sudo_run( cmd, enter_chroot=True, print_cmd=False, combine_stdout_stderr=True, redirect_stdout=True, redirect_stderr=True, cwd=constants.SOURCE_ROOT)
def _TryCreateBridgeDevice(): """Creates a bridge device named moblabvmbrXX, generating XX randomly. Returns: num, name: Counter to be used to generate unique names, name of the bridge. """ # Keep this number between 1024-49151 (with padding) because: # - We use it to reserve networking ports, so stay within user range. # - We use it to name kernel devices, which has length restrictions. num = random.randint(10000, 30000) # device names can only be 16 char long. So suffix can be between 0 - 10^9. name = 'brmob%s' % num cros_build_lib.sudo_run(['ip', 'link', 'add', name, 'type', 'bridge'], quiet=True) return num + 1, name
def _ExtractLibc(self, sysroot, board_chost, libc_path): """Extract the libc archive to the sysroot. Args: sysroot: sysroot_lib.Sysroot - The sysroot where it's being installed. board_chost: str - The board's CHOST value. libc_path: str - The location of the libc archive. """ compressor = cros_build_lib.FindCompressor(cros_build_lib.COMP_BZIP2) if compressor.endswith('pbzip2'): compressor = '%s --ignore-trailing-garbage=1' % compressor with osutils.TempDir(sudo_rm=True) as tempdir: # Extract to the temporary directory. cmd = ['tar', '-I', compressor, '-xpf', libc_path, '-C', tempdir] result = cros_build_lib.sudo_run(cmd, check=False, capture_output=True, stderr=subprocess.STDOUT) if result.returncode: raise ToolchainInstallError( 'Error extracting libc: %s' % result.stdout, result) # Sync the files to the sysroot to install. # Trailing / on source to sync contents instead of the directory itself. source = os.path.join(tempdir, 'usr', board_chost) cmd = ['rsync', '--archive', '%s/' % source, '%s/' % sysroot.path] result = cros_build_lib.sudo_run(cmd, check=False, capture_output=True, stderr=subprocess.STDOUT) if result.returncode: raise ToolchainInstallError( 'Error installing libc: %s' % result.stdout, result) # Make the debug directory. debug_dir = os.path.join(sysroot.path, 'usr/lib/debug') osutils.SafeMakedirs(debug_dir, sudo=True) # Sync the debug files to the debug directory. source = os.path.join(tempdir, 'usr/lib/debug/usr', board_chost) cmd = ['rsync', '--archive', '%s/' % source, '%s/' % debug_dir] result = cros_build_lib.sudo_run(cmd, check=False, capture_output=True, stderr=subprocess.STDOUT) if result.returncode: logging.warning('libc debug info not copied: %s', result.stdout)
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 is not None: 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') # We might build chrome, in which case we need to pass 'CHROME_ORIGIN'. cros_build_lib.sudo_run(cmd + packages, preserve_env=True)