/* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ import java.util.*; import java.io.File; class BuildConfig { Hashtable vars; Vector basicNames, basicPaths; String[] context; static CompilerInterface ci; static CompilerInterface getCI() { if (ci == null) { String comp = (String)getField(null, "CompilerVersion"); try { ci = (CompilerInterface)Class.forName("CompilerInterface" + comp).newInstance(); } catch (Exception cnfe) { System.err.println("Cannot find support for compiler " + comp); throw new RuntimeException(cnfe.toString()); } } return ci; } protected void initNames(String flavour, String build, String outDll) { if (vars == null) vars = new Hashtable(); String flavourBuild = flavour + "_" + build; System.out.println(); System.out.println(flavourBuild); put("Name", getCI().makeCfgName(flavourBuild)); put("Flavour", flavour); put("Build", build); // ones mentioned above were needed to expand format String buildBase = expandFormat(getFieldString(null, "BuildBase")); String jdkDir = getFieldString(null, "JdkTargetRoot"); String sourceBase = getFieldString(null, "SourceBase"); String outDir = buildBase; put("Id", flavourBuild); put("OutputDir", outDir); put("SourceBase", sourceBase); put("BuildBase", buildBase); put("OutputDll", jdkDir + Util.sep + outDll); context = new String [] {flavourBuild, flavour, build, null}; } protected void init(Vector includes, Vector defines) { initDefaultDefines(defines); initDefaultCompilerFlags(includes); initDefaultLinkerFlags(); handleDB(); } protected void initDefaultCompilerFlags(Vector includes) { Vector compilerFlags = new Vector(); compilerFlags.addAll(getCI().getBaseCompilerFlags(getV("Define"), includes, get("OutputDir"))); put("CompilerFlags", compilerFlags); } protected void initDefaultLinkerFlags() { Vector linkerFlags = new Vector(); linkerFlags.addAll(getCI().getBaseLinkerFlags( get("OutputDir"), get("OutputDll"))); put("LinkerFlags", linkerFlags); } DirectoryTree getSourceTree(String sourceBase, String startAt) { DirectoryTree tree = new DirectoryTree(); tree.addSubdirToIgnore("Codemgr_wsdata"); tree.addSubdirToIgnore("deleted_files"); tree.addSubdirToIgnore("SCCS"); tree.setVerbose(true); if (startAt != null) { tree.readDirectory(sourceBase + File.separator + startAt); } else { tree.readDirectory(sourceBase); } return tree; } Vector getPreferredPaths(MacroDefinitions macros) { Vector preferredPaths = new Vector(); // In the case of multiple files with the same name in // different subdirectories, prefer the versions specified in // the platform file as the "os_family" and "arch" macros. for (Iterator iter = macros.getMacros(); iter.hasNext(); ) { Macro macro = (Macro) iter.next(); if (macro.name.equals("os_family") || macro.name.equals("arch")) { preferredPaths.add(macro.contents); } } // Also prefer "opto" over "adlc" for adlcVMDeps.hpp preferredPaths.add("opto"); return preferredPaths; } void handleDB() { WinGammaPlatform platform = (WinGammaPlatform)getField(null, "PlatformObject"); File incls = new File(get("OutputDir")+Util.sep+"incls"); incls.mkdirs(); MacroDefinitions macros = new MacroDefinitions(); try { macros.readFrom(getFieldString(null, "Platform"), false); } catch (Exception e) { throw new RuntimeException(e); } putSpecificField("AllFilesHash", computeAllFiles(platform, macros)); } private boolean matchesIgnoredPath(String prefixedName) { Vector rv = new Vector(); collectRelevantVectors(rv, "IgnorePath"); for (Iterator i = rv.iterator(); i.hasNext(); ) { String pathPart = (String) i.next(); if (prefixedName.contains(Util.normalize(pathPart))) { return true; } } return false; } void addAll(Iterator i, Hashtable hash, WinGammaPlatform platform, DirectoryTree tree, Vector preferredPaths, Vector filesNotFound, Vector filesDuplicate) { for (; i.hasNext(); ) { String fileName = (String) i.next(); if (lookupHashFieldInContext("IgnoreFile", fileName) == null) { String prefixedName = platform.envVarPrefixedFileName(fileName, 0, /* ignored */ tree, preferredPaths, filesNotFound, filesDuplicate); if (prefixedName != null) { prefixedName = Util.normalize(prefixedName); if (!matchesIgnoredPath(prefixedName)) { addTo(hash, prefixedName, fileName); } } } } } void addTo(Hashtable ht, String key, String value) { ht.put(expandFormat(key), expandFormat(value)); } Hashtable computeAllFiles(WinGammaPlatform platform, MacroDefinitions macros) { Hashtable rv = new Hashtable(); DirectoryTree tree = getSourceTree(get("SourceBase"), getFieldString(null, "StartAt")); Vector preferredPaths = getPreferredPaths(macros); // Hold errors until end Vector filesNotFound = new Vector(); Vector filesDuplicate = new Vector(); Vector includedFiles = new Vector(); // find all files Vector dirs = getSourceIncludes(); for (Iterator i = dirs.iterator(); i.hasNext(); ) { String dir = (String)i.next(); DirectoryTree subtree = getSourceTree(dir, null); for (Iterator fi = subtree.getFileIterator(); fi.hasNext(); ) { String name = ((File)fi.next()).getName(); includedFiles.add(name); } } addAll(includedFiles.iterator(), rv, platform, tree, preferredPaths, filesNotFound, filesDuplicate); Vector addFiles = new Vector(); collectRelevantVectors(addFiles, "AdditionalFile"); addAll(addFiles.iterator(), rv, platform, tree, preferredPaths, filesNotFound, filesDuplicate); collectRelevantHashes(rv, "AdditionalGeneratedFile"); if ((filesNotFound.size() != 0) || (filesDuplicate.size() != 0)) { System.err.println("Error: some files were not found or " + "appeared in multiple subdirectories of " + "directory " + get("SourceBase") + " and could not " + "be resolved with the os_family and arch " + "macros in the platform file."); if (filesNotFound.size() != 0) { System.err.println("Files not found:"); for (Iterator iter = filesNotFound.iterator(); iter.hasNext(); ) { System.err.println(" " + (String) iter.next()); } } if (filesDuplicate.size() != 0) { System.err.println("Duplicate files:"); for (Iterator iter = filesDuplicate.iterator(); iter.hasNext(); ) { System.err.println(" " + (String) iter.next()); } } throw new RuntimeException(); } return rv; } void initDefaultDefines(Vector defines) { Vector sysDefines = new Vector(); sysDefines.add("WIN32"); sysDefines.add("_WINDOWS"); sysDefines.add("HOTSPOT_BUILD_USER="+System.getProperty("user.name")); sysDefines.add("HOTSPOT_BUILD_TARGET=\\\""+get("Build")+"\\\""); sysDefines.add("_JNI_IMPLEMENTATION_"); sysDefines.add("HOTSPOT_LIB_ARCH=\\\"i386\\\""); sysDefines.addAll(defines); put("Define", sysDefines); } String get(String key) { return (String)vars.get(key); } Vector getV(String key) { return (Vector)vars.get(key); } Object getO(String key) { return vars.get(key); } Hashtable getH(String key) { return (Hashtable)vars.get(key); } Object getFieldInContext(String field) { for (int i=0; i