Ejemplo n.º 1
0
def CheckVersion(input_api, output_api):
    """Checks that
  - the version was upraded if assets files were changed,
  - the version was not downgraded.
  """
    sys.path.append(input_api.PresubmitLocalPath())
    import parse_version

    old_version = None
    new_version = None
    changed_assets = False
    changed_version = False
    for file in input_api.AffectedFiles():
        basename = input_api.os_path.basename(file.LocalPath())
        extension = input_api.os_path.splitext(basename)[1][1:].strip().lower()
        if (extension == 'sha1'
                or basename == 'vr_assets_component_files.json'):
            changed_assets = True
        if (basename == 'VERSION'):
            changed_version = True
            old_version = parse_version.ParseVersion(file.OldContents())
            new_version = parse_version.ParseVersion(file.NewContents())

    local_version_filename = input_api.os_path.join(
        input_api.os_path.dirname(input_api.AffectedFiles()[0].LocalPath()),
        'VERSION')

    if changed_version and (not old_version or not new_version):
        return [
            output_api.PresubmitError('Cannot parse version in \'%s\'.' %
                                      local_version_filename)
        ]

    version_upgraded = IsNewer(old_version, new_version)
    if changed_assets and not version_upgraded:
        return [
            output_api.PresubmitError('Must increment version in \'%s\' when '
                                      'updating VR assets.' %
                                      local_version_filename)
        ]
    if changed_version and not version_upgraded:
        return [
            output_api.PresubmitError('Must not downgrade version in \'%s\'.' %
                                      local_version_filename)
        ]

    return []
Ejemplo n.º 2
0
def main():
  parser = argparse.ArgumentParser()
  parser.add_argument('--output',
                      required=True,
                      help='The gen directory to put the profile directory in')
  parser.add_argument('--asset-dir',
                      required=True,
                      help='The directory containing the asset information')
  args, _ = parser.parse_known_args()

  # Add the directory to the path so we can get the parse_version script.
  asset_dir = args.asset_dir
  sys.path.append(asset_dir)
  #pylint: disable=import-error
  import parse_version

  # Get the assets version.
  with open(os.path.join(asset_dir, 'VERSION'), 'r') as version_file:
    version = parse_version.ParseVersion(version_file.readlines())
  if not version:
    raise RuntimeError('Could not get version for VR assets')

  # Clean up a pre-existing profile and create the necessary directories.
  profile_dir = os.path.join(args.output, 'vr_assets_profile')
  if os.path.isdir(profile_dir):
    shutil.rmtree(profile_dir)
  os.makedirs(profile_dir)

  # Check whether there are actually files to copy - if not, the lack of a
  # directory will cause Telemetry to fail if we actually try to use the profile
  # directory. This is a workaround for not being able to check whether we
  # should have the files in GN. This way, we won't just fail silently during
  # tests, i.e. use the fallback assets, but we don't get build errors on bots
  # due to trying to copy non-existent files.
  found_asset = False
  for asset in os.listdir(os.path.join(asset_dir, 'google_chrome')):
    if asset.endswith('.png') or asset.endswith('.jpeg'):
      found_asset = True
      break
  if not found_asset:
    return
  profile_dir = os.path.join(profile_dir, 'VrAssets',
                             '%d.%d' % (version.major, version.minor))
  os.makedirs(profile_dir)

  # Only copy the files specified by the asset JSON file.
  with open(os.path.join(asset_dir,
        'vr_assets_component_files.json'), 'r') as asset_json_file:
      asset_files = json.load(asset_json_file)
      for asset in asset_files:
        shutil.copy(os.path.join(asset_dir, asset), profile_dir)

  # Generate the manifest file.
  with open(os.path.join(profile_dir, 'manifest.json'), 'w') as manifest_file:
    json.dump({
        'manifest_version': 2,
        'name': 'VrAssets',
        'version': '%d.%d' % (version.major, version.minor)}, manifest_file)
Ejemplo n.º 3
0
def main():
    assets_dir = os.path.dirname(os.path.abspath(__file__))

    files = []
    with open(os.path.join(assets_dir,
                           'vr_assets_component_files.json')) as json_file:
        files = json.load(json_file)

    version = None
    with open(os.path.join(assets_dir, 'VERSION')) as version_file:
        version = parse_version.ParseVersion(version_file.readlines())
    assert version

    PrintInfo('Version', ['%s.%s' % (version.major, version.minor)])
    PrintInfo('Platform', [PLATFORM])
    PrintInfo('Asset files', files)

    with TempDir() as temp_dir:
        zip_dir = os.path.join(temp_dir,
                               '%s.%s' % (version.major, version.minor),
                               PLATFORM)
        zip_path = os.path.join(zip_dir, 'vr-assets.zip')

        os.makedirs(zip_dir)
        zip_files = []
        with zipfile.ZipFile(zip_path, 'w') as zip:
            for file in files:
                file_path = os.path.join(assets_dir, file)
                zip.write(file_path, os.path.basename(file_path),
                          zipfile.ZIP_DEFLATED)
            for info in zip.infolist():
                zip_files.append(info.filename)

        # Upload component.
        command = ['gsutil', 'cp', '-nR', '.', DEST_BUCKET]
        PrintInfo('Going to run the following command', [' '.join(command)])
        PrintInfo('In directory', [temp_dir])
        PrintInfo('Which pushes the following file', [zip_path])
        PrintInfo('Which contains the files', zip_files)

        if raw_input('\nAre you sure (y/N) ').lower() != 'y':
            print 'aborting'
            return 1
        return subprocess.call(command, cwd=temp_dir)
Ejemplo n.º 4
0
def CheckVersionAndAssetParity(input_api, output_api):
  """Checks that
  - the version was upraded if assets files were changed,
  - the version was not downgraded,
  - both the google_chrome and the chromium assets have the same files.
  """
  sys.path.append(input_api.PresubmitLocalPath())
  import parse_version

  old_version = None
  new_version = None
  changed_assets = False
  changed_version = False
  changed_asset_files = {'google_chrome': [], 'chromium': []}
  for file in input_api.AffectedFiles():
    basename = input_api.os_path.basename(file.LocalPath())
    extension = input_api.os_path.splitext(basename)[1][1:].strip().lower()
    basename_without_extension = input_api.os_path.splitext(basename)[
        0].strip().lower()
    if extension == 'sha1':
      basename_without_extension = input_api.os_path.splitext(
          basename_without_extension)[0]
    dirname = input_api.os_path.basename(
        input_api.os_path.dirname(file.LocalPath()))
    action = file.Action()
    if (dirname in changed_asset_files and extension in {'sha1', 'png'} and
        action in {'A', 'D'}):
      changed_asset_files[dirname].append((action, basename_without_extension))
    if (extension == 'sha1' or basename == 'vr_assets_component_files.json'):
      changed_assets = True
    if (basename == 'VERSION'):
      changed_version = True
      old_version = parse_version.ParseVersion(file.OldContents())
      new_version = parse_version.ParseVersion(file.NewContents())

  local_version_filename = input_api.os_path.join(
      input_api.os_path.dirname(input_api.AffectedFiles()[0].LocalPath()),
      'VERSION')

  if changed_asset_files['google_chrome'] != changed_asset_files['chromium']:
    return [
        output_api.PresubmitError(
            'Must have same asset files for %s in \'%s\'.' %
            (changed_asset_files.keys(),
             input_api.os_path.dirname(
                 input_api.AffectedFiles()[0].LocalPath())))
    ]

  if changed_version and (not old_version or not new_version):
    return [
        output_api.PresubmitError(
            'Cannot parse version in \'%s\'.' % local_version_filename)
    ]

  version_upgraded = IsNewer(old_version, new_version)
  if changed_assets and not version_upgraded:
    return [
        output_api.PresubmitError(
            'Must increment version in \'%s\' when '
            'updating VR assets.' % local_version_filename)
    ]
  if changed_version and not version_upgraded:
    return [
        output_api.PresubmitError(
            'Must not downgrade version in \'%s\'.' % local_version_filename)
    ]

  return []