def __init__(self): generator.Generator.__init__(self) self.generators = [] self.phases = [ ] antprops = propstack.get_properties() # the name of the script to emit to do the building. self.BUILD_SCRIPT_NAME = antprops.getProperty("build-script", DEFAULT_BUILD_SCRIPT_NAME)
def ensureHandle(self): if self.handle == None: # parse the properties files that govern this build tree # to determine the build directory. Then put build.xml in # there. antprops = propstack.get_properties() build_outputs_dir = antprops.getProperty("outsubdir", "build") if not os.path.exists(build_outputs_dir): os.mkdir(build_outputs_dir) self.handle = open(os.path.join(build_outputs_dir, "build.xml"), "w")
def load_extensions(): """ If there's a stitch-ext/ dir in the root of the build tree, load any python files from there as modules and retain their environments to load into all targets files we process. """ global __extension_objs # Clear existing extensions __extension_objs = {} props = propstack.get_properties() ext_dir = props.getProperty("stitch-extensions") if ext_dir == None: return # no work to do. if not os.path.exists(ext_dir): return # no extensions in this project. # Add the extension dir as a module import source old_sys_path = sys.path sys.path.append(ext_dir) try: # import all those files as modules files = os.listdir(ext_dir) for file in files: if file.endswith(".py"): modname = file[:-3] # chop of the extension to get module name # Load and execute this module, and incorporate its env dictionary # into the master extension dictionary print "Loading module:", modname mod = __import__(modname) __extension_objs[modname] = mod finally: # restore the configured sys.path sys.path = old_sys_path
def getTopLevelScript(self, allTargets): """ Return the top-level script steps to put into the main 'build' script to run ant generated actions """ antprops = propstack.get_properties() build_dir = antprops.getProperty("outsubdir", "build") text = """ def formatProperties(): # return properties definition string from the user: global props propStr = "" for prop in props: propStr = propStr + "'" + prop + "' " return propStr ant_map = {} # run anything from ant def run_ant_target(ant_target): # Hack - Ant 1.7.1 on dev server doesn't seem to respect its # own classpath with respect to JUnit and ant.jar. So we're # hardcoding it in here. # TODO(aaron): Remove this hard-coded path dependency. if os.path.exists("/usr/share/ant/lib/ant.jar"): classpath = os.getenv("CLASSPATH", "") if len(classpath) > 0 and not classpath.endswith(":"): classpath = classpath + ":" classpath = classpath + "/usr/share/ant/lib/ant.jar" os.environ["CLASSPATH"] = classpath callString = "ant -f %(BUILD_DIR)s/build.xml " + formatProperties() + ant_target ret = os.system(callString) if ret > 0: sys.exit(1) def ant_phase(phase): run_ant_target(phase) sys.exit(0) def ant_topLevelAnt(phase, target): global ant_map, lookup_only, cwd, common_path if not target.startswith(os.sep): # This is not guaranteed to be an absolute target. # Try it relative to the build root (the build script's path). target_parts = target.split(":") abs_name_part = os.path.abspath(os.path.join(cwd, target_parts[0])) abs_target = abs_name_part[len(common_path):] if len(target_parts) > 1: abs_target += ":" + ":".join(target_parts[1:]) try: ant_target = ant_map[(phase, abs_target)] except KeyError: # Couldn't find that. Try it as an absolute. ant_target = ant_map[(phase, target)] else: # Definitely an absolute target. ant_target = ant_map[(phase, target)] if lookup_only: # lookup succeeded return True else: run_ant_target(ant_target) target_handlers.append(ant_topLevelAnt) phase_handlers.append(ant_phase) """ % { "BUILD_DIR" : build_dir } text = text + self.getBuildScriptMap(allTargets) return text