1cef7893435aa41160dd1255c43cb8498279738ccChris Craik#!/usr/bin/env python 2cef7893435aa41160dd1255c43cb8498279738ccChris Craik# Copyright (c) 2014 The Chromium Authors. All rights reserved. 3cef7893435aa41160dd1255c43cb8498279738ccChris Craik# Use of this source code is governed by a BSD-style license that can be 4cef7893435aa41160dd1255c43cb8498279738ccChris Craik# found in the LICENSE file. 5cef7893435aa41160dd1255c43cb8498279738ccChris Craik 6cef7893435aa41160dd1255c43cb8498279738ccChris Craikimport argparse 7cef7893435aa41160dd1255c43cb8498279738ccChris Craikimport sys 8cef7893435aa41160dd1255c43cb8498279738ccChris Craikimport os 9cef7893435aa41160dd1255c43cb8498279738ccChris Craikimport json 10cef7893435aa41160dd1255c43cb8498279738ccChris Craik 11cef7893435aa41160dd1255c43cb8498279738ccChris Craik""" 12cef7893435aa41160dd1255c43cb8498279738ccChris CraikPrints the source path of the provided project name. 13cef7893435aa41160dd1255c43cb8498279738ccChris Craik 14cef7893435aa41160dd1255c43cb8498279738ccChris CraikThis utility loads the specified x_project.py from one of our standard 15cef7893435aa41160dd1255c43cb8498279738ccChris Craikmodule folders, constructs its project module, and prints the source paths that 16cef7893435aa41160dd1255c43cb8498279738ccChris Craikit uses. 17cef7893435aa41160dd1255c43cb8498279738ccChris Craik 18cef7893435aa41160dd1255c43cb8498279738ccChris CraikThis is used by the node_bootstrap.js to load the tracing code into node. 19cef7893435aa41160dd1255c43cb8498279738ccChris Craik""" 20cef7893435aa41160dd1255c43cb8498279738ccChris Craik 21cef7893435aa41160dd1255c43cb8498279738ccChris Craikdef _ToUpperCamelCase(name): 22cef7893435aa41160dd1255c43cb8498279738ccChris Craik in_parts = name.split('_') 23cef7893435aa41160dd1255c43cb8498279738ccChris Craik out_parts = [] 24cef7893435aa41160dd1255c43cb8498279738ccChris Craik for part in in_parts: 25cef7893435aa41160dd1255c43cb8498279738ccChris Craik out_part = part[0].upper() + part[1:] 26cef7893435aa41160dd1255c43cb8498279738ccChris Craik out_parts.append(out_part) 27cef7893435aa41160dd1255c43cb8498279738ccChris Craik return ''.join(out_parts) 28cef7893435aa41160dd1255c43cb8498279738ccChris Craik 29cef7893435aa41160dd1255c43cb8498279738ccChris Craikdef _RelPathToUnixPath(p): 30cef7893435aa41160dd1255c43cb8498279738ccChris Craik return p.replace(os.sep, '/') 31cef7893435aa41160dd1255c43cb8498279738ccChris Craik 32cef7893435aa41160dd1255c43cb8498279738ccChris Craikdef Main(args): 33cef7893435aa41160dd1255c43cb8498279738ccChris Craik parser = argparse.ArgumentParser( 34cef7893435aa41160dd1255c43cb8498279738ccChris Craik usage='%(prog)s project_name', 35cef7893435aa41160dd1255c43cb8498279738ccChris Craik epilog='Prints the source paths for the provided catapult project\n') 36cef7893435aa41160dd1255c43cb8498279738ccChris Craik parser.add_argument('--source-paths', action='store_true') 37cef7893435aa41160dd1255c43cb8498279738ccChris Craik parser.add_argument('--headless-test-module-filenames', action='store_true') 38cef7893435aa41160dd1255c43cb8498279738ccChris Craik parser.add_argument('project_name', nargs=1) 39cef7893435aa41160dd1255c43cb8498279738ccChris Craik args = parser.parse_args(args) 40cef7893435aa41160dd1255c43cb8498279738ccChris Craik 41cef7893435aa41160dd1255c43cb8498279738ccChris Craik catapult_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 42cef7893435aa41160dd1255c43cb8498279738ccChris Craik '..')) 43cef7893435aa41160dd1255c43cb8498279738ccChris Craik 44cef7893435aa41160dd1255c43cb8498279738ccChris Craik project_name = args.project_name[0] 45cef7893435aa41160dd1255c43cb8498279738ccChris Craik project_path = os.path.join(catapult_path, project_name) 46cef7893435aa41160dd1255c43cb8498279738ccChris Craik sys.path.append(project_path) 47cef7893435aa41160dd1255c43cb8498279738ccChris Craik 48cef7893435aa41160dd1255c43cb8498279738ccChris Craik project_module_name = project_name + '_project' 49cef7893435aa41160dd1255c43cb8498279738ccChris Craik try: 50cef7893435aa41160dd1255c43cb8498279738ccChris Craik project_module = __import__(project_module_name, fromlist=[True]) 51cef7893435aa41160dd1255c43cb8498279738ccChris Craik except: 52cef7893435aa41160dd1255c43cb8498279738ccChris Craik sys.stderr.write('Could not import %s from %s' % (project_module_name, 53cef7893435aa41160dd1255c43cb8498279738ccChris Craik project_path)) 54cef7893435aa41160dd1255c43cb8498279738ccChris Craik return 1 55cef7893435aa41160dd1255c43cb8498279738ccChris Craik 56cef7893435aa41160dd1255c43cb8498279738ccChris Craik project_module.UpdateSysPathIfNeeded() 57cef7893435aa41160dd1255c43cb8498279738ccChris Craik 58cef7893435aa41160dd1255c43cb8498279738ccChris Craik class_name = _ToUpperCamelCase(project_name) + 'Project' 59cef7893435aa41160dd1255c43cb8498279738ccChris Craik 60cef7893435aa41160dd1255c43cb8498279738ccChris Craik try: 61cef7893435aa41160dd1255c43cb8498279738ccChris Craik project_class = project_module.__dict__[class_name] 62cef7893435aa41160dd1255c43cb8498279738ccChris Craik except: 63cef7893435aa41160dd1255c43cb8498279738ccChris Craik sys.stderr.write('Could not find %s in %s' % (class_name, 64cef7893435aa41160dd1255c43cb8498279738ccChris Craik project_module_name)) 65cef7893435aa41160dd1255c43cb8498279738ccChris Craik return 1 66cef7893435aa41160dd1255c43cb8498279738ccChris Craik 67cef7893435aa41160dd1255c43cb8498279738ccChris Craik project = project_class() 68cef7893435aa41160dd1255c43cb8498279738ccChris Craik 69cef7893435aa41160dd1255c43cb8498279738ccChris Craik if args.source_paths: 70cef7893435aa41160dd1255c43cb8498279738ccChris Craik print json.dumps(project.source_paths) 71cef7893435aa41160dd1255c43cb8498279738ccChris Craik 72cef7893435aa41160dd1255c43cb8498279738ccChris Craik if args.headless_test_module_filenames: 73cef7893435aa41160dd1255c43cb8498279738ccChris Craik headless_test_module_filenames = ['/' + _RelPathToUnixPath(x) 74cef7893435aa41160dd1255c43cb8498279738ccChris Craik for x in project.FindAllD8TestModuleRelPaths()] 75cef7893435aa41160dd1255c43cb8498279738ccChris Craik headless_test_module_filenames.sort() 76cef7893435aa41160dd1255c43cb8498279738ccChris Craik print json.dumps(headless_test_module_filenames) 77cef7893435aa41160dd1255c43cb8498279738ccChris Craik 78cef7893435aa41160dd1255c43cb8498279738ccChris Craik 79cef7893435aa41160dd1255c43cb8498279738ccChris Craikif __name__ == '__main__': 80cef7893435aa41160dd1255c43cb8498279738ccChris Craik sys.exit(Main(sys.argv[1:]))