summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/build/cipd/cipd_from_file.py
blob: 0f08f692e3469a981b19fc4571b4a9c1047f3684 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
# Copyright 2021 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Script to generate yaml file based on FILES.cfg."""

import argparse
import os


def _ParseFilesCfg(files_file):
  """Return the dictionary of archive file info read from the given file."""
  if not os.path.exists(files_file):
    raise IOError('Files list does not exist (%s).' % files_file)
  exec_globals = {'__builtins__': None}

  exec(open(files_file).read(), exec_globals)
  return exec_globals['FILES']


def _Process(args):
  yaml_content = ('package: ' + args.package + '\ndescription: ' +
                  args.description + '\ninstall_mode: ' + args.install_mode +
                  '\ndata:\n')
  fileobj = _ParseFilesCfg(args.files_file)
  for item in fileobj:
    if 'buildtype' in item:
      if args.buildtype not in item['buildtype']:
        continue
    if 'arch' in item:
      if args.arch not in item['arch']:
        continue
    if 'type' in item and item['type'] == 'folder':
      yaml_content += ' - dir: ' + item['filename'] + '\n'
    else:
      yaml_content += ' - file: ' + item['filename'] + '\n'

  with open(args.output_yaml_file, 'w') as f:
    f.write(yaml_content)


def main():
  parser = argparse.ArgumentParser()
  parser.add_argument('--output_yaml_file', help='File to create.')
  parser.add_argument(
      '--package',
      help='The path where the package will be located inside the CIPD\
           repository.')
  parser.add_argument(
      '--description',
      help='Sets the "description" field in CIPD package definition.')
  parser.add_argument('--install_mode',
                      help='String, should be either "symlink" or "copy".')
  parser.add_argument('--files_file',
                      help='FILES.cfg describes what files to include.')
  parser.add_argument('--buildtype', help='buildtype for FILES.cfg.')
  parser.add_argument('--arch', help='arch for FILES.cfg')

  args = parser.parse_args()

  _Process(args)


if __name__ == '__main__':
  main()