Ejemplo n.º 1
0
def CreatePackages(targets_wanted, output_dir, root='/'):
  """Create redistributable cross-compiler packages for the specified targets

  This creates toolchain packages that should be usable in conjunction with
  a downloaded sysroot (created elsewhere).

  Tarballs (one per target) will be created in $PWD.

  Args:
    targets_wanted: The targets to package up.
    output_dir: The directory to put the packages in.
    root: The root path to pull all packages/files from.
  """
  logging.info('Writing tarballs to %s', output_dir)
  osutils.SafeMakedirs(output_dir)
  ldpaths = lddtree.LoadLdpaths(root)
  targets = ExpandTargets(targets_wanted)

  with osutils.TempDir() as tempdir:
    # We have to split the root generation from the compression stages.  This is
    # because we hardlink in all the files (to avoid overhead of reading/writing
    # the copies multiple times).  But tar gets angry if a file's hardlink count
    # changes from when it starts reading a file to when it finishes.
    with parallel.BackgroundTaskRunner(CreatePackagableRoot) as queue:
      for target in targets:
        output_target_dir = os.path.join(tempdir, target)
        queue.put([target, output_target_dir, ldpaths, root])

    # Build the tarball.
    with parallel.BackgroundTaskRunner(cros_build_lib.CreateTarball) as queue:
      for target in targets:
        tar_file = os.path.join(output_dir, target + '.tar.xz')
        queue.put([tar_file, os.path.join(tempdir, target)])
Ejemplo n.º 2
0
    def TestLinkage(self):
        """Find main executable binaries and check their linkage."""
        binaries = [
            'bin/sed',
        ]

        if self._IsPackageMerged('chromeos-base/chromeos-login'):
            binaries.append('sbin/session_manager')

        if self._IsPackageMerged('x11-base/xorg-server'):
            binaries.append('usr/bin/Xorg')

        # When chrome is built with USE="pgo_generate", rootfs chrome is actually a
        # symlink to a real binary which is in the stateful partition. So we do not
        # check for a valid chrome binary in that case.
        if not self._IsPackageMerged(
                'chromeos-base/chromeos-chrome[pgo_generate]'):
            if self._IsPackageMerged(
                    'chromeos-base/chromeos-chrome[app_shell]'):
                binaries.append('opt/google/chrome/app_shell')
            elif self._IsPackageMerged('chromeos-base/chromeos-chrome'):
                binaries.append('opt/google/chrome/chrome')

        binaries = [os.path.join(image_test_lib.ROOT_A, x) for x in binaries]

        # Grab all .so files
        libraries = []
        for root, _, files in os.walk(image_test_lib.ROOT_A):
            for name in files:
                filename = os.path.join(root, name)
                if '.so' in filename:
                    libraries.append(filename)

        ldpaths = lddtree.LoadLdpaths(image_test_lib.ROOT_A)
        for to_test in itertools.chain(binaries, libraries):
            # to_test could be a symlink, we need to resolve it relative to ROOT_A.
            while os.path.islink(to_test):
                link = os.readlink(to_test)
                if link.startswith('/'):
                    to_test = os.path.join(image_test_lib.ROOT_A, link[1:])
                else:
                    to_test = os.path.join(os.path.dirname(to_test), link)
            try:
                lddtree.ParseELF(to_test,
                                 root=image_test_lib.ROOT_A,
                                 ldpaths=ldpaths)
            except lddtree.exceptions.ELFError:
                continue
            except IOError as e:
                self.fail('Fail linkage test for %s: %s' % (to_test, e))