Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/tools/ProjectCreator/WinGammaPlatform.java
32285 views
/*1* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324import java.io.File;25import java.io.IOException;26import java.io.PrintWriter;27import java.util.Enumeration;28import java.util.Hashtable;29import java.util.Iterator;30import java.util.List;31import java.util.Stack;32import java.util.TreeSet;33import java.util.Vector;3435abstract class HsArgHandler extends ArgHandler {36static final int STRING = 1;37static final int VECTOR = 2;38static final int HASH = 3;3940boolean nextNotKey(ArgIterator it) {41if (it.next()) {42String s = it.get();43return (s.length() == 0) || (s.charAt(0) != '-');44} else {45return false;46}47}4849void empty(String key, String message) {50if (key != null) {51System.err.println("** Error: empty " + key);52}53if (message != null) {54System.err.println(message);55}56WinGammaPlatform.usage();57}5859static String getCfg(String val) {60int under = val.indexOf('_');61int len = val.length();62if (under != -1 && under < len - 1) {63return val.substring(under+1, len);64} else {65return null;66}67}68}6970class ArgRuleSpecific extends ArgRule {71ArgRuleSpecific(String arg, ArgHandler handler) {72super(arg, handler);73}7475boolean match(String rulePattern, String arg) {76return rulePattern.startsWith(arg);77}78}798081class SpecificHsArgHandler extends HsArgHandler {8283String message, argKey, valKey;84int type;8586public void handle(ArgIterator it) {87String cfg = getCfg(it.get());88if (nextNotKey(it)) {89String val = it.get();90switch (type) {91case VECTOR:92BuildConfig.addFieldVector(cfg, valKey, val);93break;94case HASH:95BuildConfig.putFieldHash(cfg, valKey, val, "1");96break;97case STRING:98BuildConfig.putField(cfg, valKey, val);99break;100default:101empty(valKey, "Unknown type: "+type);102}103it.next();104105} else {106empty(argKey, message);107}108}109110SpecificHsArgHandler(String argKey, String valKey, String message, int type) {111this.argKey = argKey;112this.valKey = valKey;113this.message = message;114this.type = type;115}116}117118119class HsArgRule extends ArgRuleSpecific {120121HsArgRule(String argKey, String valKey, String message, int type) {122super(argKey, new SpecificHsArgHandler(argKey, valKey, message, type));123}124125}126127public abstract class WinGammaPlatform {128129public boolean fileNameStringEquality(String s1, String s2) {130return s1.equalsIgnoreCase(s2);131}132133static void usage() throws IllegalArgumentException {134System.err.println("WinGammaPlatform platform-specific options:");135System.err.println(" -sourceBase <path to directory (workspace) " +136"containing source files; no trailing slash>");137System.err.println(" -projectFileName <full pathname to which project file " +138"will be written; all parent directories must " +139"already exist>");140System.err.println(" If any of the above are specified, "+141"they must all be.");142System.err.println(" Note: if '-altRelativeInclude' option below " +143"is used, then the '-relativeAltSrcInclude' " +144"option must be used to specify the alternate " +145"source dir, e.g., 'src\\closed'");146System.err.println(" Additional, optional arguments, which can be " +147"specified multiple times:");148System.err.println(" -absoluteInclude <string containing absolute " +149"path to include directory>");150System.err.println(" -altRelativeInclude <string containing " +151"alternate include directory relative to " +152"-sourceBase>");153System.err.println(" -relativeInclude <string containing include " +154"directory relative to -sourceBase>");155System.err.println(" -define <preprocessor flag to be #defined " +156"(note: doesn't yet support " +157"#define (flag) (value))>");158System.err.println(" -startAt <subdir of sourceBase>");159System.err.println(" -additionalFile <file not in database but " +160"which should show up in project file>");161System.err.println(" -additionalGeneratedFile <absolute path to " +162"directory containing file; no trailing slash> " +163"<name of file generated later in the build process>");164throw new IllegalArgumentException();165}166167168public void addPerFileLine(Hashtable table,169String fileName,170String line) {171Vector v = (Vector) table.get(fileName);172if (v != null) {173v.add(line);174} else {175v = new Vector();176v.add(line);177table.put(fileName, v);178}179}180181protected static class PerFileCondData {182public String releaseString;183public String debugString;184}185186protected void addConditionalPerFileLine(Hashtable table,187String fileName,188String releaseLine,189String debugLine) {190PerFileCondData data = new PerFileCondData();191data.releaseString = releaseLine;192data.debugString = debugLine;193Vector v = (Vector) table.get(fileName);194if (v != null) {195v.add(data);196} else {197v = new Vector();198v.add(data);199table.put(fileName, v);200}201}202203protected static class PrelinkCommandData {204String description;205String commands;206}207208protected void addPrelinkCommand(Hashtable table,209String build,210String description,211String commands) {212PrelinkCommandData data = new PrelinkCommandData();213data.description = description;214data.commands = commands;215table.put(build, data);216}217218public boolean findString(Vector v, String s) {219for (Iterator iter = v.iterator(); iter.hasNext(); ) {220if (((String) iter.next()).equals(s)) {221return true;222}223}224225return false;226}227228String getProjectName(String fullPath, String extension)229throws IllegalArgumentException, IOException {230File file = new File(fullPath).getCanonicalFile();231fullPath = file.getCanonicalPath();232String parent = file.getParent();233234if (!fullPath.endsWith(extension)) {235throw new IllegalArgumentException("project file name \"" +236fullPath +237"\" does not end in "+extension);238}239240if ((parent != null) &&241(!fullPath.startsWith(parent))) {242throw new RuntimeException(243"Internal error: parent of file name \"" + parent +244"\" does not match file name \"" + fullPath + "\""245);246}247248int len = parent.length();249if (!parent.endsWith(Util.sep)) {250len += Util.sep.length();251}252253int end = fullPath.length() - extension.length();254255if (len == end) {256throw new RuntimeException(257"Internal error: file name was empty"258);259}260261return fullPath.substring(len, end);262}263264protected abstract String getProjectExt();265266public void createVcproj(String[] args)267throws IllegalArgumentException, IOException {268269parseArguments(args);270271String projectFileName = BuildConfig.getFieldString(null, "ProjectFileName");272String ext = getProjectExt();273274String projectName = getProjectName(projectFileName, ext);275276writeProjectFile(projectFileName, projectName, createAllConfigs(BuildConfig.getFieldString(null, "PlatformName")));277}278279protected void writePrologue(String[] args) {280System.err.println("WinGammaPlatform platform-specific arguments:");281for (int i = 0; i < args.length; i++) {282System.err.print(args[i] + " ");283}284System.err.println();285}286287288void parseArguments(String[] args) {289new ArgsParser(args,290new ArgRule[]291{292new ArgRule("-sourceBase",293new HsArgHandler() {294public void handle(ArgIterator it) {295String cfg = getCfg(it.get());296if (nextNotKey(it)) {297String sb = (String) it.get();298if (sb.endsWith(Util.sep)) {299sb = sb.substring(0, sb.length() - 1);300}301BuildConfig.putField(cfg, "SourceBase", sb);302it.next();303} else {304empty("-sourceBase", null);305}306}307}308),309310new HsArgRule("-buildBase",311"BuildBase",312" (Did you set the HotSpotBuildSpace environment variable?)",313HsArgHandler.STRING314),315316new HsArgRule("-buildSpace",317"BuildSpace",318null,319HsArgHandler.STRING320),321322new HsArgRule("-platformName",323"PlatformName",324null,325HsArgHandler.STRING326),327328new HsArgRule("-projectFileName",329"ProjectFileName",330null,331HsArgHandler.STRING332),333334new HsArgRule("-jdkTargetRoot",335"JdkTargetRoot",336" (Did you set the HotSpotJDKDist environment variable?)",337HsArgHandler.STRING338),339340new HsArgRule("-compiler",341"CompilerVersion",342" (Did you set the VcVersion correctly?)",343HsArgHandler.STRING344),345346new HsArgRule("-absoluteInclude",347"AbsoluteInclude",348null,349HsArgHandler.VECTOR350),351352new HsArgRule("-altRelativeInclude",353"AltRelativeInclude",354null,355HsArgHandler.VECTOR356),357358new HsArgRule("-relativeInclude",359"RelativeInclude",360null,361HsArgHandler.VECTOR362),363364new HsArgRule("-absoluteSrcInclude",365"AbsoluteSrcInclude",366null,367HsArgHandler.VECTOR368),369370new HsArgRule("-relativeAltSrcInclude",371"RelativeAltSrcInclude",372null,373HsArgHandler.STRING374),375376new HsArgRule("-relativeSrcInclude",377"RelativeSrcInclude",378null,379HsArgHandler.VECTOR380),381382new HsArgRule("-define",383"Define",384null,385HsArgHandler.VECTOR386),387388new HsArgRule("-useToGeneratePch",389"UseToGeneratePch",390null,391HsArgHandler.STRING392),393394new ArgRuleSpecific("-perFileLine",395new HsArgHandler() {396public void handle(ArgIterator it) {397String cfg = getCfg(it.get());398if (nextNotKey(it)) {399String fileName = it.get();400if (nextNotKey(it)) {401String line = it.get();402BuildConfig.putFieldHash(cfg, "PerFileLine", fileName, line);403it.next();404return;405}406}407empty(null, "** Error: wrong number of args to -perFileLine");408}409}410),411412new ArgRuleSpecific("-conditionalPerFileLine",413new HsArgHandler() {414public void handle(ArgIterator it) {415String cfg = getCfg(it.get());416if (nextNotKey(it)) {417String fileName = it.get();418if (nextNotKey(it)) {419String productLine = it.get();420if (nextNotKey(it)) {421String debugLine = it.get();422BuildConfig.putFieldHash(cfg+"_debug", "CondPerFileLine",423fileName, debugLine);424BuildConfig.putFieldHash(cfg+"_product", "CondPerFileLine",425fileName, productLine);426it.next();427return;428}429}430}431432empty(null, "** Error: wrong number of args to -conditionalPerFileLine");433}434}435),436437new HsArgRule("-disablePch",438"DisablePch",439null,440HsArgHandler.HASH441),442443new ArgRule("-startAt",444new HsArgHandler() {445public void handle(ArgIterator it) {446if (BuildConfig.getField(null, "StartAt") != null) {447empty(null, "** Error: multiple -startAt");448}449if (nextNotKey(it)) {450BuildConfig.putField(null, "StartAt", it.get());451it.next();452} else {453empty("-startAt", null);454}455}456}457),458459new HsArgRule("-ignoreFile",460"IgnoreFile",461null,462HsArgHandler.HASH463),464465new HsArgRule("-ignorePath",466"IgnorePath",467null,468HsArgHandler.VECTOR469),470471new HsArgRule("-hidePath",472"HidePath",473null,474HsArgHandler.VECTOR475),476477new HsArgRule("-additionalFile",478"AdditionalFile",479null,480HsArgHandler.VECTOR481),482483new ArgRuleSpecific("-additionalGeneratedFile",484new HsArgHandler() {485public void handle(ArgIterator it) {486String cfg = getCfg(it.get());487if (nextNotKey(it)) {488String dir = it.get();489if (nextNotKey(it)) {490String fileName = it.get();491BuildConfig.putFieldHash(cfg, "AdditionalGeneratedFile",492Util.normalize(dir + Util.sep + fileName),493fileName);494it.next();495return;496}497}498empty(null, "** Error: wrong number of args to -additionalGeneratedFile");499}500}501),502503new ArgRule("-prelink",504new HsArgHandler() {505public void handle(ArgIterator it) {506if (nextNotKey(it)) {507if (nextNotKey(it)) {508String description = it.get();509if (nextNotKey(it)) {510String command = it.get();511BuildConfig.putField(null, "PrelinkDescription", description);512BuildConfig.putField(null, "PrelinkCommand", command);513it.next();514return;515}516}517}518519empty(null, "** Error: wrong number of args to -prelink");520}521}522),523524new ArgRule("-postbuild",525new HsArgHandler() {526public void handle(ArgIterator it) {527if (nextNotKey(it)) {528if (nextNotKey(it)) {529String description = it.get();530if (nextNotKey(it)) {531String command = it.get();532BuildConfig.putField(null, "PostbuildDescription", description);533BuildConfig.putField(null, "PostbuildCommand", command);534it.next();535return;536}537}538}539540empty(null, "** Error: wrong number of args to -postbuild");541}542}543),544},545new ArgHandler() {546public void handle(ArgIterator it) {547548throw new RuntimeException("Arg Parser: unrecognized option "+it.get());549}550}551);552if (BuildConfig.getField(null, "SourceBase") == null ||553BuildConfig.getField(null, "BuildBase") == null ||554BuildConfig.getField(null, "ProjectFileName") == null ||555BuildConfig.getField(null, "CompilerVersion") == null) {556usage();557}558559if (BuildConfig.getField(null, "UseToGeneratePch") == null) {560throw new RuntimeException("ERROR: need to specify one file to compute PCH, with -useToGeneratePch flag");561}562563BuildConfig.putField(null, "PlatformObject", this);564}565566Vector createAllConfigs(String platform) {567Vector allConfigs = new Vector();568569allConfigs.add(new C1DebugConfig());570allConfigs.add(new C1FastDebugConfig());571allConfigs.add(new C1ProductConfig());572573allConfigs.add(new C2DebugConfig());574allConfigs.add(new C2FastDebugConfig());575allConfigs.add(new C2ProductConfig());576577allConfigs.add(new TieredDebugConfig());578allConfigs.add(new TieredFastDebugConfig());579allConfigs.add(new TieredProductConfig());580581return allConfigs;582}583584PrintWriter printWriter;585586public void writeProjectFile(String projectFileName, String projectName,587Vector<BuildConfig> allConfigs) throws IOException {588throw new RuntimeException("use compiler version specific version");589}590591int indent;592private Stack<String> tagStack = new Stack<String>();593594private void startTagPrim(String name, String[] attrs, boolean close) {595startTagPrim(name, attrs, close, true);596}597598private void startTagPrim(String name, String[] attrs, boolean close,599boolean newline) {600doIndent();601printWriter.print("<" + name);602indent++;603604if (attrs != null && attrs.length > 0) {605for (int i = 0; i < attrs.length; i += 2) {606printWriter.print(" " + attrs[i] + "=\"" + attrs[i + 1] + "\"");607if (i < attrs.length - 2) {608}609}610}611612if (close) {613indent--;614printWriter.print(" />");615} else {616// TODO push tag name, and change endTag to pop and print.617tagStack.push(name);618printWriter.print(">");619}620if (newline) {621printWriter.println();622}623}624625void startTag(String name, String... attrs) {626startTagPrim(name, attrs, false);627}628629void startTagV(String name, Vector attrs) {630String s[] = new String[attrs.size()];631for (int i = 0; i < attrs.size(); i++) {632s[i] = (String) attrs.elementAt(i);633}634startTagPrim(name, s, false);635}636637void endTag() {638String name = tagStack.pop();639indent--;640doIndent();641printWriter.println("</" + name + ">");642}643644private void endTagNoIndent() {645String name = tagStack.pop();646indent--;647printWriter.println("</" + name + ">");648}649650void tag(String name, String... attrs) {651startTagPrim(name, attrs, true);652}653654void tagData(String name, String data) {655startTagPrim(name, null, false, false);656printWriter.print(data);657endTagNoIndent();658}659660void tagData(String name, String data, String... attrs) {661startTagPrim(name, attrs, false, false);662printWriter.print(data);663endTagNoIndent();664}665666void tagV(String name, Vector attrs) {667String s[] = new String[attrs.size()];668for (int i = 0; i < attrs.size(); i++) {669s[i] = (String) attrs.elementAt(i);670}671startTagPrim(name, s, true);672}673674void doIndent() {675for (int i = 0; i < indent; i++) {676printWriter.print(" ");677}678}679680681}682683684