use of com.ibm.uma.om.SubdirArtifact in project openj9 by eclipse.
the class UMA method writeDirectoryMakefile.
// This function takes a module and creates a makefile for the directory,
// then recursively calls this function on all sub-modules.
void writeDirectoryMakefile(Module module) throws UMAException {
if (!module.evaluate())
return;
String modulePath = new File(module.getModulePath()).getParent();
Logger.getLogger().println(Logger.InformationL2Log, "Producing makefile(s) for " + modulePath);
for (Artifact artifact : module.getArtifacts()) {
writeMakefileForArtifact(artifact);
}
if (module.requiresDispatchMakefile()) {
// There needs to be a dispatch makefile
String makefileName = modulePath + File.separator + "makefile";
StringBuffer buffer = new StringBuffer();
FileAssistant fa = new FileAssistant(makefileName, buffer);
buffer.append(configuration.getMakefileCopyrightNotice());
String pathToRoot = determinePathToRoot(module);
Vector<String> targets = new Vector<String>();
Vector<String> specialTargets = new Vector<String>();
for (Artifact artifact : module.getAllArtifactsInTree()) {
if (!artifact.evaluate())
continue;
if (artifact.getType() == Artifact.TYPE_TARGET) {
if (artifact.includeInAllTarget()) {
/*
* The separation of targets into targets and specialTargets
* is being done to allow the 'TARGET' type artifacts to be built first.
* This is a weak way of saying that the whole system is dependent on
* these targets without having to add the dependency to each and every
* artifact.
*
* This only works when not using -j on gmake and because
* gmake will do the targets in the order they are on the dependency line.
*
*/
specialTargets.add(artifact.getMakefileName());
}
} else {
if (artifact.includeInAllTarget()) {
targets.add(artifact.getMakefileName());
}
}
}
buffer.append(UMA_PATH_TO_ROOT + "=" + pathToRoot + "\n");
buffer.append(OMR_DIR + "?=" + pathToRoot + "omr\n");
StringBuffer targetsInTreeBuffer = new StringBuffer();
LineWrapMakefileDirective lwmd = new LineWrapMakefileDirective(targetsInTreeBuffer);
targetsInTreeBuffer.append(UMA_TARGETS_IN_TREE + "=");
for (String target : specialTargets) {
lwmd.addItem(target);
}
for (String target : targets) {
lwmd.addItem(target);
}
buffer.append(targetsInTreeBuffer.toString());
buffer.append("\n\ninclude " + UMA_PATH_TO_ROOT_VAR + UMA_MKCONSTANTS_PATH_FROM_ROOT + "\n");
buffer.append("include " + UMA_PATH_TO_ROOT_VAR + UMA_MACROS_PATH_FROM_ROOT + "\n\n");
buffer.append(phasePrefix + "all: " + UMA_TARGETS_IN_TREE_VAR + "\n\n");
buffer.append("clean: $(addprefix clean_," + UMA_TARGETS_IN_TREE_VAR + ")\n\n");
buffer.append("ddrgen: $(addprefix ddrgen_," + UMA_TARGETS_IN_TREE_VAR + ")\n\n");
buffer.append("static: UMA_STATIC_BUILD=1\n" + " export UMA_STATIC_BUILD\n\n" + "static:\n" + " $(MAKE) -f makefile\n\n\n");
for (int phase = 0; phase < configuration.numberOfPhases(); phase++) {
Vector<String> phaseTargets = new Vector<String>();
Vector<String> specialPhaseTargets = new Vector<String>();
for (Artifact artifact : module.getAllArtifactsInTree()) {
if (!artifact.evaluate())
continue;
if (!artifact.isInPhase(phase))
continue;
if (artifact.getType() == Artifact.TYPE_TARGET) {
/*
* The separation of targets into phaseTargets and specialPhaseTargets
* is being done to allow the 'TARGET' type artifacts to be built first.
* This is a weak way of saying that the whole system is dependent on
* these targets without having to add the dependency to each and every
* artifact.
*
* This only works when not using -j on gmake and because
* gmake will do the targets in the order they are on the dependency line.
*
*/
specialPhaseTargets.add(artifact.getMakefileName());
} else {
phaseTargets.add(artifact.getMakefileName());
}
}
buffer.append(phasePrefix + "phase_" + configuration.phaseName(phase) + ":");
StringBuffer targetsInPhaseBuffer = new StringBuffer();
lwmd = new LineWrapMakefileDirective(targetsInPhaseBuffer);
for (String target : specialPhaseTargets) {
lwmd.addItem(target);
}
for (String target : phaseTargets) {
lwmd.addItem(target);
}
buffer.append(targetsInPhaseBuffer.toString() + "\n");
}
buffer.append("\n");
for (Artifact artifact : module.getAllArtifactsInTree()) {
if (!artifact.evaluate())
continue;
switch(artifact.getType()) {
case Artifact.TYPE_SUBDIR:
// to glue the tree together.
break;
case Artifact.TYPE_TARGET:
buffer.append("clean_" + artifact.getMakefileName() + ":\n");
for (Command command : artifact.getCommands()) {
if (!command.evaluate() || command.getType() != Command.TYPE_CLEAN)
continue;
buffer.append("\t" + command.getCommand() + "\n");
}
buffer.append("\n");
buffer.append("ddrgen_" + artifact.getMakefileName() + ":\n");
for (Command command : artifact.getCommands()) {
if (!command.evaluate() || command.getType() != Command.TYPE_DDRGEN)
continue;
buffer.append("\t" + command.getCommand() + "\n");
}
buffer.append("\n");
buffer.append(artifact.getMakefileName() + ":");
for (Dependency dependency : artifact.getDependendies()) {
if (!dependency.evaluate())
continue;
buffer.append(" " + dependency.getDependency());
}
buffer.append("\n");
for (Command command : artifact.getCommands()) {
if (!command.evaluate() || command.getType() != Command.TYPE_ALL)
continue;
buffer.append("\t" + command.getCommand() + "\n");
}
buffer.append("\n");
break;
default:
buffer.append("clean_" + artifact.getMakefileName() + ":\n\t$(" + artifact.getMakefileName() + "_build) clean\n\n");
buffer.append("ddrgen_" + artifact.getMakefileName() + ":\n\t$(" + artifact.getMakefileName() + "_build) ddrgen\n\n");
buffer.append(artifact.getMakefileName() + ": $(" + artifact.getMakefileName() + "_dependencies)\n\t$(" + artifact.getMakefileName() + "_build)\n\n");
break;
}
}
if (module.isTopLevel()) {
platform.writeTopLevelTargets(buffer);
}
buffer.append(".PHONY: all clean ddrgen");
StringBuffer phonyTargetsBuffer = new StringBuffer();
lwmd = new LineWrapMakefileDirective(phonyTargetsBuffer);
for (String phonyTarget : specialTargets) {
lwmd.addItem(phonyTarget);
lwmd.addItem(" clean_" + phonyTarget);
}
for (String phonyTarget : targets) {
lwmd.addItem(phonyTarget);
lwmd.addItem(" clean_" + phonyTarget);
}
buffer.append(phonyTargetsBuffer.toString() + "\n");
fa.writeToDisk();
}
for (Artifact artifact : module.getArtifacts()) {
if (artifact.getType() == Artifact.TYPE_SUBDIR) {
SubdirArtifact subdirArtifact = (SubdirArtifact) artifact;
writeDirectoryMakefile(subdirArtifact.getSubdirModule());
}
}
}
use of com.ibm.uma.om.SubdirArtifact in project openj9 by eclipse.
the class Parser method resolveModuleHierarchy.
void resolveModuleHierarchy() throws UMAException {
generator.validateArtifactLocations();
// Make sure that all modules have parents all the way to the root.
// If a hole is found and a module with artifacts of type subdir.
// System.out.println("resolveModuleHierarchy");
boolean modulesToBeChecked = true;
while (modulesToBeChecked) {
// root/gc/modron/base/module.xml is 'gc/modron/base'
for (Module module : modules) {
if (!module.evaluate())
continue;
addModuleByLogicalFullname(module);
}
Vector<Module> newModules = new Vector<Module>();
modulesToBeChecked = false;
for (Module module : modules) {
if (!module.evaluate())
continue;
// ensure each parent of a module exists.
if (module.isTopLevel())
continue;
String[] parents = module.getParents();
for (int depth = 0; depth < module.getModuleDepth(); depth++) {
Module parentMod = getModuleByLogicalFullname(parents[depth]);
if (parentMod == null) {
// need to create the parent
String moduleXmlFilename = UMA.getUma().getRootDirectory();
for (int d = 1; d <= depth; d++) {
moduleXmlFilename = moduleXmlFilename + module.moduleNameAtDepth(d) + "/";
}
moduleXmlFilename = moduleXmlFilename + getConfiguration().getMetadataFilename();
parentMod = new Module(moduleXmlFilename);
addModuleByLogicalFullname(parentMod);
newModules.add(parentMod);
modulesToBeChecked = true;
}
}
}
modules.addAll(newModules);
for (Module module : modules) {
if (!module.evaluate())
continue;
// ensure each parent of a module exists.
if (module.isTopLevel())
continue;
String[] parents = module.getParents();
for (int depth = 0; depth < module.getModuleDepth(); depth++) {
Module parentMod = getModuleByLogicalFullname(parents[depth]);
boolean found = false;
String child = module.moduleNameAtDepth(depth + 1);
for (Artifact artifact : parentMod.getArtifacts()) {
if (!artifact.evaluate())
continue;
if (artifact.getType() == Artifact.TYPE_SUBDIR) {
if (artifact.getTargetName().equalsIgnoreCase(child)) {
found = true;
}
}
}
if (!found && !child.equalsIgnoreCase(UMA.getUma().getConfiguration().getMetadataFilename())) {
Module subdirModule = getModuleByLogicalFullname(parentMod.getLogicalFullName() + "/" + child);
Artifact artifact = new SubdirArtifact(child, subdirModule, parentMod);
parentMod.addArtifact(artifact);
}
}
}
}
}
Aggregations