def include(name): from blade import build_manager if name.startswith('//'): dir = build_manager.instance.get_root_dir() name = name[2:] else: dir = build_manager.instance.get_current_source_path() exec_(os.path.join(dir, name), __current_globles, None)
def try_parse_file(self, filename): """load the configuration file and parse. """ try: self.current_file_name = filename if os.path.exists(filename): console.info('Loading config file "%s"' % filename) exec_(filename, _config_globals, None) except SystemExit: console.fatal('Parse error in config file %s' % filename) finally: self.current_file_name = ''
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(source_dir, source_dir, blade) old_current_source_path = blade.get_current_source_path() 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_(build_file, __current_globles, None) except SystemExit: console.error_exit('%s: Fatal error' % build_file) except: # pylint: disable=bare-except console.error_exit('Parse error in %s\n%s' % ( build_file, traceback.format_exc())) else: _report_not_exist(source_dir, build_file, blade) blade.set_current_source_path(old_current_source_path)