| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Helper script to generate file lists for documentation.gyp.""" | 6 """Helper script to generate file lists for documentation.gyp.""" |
| 7 | 7 |
| 8 import os | 8 import os |
| 9 import sys | 9 import sys |
| 10 import types | 10 import types |
| 11 | 11 |
| 12 | 12 |
| 13 GlobalsDict = { } | |
| 14 | |
| 15 | |
| 16 def UpdateGlobals(dict): | |
| 17 """Copies pairs from dict into GlobalDict.""" | |
| 18 for i, v in dict.items(): | |
| 19 GlobalsDict.__setitem__(i, v) | |
| 20 | |
| 21 | |
| 22 def AppendBasePath(folder, filenames): | 13 def AppendBasePath(folder, filenames): |
| 23 """Appends a base path to a ist of files""" | 14 """Appends a base path to a ist of files""" |
| 24 return [os.path.join(folder, filename) for filename in filenames] | 15 return [os.path.join(folder, filename) for filename in filenames] |
| 25 | 16 |
| 26 | 17 |
| 27 def GetCallingNamespaces(): | |
| 28 """Return the locals and globals for the function that called | |
| 29 into this module in the current call stack.""" | |
| 30 try: 1/0 | |
| 31 except ZeroDivisionError: | |
| 32 # Don't start iterating with the current stack-frame to | |
| 33 # prevent creating reference cycles (f_back is safe). | |
| 34 frame = sys.exc_info()[2].tb_frame.f_back | |
| 35 | |
| 36 # Find the first frame that *isn't* from this file | |
| 37 while frame.f_globals.get("__name__") == __name__: | |
| 38 frame = frame.f_back | |
| 39 | |
| 40 return frame.f_locals, frame.f_globals | |
| 41 | |
| 42 | |
| 43 def ComputeExports(exports): | |
| 44 """Compute a dictionary of exports given one of the parameters | |
| 45 to the Export() function or the exports argument to SConscript().""" | |
| 46 | |
| 47 loc, glob = GetCallingNamespaces() | |
| 48 | |
| 49 retval = {} | |
| 50 try: | |
| 51 for export in exports: | |
| 52 if isinstance(export, types.DictType): | |
| 53 retval.update(export) | |
| 54 else: | |
| 55 try: | |
| 56 retval[export] = loc[export] | |
| 57 except KeyError: | |
| 58 retval[export] = glob[export] | |
| 59 except KeyError, x: | |
| 60 raise Error, "Export of non-existent variable '%s'"%x | |
| 61 | |
| 62 return retval | |
| 63 | |
| 64 | |
| 65 def Export(*vars): | |
| 66 """Copies the named variables to GlobalDict.""" | |
| 67 for var in vars: | |
| 68 UpdateGlobals(ComputeExports(vars)) | |
| 69 | |
| 70 | |
| 71 def Import(filename): | |
| 72 """Imports a python file in a scope with 'Export' defined.""" | |
| 73 scope = {'__builtins__': globals()['__builtins__'], | |
| 74 'Export': Export} | |
| 75 file = open(filename, 'r') | |
| 76 exec file in scope | |
| 77 file.close() | |
| 78 | |
| 79 | |
| 80 def GetIdlFiles(): | 18 def GetIdlFiles(): |
| 81 idl_list_filename = os.path.join('..', 'plugin', 'idl_list.manifest') | 19 idl_list_filename = os.path.join('..', 'plugin', 'idl_list.manifest') |
| 82 idl_list_basepath = os.path.dirname(idl_list_filename) | 20 idl_list_basepath = os.path.dirname(idl_list_filename) |
| 83 Import(idl_list_filename) | 21 files = eval(open(idl_list_filename, "r").read()) |
| 84 idl_files = AppendBasePath(idl_list_basepath, GlobalsDict['O3D_IDL_SOURCES']) | 22 idl_files = AppendBasePath(idl_list_basepath, files) |
| 85 return idl_files | 23 return idl_files |
| 86 | 24 |
| 87 | 25 |
| 88 def GetJsFiles(): | 26 def GetJsFiles(): |
| 89 js_list_filename = os.path.join('..', 'samples', 'o3djs', 'js_list.manifest') | 27 js_list_filename = os.path.join('..', 'samples', 'o3djs', 'js_list.manifest') |
| 90 js_list_basepath = os.path.dirname(js_list_filename) | 28 js_list_basepath = os.path.dirname(js_list_filename) |
| 91 Import(js_list_filename) | 29 files = eval(open(js_list_filename, "r").read()) |
| 92 o3djs_files = AppendBasePath(js_list_basepath, GlobalsDict['O3D_JS_SOURCES']) | 30 o3djs_files = AppendBasePath(js_list_basepath, files) |
| 93 return o3djs_files | 31 return o3djs_files |
| 94 | 32 |
| 95 | 33 |
| 96 # Read in the manifest files (which are just really simple python files), | 34 # Read in the manifest files (which are just really simple python files), |
| 97 # and scrape out the file lists. | 35 # and scrape out the file lists. |
| 98 # TODO(gspencer): Since we no longer use the scons build, we should | 36 # TODO(gspencer): Since we no longer use the scons build, we should |
| 99 # rework this so that the lists are just python lists so we can just | 37 # rework this so that the lists are just python lists so we can just |
| 100 # do a simple eval instead of having to emulate scons import. | 38 # do a simple eval instead of having to emulate scons import. |
| 101 def main(argv): | 39 def main(argv): |
| 102 files = [] | 40 files = [] |
| 103 if argv[0] == '--js': | 41 if argv[0] == '--js': |
| 104 files = GetJsFiles() | 42 files = GetJsFiles() |
| 105 if argv[0] == '--idl': | 43 if argv[0] == '--idl': |
| 106 files = GetIdlFiles() | 44 files = GetIdlFiles() |
| 107 files.sort() | 45 files.sort() |
| 108 for file in files: | 46 for file in files: |
| 109 # gyp wants paths with slashes, not backslashes. | 47 # gyp wants paths with slashes, not backslashes. |
| 110 print file.replace("\\", "/") | 48 print file.replace("\\", "/") |
| 111 | 49 |
| 112 | 50 |
| 113 if __name__ == "__main__": | 51 if __name__ == "__main__": |
| 114 main(sys.argv[1:]) | 52 main(sys.argv[1:]) |
| OLD | NEW |