3 # Copyright (c) 2014 Intel Corporation. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
13 def CreateResourceMap(r_java, res_map):
14 package_regex = re.compile('^package ([a-zA-Z0-9_\.]*);$')
17 for line in open(r_java, 'r').readlines():
19 package_match = package_regex.match(line)
21 package = package_match.group(1)
22 output_content.append(re.sub(r'\s*=\s*0x[0-9a-f]{8};', ';', line))
23 output_path = os.path.join(res_map, os.path.sep.join(package.split('.')))
24 if not os.path.isdir(output_path):
25 os.makedirs(output_path)
26 with open(os.path.join(output_path, 'R.java'), 'w') as output:
27 output.write(''.join(output_content))
31 parser = optparse.OptionParser()
32 info = ('The folder contains generated R.java')
33 parser.add_option('--gen-dir', help=info)
34 info = ('The folder to place resource maps')
35 parser.add_option('--resource-map-dir', help=info)
36 options, _ = parser.parse_args()
38 if not os.path.isdir(options.gen_dir):
40 for root, _, files in os.walk(options.gen_dir):
42 r_java = os.path.join(root, 'R.java')
43 CreateResourceMap(r_java, options.resource_map_dir)
46 if __name__ == '__main__':