def _load_extension(name): """Load symbols from file or obtain from loaded cache.""" full_path = _expand_include_path(name) if full_path in __loaded_extension_info: return __loaded_extension_info[full_path] if not os.path.isfile(full_path): console.diagnose(_current_source_location(), 'error', 'File "%s" does not exist' % name) return {} # The symbols in the current context should be invisible to the extension, # make an isolated symbol set to implement this approach. origin_globals = build_rules.get_all() extension_globals = origin_globals.copy() exec_file(full_path, extension_globals, None) # Extract new symbols result = {} for symbol, value in extension_globals.items(): if symbol.startswith('_'): continue if symbol in origin_globals and value is origin_globals[symbol]: continue if isinstance(value, types.ModuleType): continue result[symbol] = value __loaded_extension_info[full_path] = result return result
def __load_build_file(source_dir, blade): """ Load and execute the BUILD file, which is a Python script, in source_dir. Statements in BUILD depends on global variable current_source_dir, and will register build target/rules into global variables target_database. Report error and exit if path/BUILD does NOT exist. """ if not os.path.isdir(source_dir): _report_not_exist('Directory', source_dir, source_dir, blade) return False old_current_source_path = blade.get_current_source_path() try: blade.set_current_source_path(source_dir) build_file = os.path.join(source_dir, 'BUILD') if os.path.isfile(build_file): try: # The magic here is that a BUILD file is a Python script, # which can be loaded and executed by execfile(). global __current_globals __current_globals = build_rules.get_all() exec_file(build_file, __current_globals, None) return True except SystemExit: console.fatal('%s: Fatal error' % build_file) except: # pylint: disable=bare-except console.fatal('Parse error in %s\n%s' % (build_file, traceback.format_exc())) else: _report_not_exist('File', build_file, source_dir, blade) finally: blade.set_current_source_path(old_current_source_path) return False
def include(name): """Include another file into current BUILD file""" full_path = _expand_include_path(name) if not os.path.isfile(full_path): console.diagnose(_current_source_location(), 'error', 'File "%s" does not exist' % name) return exec_file(full_path, __current_globals, None)
def include(name): from blade import build_manager # pylint: disable=import-outside-toplevel if name.startswith('//'): dir = build_manager.instance.get_root_dir() name = name[2:] else: dir = build_manager.instance.get_current_source_path() exec_file(os.path.join(dir, name), __current_globles, None)
def _load_build_file(source_dir, processed_source_dirs, blade): """Load the BUILD and place the targets into database. Invoked by _load_targets. Load and execute the BUILD file, which is a Python script, in source_dir. Statements in BUILD depends on global variable current_source_dir, and will register build target/rules into global variables target_database. Report error and exit if path/BUILD does NOT exist. The parameters processed_source_dirs refers to a set defined in the caller and used to avoid duplicated execution of BUILD files. """ source_dir = os.path.normpath(source_dir) # TODO(yiwang): the character '#' is a magic value. if source_dir in processed_source_dirs or source_dir == '#': return processed_source_dirs.add(source_dir) if not os.path.exists(source_dir): _report_not_exist('Directory', source_dir, source_dir, blade) return old_current_source_path = blade.get_current_source_path() try: blade.set_current_source_path(source_dir) build_file = os.path.join(source_dir, 'BUILD') if os.path.exists(build_file) and not os.path.isdir(build_file): try: # The magic here is that a BUILD file is a Python script, # which can be loaded and executed by execfile(). global __current_globles __current_globles = build_rules.get_all() exec_file(build_file, __current_globles, None) except SystemExit: console.fatal('%s: Fatal error' % build_file) except: # pylint: disable=bare-except console.fatal('Parse error in %s\n%s' % ( build_file, traceback.format_exc())) else: _report_not_exist('File', build_file, source_dir, blade) finally: blade.set_current_source_path(old_current_source_path)
def _load_extension(name): """Load symbols from file or obtain from loaded cache.""" full_path = _expand_include_path(name) if full_path in __loaded_extension_info: return __loaded_extension_info[full_path] # The symbols in the current context should be invisible to the extension, # make an isolated symbol set to implement this approach. origin_globals = build_rules.get_all() extension_globals = origin_globals.copy() exec_file(full_path, extension_globals, None) # Extract new symbols result = {} for symbol, value in extension_globals.items(): if symbol.startswith('_'): continue if symbol in origin_globals and value is origin_globals[symbol]: continue if type(value) is types.ModuleType: continue result[symbol] = value __loaded_extension_info[full_path] = result return result
def include(name): """Include another file into current BUILD file""" exec_file(_expand_include_path(name), __current_globals, None)