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

content / public / android / generate_child_service.py [blame]

#!/usr/bin/env python
#
# Copyright 2018 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import optparse
import os
import sys
import zipfile

SRC_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__),
    '..', '..', '..'))
sys.path.append(os.path.join(SRC_DIR, 'build'))

import action_helpers
import zip_helpers


def GenerateService(i):
  template = """// THIS FILE IS GENERATED BY generate_child_service.py

package org.chromium.content.app;

/**
 * This is needed to register multiple SandboxedProcess services so that we
 * can have more than one sandboxed process.
 */
public class SandboxedProcessService{0} extends SandboxedProcessService {{
}}"""
  return template.format(str(i))


def DoMain(argv):
  usage = 'usage: %prog [number] [output]'
  parser = optparse.OptionParser(usage=usage)

  options, args = parser.parse_args(argv)

  if len(args) != 2:
    parser.error('Need to specify number and output_dir')
  number, output = args
  number = int(number)

  path_template = "org/chromium/content/app/SandboxedProcessService{0}.java"
  with action_helpers.atomic_output(output) as f:
    with zipfile.ZipFile(f, 'w', zipfile.ZIP_STORED) as srcjar:
      for i in range(number):
        zip_helpers.add_to_zip_hermetic(srcjar,
                                        path_template.format(i),
                                        data=GenerateService(i))

if __name__ == '__main__':
  DoMain(sys.argv[1:])