def main():
    """The main function."""
    options = ParseOptions()
    if options.version_file is None:
        logging.error('--version_file is not specified.')
        exit(-1)
    if options.output is None:
        logging.error('--output is not specified.')
        exit(-1)
    if options.input is None:
        logging.error('--input is not specified.')
        exit(-1)
    if options.branding is None:
        logging.error('--branding is not specified.')
        exit(-1)

    version = mozc_version.MozcVersion(options.version_file)
    branding_name = GetBrandingName(version, options.branding)
    with open(options.input) as f:
        result = f.read()
    result = version.GetVersionInFormat(result)
    for (key, value) in branding_name.items():
        result = result.replace('@%s@' % key, value)

    with open(options.output, 'w') as f:
        f.write(result)
def main():
    """The main function."""
    options = ParseOptions()
    required_flags = ['version_file', 'output', 'input']
    for flag in required_flags:
        if getattr(options, flag) is None:
            logging.error('--%s is not specified.', flag)
            exit(-1)

    version = mozc_version.MozcVersion(options.version_file)

    if options.build_type == 'dev':
        omaha_tag = 'external-dev'
    else:
        omaha_tag = 'external-stable'

    # This definition is copied from tools/scons/script.py
    variables = [
        ('@@@MOZC_VERSION@@@', version.GetVersionString()),
        ('@@@MOZC_PRODUCT_ID@@@', 'com.google.JapaneseIME'),
        ('@@@MOZC_APP_PATH@@@',
         '/Library/Input Methods/GoogleJapaneseInput.app'),
        ('@@@MOZC_APPLICATIONS_DIR@@@',
         '/Applications/GoogleJapaneseInput.localized'),
        ('@@@MOZC_OMAHA_TAG@@@', omaha_tag),
        ('@@@MOZC_PACKAGE_NAME@@@', 'GoogleJapaneseInput.pkg'),
    ]

    open(options.output,
         'w').write(_ReplaceVariables(open(options.input).read(), variables))
Exemple #3
0
def GenerateVersionFile(version_template_path, version_path):
    """Reads the version template file and stores it into version_path.

  This doesn't update the "version_path" if nothing will be changed to
  reduce unnecessary build caused by file timestamp.

  Args:
    version_template_path: a file name which contains the template of version.
    version_path: a file name to be stored the official version.
  """
    version = mozc_version.MozcVersion(version_template_path,
                                       expand_daily=True)
    version_definition = version.GetVersionInFormat(
        'MAJOR=@MAJOR@\n'
        'MINOR=@MINOR@\n'
        'BUILD=@BUILD@\n'
        'REVISION=@REVISION@\n'
        'ANDROID_VERSION_CODE=@ANDROID_VERSION_CODE@\n'
        'FLAG=@FLAG@\n')
    old_content = ''
    if os.path.exists(version_path):
        # if the target file already exists, need to check the necessity of update.
        old_content = open(version_path).read()

    if version_definition != old_content:
        open(version_path, 'w').write(version_definition)
Exemple #4
0
def main():
    """The main function."""
    options = ParseOptions()
    required_flags = [
        'version_file',
        'output',
        'input',
        'build_dir',
        'gen_out_dir',
        'auto_updater_dir',
        'build_type',
        'launch_agent_dir',
    ]
    for flag in required_flags:
        if getattr(options, flag) is None:
            logging.error('--%s is not specified.', flag)
            exit(-1)

    version = mozc_version.MozcVersion(options.version_file)

    copyright_message = '© %d Google Inc.' % _COPYRIGHT_YEAR
    long_version = version.GetVersionString()
    short_version = version.GetVersionInFormat('@MAJOR@.@MINOR@.@BUILD@')
    if options.mozc_dir:
        mozc_dir = options.mozc_dir
    else:
        mozc_dir = os.path.abspath(os.path.join(os.getcwd(), '..'))

    variables = {
        'MOZC_VERSIONINFO_MAJOR':
        version.GetVersionInFormat('@MAJOR@'),
        'MOZC_VERSIONINFO_MINOR':
        version.GetVersionInFormat('@MINOR@'),
        'MOZC_VERSIONINFO_LONG':
        long_version,
        'MOZC_VERSIONINFO_SHORT':
        short_version,
        'MOZC_VERSIONINFO_FINDER':
        'Google Japanese Input %s, %s' % (long_version, copyright_message),
        'GEN_OUT_DIR':
        os.path.abspath(options.gen_out_dir),
        'BUILD_DIR':
        os.path.abspath(options.build_dir),
        'AUTO_UPDATER_DIR':
        os.path.abspath(options.auto_updater_dir),
        'MOZC_DIR':
        mozc_dir,
        'LAUNCH_AGENT_DIR':
        os.path.abspath(options.launch_agent_dir),
    }

    with open(options.input, encoding='utf-8') as input_file:
        with open(options.output, 'w', encoding='utf-8') as output_file:
            output_file.write(
                _RemoveDevOnlyLines(
                    _ReplaceVariables(input_file.read(), variables),
                    options.build_type))
Exemple #5
0
def main():
  """The main function."""
  options = ParseOptions()
  if options.version_file is None:
    logging.error('--version_file is not specified.')
    sys.exit(-1)
  if options.output is None:
    logging.error('--output is not specified.')
    sys.exit(-1)
  if options.input is None:
    logging.error('--input is not specified.')
    sys.exit(-1)
  if options.branding is None:
    logging.error('--branding is not specified.')
    sys.exit(-1)

  version = mozc_version.MozcVersion(options.version_file)

  copyright_message = u'© %d Google Inc.' % _COPYRIGHT_YEAR
  long_version = version.GetVersionString()
  short_version = version.GetVersionInFormat('@MAJOR@.@MINOR@.@BUILD@')

  if options.branding == 'GoogleJapaneseInput':
    domain_prefix = 'com.google'
    product_name = 'Google Japanese Input'
    breakpad_product = 'Google_Japanese_IME_Mac'
    breakpad_url = 'https://clients2.google.com/cr/report'
  else:
    domain_prefix = 'org.mozc'
    product_name = 'Mozc'
    breakpad_product = 'Mozc'
    # Reports are generated under $TMPDIR, but not sent to a server.
    breakpad_url = 'file:///dev/null'

  variables = {
      'GOOGLE_VERSIONINFO_LONG': long_version,
      'GOOGLE_VERSIONINFO_SHORT': short_version,
      'GOOGLE_VERSIONINFO_ABOUT': copyright_message,
      'GOOGLE_VERSIONINFO_FINDER':
          '%s %s, %s' % (product_name, long_version, copyright_message),
      'BRANDING':
          options.branding,
      'DOMAIN_PREFIX':
          domain_prefix,
      'BREAKPAD_PRODUCT':
          breakpad_product,
      'BREAKPAD_URL':
          breakpad_url,
  }

  codecs.open(options.output, 'w', encoding='utf-8').write(
      tweak_data.ReplaceVariables(open(options.input).read(), variables))
Exemple #6
0
def main():
    parser = optparse.OptionParser(usage='Usage: %prog [options] files...')
    parser.add_option('--base_path',
                      dest='base_path',
                      action='store',
                      type='string',
                      default='')
    parser.add_option('--zip_output',
                      dest='zip_output',
                      action='store',
                      type='string',
                      default='')
    parser.add_option('--tgz_output',
                      dest='tgz_output',
                      action='store',
                      type='string',
                      default='')
    parser.add_option('--version_file',
                      dest='version_file',
                      action='store',
                      type='string',
                      default='')
    parser.add_option('--top_dir_base',
                      dest='top_dir_base',
                      action='store',
                      type='string',
                      default='')
    (options, args) = parser.parse_args()

    assert options.base_path, 'No --base_path was specified.'
    assert options.zip_output, 'No --zip_output was specified.'
    assert options.tgz_output, 'No --tgz_output was specified.'
    assert options.version_file, 'No --version_file was specified.'
    assert options.top_dir_base, 'No --top_dir_base was specified.'

    version = mozc_version.MozcVersion(options.version_file)
    top_dir_name = options.top_dir_base + '-%s' % version.GetVersionString()

    zip_file = zipfile.ZipFile(options.zip_output, 'w', zipfile.ZIP_DEFLATED)
    tgz_file = tarfile.open(options.tgz_output, 'w:gz')

    for file_name in args:
        if not file_name.startswith(options.base_path):
            raise RuntimeError(file_name + ' is not in ' + options.base_path)
        arc_name = os.path.join(top_dir_name,
                                os.path.relpath(file_name, options.base_path))
        zip_file.write(file_name, arc_name)
        tgz_file.add(file_name, arc_name)

    zip_file.close()
    tgz_file.close()
Exemple #7
0
def main():
  """The main function."""
  parser = optparse.OptionParser()
  parser.add_option('--version_file', dest='version_file')
  parser.add_option('--configuration', dest='configuration')

  (options, args) = parser.parse_args()
  if options.version_file is None:
    logging.error('--version_file is not specified.')
    exit(-1)
  if options.configuration is None:
    logging.error('--configuration is not specified.')
    exit(-1)
  version = mozc_version.MozcVersion(options.version_file)
  version_string = version.GetVersionString()
  is_debug = (options.configuration == 'Debug')
  VersioningFiles(version_string, is_debug, args)
Exemple #8
0
def main():
    """The main function."""
    options = ParseOptions()
    if options.version_file is None:
        logging.error('--version_file is not specified.')
        exit(-1)
    if options.outdir is None:
        logging.error('--outdir is not specified.')
        exit(-1)

    version = mozc_version.MozcVersion(options.version_file)
    for locale in _SUPPORTED_LOCALES:
        dest_path = os.path.join(options.outdir, locale)
        if not os.path.exists(dest_path):
            os.mkdir(dest_path)
        with open(os.path.join(dest_path, 'messages.json'), 'w') as f:
            messages = GetTranslationMessages(version, locale)
            output = json.dumps(messages, indent=2, separators=(',', ': '))
            f.write(output)
Exemple #9
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--base')
    parser.add_argument('--input')
    parser.add_argument('--version_file')
    parser.add_argument('--output')
    args = parser.parse_args()

    if args.version_file:
        version = mozc_version.MozcVersion(args.version_file)
        version_string = version.GetShortVersionString()
    else:
        version_string = ''

    if args.base:
        base_data = LoadBase(args.base)
    else:
        base_data = {}

    output_lines = LoadInput(args.input, version_string, base_data)
    SaveOutput(args.output, output_lines)
Exemple #10
0
def GetMozcVersion():
  """Returns MozcVersion instance."""
  # TODO(matsuzakit): Caching might be better.
  return mozc_version.MozcVersion('%s/mozc_version.txt' % SRC_DIR)
Exemple #11
0
def GypMain(options, unused_args):
    """The main function for the 'gyp' command."""
    # Copy rx.gyp and jsoncpp.gyp to the third party directory.
    CopyFile('%s/gyp/rx.gyp' % SRC_DIR, 'third_party/rx/rx.gyp')
    CopyFile('%s/gyp/jsoncpp.gyp' % SRC_DIR, 'third_party/jsoncpp/jsoncpp.gyp')
    # Copy breakpad.gyp to the third party directory, if necessary.
    if IsWindows():
        CopyFile('%s/gyp/breakpad.gyp' % SRC_DIR,
                 'third_party/breakpad/breakpad.gyp')

    # Determine the generator name.
    generator = GetGeneratorName(options.gyp_generator)
    os.environ['GYP_GENERATORS'] = generator
    print 'Build tool: %s' % generator

    # Get and show the list of .gyp file names.
    gyp_file_names = GetGypFileNames(options)
    print 'GYP files:'
    for file_name in gyp_file_names:
        print '- %s' % file_name
    # We use the one in third_party/gyp
    gyp_script = os.path.join(options.gypdir, 'gyp')
    # Run GYP.
    print 'Running GYP...'
    command_line = [
        sys.executable, gyp_script, '--depth=.',
        '--include=%s/gyp/common.gypi' % SRC_DIR
    ]
    command_line.extend(['-D', 'python_executable=%s' % sys.executable])

    command_line.extend(gyp_file_names)

    if options.branding:
        command_line.extend(['-D', 'branding=%s' % options.branding])
    if options.noqt:
        command_line.extend(['-D', 'use_qt=NO'])
    else:
        command_line.extend(['-D', 'use_qt=YES'])
    if options.qtdir:
        command_line.extend(
            ['-D', 'qt_dir=%s' % os.path.abspath(options.qtdir)])
    else:
        command_line.extend(['-D', 'qt_dir='])

    if IsWindows() and options.wix_dir:
        command_line.extend(['-D', 'use_wix=YES'])
        command_line.extend(['-D', 'wix_dir=%s' % options.wix_dir])
    else:
        command_line.extend(['-D', 'use_wix=NO'])

    command_line.extend(['-D', 'build_base=%s' % GetBuildBaseName(options)])

    disable_unittest_if_not_available = True
    if disable_unittest_if_not_available:
        required_modules = ['gmock', 'gtest']
        for module in required_modules:
            module_dir = os.path.abspath(
                os.path.join(GetTopLevelSourceDirectoryName(), 'third_party',
                             module))
            if not os.path.exists(module_dir):
                print '%s not found.' % module
                print 'Disabling unittest.'
                command_line.extend(['-D', 'enable_unittest=0'])
                break

    mac_dir = options.mac_dir or '../mac'
    if not os.path.isabs(mac_dir):
        mac_dir = os.path.join('<(DEPTH)', mac_dir)
    command_line.extend(['-D', 'mac_dir=%s' % mac_dir])

    # Check the version and determine if the building version is dev-channel or
    # not. Note that if --channel_dev is explicitly set, we don't check the
    # version number.
    (template_path, unused_version_path) = GetVersionFileNames(options)
    version = mozc_version.MozcVersion(template_path, expand_daily=False)
    if options.channel_dev is None:
        options.channel_dev = version.IsDevChannel()
    if options.channel_dev:
        command_line.extend(['-D', 'channel_dev=1'])

    def SetCommandLineForFeature(option_name,
                                 windows=False,
                                 mac=False,
                                 linux=False,
                                 chromeos=False,
                                 android=False):
        """Updates an option like '--enable_foober' and add a -D argument for gyp.

    This function ensures an option like '--enable_foober' exists and it has a
    default boolean for each platform based on givem parameters. This
    function also sets a '-D' command line option for gyp as
    '-D enable_foober=0' or '-D enable_foober=1' depending on the actual value
    of the target option.

    Args:
      option_name: A base name of the option. If 'foobar' is given,
          '--enable_foober' option will be checked.
      windows: A boolean which replesents the default value of the target
          option on Windows platform.
      mac: A boolean which replesents the default value of the target option
          on MacOS X platform.
      linux: A boolean which replesents the default value of the target option
          on Linux platform.
      chromeos: A boolean which replesents the default value of the target
          option on ChromeOS platform.
      android: A boolean which replesents the default value of the target
          option on Android platform.

    Raises:
      ValueError: An error occurred when 'option_name' is empty.
    """
        if not option_name:
            raise ValueError('"option_name" should be specified')

        default_enabled = False
        default_enabled = {
            'Windows': windows,
            'Mac': mac,
            'Linux': linux,
            'ChromeOS': chromeos,
            'Android': android
        }[options.target_platform]
        enable_option_name = 'enable_%s' % option_name
        enabled = options.ensure_value(enable_option_name, default_enabled)
        command_line.extend(
            ['-D', '%s=%s' % (enable_option_name, 1 if enabled else 0)])

    is_official_dev = ((options.language == 'japanese')
                       and (options.branding == 'GoogleJapaneseInput')
                       and options.channel_dev)

    SetCommandLineForFeature(option_name='webservice_infolist')
    enable_gtk_renderer_by_default = False
    SetCommandLineForFeature(option_name='gtk_renderer',
                             linux=enable_gtk_renderer_by_default)
    SetCommandLineForFeature(option_name='cloud_sync',
                             linux=is_official_dev,
                             windows=is_official_dev,
                             mac=is_official_dev)
    SetCommandLineForFeature(option_name='cloud_handwriting',
                             linux=is_official_dev,
                             windows=is_official_dev,
                             mac=is_official_dev)

    command_line.extend(['-D', 'target_platform=%s' % options.target_platform])

    if IsWindows():
        command_line.extend(['-G', 'msvs_version=%s' % options.msvs_version])

    if options.use_dynamically_linked_qt:
        command_line.extend(['-D', 'use_dynamically_linked_qt=YES'])
    else:
        command_line.extend(['-D', 'use_dynamically_linked_qt=NO'])

    if options.use_zinnia:
        command_line.extend(['-D', 'use_zinnia=YES'])
    else:
        command_line.extend(['-D', 'use_zinnia=NO'])

    if IsLinux():
        if '%s/unix/ibus/ibus.gyp' % SRC_DIR in gyp_file_names:
            command_line.extend(['-D', 'use_libibus=1'])
        if '%s/unix/scim/scim.gyp' % SRC_DIR in gyp_file_names:
            command_line.extend(['-D', 'use_libscim=1'])

    if options.use_libprotobuf:
        command_line.extend(['-D', 'use_libprotobuf=1'])

    # Dictionary configuration
    if options.target_platform == 'ChromeOS':
        # Note that the OSS version of mozc ignores the dictionary variable.
        command_line.extend(['-D', 'dictionary=small'])
        command_line.extend(['-D', 'use_separate_connection_data=0'])
        command_line.extend(['-D', 'use_separate_dictionary=0'])
    else:
        command_line.extend(['-D', 'dictionary=desktop'])
        command_line.extend(['-D', 'use_separate_connection_data=0'])
        command_line.extend(['-D', 'use_separate_dictionary=0'])

    # Specifying pkg-config command.  Some environment (such like
    # cross-platform ChromeOS build) requires us to call a different
    # command for pkg-config.  Here we catch the environment variable
    # and use the specified command instead of actual pkg-config
    # command.
    if IsLinux():
        command_line.extend(
            ['-D', 'pkg_config_command=%s' % GetPkgConfigCommand()])
    else:
        command_line.extend(['-D', 'pkg_config_command='])

    if os.path.isdir(options.nacl_sdk_root):
        nacl_sdk_root = os.path.abspath(options.nacl_sdk_root)
    elif options.nacl_sdk_root:
        PrintErrorAndExit(
            'The directory specified with --nacl_sdk_root does not '
            'exist: %s' % options.nacl_sdk_root)
    else:
        nacl_sdk_root = ''
    command_line.extend(['-D', 'nacl_sdk_root=%s' % nacl_sdk_root])

    command_line.extend(['-D', 'language=%s' % options.language])

    command_line.extend(
        ['-D', 'server_dir=%s' % os.path.abspath(options.server_dir)])

    # Add options.gypdir/pylib to PYTHONPATH so gyp uses its own library modules,
    # otherwise gyp can use ones of a different version.
    original_python_path = os.environ.get('PYTHONPATH', '')
    os.environ['PYTHONPATH'] = (
        os.path.abspath(os.path.join(options.gypdir, 'pylib')) + os.pathsep +
        original_python_path)
    RunOrDie(command_line)
    os.environ['PYTHONPATH'] = original_python_path

    # Done!
    print 'Done'