aoqi@0: /* aoqi@0: * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: import java.util.Enumeration; aoqi@0: import java.util.Hashtable; aoqi@0: import java.util.Vector; aoqi@0: aoqi@0: class BuildConfig { aoqi@0: @SuppressWarnings("rawtypes") aoqi@0: Hashtable vars; aoqi@0: Vector basicNames, basicPaths; aoqi@0: String[] context; aoqi@0: aoqi@0: static CompilerInterface ci; aoqi@0: static CompilerInterface getCI() { aoqi@0: if (ci == null) { aoqi@0: String comp = (String)getField(null, "CompilerVersion"); aoqi@0: try { aoqi@0: ci = (CompilerInterface)Class.forName("CompilerInterface" + comp).newInstance(); aoqi@0: } catch (Exception cnfe) { aoqi@0: System.err.println("Cannot find support for compiler " + comp); aoqi@0: throw new RuntimeException(cnfe.toString()); aoqi@0: } aoqi@0: } aoqi@0: return ci; aoqi@0: } aoqi@0: aoqi@0: @SuppressWarnings("rawtypes") aoqi@0: protected void initNames(String flavour, String build, String outDll) { aoqi@0: if (vars == null) vars = new Hashtable(); aoqi@0: aoqi@0: String flavourBuild = flavour + "_" + build; aoqi@0: String platformName = getFieldString(null, "PlatformName"); aoqi@0: System.out.println(); aoqi@0: System.out.println(flavourBuild); aoqi@0: aoqi@0: put("Name", getCI().makeCfgName(flavourBuild, platformName)); aoqi@0: put("Flavour", flavour); aoqi@0: put("Build", build); aoqi@0: put("PlatformName", platformName); aoqi@0: aoqi@0: // ones mentioned above were needed to expand format aoqi@0: String buildBase = expandFormat(getFieldString(null, "BuildBase")); aoqi@0: String sourceBase = getFieldString(null, "SourceBase"); aoqi@0: String buildSpace = getFieldString(null, "BuildSpace"); aoqi@0: String outDir = buildBase; aoqi@0: String jdkTargetRoot = getFieldString(null, "JdkTargetRoot"); aoqi@0: aoqi@0: put("Id", flavourBuild); aoqi@0: put("OutputDir", outDir); aoqi@0: put("SourceBase", sourceBase); aoqi@0: put("BuildBase", buildBase); aoqi@0: put("BuildSpace", buildSpace); aoqi@0: put("OutputDll", outDir + Util.sep + outDll); aoqi@0: put("JdkTargetRoot", jdkTargetRoot); aoqi@0: aoqi@0: context = new String [] {flavourBuild, flavour, build, null}; aoqi@0: } aoqi@0: aoqi@0: protected void init(Vector includes, Vector defines) { aoqi@0: initDefaultDefines(defines); aoqi@0: initDefaultCompilerFlags(includes); aoqi@0: initDefaultLinkerFlags(); aoqi@0: //handleDB(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: protected void initDefaultCompilerFlags(Vector includes) { aoqi@0: Vector compilerFlags = new Vector(); aoqi@0: aoqi@0: compilerFlags.addAll(getCI().getBaseCompilerFlags(getV("Define"), aoqi@0: includes, aoqi@0: get("OutputDir"))); aoqi@0: aoqi@0: put("CompilerFlags", compilerFlags); aoqi@0: } aoqi@0: aoqi@0: protected void initDefaultLinkerFlags() { aoqi@0: Vector linkerFlags = new Vector(); aoqi@0: aoqi@0: linkerFlags.addAll(getCI().getBaseLinkerFlags( get("OutputDir"), get("OutputDll"), get("PlatformName"))); aoqi@0: aoqi@0: put("LinkerFlags", linkerFlags); aoqi@0: } aoqi@0: aoqi@0: public boolean matchesIgnoredPath(String path) { aoqi@0: Vector rv = new Vector(); aoqi@0: collectRelevantVectors(rv, "IgnorePath"); aoqi@0: for (String pathPart : rv) { aoqi@0: if (path.contains(pathPart)) { aoqi@0: return true; aoqi@0: } aoqi@0: } aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: public boolean matchesHidePath(String path) { aoqi@0: Vector rv = new Vector(); aoqi@0: collectRelevantVectors(rv, "HidePath"); aoqi@0: for (String pathPart : rv) { aoqi@0: if (path.contains(Util.normalize(pathPart))) { aoqi@0: return true; aoqi@0: } aoqi@0: } aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: public Vector matchesAdditionalGeneratedPath(String fullPath) { aoqi@0: Vector rv = new Vector(); aoqi@0: Hashtable v = (Hashtable)BuildConfig.getField(this.toString(), "AdditionalGeneratedFile"); aoqi@0: if (v != null) { aoqi@0: for (Enumeration e=v.keys(); e.hasMoreElements(); ) { aoqi@0: String key = e.nextElement(); aoqi@0: String val = v.get(key); aoqi@0: aoqi@0: if (fullPath.endsWith(expandFormat(key))) { aoqi@0: rv.add(expandFormat(val)); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: return rv; aoqi@0: } aoqi@0: aoqi@0: // Returns true if the specified path refers to a relative alternate aoqi@0: // source file. RelativeAltSrcInclude is usually "src\closed". aoqi@0: public static boolean matchesRelativeAltSrcInclude(String path) { aoqi@0: String relativeAltSrcInclude = aoqi@0: getFieldString(null, "RelativeAltSrcInclude"); aoqi@0: Vector v = getFieldVector(null, "AltRelativeInclude"); aoqi@0: for (String pathPart : v) { aoqi@0: if (path.contains(relativeAltSrcInclude + Util.sep + pathPart)) { aoqi@0: return true; aoqi@0: } aoqi@0: } aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: // Returns the relative alternate source file for the specified path. aoqi@0: // Null is returned if the specified path does not have a matching aoqi@0: // alternate source file. aoqi@0: public static String getMatchingRelativeAltSrcFile(String path) { aoqi@0: Vector v = getFieldVector(null, "RelativeAltSrcFileList"); aoqi@0: if (v == null) { aoqi@0: return null; aoqi@0: } aoqi@0: for (String pathPart : v) { aoqi@0: if (path.endsWith(pathPart)) { aoqi@0: String relativeAltSrcInclude = aoqi@0: getFieldString(null, "RelativeAltSrcInclude"); aoqi@0: return relativeAltSrcInclude + Util.sep + pathPart; aoqi@0: } aoqi@0: } aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: // Returns true if the specified path has a matching alternate aoqi@0: // source file. aoqi@0: public static boolean matchesRelativeAltSrcFile(String path) { aoqi@0: return getMatchingRelativeAltSrcFile(path) != null; aoqi@0: } aoqi@0: aoqi@0: // Track the specified alternate source file. The source file is aoqi@0: // tracked without the leading .* aoqi@0: // part to make matching regular source files easier. aoqi@0: public static void trackRelativeAltSrcFile(String path) { aoqi@0: String pattern = getFieldString(null, "RelativeAltSrcInclude") + aoqi@0: Util.sep; aoqi@0: int altSrcInd = path.indexOf(pattern); aoqi@0: if (altSrcInd == -1) { aoqi@0: // not an AltSrc path aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: altSrcInd += pattern.length(); aoqi@0: if (altSrcInd >= path.length()) { aoqi@0: // not a valid AltSrc path aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: String altSrcFile = path.substring(altSrcInd); aoqi@0: Vector v = getFieldVector(null, "RelativeAltSrcFileList"); aoqi@0: if (v == null || !v.contains(altSrcFile)) { aoqi@0: addFieldVector(null, "RelativeAltSrcFileList", altSrcFile); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void addTo(Hashtable ht, String key, String value) { aoqi@0: ht.put(expandFormat(key), expandFormat(value)); aoqi@0: } aoqi@0: aoqi@0: void initDefaultDefines(Vector defines) { aoqi@0: Vector sysDefines = new Vector(); aoqi@0: sysDefines.add("WIN32"); aoqi@0: sysDefines.add("_WINDOWS"); aoqi@0: sysDefines.add("HOTSPOT_BUILD_USER=\\\""+System.getProperty("user.name")+"\\\""); aoqi@0: sysDefines.add("HOTSPOT_BUILD_TARGET=\\\""+get("Build")+"\\\""); aoqi@0: sysDefines.add("INCLUDE_TRACE=1"); aoqi@0: sysDefines.add("_JNI_IMPLEMENTATION_"); aoqi@0: if (vars.get("PlatformName").equals("Win32")) { aoqi@0: sysDefines.add("HOTSPOT_LIB_ARCH=\\\"i386\\\""); aoqi@0: } else { aoqi@0: sysDefines.add("HOTSPOT_LIB_ARCH=\\\"amd64\\\""); aoqi@0: } aoqi@0: aoqi@0: sysDefines.addAll(defines); aoqi@0: aoqi@0: put("Define", sysDefines); aoqi@0: } aoqi@0: aoqi@0: String get(String key) { aoqi@0: return (String)vars.get(key); aoqi@0: } aoqi@0: aoqi@0: Vector getV(String key) { aoqi@0: return (Vector)vars.get(key); aoqi@0: } aoqi@0: aoqi@0: Object getO(String key) { aoqi@0: return vars.get(key); aoqi@0: } aoqi@0: aoqi@0: Hashtable getH(String key) { aoqi@0: return (Hashtable)vars.get(key); aoqi@0: } aoqi@0: aoqi@0: Object getFieldInContext(String field) { aoqi@0: for (int i=0; i v = getFieldVector(ctx, field); aoqi@0: if (v != null) { aoqi@0: for (String val : v) { aoqi@0: rv.add(expandFormat(val).replace('/', '\\')); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void collectRelevantHashes(Hashtable rv, String field) { aoqi@0: for (String ctx : context) { aoqi@0: Hashtable v = (Hashtable)getField(ctx, field); aoqi@0: if (v != null) { aoqi@0: for (Enumeration e=v.keys(); e.hasMoreElements(); ) { aoqi@0: String key = (String)e.nextElement(); aoqi@0: String val = (String)v.get(key); aoqi@0: addTo(rv, key, val); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: Vector getDefines() { aoqi@0: Vector rv = new Vector(); aoqi@0: collectRelevantVectors(rv, "Define"); aoqi@0: return rv; aoqi@0: } aoqi@0: aoqi@0: Vector getIncludes() { aoqi@0: Vector rv = new Vector(); aoqi@0: collectRelevantVectors(rv, "AbsoluteInclude"); aoqi@0: rv.addAll(getSourceIncludes()); aoqi@0: return rv; aoqi@0: } aoqi@0: aoqi@0: private Vector getSourceIncludes() { aoqi@0: Vector rv = new Vector(); aoqi@0: String sourceBase = getFieldString(null, "SourceBase"); aoqi@0: aoqi@0: // add relative alternate source include values: aoqi@0: String relativeAltSrcInclude = aoqi@0: getFieldString(null, "RelativeAltSrcInclude"); aoqi@0: Vector asri = new Vector(); aoqi@0: collectRelevantVectors(asri, "AltRelativeInclude"); aoqi@0: for (String f : asri) { aoqi@0: rv.add(sourceBase + Util.sep + relativeAltSrcInclude + aoqi@0: Util.sep + f); aoqi@0: } aoqi@0: aoqi@0: Vector ri = new Vector(); aoqi@0: collectRelevantVectors(ri, "RelativeInclude"); aoqi@0: for (String f : ri) { aoqi@0: rv.add(sourceBase + Util.sep + f); aoqi@0: } aoqi@0: return rv; aoqi@0: } aoqi@0: aoqi@0: static Hashtable cfgData = new Hashtable(); aoqi@0: static Hashtable globalData = new Hashtable(); aoqi@0: aoqi@0: static boolean appliesToTieredBuild(String cfg) { aoqi@0: return (cfg != null && aoqi@0: (cfg.startsWith("compiler1") || aoqi@0: cfg.startsWith("compiler2"))); aoqi@0: } aoqi@0: aoqi@0: // Filters out the IgnoreFile and IgnorePaths since they are aoqi@0: // handled specially for tiered builds. aoqi@0: static boolean appliesToTieredBuild(String cfg, String key) { aoqi@0: return (appliesToTieredBuild(cfg))&& (key != null && !key.startsWith("Ignore")); aoqi@0: } aoqi@0: aoqi@0: static String getTieredBuildCfg(String cfg) { aoqi@0: assert appliesToTieredBuild(cfg) : "illegal configuration " + cfg; aoqi@0: return "tiered" + cfg.substring(9); aoqi@0: } aoqi@0: aoqi@0: static Object getField(String cfg, String field) { aoqi@0: if (cfg == null) { aoqi@0: return globalData.get(field); aoqi@0: } aoqi@0: aoqi@0: Hashtable ht = (Hashtable)cfgData.get(cfg); aoqi@0: return ht == null ? null : ht.get(field); aoqi@0: } aoqi@0: aoqi@0: static String getFieldString(String cfg, String field) { aoqi@0: return (String)getField(cfg, field); aoqi@0: } aoqi@0: aoqi@0: static Vector getFieldVector(String cfg, String field) { aoqi@0: return (Vector)getField(cfg, field); aoqi@0: } aoqi@0: aoqi@0: static void putField(String cfg, String field, Object value) { aoqi@0: putFieldImpl(cfg, field, value); aoqi@0: if (appliesToTieredBuild(cfg, field)) { aoqi@0: putFieldImpl(getTieredBuildCfg(cfg), field, value); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: private static void putFieldImpl(String cfg, String field, Object value) { aoqi@0: if (cfg == null) { aoqi@0: globalData.put(field, value); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: Hashtable ht = (Hashtable)cfgData.get(cfg); aoqi@0: if (ht == null) { aoqi@0: ht = new Hashtable(); aoqi@0: cfgData.put(cfg, ht); aoqi@0: } aoqi@0: aoqi@0: ht.put(field, value); aoqi@0: } aoqi@0: aoqi@0: static Object getFieldHash(String cfg, String field, String name) { aoqi@0: Hashtable ht = (Hashtable)getField(cfg, field); aoqi@0: aoqi@0: return ht == null ? null : ht.get(name); aoqi@0: } aoqi@0: aoqi@0: static void putFieldHash(String cfg, String field, String name, Object val) { aoqi@0: putFieldHashImpl(cfg, field, name, val); aoqi@0: if (appliesToTieredBuild(cfg, field)) { aoqi@0: putFieldHashImpl(getTieredBuildCfg(cfg), field, name, val); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: private static void putFieldHashImpl(String cfg, String field, String name, Object val) { aoqi@0: Hashtable ht = (Hashtable)getField(cfg, field); aoqi@0: aoqi@0: if (ht == null) { aoqi@0: ht = new Hashtable(); aoqi@0: putFieldImpl(cfg, field, ht); aoqi@0: } aoqi@0: aoqi@0: ht.put(name, val); aoqi@0: } aoqi@0: aoqi@0: static void addFieldVector(String cfg, String field, String element) { aoqi@0: addFieldVectorImpl(cfg, field, element); aoqi@0: if (appliesToTieredBuild(cfg, field)) { aoqi@0: addFieldVectorImpl(getTieredBuildCfg(cfg), field, element); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: private static void addFieldVectorImpl(String cfg, String field, String element) { aoqi@0: Vector v = (Vector)getField(cfg, field); aoqi@0: aoqi@0: if (v == null) { aoqi@0: v = new Vector(); aoqi@0: putFieldImpl(cfg, field, v); aoqi@0: } aoqi@0: aoqi@0: v.add(element); aoqi@0: } aoqi@0: aoqi@0: String expandFormat(String format) { aoqi@0: if (format == null) { aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: if (format.indexOf('%') == -1) { aoqi@0: return format; aoqi@0: } aoqi@0: aoqi@0: StringBuffer sb = new StringBuffer(); aoqi@0: int len = format.length(); aoqi@0: for (int i=0; i