1*635a8641SAndroid Build Coastguard Worker# Copyright (c) 2012 The Chromium Authors. All rights reserved. 2*635a8641SAndroid Build Coastguard Worker# Use of this source code is governed by a BSD-style license that can be 3*635a8641SAndroid Build Coastguard Worker# found in the LICENSE file. 4*635a8641SAndroid Build Coastguard Worker 5*635a8641SAndroid Build Coastguard Worker"""This script is now only used by the closure_compilation builders.""" 6*635a8641SAndroid Build Coastguard Worker 7*635a8641SAndroid Build Coastguard Workerimport argparse 8*635a8641SAndroid Build Coastguard Workerimport glob 9*635a8641SAndroid Build Coastguard Workerimport gyp_environment 10*635a8641SAndroid Build Coastguard Workerimport os 11*635a8641SAndroid Build Coastguard Workerimport shlex 12*635a8641SAndroid Build Coastguard Workerimport sys 13*635a8641SAndroid Build Coastguard Worker 14*635a8641SAndroid Build Coastguard Workerscript_dir = os.path.dirname(os.path.realpath(__file__)) 15*635a8641SAndroid Build Coastguard Workerchrome_src = os.path.abspath(os.path.join(script_dir, os.pardir)) 16*635a8641SAndroid Build Coastguard Worker 17*635a8641SAndroid Build Coastguard Workersys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib')) 18*635a8641SAndroid Build Coastguard Workerimport gyp 19*635a8641SAndroid Build Coastguard Worker 20*635a8641SAndroid Build Coastguard Worker 21*635a8641SAndroid Build Coastguard Workerdef ProcessGypDefinesItems(items): 22*635a8641SAndroid Build Coastguard Worker """Converts a list of strings to a list of key-value pairs.""" 23*635a8641SAndroid Build Coastguard Worker result = [] 24*635a8641SAndroid Build Coastguard Worker for item in items: 25*635a8641SAndroid Build Coastguard Worker tokens = item.split('=', 1) 26*635a8641SAndroid Build Coastguard Worker # Some GYP variables have hyphens, which we don't support. 27*635a8641SAndroid Build Coastguard Worker if len(tokens) == 2: 28*635a8641SAndroid Build Coastguard Worker result += [(tokens[0], tokens[1])] 29*635a8641SAndroid Build Coastguard Worker else: 30*635a8641SAndroid Build Coastguard Worker # No value supplied, treat it as a boolean and set it. Note that we 31*635a8641SAndroid Build Coastguard Worker # use the string '1' here so we have a consistent definition whether 32*635a8641SAndroid Build Coastguard Worker # you do 'foo=1' or 'foo'. 33*635a8641SAndroid Build Coastguard Worker result += [(tokens[0], '1')] 34*635a8641SAndroid Build Coastguard Worker return result 35*635a8641SAndroid Build Coastguard Worker 36*635a8641SAndroid Build Coastguard Worker 37*635a8641SAndroid Build Coastguard Workerdef GetSupplementalFiles(): 38*635a8641SAndroid Build Coastguard Worker return [] 39*635a8641SAndroid Build Coastguard Worker 40*635a8641SAndroid Build Coastguard Worker 41*635a8641SAndroid Build Coastguard Workerdef GetGypVars(_): 42*635a8641SAndroid Build Coastguard Worker """Returns a dictionary of all GYP vars.""" 43*635a8641SAndroid Build Coastguard Worker # GYP defines from the environment. 44*635a8641SAndroid Build Coastguard Worker env_items = ProcessGypDefinesItems( 45*635a8641SAndroid Build Coastguard Worker shlex.split(os.environ.get('GYP_DEFINES', ''))) 46*635a8641SAndroid Build Coastguard Worker 47*635a8641SAndroid Build Coastguard Worker # GYP defines from the command line. 48*635a8641SAndroid Build Coastguard Worker parser = argparse.ArgumentParser() 49*635a8641SAndroid Build Coastguard Worker parser.add_argument('-D', dest='defines', action='append', default=[]) 50*635a8641SAndroid Build Coastguard Worker cmdline_input_items = parser.parse_known_args()[0].defines 51*635a8641SAndroid Build Coastguard Worker cmdline_items = ProcessGypDefinesItems(cmdline_input_items) 52*635a8641SAndroid Build Coastguard Worker 53*635a8641SAndroid Build Coastguard Worker return dict(env_items + cmdline_items) 54*635a8641SAndroid Build Coastguard Worker 55*635a8641SAndroid Build Coastguard Worker 56*635a8641SAndroid Build Coastguard Workerdef main(): 57*635a8641SAndroid Build Coastguard Worker gyp_environment.SetEnvironment() 58*635a8641SAndroid Build Coastguard Worker 59*635a8641SAndroid Build Coastguard Worker print('Updating projects from gyp files...') 60*635a8641SAndroid Build Coastguard Worker sys.stdout.flush() 61*635a8641SAndroid Build Coastguard Worker sys.exit(gyp.main(sys.argv[1:] + [ 62*635a8641SAndroid Build Coastguard Worker '--check', 63*635a8641SAndroid Build Coastguard Worker '--no-circular-check', 64*635a8641SAndroid Build Coastguard Worker '-I', os.path.join(script_dir, 'common.gypi'), 65*635a8641SAndroid Build Coastguard Worker '-D', 'gyp_output_dir=out'])) 66*635a8641SAndroid Build Coastguard Worker 67*635a8641SAndroid Build Coastguard Workerif __name__ == '__main__': 68*635a8641SAndroid Build Coastguard Worker sys.exit(main()) 69