Beispiel #1
0
def BundleChromeOSConfig(input_proto, output_proto, _config):
  """Output the ChromeOS Config payload for a build target.

  Args:
    input_proto (BundleRequest): The input proto.
    output_proto (BundleResponse): The output proto.
    _config (api_config.ApiConfig): The API call config.
  """
  output_dir = input_proto.output_dir
  sysroot_path = input_proto.sysroot.path
  chroot = controller_util.ParseChroot(input_proto.chroot)

  # TODO(mmortensen) Cleanup legacy handling after it has been switched over.
  target = input_proto.build_target.name
  if target:
    # Legacy handling.
    build_root = constants.SOURCE_ROOT
    chroot = chroot_lib.Chroot(path=os.path.join(build_root, 'chroot'))
    sysroot_path = os.path.join('/build', target)

  sysroot = sysroot_lib.Sysroot(sysroot_path)
  chromeos_config = artifacts.BundleChromeOSConfig(chroot, sysroot, output_dir)
  if chromeos_config is None:
    cros_build_lib.Die(
        'Could not create ChromeOS Config payload. No config found for %s.',
        sysroot.path)
  output_proto.artifacts.add().path = os.path.join(output_dir, chromeos_config)
Beispiel #2
0
    def testBundleChromeOSConfig(self):
        """Verifies that the correct ChromeOS config file is bundled."""
        # Create parent dir for ChromeOS Config output.
        config_parent_dir = os.path.join(self.chroot.path, 'build')

        # Names of ChromeOS Config files typically found in a build directory.
        config_files = ('config.json',
                        cros_test_lib.Directory('yaml', [
                            'config.c', 'config.yaml', 'ec_config.c',
                            'ec_config.h', 'model.yaml', 'private-model.yaml'
                        ]))
        config_files_root = os.path.join(
            config_parent_dir, '%s/usr/share/chromeos-config' % self.board)
        # Generate a representative set of config files produced by a typical build.
        cros_test_lib.CreateOnDiskHierarchy(config_files_root, config_files)

        # Write a payload to the config.yaml file.
        test_config_payload = {
            'chromeos': {
                'configs': [{
                    'identity': {
                        'platform-name': 'Samus'
                    }
                }]
            }
        }
        with open(os.path.join(config_files_root, 'yaml', 'config.yaml'),
                  'w') as f:
            json.dump(test_config_payload, f)

        config_filename = artifacts.BundleChromeOSConfig(
            self.chroot, self.sysroot, self.archive_dir)
        self.assertEqual('config.yaml', config_filename)

        with open(os.path.join(self.archive_dir, config_filename), 'r') as f:
            self.assertEqual(test_config_payload, json.load(f))
Beispiel #3
0
 def testNoChromeOSConfigFound(self):
     """Verifies that None is returned when no ChromeOS config file is found."""
     self.assertIsNone(
         artifacts.BundleChromeOSConfig(self.chroot, self.sysroot,
                                        self.archive_dir))