#!/usr/bin/env python # Copyright (c) 2011 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. """Helper script to repack paks for a list of locales. Gyp doesn't have any built-in looping capability, so this just provides a way to loop over a list of locales when repacking pak files, thus avoiding a proliferation of mostly duplicate, cut-n-paste gyp actions. """ import getopt import os import sys sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'tools', 'grit')) from grit.format import data_pack # Some build paths defined by gyp. GRIT_DIR = None SHARE_INT_DIR = None INT_DIR = None class Usage(Exception): def __init__(self, msg): self.msg = msg def calc_output(locale, create_dir): """Determine the file that will be generated for the given locale.""" #e.g. '<(INTERMEDIATE_DIR)/da.pak', # For Fake Bidi, generate it at a fixed path so that tests can safely # reference it. if locale == 'fake-bidi': return '%s/%s.pak' % (INT_DIR, locale) if sys.platform in ('darwin',): # For Cocoa to find the locale at runtime, it needs to use '_' instead # of '-' (http://crbug.com/20441). Also, 'en-US' should be represented # simply as 'en' (http://crbug.com/19165, http://crbug.com/25578). if locale == 'en-US': locale = 'en' dir = '%s/%s.lproj' % (INT_DIR, locale.replace('-', '_')) if create_dir and not os.path.exists(dir): os.makedirs(dir) return dir + '/locale.pak' else: return os.path.join(INT_DIR, locale + '.pak') def calc_inputs(locale): """Determine the files that need processing for the given locale.""" inputs = [] #e.g. # '<(SHARED_INTERMEDIATE_DIR)/components/strings/components_strings_da.pak' inputs.append(os.path.join(SHARE_INT_DIR, 'components', 'strings', 'components_strings_%s.pak' % locale)) #e.g. # '<(SHARED_INTERMEDIATE_DIR)/content/app/strings/content_strings_da.pak' inputs.append(os.path.join(SHARE_INT_DIR, 'content', 'app', 'strings', 'content_strings_%s.pak' % locale)) #e.g. # '<(SHARED_INTERMEDIATE_DIR)/extensions/strings/extensions_strings_da.pak' inputs.append(os.path.join(SHARE_INT_DIR, 'extensions', 'strings', 'extensions_strings_%s.pak' % locale)) #e.g. '<(SHARED_INTERMEDIATE_DIR)/ui/strings/ui_strings_da.pak', inputs.append(os.path.join(SHARE_INT_DIR, 'ui', 'strings', 'ui_strings_%s.pak' % locale)) #e.g. '<(SHARED_INTERMEDIATE_DIR)/ui/strings/app_locale_settings_da.pak', inputs.append(os.path.join(SHARE_INT_DIR, 'ui', 'strings', 'app_locale_settings_%s.pak' % locale)) #e.g. '<(SHARED_INTERMEDIATE_DIR)/cef/cef_strings_da.pak' inputs.append(os.path.join(SHARE_INT_DIR, 'cef', 'cef_strings_%s.pak' % locale)) return inputs def list_outputs(locales): """Returns the names of files that will be generated for the given locales. This is to provide gyp the list of output files, so build targets can properly track what needs to be built. """ outputs = [] for locale in locales: outputs.append(calc_output(locale, False)) # Quote each element so filename spaces don't mess up gyp's attempt to parse # it into a list. return " ".join(['"%s"' % x for x in outputs]) def list_inputs(locales): """Returns the names of files that will be processed for the given locales. This is to provide gyp the list of input files, so build targets can properly track their prerequisites. """ inputs = [] for locale in locales: inputs += calc_inputs(locale) # Quote each element so filename spaces don't mess up gyp's attempt to parse # it into a list. return " ".join(['"%s"' % x for x in inputs]) def repack_locales(locales): """ Loop over and repack the given locales.""" for locale in locales: inputs = [] inputs += calc_inputs(locale) output = calc_output(locale, True) data_pack.DataPack.RePack(output, inputs) def DoMain(argv): global GRIT_DIR global SHARE_INT_DIR global INT_DIR short_options = 'iog:s:x:b:h' long_options = 'help' print_inputs = False print_outputs = False usage_msg = '' helpstr = """\ Usage: %s [-h] [-i | -o] -g