use of com.ibm.uma.om.Module in project openj9 by eclipse.
the class UMA method generate.
public void generate() throws UMAException {
Parser parser = new Parser(this);
if (!parser.parse()) {
return;
}
modules = parser.getModules();
platform.decorateModules(modules);
try {
Map<String, TemplateModel> map = new HashMap<String, TemplateModel>();
map.put(FREEMARKER_UMA, new com.ibm.uma.freemarker.UMA());
for (String tmp : templateLoader.getTemplates()) {
Template template = freemarkerConfig.getTemplate(tmp);
String filename = tmp.substring(0, tmp.lastIndexOf(".ftl"));
StringWriter writer = new StringWriter();
template.process(map, writer);
new FileAssistant(this.rootDirectory + filename, writer.getBuffer()).writeToDisk();
}
} catch (IOException e) {
throw new UMAException(e);
} catch (TemplateException e) {
throw new UMAException(e);
}
writeTargetInformationMacrosFile();
// top level module is the first in the list.
Module rootModule = null;
for (Module module : modules) {
if (module.isTopLevel()) {
if (rootModule != null) {
throw new UMAException("Error: more than one root module " + rootModule.getFullName() + " and " + module.getFullName());
}
rootModule = module;
}
}
if (rootModule == null) {
throw new UMAException("Error: no " + configuration.getMetadataFilename() + " found in the root directory " + getRootDirectory());
}
writeDirectoryMakefile(rootModule);
Logger.getLogger().println(Logger.InformationL1Log, "Complete");
}
use of com.ibm.uma.om.Module in project openj9 by eclipse.
the class UMA method writeMakefileForArtifact.
void writeMakefileForArtifact(Artifact artifact) throws UMAException {
if (!artifact.evaluate() || artifact.getType() == Artifact.TYPE_SUBDIR || artifact.getType() == Artifact.TYPE_REFERENCE || artifact.getType() == Artifact.TYPE_TARGET)
return;
Module module = artifact.getContainingModule();
String modulePath = new File(module.getModulePath()).getParent();
String makefileName = artifact.getMakefileFileName();
makefileName = modulePath + File.separator + makefileName;
platform.writePlatformSpecificFiles(artifact);
FileAssistant fa = new FileAssistant(makefileName);
StringBuffer buffer = fa.getStringBuffer();
buffer.append("# Makefile for '" + artifact.getMakefileName() + "'\n");
buffer.append(configuration.getMakefileCopyrightNotice());
String pathToRoot = determinePathToRoot(module);
buffer.append(UMA_PATH_TO_ROOT + "=" + pathToRoot + "\n");
buffer.append(OMR_DIR + "?=" + pathToRoot + "omr\n");
switch(artifact.getType()) {
// fall-thru
case Artifact.TYPE_BUNDLE:
case Artifact.TYPE_SHARED:
buffer.append("UMA_TARGET_TYPE=DLL\n");
break;
case Artifact.TYPE_EXECUTABLE:
buffer.append("UMA_TARGET_TYPE=EXE\n");
break;
case Artifact.TYPE_STATIC:
buffer.append("UMA_TARGET_TYPE=LIB\n");
break;
}
buffer.append("UMA_TARGET_NAME=" + artifact.getTargetNameWithScope() + "\n");
if (artifact.getTargetPath() != null) {
buffer.append("UMA_TARGET_PATH=" + UMA_PATH_TO_ROOT_VAR + artifact.getTargetPath() + "\n");
}
if (artifact.flagSet("isCPlusPlus")) {
buffer.append("UMA_IS_C_PLUS_PLUS=1\n");
}
platform.addArtifactSpecificMakefileInformation(artifact, buffer);
buffer.append("\ninclude " + UMA_PATH_TO_ROOT_VAR + UMA_MKCONSTANTS_PATH_FROM_ROOT + "\n\n");
writeMakefileIncludeLine(buffer, module, artifact);
writeMakefileLibraryLine(buffer, module, artifact);
buffer.append(platform.writeMakefileFlagsLine(artifact).toString());
writeMakefileObjectLine(buffer, module, artifact);
buffer.append(platform.writeMakefileExtras(artifact).toString());
writeMakefileStubs(buffer, module, artifact);
writeMakefileVPathInformation(buffer, module, artifact);
buffer.append(platform.writeMakefilePostscript(artifact).toString());
if (artifact.getCommands().isEmpty()) {
buffer.append("\ninclude " + UMA_PATH_TO_ROOT_VAR + UMA_TARGET_MAKEFILE_WITH_PATH + "\n");
} else {
/* Support custom recipes for building a target.
*
* If module.xml specifies <commands /> for this artifact, we will use the commands
* to build the on-disk artifact, instead of the rules in targets.mk.
*/
/* uma_macros.mk defines the names of the ondisk artifact and its dependencies */
buffer.append("include " + UMA_PATH_TO_ROOT_VAR + UMA_MACROS_PATH_FROM_ROOT + "\n\n");
/* Defines the default target.
*
* $($(target)_ondisk): $($(target)_dependencies)
* commands with type="all"
*/
buffer.append("$(" + artifact.getTargetNameWithScope() + "_ondisk): ");
buffer.append("$(" + artifact.getTargetNameWithScope() + "_dependencies)\n");
for (Command command : artifact.getCommands()) {
if (!command.evaluate() || command.getType() != Command.TYPE_ALL)
continue;
buffer.append("\t" + command.getCommand() + "\n");
}
buffer.append("\n");
/* Defines the clean target.
*
* clean:
* commands with type="clean"
*/
buffer.append("clean:\n");
for (Command command : artifact.getCommands()) {
if (!command.evaluate() || command.getType() != Command.TYPE_CLEAN)
continue;
buffer.append("\t" + command.getCommand() + "\n");
}
buffer.append("\n");
/* Defines the ddrgen target.
*
* ddrgen:
* commands with type="ddrgen"
*/
buffer.append("ddrgen:\n");
for (Command command : artifact.getCommands()) {
if (!command.evaluate() || command.getType() != Command.TYPE_DDRGEN)
continue;
buffer.append("\t" + command.getCommand() + "\n");
}
buffer.append("\n");
}
fa.writeToDisk();
}
use of com.ibm.uma.om.Module in project openj9 by eclipse.
the class UMA method writeTargetInformationMacrosFile.
void writeTargetInformationMacrosFile() throws UMAException {
/*
* Buffer for information about which libraries are static vs. shared
* and their locations on disk and references on the target and link lines.
*/
StringBuffer libLocations = new StringBuffer();
/*
* Buffer for target rules.
*/
StringBuffer targetRules = new StringBuffer();
/*
* A couple of hashtable to gather information an artifacts build dependencies.
*/
Hashtable<String, LinkedHashSet<String>> buildDependencies = new Hashtable<String, LinkedHashSet<String>>();
Hashtable<String, LinkedHashSet<String>> staticBuildDependencies = new Hashtable<String, LinkedHashSet<String>>();
for (Module module : modules) {
if (!module.evaluate())
continue;
// determine build dependencies
for (Artifact artifact : module.getArtifacts()) {
if (!artifact.evaluate())
continue;
switch(artifact.getType()) {
// Fall Through
case Artifact.TYPE_BUNDLE:
case Artifact.TYPE_SHARED:
libLocations.append(artifact.getTargetNameWithScope() + "_alllib=" + artifact.getTargetName() + "\n");
libLocations.append(artifact.getTargetNameWithScope() + "_sharedlib=" + artifact.getTargetName() + "\n");
platform.addLibraryLocationInformation(artifact, libLocations);
expandLibraryDependencies(artifact, libLocations);
break;
case Artifact.TYPE_STATIC:
libLocations.append(artifact.getTargetNameWithScope() + "_alllib=" + artifact.getTargetName() + "\n");
libLocations.append(artifact.getTargetNameWithScope() + "_staticlib=" + artifact.getTargetName() + "\n");
platform.addLibraryLocationInformation(artifact, libLocations);
expandLibraryDependencies(artifact, libLocations);
break;
case Artifact.TYPE_EXECUTABLE:
break;
}
switch(artifact.getType()) {
// Fall Through
case Artifact.TYPE_BUNDLE:
// Fall Through
case Artifact.TYPE_SHARED:
// Fall Through
case Artifact.TYPE_STATIC:
case // Fall Through
Artifact.TYPE_EXECUTABLE:
targetRules.append(artifact.getMakefileName() + "_build" + "=+$(MAKE) $(UMA_WINDOWS_PARRALLEL_HACK) -C " + UMA_PATH_TO_ROOT_VAR + artifact.getContainingModule().getFullName() + " -f " + artifact.getMakefileFileName() + "\n");
break;
}
addDependencies(artifact.getLibraries(), buildDependencies, artifact);
addDependencies(artifact.getStaticLinkLibraries(), staticBuildDependencies, artifact);
}
}
/*
* Write uma macros helper makefile. This file contains several variable definitions that allow
* easy reference to information about the artifacts. e.g.,
*/
File makelibDirectory = new File(UMA.getUma().getRootDirectory() + UMA_MAKELIB_DIR);
makelibDirectory.mkdir();
FileAssistant fa = new FileAssistant(UMA.getUma().getRootDirectory() + UMA_MACROS_PATH_FROM_ROOT);
StringBuffer buffer = fa.getStringBuffer();
buffer.append("# UMA Macro Helper Definition Makefile\n");
buffer.append(configuration.getMakefileCopyrightNotice());
buffer.append(libLocations.toString() + "\n\n\n");
for (String target : buildDependencies.keySet()) {
buffer.append("\n");
for (String dependency : buildDependencies.get(target)) {
buffer.append(target + "_dependencies+=$(findstring " + dependency + "," + UMA_TARGETS_IN_TREE_VAR + ")\n");
}
buffer.append("\n");
}
buffer.append("\n\nifdef UMA_STATIC_BUILD\n\n");
for (String target : staticBuildDependencies.keySet()) {
buffer.append("\n");
for (String dependency : staticBuildDependencies.get(target)) {
buffer.append(target + "_dependencies+=$(findstring " + dependency + "," + UMA_TARGETS_IN_TREE_VAR + ")\n");
}
buffer.append("\n");
}
buffer.append("\n\nendif\n\n");
buffer.append(targetRules.toString());
fa.writeToDisk();
}
use of com.ibm.uma.om.Module 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);
}
}
}
}
}
use of com.ibm.uma.om.Module in project openj9 by eclipse.
the class Parser method parse.
public boolean parse() throws UMAException {
Vector<String> moduleFilenames = new Vector<String>();
File rootDirectory = new File(generator.getRootDirectory());
addAllModulesFoundInDiretory(rootDirectory, moduleFilenames);
// parse it to determine directories to search for module.xml files.
moduleFilenames = getModuleFilenames(moduleFilenames);
// parse all found module.xml files.
for (String moduleXmlFilename : moduleFilenames) {
try {
Logger.getLogger().println(Logger.InformationL2Log, "Parsing " + moduleXmlFilename);
Document doc = parseFile(moduleXmlFilename);
Module module = ModuleParser.parse(doc, moduleXmlFilename);
modules.add(module);
} catch (SAXException e) {
throw new UMAException("Error: Module " + moduleXmlFilename + " failed to parse.", e);
} catch (IOException e) {
throw new UMAException("Error: " + e.getMessage(), e);
}
}
resolveModuleHierarchy();
return true;
}
Aggregations