Example #1
0
    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)

        self.chrome_root = os.path.join(self.tempdir, 'chrome_root')
Example #2
0
    def setUp(self):
        self.image_dir = os.path.join(self.tempdir, 'images')
        osutils.SafeMakedirs(self.image_dir)
        self.output_dir = os.path.join(self.tempdir, 'output')
        osutils.SafeMakedirs(self.output_dir)

        self.images = []
        for img in artifacts.IMAGE_TARS.keys():
            full_path = os.path.join(self.image_dir, img)
            self.images.append(full_path)
            osutils.Touch(full_path)

        osutils.Touch(os.path.join(self.image_dir, 'irrelevant_image.bin'))
        osutils.Touch(os.path.join(self.image_dir, 'foo.txt'))
        osutils.Touch(os.path.join(self.image_dir, 'bar'))
def CreateTmpGitRepo(project, project_url):
    """Create a temporary git repo locally.

  Args:
    project: git project name to clone.
    project_url: git project url to clone.

  Returns:
    project_dir: local project directory.
  """

    work_dir = GetWorkDir(project)

    if not cros_build_lib.IsInsideChroot():
        work_dir = os.path.join(constants.SOURCE_ROOT,
                                constants.DEFAULT_CHROOT_DIR, work_dir)

    # Delete the work_dir built by previous runs.
    osutils.RmDir(work_dir, ignore_missing=True, sudo=True)

    # Safely create work_dir
    osutils.SafeMakedirs(work_dir)

    project_dir = os.path.join(work_dir, project)
    ref = os.path.join(constants.SOURCE_ROOT, project)

    logging.info('Cloning %s %s to %s', project_url, ref, project_dir)
    repository.CloneWorkingRepo(dest=project_dir,
                                url=project_url,
                                reference=ref)
    return project_dir
    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
Example #5
0
 def setUp(self):
     self.board = 'board'
     self.chroot_path = os.path.join(self.tempdir, 'chroot')
     self.sysroot_path = '/build/board'
     self.full_sysroot_path = os.path.join(self.chroot_path,
                                           self.sysroot_path.lstrip(os.sep))
     osutils.SafeMakedirs(self.full_sysroot_path)
Example #6
0
    def _SetupCache(self):
        """Make sure that our cache contains only files/directories we expect."""
        try:
            osutils.SafeMakedirs(self._cache_dir)
            # The purge lock ensures nobody else is modifying the cache in any way.
            with self._PurgeLock(blocking=False, shared=False):
                # We have changed the layout of our cache directories over time.
                # Clean up any left over files.
                expected = (self._CACHE_LOCK, self._FILE_DIR, self._LOCK_DIR)
                unexpected = set(os.listdir(
                    self._cache_dir)).difference(expected)

                for name in unexpected:
                    filename = os.path.join(self._cache_dir, name)
                    if os.path.isdir(filename):
                        shutil.rmtree(filename)
                    else:
                        os.unlink(filename)

                # Create the cache file dir if needed.
                if not os.path.exists(self._file_dir):
                    os.makedirs(self._file_dir)

                # Create the lock dir if needed.
                if not os.path.exists(self._lock_dir):
                    os.makedirs(self._lock_dir)
        except locking.LockNotAcquiredError:
            # If we can't get an exclusive lock on the cache, someone else set it up.
            pass
Example #7
0
    def PreLoad(self, source_repo=None):
        """Preinitialize new .repo directory for faster initial sync.

    This is a hint that the new .repo directory can be copied from
    source_repo/.repo to avoid network sync operations. It does nothing if the
    .repo already exists, or source is invalid. source_repo defaults to the repo
    of the current checkout for the script.

    This should be done before the target is cleaned, to avoid corruption, since
    the source is in an unknown state.

    Args:
      source_repo: Directory path to use as a template for new repo checkout.
    """
        if not source_repo:
            source_repo = constants.SOURCE_ROOT

        # If target already exist, or source is invalid, don't copy.
        if IsARepoRoot(self.directory) or not IsARepoRoot(source_repo):
            return

        osutils.SafeMakedirs(self.directory)

        logging.info("Preloading '%s' from '%s'.", self.directory, source_repo)
        repo_util.Repository(source_repo).Copy(self.directory)
        logging.info('Preload Finsihed.')
Example #8
0
    def setUp(self):
        self.rc_mock = cros_build_lib_unittest.RunCommandMock()
        self.rc_mock.SetDefaultCmdResult()
        self.StartPatcher(self.rc_mock)

        self.sdk_mock = self.StartPatcher(
            SDKFetcherMock(external_mocks=[self.rc_mock]))

        # This needs to occur before initializing MockChromeSDKCommand.
        self.bashrc = os.path.join(self.tempdir, 'bashrc')
        self.PatchObject(constants, 'CHROME_SDK_BASHRC', new=self.bashrc)

        self.PatchObject(osutils,
                         'SourceEnvironment',
                         autospec=True,
                         side_effect=self.SourceEnvironmentMock)
        self.rc_mock.AddCmdResult(
            cros_chrome_sdk.ChromeSDKCommand.GOMACC_PORT_CMD, output='8088')

        # Initialized by SetupCommandMock.
        self.cmd_mock = None

        # Set up a fake Chrome src/ directory
        self.chrome_root = os.path.join(self.tempdir, 'chrome_root')
        self.chrome_src_dir = os.path.join(self.chrome_root, 'src')
        osutils.SafeMakedirs(self.chrome_src_dir)
        osutils.Touch(os.path.join(self.chrome_root, '.gclient'))
Example #9
0
 def _ChromeSdkRunSideEffect(self, *args, **unused_kwargs):
   if args and len(args[0]) == 3:
     bash_command = args[0][2]
     if 'gn gen' in bash_command:
       build_dir = bash_command.split()[2]
       osutils.SafeMakedirs(os.path.join(self.default_repo_dir, build_dir))
     return mock.DEFAULT
Example #10
0
    def setUp(self):
        os.makedirs(os.path.join(self.tempdir, '.repo'))
        self.source_repo = 'ssh://source/repo'
        self.manifest_repo = 'ssh://manifest/repo'
        self.version_file = 'version-file.sh'
        self.branch = 'master'
        self.build_names = ['x86-generic-paladin']
        self.incr_type = 'branch'

        repo = repository.RepoRepository(self.source_repo, self.tempdir,
                                         self.branch)
        self.manager = manifest_version.BuildSpecsManager(repo,
                                                          self.manifest_repo,
                                                          self.build_names,
                                                          self.incr_type,
                                                          False,
                                                          branch=self.branch,
                                                          dry_run=True)

        # Change default to something we clean up.
        self.tmpmandir = os.path.join(self.tempdir, 'man')
        osutils.SafeMakedirs(self.tmpmandir)
        self.manager.manifest_dir = self.tmpmandir
        # Shorten the sleep between attempts.
        self.manager.SLEEP_TIMEOUT = 1
    def setUp(self):
        self.buildroot = os.path.join(self.tempdir, 'buildroot')
        osutils.SafeMakedirs(self.buildroot)
        # Always stub RunCommmand out as we use it in every method.
        self.bot_id = 'x86-generic-paladin'
        self.build_config = config.config[self.bot_id]
        self.build_config['master'] = False
        self.build_config['important'] = False

        # Use the cbuildbot parser to create properties and populate default values.
        self.parser = cbuildbot._CreateParser()

        argv = [
            '-r', self.buildroot, '--buildbot', '--debug',
            'x86-generic-paladin'
        ]
        (self.options, _) = cbuildbot._ParseCommandLine(self.parser, argv)
        self.options.bootstrap = False
        self.options.clean = False
        self.options.resume = False
        self.options.sync = False
        self.options.build = False
        self.options.uprev = False
        self.options.tests = False
        self.options.archive = False
        self.options.remote_test_status = False
        self.options.patches = None
        self.options.prebuilts = False

        self.mox.StubOutWithMock(stages.SyncStage, 'HandleSkip')
        stages.SyncStage.HandleSkip()
Example #12
0
  def testCopyingSubDirWithPathArgs(self):
    """Copying given |Path| arguments works properly for subdirectories."""
    in_dir = Path(self.tempdir) / 'input'
    osutils.SafeMakedirs(in_dir)

    tmp_file = in_dir / 'subdir' / 'a.txt'
    osutils.SafeMakedirs(tmp_file.parent)

    tmp_file.write_text('aaa', encoding='utf-8')

    out_dir = Path(self.tempdir) / 'output'
    osutils.SafeMakedirs(out_dir)
    osutils.CopyDirContents(in_dir, out_dir, symlinks=True)

    out_tmp_file = out_dir / 'subdir' / tmp_file.name
    self.assertEqual(out_tmp_file.read_text(encoding='utf-8'), 'aaa')
Example #13
0
def Manager():
    """Create a background process for managing interprocess communication.

  This manager wraps multiprocessing.Manager() and ensures that any sockets
  created during initialization are created under the /tmp tree rather than in a
  custom temp directory. This is needed because TMPDIR might be really long, and
  named sockets are limited to 108 characters.

  Examples:
    with Manager() as manager:
      queue = manager.Queue()
      ...

  Returns:
    The return value of multiprocessing.Manager()
  """
    # Use a short directory in /tmp. Do not use /tmp directly to keep these
    # temperary files together and because certain environments do not like too
    # many top-level paths in /tmp (see crbug.com/945523).
    # Make it mode 1777 to mirror /tmp, so that we don't have failures when root
    # calls parallel first, and some other user calls it later.
    tmp_dir = '/tmp/chromite.parallel.%d' % os.geteuid()
    osutils.SafeMakedirs(tmp_dir, mode=0o1777)
    old_tempdir_value, old_tempdir_env = osutils.SetGlobalTempDir(tmp_dir)
    try:
        m = HackTimeoutSyncManager()
        # SyncManager doesn't handle KeyboardInterrupt exceptions well; pipes get
        # broken and E_NOENT or E_PIPE errors are thrown from various places. We
        # can just ignore SIGINT in the SyncManager and things will close properly
        # when the enclosing with-statement exits.
        m.start(IgnoreSigintAndSigterm)
        return m
    finally:
        osutils.SetGlobalTempDir(old_tempdir_value, old_tempdir_env)
Example #14
0
 def setUp(self):
     self.run_mock = self.PatchObject(cros_build_lib,
                                      'run',
                                      return_value=True)
     self.source_root = os.path.join(self.tempdir, 'source_root')
     osutils.SafeMakedirs(self.source_root)
     self.PatchObject(constants, 'SOURCE_ROOT', new=self.source_root)
 def testCleanupChrootNormal(self):
   """Check normal CleanupChroot."""
   osutils.SafeMakedirs(self.chroot)
   osutils.Touch(self.chroot + '.img')
   self.StartPatcher(cros_test_lib.RunCommandMock())
   with mock.patch.object(cros_sdk_lib, 'CleanupChrootMount'):
     cbuildbot_launch.CleanupChroot(self.buildroot)
 def setUp(self):
   for d in ('foo', 'bar', 'some/dir/here'):
     d = os.path.join(self.tempdir, d)
     osutils.SafeMakedirs(d)
     for f in ('ignored', 'real.sym', 'no.sym.here'):
       f = os.path.join(d, f)
       osutils.Touch(f)
    def GetDlcGenerator(self, fs_type=dlc_lib.SQUASHFS_TYPE):
        """Factory method for a DcGenerator object"""
        src_dir = os.path.join(self.tempdir, 'src')
        osutils.SafeMakedirs(src_dir)

        sysroot = os.path.join(self.tempdir, 'build_root')
        osutils.WriteFile(os.path.join(sysroot, dlc_lib.LSB_RELEASE),
                          '%s=%s\n' %
                          (cros_set_lsb_release.LSB_KEY_APPID_RELEASE, 'foo'),
                          makedirs=True)
        ue_conf = os.path.join(sysroot, 'etc', 'update_engine.conf')
        osutils.WriteFile(ue_conf, 'foo-content', makedirs=True)

        params = dlc_lib.EbuildParams(
            dlc_id=_ID,
            dlc_package=_PACKAGE,
            fs_type=fs_type,
            name=_NAME,
            description=_DESCRIPTION,
            pre_allocated_blocks=_PRE_ALLOCATED_BLOCKS,
            version=_VERSION,
            preload=False,
            used_by=dlc_lib.USED_BY_SYSTEM,
            mount_file_required=False,
            fullnamerev=_FULLNAME_REV)
        return dlc_lib.DlcGenerator(ebuild_params=params,
                                    src_dir=src_dir,
                                    sysroot=sysroot,
                                    install_root_dir=sysroot,
                                    board=_BOARD)
Example #18
0
    def _GenerateProfile(self):
        """Generates the portage profile for this sysroot.

    The generated portage profile depends on the profiles of all used bricks in
    order as well as the general brillo profile for this architecture.
    """
        overlays = self.GetStandardField(
            STANDARD_FIELD_BOARD_OVERLAY).splitlines()
        profile_list = [os.path.join(o, 'profiles', 'base') for o in overlays]

        # Keep only the profiles that exist.
        profile_list = [p for p in profile_list if os.path.exists(p)]

        # Add the arch specific profile.
        # The profile list is ordered from the lowest to the highest priority. This
        # profile has to go first so that other profiles can override it.
        arch = self.GetStandardField(STANDARD_FIELD_ARCH)
        profile_list.insert(0, 'chromiumos:default/linux/%s/brillo' % arch)

        generated_parent = os.path.join(self.path, 'build',
                                        'generated_profile', 'parent')
        osutils.WriteFile(generated_parent,
                          '\n'.join(profile_list),
                          sudo=True,
                          makedirs=True)
        profile_link = os.path.join(self.path, 'etc', 'portage',
                                    'make.profile')
        osutils.SafeMakedirs(os.path.dirname(profile_link), sudo=True)
        osutils.SafeSymlink(os.path.dirname(generated_parent),
                            profile_link,
                            sudo=True)
    def setUp(self):
        # List of all stages that would have been called as part of this run.
        self.called_stages = []

        # Simple new function that redirects RunStage to record all stages to be
        # run rather than mock them completely. These can be used in a test to
        # assert something has been called.
        def run_stage(_class_instance, stage_name, *_args, **_kwargs):
            self.called_stages.append(stage_name)

        # Parallel version.
        def run_parallel_stages(_class_instance, stages_list):
            for stage in stages_list:
                self.called_stages.append(type(stage))

        self.buildroot = os.path.join(self.tempdir, 'buildroot')
        chroot_path = os.path.join(self.buildroot,
                                   constants.DEFAULT_CHROOT_DIR)
        osutils.SafeMakedirs(os.path.join(chroot_path, 'tmp'))

        # Parallel mock is used since some work in simple builders get done on a
        # separate process.
        self.StartPatcher(parallel_unittest.ParallelMock())
        self.PatchObject(generic_builders.Builder, '_RunStage', new=run_stage)
        self.PatchObject(simple_builders.SimpleBuilder,
                         '_RunParallelStages',
                         new=run_parallel_stages)
        self.PatchObject(cbuildbot_run._BuilderRunBase,
                         'GetVersion',
                         return_value='R32-1234.0.0')

        self._manager = parallel.Manager()
        self._manager.__enter__()
    def setUp(self):
        self.buildroot = os.path.join(self.tempdir, 'buildroot')
        osutils.SafeMakedirs(self.buildroot)
        # Always stub RunCommmand out as we use it in every method.
        self.site_config = config_lib_unittest.MockSiteConfig()
        self.build_config = config_lib_unittest.MockBuildConfig()
        self.bot_id = self.build_config.name
        self.build_config['master'] = False
        self.build_config['important'] = False

        # Use the cbuildbot parser to create properties and populate default values.
        self.parser = cbuildbot._CreateParser()

        argv = ['-r', self.buildroot, '--buildbot', '--debug', self.bot_id]
        self.options, _ = cbuildbot._ParseCommandLine(self.parser, argv)
        self.options.bootstrap = False
        self.options.clean = False
        self.options.resume = False
        self.options.sync = False
        self.options.build = False
        self.options.uprev = False
        self.options.tests = False
        self.options.archive = False
        self.options.remote_test_status = False
        self.options.patches = None
        self.options.prebuilts = False

        self._manager = parallel.Manager()
        self._manager.__enter__()
        self.run = cbuildbot_run.BuilderRun(self.options, self.site_config,
                                            self.build_config, self._manager)

        self.rc.AddCmdResult(
            [constants.PATH_TO_CBUILDBOT, '--reexec-api-version'],
            output=constants.REEXEC_API_VERSION)
def GetProjectRepoDir(project, project_url, clean_old_dir=False):
    """Clone the project repo locally and return the repo directory.

  Args:
    project: git project name to clone.
    project_url: git project url to clone.
    clean_old_dir: Boolean to indicate whether to clean old work_dir. Default
      to False.

  Returns:
    project_dir: local project directory.
  """
    work_dir = GetProjectWorkDir(project)

    if clean_old_dir:
        # Delete the work_dir built by previous runs.
        osutils.RmDir(work_dir, ignore_missing=True, sudo=True)

    osutils.SafeMakedirs(work_dir)

    project_dir = os.path.join(work_dir, project)
    if not os.path.exists(project_dir):
        ref = os.path.join(constants.SOURCE_ROOT, project)
        logging.info('Cloning %s %s to %s', project_url, ref, project_dir)
        repository.CloneWorkingRepo(dest=project_dir,
                                    url=project_url,
                                    reference=ref)

    return project_dir
Example #22
0
    def Initialize(cls,
                   root,
                   manifest_url,
                   repo_url=None,
                   repo_branch=None,
                   groups=None):
        """Initialize the checkout if necessary. Otherwise a no-op.

    Args:
      root: The repo root.
      manifest_url: Manifest repository URL.
      repo_url: Repo repository URL. Uses default googlesource repo if None.
      repo_branch: Repo repository branch.
      groups: Repo groups to sync.
    """
        osutils.SafeMakedirs(root)
        if git.FindRepoCheckoutRoot(root) is None:
            logging.notice('Will initialize checkout %s for this run.', root)
            repo_util.Repository.Initialize(root,
                                            manifest_url,
                                            repo_url=repo_url,
                                            repo_branch=repo_branch,
                                            groups=groups)
        else:
            logging.notice('Will use existing checkout %s for this run.', root)
        return cls(root,
                   manifest_url=manifest_url,
                   repo_url=repo_url,
                   groups=groups)
Example #23
0
    def testSdkPrebuilts(self):
        """Test UploadPrebuilts for SDK builds."""
        # A magical date for a magical time.
        version = '1994.04.02.000000'

        # Fake out toolchain tarballs.
        tarball_dir = os.path.join(self._buildroot,
                                   constants.DEFAULT_CHROOT_DIR,
                                   constants.SDK_TOOLCHAINS_OUTPUT)
        osutils.SafeMakedirs(tarball_dir)

        tarball_args = []
        for tarball_base in ('i686', 'arm-none-eabi'):
            tarball = '%s.tar.xz' % tarball_base
            tarball_path = os.path.join(tarball_dir, tarball)
            osutils.Touch(tarball_path)
            tarball_arg = '%s:%s' % (tarball_base, tarball_path)
            tarball_args.append(['--toolchain-tarball', tarball_arg])

        with mock.patch.object(commands,
                               '_GenerateSdkVersion',
                               return_value=version):
            self.testUploadPrebuilts(
                builder_type=constants.CHROOT_BUILDER_TYPE)
        self.assertCommandContains([
            '--toolchain-upload-path', '1994/04/%%(target)s-%(version)s.tar.xz'
        ])
        for args in tarball_args:
            self.assertCommandContains(args)
        self.assertCommandContains(['--set-version', version])
        self.assertCommandContains([
            '--prepackaged-tarball',
            os.path.join(self._buildroot, 'built-sdk.tar.xz')
        ])
Example #24
0
def CloneGitRepo(working_dir, repo_url, reference=None, bare=False,
                 mirror=False, retries=constants.SYNC_RETRIES, depth=None):
  """Clone given git repo
  Args:
    repo_url: git repo to clone
    repo_dir: location where it should be cloned to
    reference: If given, pathway to a git repository to access git objects
      from.  Note that the reference must exist as long as the newly created
      repo is to be usable.
    bare: Clone a bare checkout.
    mirror: Clone a mirror checkout.
    retries: If error code 128 is encountered, how many times to retry.  When
      128 is returned from git, it's essentially a server error- specifically
      common to manifest-versions and gerrit.
    depth: If given, do a shallow clone limiting the objects pulled to just
      that # of revs of history.  This option is mutually exclusive to
      reference.
  """
  osutils.SafeMakedirs(working_dir)
  cmd = ['git', 'clone', repo_url, working_dir]
  if reference:
    if depth:
      raise ValueError("reference and depth are mutually exclusive "
                       "options; please pick one or the other.")
    cmd += ['--reference', reference]
  if bare:
    cmd += ['--bare']
  if mirror:
    cmd += ['--mirror']
  if depth:
    cmd += ['--depth', str(int(depth))]
  cros_build_lib.RunCommandWithRetries(
      retries, cmd, cwd=working_dir, redirect_stdout=True, redirect_stderr=True,
      retry_on=[128])
Example #25
0
    def setUp(self):
        """Sets up the objects needed for testing."""
        self._CreateStatefulUpdate()
        self._stateful_dir = os.path.join(self.tempdir, 'target')
        osutils.SafeMakedirs(self._stateful_dir)

        self.StartPatcher(ChromiumOSDeviceMock())
  def LocalCIDBConnection(self, cidb_user):
    """Create a CIDBConnection with the local mysqld instance.

    Args:
      cidb_user: The mysql user to connect as.

    Returns:
      The created CIDBConnection object.
    """
    creds_dir_path = os.path.join(self.tempdir, 'local_cidb_creds')
    osutils.RmDir(creds_dir_path, ignore_missing=True)
    osutils.SafeMakedirs(creds_dir_path)

    osutils.WriteFile(os.path.join(creds_dir_path, 'host.txt'),
                      self.mysqld_host)
    osutils.WriteFile(os.path.join(creds_dir_path, 'port.txt'),
                      str(self.mysqld_port))
    osutils.WriteFile(os.path.join(creds_dir_path, 'user.txt'), cidb_user)

    if cidb_user in self.CIDB_CREDS_DIR:
      shutil.copy(os.path.join(self.CIDB_CREDS_DIR[cidb_user], 'password.txt'),
                  creds_dir_path)

    return cidb.CIDBConnection(
        creds_dir_path,
        query_retry_args=cidb.SqlConnectionRetryArgs(4, 1, 1.1))
Example #27
0
    def createSymbolFile(self,
                         filename,
                         content=FAT_CONTENT,
                         size=0,
                         status=None,
                         dedupe=False):
        fullname = os.path.join(self.data, filename)
        osutils.SafeMakedirs(os.path.dirname(fullname))

        # If a file size is given, force that to be the minimum file size. Create
        # a sparse file so large files are practical.
        with open(fullname, 'w+b') as f:
            f.truncate(size)
            f.seek(0)
            f.write(content)

        result = upload_symbols.SymbolFile(display_path=filename,
                                           file_name=fullname)

        if status:
            result.status = status

        if dedupe:
            result.dedupe_item = upload_symbols.DedupeItem(result)
            result.dedupe_push_state = 'push_state'

        return result
Example #28
0
 def _LockForKey(self, key, suffix='.lock'):
     """Returns an unacquired lock associated with a key."""
     key_path = self._GetKeyPath(key)
     osutils.SafeMakedirs(os.path.dirname(key_path))
     lock_path = os.path.join(self._cache_dir, os.path.dirname(key_path),
                              os.path.basename(key_path) + suffix)
     return locking.FileLock(lock_path)
Example #29
0
    def testUprev(self):
        recorded_args = []
        self.PatchObject(upload_prebuilts, 'RevGitFile',
                         lambda *args, **kwargs: recorded_args.append(args))

        out_dir = os.path.join(self.build_root, 'chroot', 'tmp',
                               'toolchain-pkgs')
        osutils.SafeMakedirs(out_dir)
        osutils.Touch(os.path.join(out_dir, 'fake_sdk.tar.xz'))

        self._Prepare('chromiumos-sdk')

        self.RunStage()
        # upload_prebuilts.RevGitFile should be called exact once.
        self.assertEqual(1, len(recorded_args))
        sdk_conf, sdk_settings = recorded_args[0]
        self.assertEqual(
            sdk_conf,
            os.path.join(self.build_root, 'src', 'third_party',
                         'chromiumos-overlay', 'chromeos', 'binhost', 'host',
                         'sdk_version.conf'))
        self.assertEqual(
            sdk_settings, {
                'SDK_LATEST_VERSION': self._VERSION,
                'TC_PATH': '2017/09/%(target)s-2017.09.01.155318.tar.xz'
            })
Example #30
0
    def _CopyFile(self, src, dest, path):
        """Perform the copy.

    Args:
      src: The path of the file/directory to copy.
      dest: The exact path of the destination. Does nothing if it already
            exists.
      path: The Path instance containing copy operation modifiers (such as
            Path.exe, Path.strip, etc.)
    """
        assert not os.path.isdir(src), '%s: Not expecting a directory!' % src

        # This file has already been copied by an earlier Path.
        if os.path.exists(dest):
            return

        osutils.SafeMakedirs(os.path.dirname(dest), mode=self.dir_mode)
        if path.exe and self.strip_bin and path.strip and os.path.getsize(
                src) > 0:
            strip_flags = (['--strip-unneeded']
                           if self.strip_flags is None else self.strip_flags)
            cros_build_lib.DebugRunCommand([self.strip_bin] + strip_flags +
                                           ['-o', dest, src])
            shutil.copystat(src, dest)
        else:
            shutil.copy2(src, dest)

        mode = path.mode
        if mode is None:
            mode = self.exe_mode if path.exe else self.default_mode
        os.chmod(dest, mode)