Search in sources :

Example 1 with Dependency

use of com.ibm.uma.om.Dependency in project openj9 by eclipse.

the class UMA method addDependencies.

void addDependencies(Vector<Library> libraries, Hashtable<String, LinkedHashSet<String>> buildDependencies, Artifact artifact) throws UMAException {
    String target = artifact.getMakefileName();
    LinkedHashSet<String> deps = buildDependencies.get(target);
    if (deps == null) {
        deps = new LinkedHashSet<String>();
        buildDependencies.put(target, deps);
    }
    for (Library library : libraries) {
        if (library.evaluate()) {
            if (library.getType() != Library.TYPE_BUILD)
                continue;
            Artifact libArtifact = getArtifact(library.getName());
            if (libArtifact == null)
                continue;
            String libName = libArtifact.getMakefileName();
            if (libArtifact.isInBundle()) {
                Artifact bundle = getBundleArtifact(libArtifact.getBundle());
                if (artifact != bundle) {
                    /* If we are not dealing with the bundle itself, then substitute the 
						 * bundle name for the library. */
                    libName = bundle.getMakefileName();
                }
            }
            if (!deps.contains(libName) && !libName.equalsIgnoreCase(target)) {
                deps.add(libName);
            }
        }
    }
    for (Dependency artifactDependency : artifact.getDependendies()) {
        if (artifactDependency.evaluate()) {
            String dependency = artifactDependency.getDependency();
            if (!deps.contains(dependency) && !dependency.equalsIgnoreCase(target)) {
                deps.add(dependency);
            }
        }
    }
}
Also used : Library(com.ibm.uma.om.Library) Dependency(com.ibm.uma.om.Dependency) SubdirArtifact(com.ibm.uma.om.SubdirArtifact) Artifact(com.ibm.uma.om.Artifact)

Example 2 with Dependency

use of com.ibm.uma.om.Dependency 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());
        }
    }
}
Also used : FileAssistant(com.ibm.uma.util.FileAssistant) Command(com.ibm.uma.om.Command) SubdirArtifact(com.ibm.uma.om.SubdirArtifact) Dependency(com.ibm.uma.om.Dependency) File(java.io.File) Vector(java.util.Vector) SubdirArtifact(com.ibm.uma.om.SubdirArtifact) Artifact(com.ibm.uma.om.Artifact)

Example 3 with Dependency

use of com.ibm.uma.om.Dependency in project openj9 by eclipse.

the class ArtifactParser method parse.

public static Artifact parse(Node artifactNode, Module module) throws UMAException {
    Artifact artifact = new Artifact(module);
    NodeList nodeList = artifactNode.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        String nodeName = node.getLocalName();
        if (nodeName == null)
            continue;
        if (nodeName.equalsIgnoreCase("description")) {
            NodeList descChildren = node.getChildNodes();
            Node descChild = descChildren.item(0);
            artifact.setDescription(descChild.getNodeValue());
        } else if (nodeName.equalsIgnoreCase("options")) {
            NodeList optionsNodeList = node.getChildNodes();
            for (int j = 0; j < optionsNodeList.getLength(); j++) {
                Node optionItem = optionsNodeList.item(j);
                NamedNodeMap attributes = optionItem.getAttributes();
                if (attributes == null)
                    continue;
                Option option = OptionParser.parse(optionItem, artifact.getContainingFile());
                artifact.addOption(option);
            }
        } else if (nodeName.equalsIgnoreCase("phase")) {
            NodeList phaseChildren = node.getChildNodes();
            for (int j = 0; j < phaseChildren.getLength(); j++) {
                Node phasesNode = phaseChildren.item(j);
                String phaselist = phasesNode.getNodeValue();
                String[] phases = phaselist.split("\\s");
                for (int k = 0; k < phases.length; k++) {
                    try {
                        artifact.setPhase(UMA.getUma().getConfiguration().phaseFromString(phases[k]), true);
                    } catch (UMABadPhaseNameException e) {
                        throw new UMAException("in file: " + artifact.getContainingFile(), e);
                    }
                }
            }
        } else if (nodeName.equalsIgnoreCase("includes")) {
            NodeList includesNodeList = node.getChildNodes();
            for (int j = 0; j < includesNodeList.getLength(); j++) {
                Node includeItem = includesNodeList.item(j);
                NamedNodeMap attributes = includeItem.getAttributes();
                if (attributes == null)
                    continue;
                Include include = new Include(artifact.getContainingFile());
                include.setPath(attributes.getNamedItem("path").getNodeValue());
                include.setType(attributes.getNamedItem("type").getNodeValue());
                artifact.addInclude(include);
                Parser.populatePredicateList(includeItem.getChildNodes(), include);
            }
        } else if (nodeName.equalsIgnoreCase("commands")) {
            NodeList commandsNodeList = node.getChildNodes();
            for (int j = 0; j < commandsNodeList.getLength(); j++) {
                Node commandItem = commandsNodeList.item(j);
                NamedNodeMap attributes = commandItem.getAttributes();
                if (attributes == null)
                    continue;
                Command command = new Command(artifact.getContainingFile());
                command.setCommand(attributes.getNamedItem("line").getNodeValue());
                command.setType(attributes.getNamedItem("type").getNodeValue());
                artifact.addCommand(command);
                Parser.populatePredicateList(commandItem.getChildNodes(), command);
            }
        } else if (nodeName.equalsIgnoreCase("dependencies")) {
            NodeList dependenciesNodeList = node.getChildNodes();
            for (int j = 0; j < dependenciesNodeList.getLength(); j++) {
                Node dependencyItem = dependenciesNodeList.item(j);
                NamedNodeMap attributes = dependencyItem.getAttributes();
                if (attributes == null)
                    continue;
                Dependency dependency = new Dependency(artifact.getContainingFile());
                dependency.setDependency(attributes.getNamedItem("name").getNodeValue());
                artifact.addDependency(dependency);
                Parser.populatePredicateList(dependencyItem.getChildNodes(), dependency);
            }
        } else if (nodeName.equalsIgnoreCase("libraries")) {
            NodeList linkNodeList = node.getChildNodes();
            for (int j = 0; j < linkNodeList.getLength(); j++) {
                Node linkItem = linkNodeList.item(j);
                if (linkItem.getNodeName().equalsIgnoreCase("library")) {
                    Library library = LibraryParser.parse(linkItem, artifact.getContainingFile());
                    artifact.addLibrary(library);
                }
            }
        } else if (nodeName.equalsIgnoreCase("static-link-libraries")) {
            NodeList linkNodeList = node.getChildNodes();
            for (int j = 0; j < linkNodeList.getLength(); j++) {
                Node linkItem = linkNodeList.item(j);
                if (linkItem.getNodeName().equalsIgnoreCase("library")) {
                    Library library = LibraryParser.parse(linkItem, artifact.getContainingFile());
                    artifact.addStaticLinkLibrary(library);
                }
            }
        } else if (nodeName.equalsIgnoreCase("objects")) {
            NodeList linkNodeList = node.getChildNodes();
            for (int j = 0; j < linkNodeList.getLength(); j++) {
                Node linkItem = linkNodeList.item(j);
                if (linkItem.getNodeName().equalsIgnoreCase("group") || linkItem.getNodeName().equalsIgnoreCase("object")) {
                    Object object = ObjectParser.parse(linkNodeList.item(j), artifact.getContainingFile());
                    artifact.addObject(object);
                }
            }
        } else if (nodeName.equalsIgnoreCase("vpaths")) {
            NodeList vpathsNodeList = node.getChildNodes();
            for (int j = 0; j < vpathsNodeList.getLength(); j++) {
                Node vpathItem = vpathsNodeList.item(j);
                if (vpathItem.getNodeName().equalsIgnoreCase("vpath")) {
                    VPath vpath = VPathParser.parse(vpathItem, artifact.getContainingFile());
                    artifact.addVPath(vpath);
                }
            }
        } else if (nodeName.equalsIgnoreCase("makefilestubs")) {
            NodeList mfsNodeList = node.getChildNodes();
            for (int j = 0; j < mfsNodeList.getLength(); j++) {
                Node mfsItem = mfsNodeList.item(j);
                if (mfsItem.getNodeName().equalsIgnoreCase("makefilestub")) {
                    NamedNodeMap attributes = mfsItem.getAttributes();
                    Node dataNode = attributes.getNamedItem("data");
                    MakefileStub makefileStub = new MakefileStub(dataNode.getNodeValue(), artifact.getContainingFile());
                    artifact.addMakefileStub(makefileStub);
                    Parser.populatePredicateList(mfsItem.getChildNodes(), makefileStub);
                }
            }
        } else if (nodeName.equalsIgnoreCase("exports")) {
            NodeList exportsNodeList = node.getChildNodes();
            for (int j = 0; j < exportsNodeList.getLength(); j++) {
                Node exportNode = exportsNodeList.item(j);
                if (exportNode.getNodeName().equalsIgnoreCase("group")) {
                    Export group = ExportParser.parse(exportNode, artifact.getContainingFile());
                    artifact.addExport(group);
                    group.setType(Export.TYPE_GROUP);
                } else if (exportNode.getNodeName().equalsIgnoreCase("export")) {
                    Export group = ExportParser.parse(exportNode, artifact.getContainingFile());
                    artifact.addExport(group);
                    group.setType(Export.TYPE_FUNCTION);
                }
            }
        } else if (nodeName.equalsIgnoreCase("flags")) {
            NodeList flagsNodeList = node.getChildNodes();
            for (int j = 0; j < flagsNodeList.getLength(); j++) {
                Node item = flagsNodeList.item(j);
                Flag f = FlagParser.parse(item, artifact.getContainingFile());
                if (f != null) {
                    artifact.addFlag(f);
                }
            }
        }
    }
    NamedNodeMap attributes = artifactNode.getAttributes();
    Node nameNode = attributes.getNamedItem("name");
    artifact.setName(nameNode.getNodeValue());
    Node typeNode = attributes.getNamedItem("type");
    artifact.setType(typeNode.getNodeValue());
    Node bundleNode = attributes.getNamedItem("bundle");
    if (bundleNode != null) {
        artifact.setBundle(bundleNode.getNodeValue());
    }
    Node scopeNode = attributes.getNamedItem("scope");
    if (scopeNode != null) {
        artifact.setScope(scopeNode.getNodeValue());
    }
    Node includeInAllTargetNode = attributes.getNamedItem("all");
    if (includeInAllTargetNode.getNodeValue().equalsIgnoreCase("true")) {
        artifact.setIncludeInAllTarget(true);
    } else {
        artifact.setIncludeInAllTarget(false);
    }
    Node loadgroupNode = attributes.getNamedItem("loadgroup");
    if (loadgroupNode != null) {
        artifact.setLoadgroup(loadgroupNode.getNodeValue());
    }
    Node buildLocal = attributes.getNamedItem("buildlocal");
    if (buildLocal.getNodeValue().equalsIgnoreCase("true")) {
        artifact.setBuildLocal(true);
    }
    Node appendReleaseNode = attributes.getNamedItem("appendrelease");
    if (appendReleaseNode.getNodeValue().equalsIgnoreCase("true")) {
        artifact.setAppendRelease(true);
    }
    Node consoleNode = attributes.getNamedItem("console");
    if (consoleNode.getNodeValue().equalsIgnoreCase("false")) {
        artifact.setConsoleApplication(false);
    } else {
        artifact.setConsoleApplication(true);
    }
    Parser.populatePredicateList(nodeList, artifact);
    return artifact;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) MakefileStub(com.ibm.uma.om.MakefileStub) Include(com.ibm.uma.om.Include) UMAException(com.ibm.uma.UMAException) Dependency(com.ibm.uma.om.Dependency) Flag(com.ibm.uma.om.Flag) Artifact(com.ibm.uma.om.Artifact) Command(com.ibm.uma.om.Command) Export(com.ibm.uma.om.Export) Option(com.ibm.uma.om.Option) Object(com.ibm.uma.om.Object) VPath(com.ibm.uma.om.VPath) Library(com.ibm.uma.om.Library) UMABadPhaseNameException(com.ibm.uma.UMABadPhaseNameException)

Aggregations

Artifact (com.ibm.uma.om.Artifact)3 Dependency (com.ibm.uma.om.Dependency)3 Command (com.ibm.uma.om.Command)2 Library (com.ibm.uma.om.Library)2 SubdirArtifact (com.ibm.uma.om.SubdirArtifact)2 UMABadPhaseNameException (com.ibm.uma.UMABadPhaseNameException)1 UMAException (com.ibm.uma.UMAException)1 Export (com.ibm.uma.om.Export)1 Flag (com.ibm.uma.om.Flag)1 Include (com.ibm.uma.om.Include)1 MakefileStub (com.ibm.uma.om.MakefileStub)1 Object (com.ibm.uma.om.Object)1 Option (com.ibm.uma.om.Option)1 VPath (com.ibm.uma.om.VPath)1 FileAssistant (com.ibm.uma.util.FileAssistant)1 File (java.io.File)1 Vector (java.util.Vector)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1