Esempio n. 1
0
def main():
    parser = optparse.OptionParser()

    parser.add_option('--inputs',
                      help='GN format list of files to archive.')
    parser.add_option('--dir-inputs',
                      help='GN format list of files to archive.')
    parser.add_option('--output', help='Path to output archive.')
    parser.add_option('--base-dir',
                      help='If provided, the paths in the archive will be '
                      'relative to this directory', default='.')

    options, _ = parser.parse_args()

    inputs = []
    if (options.inputs):
        parser = gn_helpers.GNValueParser(options.inputs)
        inputs = parser.ParseList()

    dir_inputs = []
    if options.dir_inputs:
        parser = gn_helpers.GNValueParser(options.dir_inputs)
        dir_inputs = parser.ParseList()

    output = options.output
    base_dir = options.base_dir

    with scoped_cwd(base_dir):
        make_zip(output, inputs, dir_inputs)
Esempio n. 2
0
def main():
  parser = optparse.OptionParser()

  parser.add_option('--inputs',
      help='GN format list of files to archive.')
  parser.add_option('--link-inputs',
      help='GN-format list of files to archive. Symbolic links are resolved.')
  parser.add_option('--zip-inputs',
      help='GN-format list of zip files to re-archive.')
  parser.add_option('--output', help='Path to output archive.')
  parser.add_option('--base-dir',
                    help='If provided, the paths in the archive will be '
                    'relative to this directory', default='.')

  options, _ = parser.parse_args()

  inputs = []
  if (options.inputs):
    parser = gn_helpers.GNValueParser(options.inputs)
    inputs = parser.ParseList()

  link_inputs = []
  if options.link_inputs:
    parser = gn_helpers.GNValueParser(options.link_inputs)
    link_inputs = parser.ParseList()

  zip_inputs = []
  if options.zip_inputs:
    parser = gn_helpers.GNValueParser(options.zip_inputs)
    zip_inputs = parser.ParseList()

  output = options.output
  base_dir = options.base_dir

  DoZip(inputs, link_inputs, zip_inputs, output, base_dir)
    def test_ReplaceImports(self):
        # Should be a no-op on args inputs without any imports.
        parser = gn_helpers.GNValueParser(
            textwrap.dedent("""
        some_arg1 = "val1"
        some_arg2 = "val2"
    """))
        parser.ReplaceImports()
        self.assertEqual(
            parser.input,
            textwrap.dedent("""
        some_arg1 = "val1"
        some_arg2 = "val2"
    """))

        # A single "import(...)" line should be replaced with the contents of the
        # file being imported.
        parser = gn_helpers.GNValueParser(
            textwrap.dedent("""
        some_arg1 = "val1"
        import("//some/args/file.gni")
        some_arg2 = "val2"
    """))
        fake_import = 'some_imported_arg = "imported_val"'
        if sys.version_info.major < 3:
            from mock import patch, mock_open
            builtin_var = '__builtin__'
        else:
            from unittest.mock import patch, mock_open
            builtin_var = 'builtins'
        open_fun = '{}.open'.format(builtin_var)
        with patch(open_fun, mock_open(read_data=fake_import)):
            parser.ReplaceImports()
        self.assertEqual(
            parser.input,
            textwrap.dedent("""
        some_arg1 = "val1"
        some_imported_arg = "imported_val"
        some_arg2 = "val2"
    """))

        # No trailing parenthesis should raise an exception.
        with self.assertRaises(gn_helpers.GNError):
            parser = gn_helpers.GNValueParser(
                textwrap.dedent('import("//some/args/file.gni"'))
            parser.ReplaceImports()

        # No double quotes should raise an exception.
        with self.assertRaises(gn_helpers.GNError):
            parser = gn_helpers.GNValueParser(
                textwrap.dedent('import(//some/args/file.gni)'))
            parser.ReplaceImports()

        # A path that's not source absolute should raise an exception.
        with self.assertRaises(gn_helpers.GNError):
            parser = gn_helpers.GNValueParser(
                textwrap.dedent('import("some/relative/args/file.gni")'))
            parser.ReplaceImports()
Esempio n. 4
0
    def test_ParseNumber(self):
        parser = gn_helpers.GNValueParser('123')
        self.assertEqual(parser.ParseNumber(), 123)

        with self.assertRaises(gn_helpers.GNException):
            parser = gn_helpers.GNValueParser('')
            parser.ParseNumber()
        with self.assertRaises(gn_helpers.GNException):
            parser = gn_helpers.GNValueParser('a123')
            parser.ParseNumber()
Esempio n. 5
0
    def test_ReplaceImports(self):
        # Should be a no-op on args inputs without any imports.
        parser = gn_helpers.GNValueParser(
            textwrap.dedent("""
        some_arg1 = "val1"
        some_arg2 = "val2"
    """))
        parser.ReplaceImports()
        self.assertEquals(
            parser.input,
            textwrap.dedent("""
        some_arg1 = "val1"
        some_arg2 = "val2"
    """))

        # A single "import(...)" line should be replaced with the contents of the
        # file being imported.
        parser = gn_helpers.GNValueParser(
            textwrap.dedent("""
        some_arg1 = "val1"
        import("//some/args/file.gni")
        some_arg2 = "val2"
    """))
        fake_import = 'some_imported_arg = "imported_val"'
        with mock.patch('__builtin__.open',
                        mock.mock_open(read_data=fake_import)):
            parser.ReplaceImports()
        self.assertEquals(
            parser.input,
            textwrap.dedent("""
        some_arg1 = "val1"
        some_imported_arg = "imported_val"
        some_arg2 = "val2"
    """))

        # No trailing parenthesis should raise an exception.
        with self.assertRaises(gn_helpers.GNError):
            parser = gn_helpers.GNValueParser(
                textwrap.dedent('import("//some/args/file.gni"'))
            parser.ReplaceImports()

        # No double quotes should raise an exception.
        with self.assertRaises(gn_helpers.GNError):
            parser = gn_helpers.GNValueParser(
                textwrap.dedent('import(//some/args/file.gni)'))
            parser.ReplaceImports()

        # A path that's not source absolute should raise an exception.
        with self.assertRaises(gn_helpers.GNError):
            parser = gn_helpers.GNValueParser(
                textwrap.dedent('import("some/relative/args/file.gni")'))
            parser.ReplaceImports()
Esempio n. 6
0
    def test_ParseString(self):
        parser = gn_helpers.GNValueParser('"asdf"')
        self.assertEqual(parser.ParseString(), 'asdf')

        with self.assertRaises(gn_helpers.GNException):
            parser = gn_helpers.GNValueParser('')  # Empty.
            parser.ParseString()
        with self.assertRaises(gn_helpers.GNException):
            parser = gn_helpers.GNValueParser('asdf')  # Unquoted.
            parser.ParseString()
        with self.assertRaises(gn_helpers.GNException):
            parser = gn_helpers.GNValueParser('"trailing')  # Unterminated.
            parser.ParseString()
Esempio n. 7
0
    def test_ParseList(self):
        parser = gn_helpers.GNValueParser('[1,]')  # Optional end comma OK.
        self.assertEqual(parser.ParseList(), [1])

        with self.assertRaises(gn_helpers.GNException):
            parser = gn_helpers.GNValueParser('')  # Empty.
            parser.ParseList()
        with self.assertRaises(gn_helpers.GNException):
            parser = gn_helpers.GNValueParser('asdf')  # No [].
            parser.ParseList()
        with self.assertRaises(gn_helpers.GNException):
            parser = gn_helpers.GNValueParser('[1, 2')  # Unterminated
            parser.ParseList()
        with self.assertRaises(gn_helpers.GNException):
            parser = gn_helpers.GNValueParser('[1 2]')  # No separating comma.
            parser.ParseList()
Esempio n. 8
0
def ParseGnList(value):
  """Converts a "GN-list" command-line parameter into a list.

  Conversions handled:
    * None -> []
    * '' -> []
    * 'asdf' -> ['asdf']
    * '["a", "b"]' -> ['a', 'b']
    * ['["a", "b"]', 'c'] -> ['a', 'b', 'c']  (flattened list)

  The common use for this behavior is in the Android build where things can
  take lists of @FileArg references that are expanded via ExpandFileArgs.
  """
  # Convert None to [].
  if not value:
    return []
  # Convert a list of GN lists to a flattened list.
  if isinstance(value, list):
    ret = []
    for arg in value:
      ret.extend(ParseGnList(arg))
    return ret
  # Convert normal GN list.
  if value.startswith('['):
    return gn_helpers.GNValueParser(value).ParseList()
  # Convert a single string value to a list.
  return [value]
Esempio n. 9
0
    def test_FromGNString(self):
        self.assertEqual(
            gn_helpers.FromGNString('[1, -20, true, false,["as\\"", []]]'),
            [1, -20, True, False, ['as"', []]])

        with self.assertRaises(gn_helpers.GNException):
            parser = gn_helpers.GNValueParser('123 456')
            parser.Parse()
Esempio n. 10
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--build-dir',
                        required=True,
                        help='The build output directory.')
    parser.add_argument('--symbols-dir',
                        required=True,
                        help='The directory where to write the symbols file.')
    parser.add_argument(
        '--libchromiumcontent-dir',
        required=True,
        help='The directory where libchromiumcontent is downloaded.')
    parser.add_argument('--binary',
                        required=True,
                        help='The path of the binary to generate symbols for.')
    parser.add_argument(
        '--clear',
        default=False,
        action='store_true',
        help='Clear the symbols directory before writing new symbols.')
    parser.add_argument('-j',
                        '--jobs',
                        default=CONCURRENT_TASKS,
                        action='store',
                        type=int,
                        help='Number of parallel tasks to run.')
    parser.add_argument('-v',
                        '--verbose',
                        action='store_true',
                        help='Print verbose status output.')

    options = parser.parse_args()

    if options.clear:
        try:
            shutil.rmtree(options.symbols_dir)
        except:  # pylint: disable=bare-except
            pass

    parser = gn_helpers.GNValueParser(options.binary)
    binary = parser.ParseList()

    # Build the transitive closure of all dependencies.
    binaries = set(binary)
    q = binary
    exe_path = os.path.dirname(binary[0])
    while q:
        deps = GetSharedLibraryDependencies(q.pop(0), exe_path)
        new_deps = set(deps) - binaries
        binaries |= new_deps
        q.extend(list(new_deps))

    GenerateSymbols(options, binaries)

    return 0
Esempio n. 11
0
def ParseGnList(gn_string):
  """Converts a command-line parameter into a list.

  If the input starts with a '[' it is assumed to be a GN-formatted list and
  it will be parsed accordingly. When empty an empty list will be returned.
  Otherwise, the parameter will be treated as a single raw string (not
  GN-formatted in that it's not assumed to have literal quotes that must be
  removed) and a list will be returned containing that string.

  The common use for this behavior is in the Android build where things can
  take lists of @FileArg references that are expanded via ExpandFileArgs.
  """
  if gn_string.startswith('['):
    parser = gn_helpers.GNValueParser(gn_string)
    return parser.ParseList()
  if len(gn_string):
    return [ gn_string ]
  return []
    def test_ParseScope(self):
        parser = gn_helpers.GNValueParser('{a = 1}')
        self.assertEqual(parser.ParseScope(), {'a': 1})

        with self.assertRaises(gn_helpers.GNError):
            parser = gn_helpers.GNValueParser('')  # Empty.
            parser.ParseScope()
        with self.assertRaises(gn_helpers.GNError):
            parser = gn_helpers.GNValueParser('asdf')  # No {}.
            parser.ParseScope()
        with self.assertRaises(gn_helpers.GNError):
            parser = gn_helpers.GNValueParser('{a = 1')  # Unterminated.
            parser.ParseScope()
        with self.assertRaises(gn_helpers.GNError):
            parser = gn_helpers.GNValueParser('{"a" = 1}')  # Not identifier.
            parser.ParseScope()
        with self.assertRaises(gn_helpers.GNError):
            parser = gn_helpers.GNValueParser('{a = }')  # No value.
            parser.ParseScope()
  def test_ParseBool(self):
    parser = gn_helpers.GNValueParser('true')
    self.assertEqual(parser.Parse(), True)

    parser = gn_helpers.GNValueParser('false')
    self.assertEqual(parser.Parse(), False)
Esempio n. 14
0
def main():
    parser = optparse.OptionParser()
    parser.add_option('',
                      '--build-dir',
                      default='',
                      help='The build output directory.')
    parser.add_option('',
                      '--symbols-dir',
                      default='',
                      help='The directory where to write the symbols file.')
    parser.add_option(
        '',
        '--libchromiumcontent-dir',
        default='',
        help='The directory where libchromiumcontent is downloaded.')
    parser.add_option('',
                      '--binary',
                      default='',
                      help='The path of the binary to generate symbols for.')
    parser.add_option('',
                      '--clear',
                      default=False,
                      action='store_true',
                      help='Clear the symbols directory before writing new '
                      'symbols.')
    parser.add_option('-j',
                      '--jobs',
                      default=CONCURRENT_TASKS,
                      action='store',
                      type='int',
                      help='Number of parallel tasks to run.')
    parser.add_option('-v',
                      '--verbose',
                      action='store_true',
                      help='Print verbose status output.')

    (options, _) = parser.parse_args()

    if not options.symbols_dir:
        print "Required option --symbols-dir missing."
        return 1

    if not options.build_dir:
        print "Required option --build-dir missing."
        return 1

    if not options.libchromiumcontent_dir:
        print "Required option --libchromiumcontent-dir missing."
        return 1

    if not options.binary:
        print "Required option --binary missing."
        return 1

    if options.clear:
        try:
            shutil.rmtree(options.symbols_dir)
        except:
            pass

    binary = []
    if options.binary:
        parser = gn_helpers.GNValueParser(options.binary)
        binary = parser.ParseList()

    # Build the transitive closure of all dependencies.
    binaries = set(binary)
    queue = binary
    exe_path = os.path.dirname(binary[0])
    while queue:
        deps = GetSharedLibraryDependencies(options, queue.pop(0), exe_path)
        new_deps = set(deps) - binaries
        binaries |= new_deps
        queue.extend(list(new_deps))

    GenerateSymbols(options, binaries)

    return 0