src/share/tools/MakeDeps/WinGammaPlatform.java

changeset 435
a61af66fc99e
child 1907
c18cbe5936b8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/tools/MakeDeps/WinGammaPlatform.java	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,765 @@
     1.4 +/*
     1.5 + * Copyright 1999-2007 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +import java.io.*;
    1.29 +import java.util.*;
    1.30 +
    1.31 +abstract class HsArgHandler extends ArgHandler {
    1.32 +    static final int STRING = 1;
    1.33 +    static final int VECTOR = 2;
    1.34 +    static final int HASH   = 3;
    1.35 +
    1.36 +    boolean nextNotKey(ArgIterator it) {
    1.37 +        if (it.next()) {
    1.38 +            String s = it.get();
    1.39 +            return (s.length() == 0) || (s.charAt(0) != '-');
    1.40 +        } else {
    1.41 +            return false;
    1.42 +        }
    1.43 +    }
    1.44 +
    1.45 +    void empty(String key, String message) {
    1.46 +        if (key != null) {
    1.47 +            System.err.println("** Error: empty " + key);
    1.48 +        }
    1.49 +        if (message != null) {
    1.50 +            System.err.println(message);
    1.51 +        }
    1.52 +        WinGammaPlatform.usage();
    1.53 +    }
    1.54 +
    1.55 +    static String getCfg(String val) {
    1.56 +        int under = val.indexOf('_');
    1.57 +        int len = val.length();
    1.58 +        if (under != -1 && under < len - 1) {
    1.59 +            return val.substring(under+1, len);
    1.60 +        } else {
    1.61 +            return null;
    1.62 +        }
    1.63 +    }
    1.64 +}
    1.65 +
    1.66 +class ArgRuleSpecific extends ArgRule {
    1.67 +    ArgRuleSpecific(String arg, ArgHandler handler) {
    1.68 +        super(arg, handler);
    1.69 +    }
    1.70 +
    1.71 +    boolean match(String rulePattern, String arg) {
    1.72 +        return rulePattern.startsWith(arg);
    1.73 +    }
    1.74 +}
    1.75 +
    1.76 +
    1.77 +class SpecificHsArgHandler extends HsArgHandler {
    1.78 +
    1.79 +    String message, argKey, valKey;
    1.80 +    int type;
    1.81 +
    1.82 +    public void handle(ArgIterator it) {
    1.83 +        String cfg = getCfg(it.get());
    1.84 +        if (nextNotKey(it)) {
    1.85 +            String val = it.get();
    1.86 +            switch (type) {
    1.87 +            case VECTOR:
    1.88 +                BuildConfig.addFieldVector(cfg, valKey, val);
    1.89 +                break;
    1.90 +            case HASH:
    1.91 +                BuildConfig.putFieldHash(cfg, valKey, val, "1");
    1.92 +                break;
    1.93 +            case STRING:
    1.94 +                BuildConfig.putField(cfg, valKey, val);
    1.95 +                break;
    1.96 +            default:
    1.97 +                empty(valKey, "Unknown type: "+type);
    1.98 +            }
    1.99 +            it.next();
   1.100 +
   1.101 +        } else {
   1.102 +            empty(argKey, message);
   1.103 +        }
   1.104 +    }
   1.105 +
   1.106 +    SpecificHsArgHandler(String argKey, String valKey, String message, int type) {
   1.107 +        this.argKey = argKey;
   1.108 +        this.valKey = valKey;
   1.109 +        this.message = message;
   1.110 +        this.type = type;
   1.111 +    }
   1.112 +}
   1.113 +
   1.114 +
   1.115 +class HsArgRule extends ArgRuleSpecific {
   1.116 +
   1.117 +    HsArgRule(String argKey, String valKey, String message, int type) {
   1.118 +        super(argKey, new SpecificHsArgHandler(argKey, valKey, message, type));
   1.119 +    }
   1.120 +
   1.121 +}
   1.122 +
   1.123 +public abstract class WinGammaPlatform extends Platform {
   1.124 +    public void setupFileTemplates() {
   1.125 +        inclFileTemplate = new FileName(this,
   1.126 +            "incls\\", "_", "",                      ".incl", "", ""
   1.127 +        );
   1.128 +        giFileTemplate = new FileName(this,
   1.129 +            "incls\\", "",  "_precompiled", ".incl", "", ""
   1.130 +        );
   1.131 +        gdFileTemplate = new FileName(this,
   1.132 +            "", "",  "Dependencies",         "",      "", ""
   1.133 +        );
   1.134 +    }
   1.135 +
   1.136 +    private static String[] suffixes = { ".cpp", ".c" };
   1.137 +
   1.138 +    public String[] outerSuffixes() {
   1.139 +        return suffixes;
   1.140 +    }
   1.141 +
   1.142 +    public String objFileSuffix() {
   1.143 +        return ".obj";
   1.144 +    }
   1.145 +
   1.146 +    public String asmFileSuffix() {
   1.147 +        return ".i";
   1.148 +    }
   1.149 +
   1.150 +    public String dependentPrefix() {
   1.151 +        return "$(VM_PATH)";
   1.152 +    }
   1.153 +
   1.154 +    public boolean includeGIInEachIncl() {
   1.155 +        return false;
   1.156 +    }
   1.157 +
   1.158 +    public boolean fileNameStringEquality(String s1, String s2) {
   1.159 +        return s1.equalsIgnoreCase(s2);
   1.160 +    }
   1.161 +
   1.162 +    static void usage() throws IllegalArgumentException {
   1.163 +        System.err.println("WinGammaPlatform platform-specific options:");
   1.164 +        System.err.println("  -sourceBase <path to directory (workspace) " +
   1.165 +                           "containing source files; no trailing slash>");
   1.166 +        System.err.println("  -projectFileName <full pathname to which project file " +
   1.167 +                           "will be written; all parent directories must " +
   1.168 +                           "already exist>");
   1.169 +        System.err.println("  If any of the above are specified, "+
   1.170 +                           "they must all be.");
   1.171 +        System.err.println("  Additional, optional arguments, which can be " +
   1.172 +                           "specified multiple times:");
   1.173 +        System.err.println("    -absoluteInclude <string containing absolute " +
   1.174 +                           "path to include directory>");
   1.175 +        System.err.println("    -relativeInclude <string containing include " +
   1.176 +                           "directory relative to -sourceBase>");
   1.177 +        System.err.println("    -define <preprocessor flag to be #defined " +
   1.178 +                           "(note: doesn't yet support " +
   1.179 +                           "#define (flag) (value))>");
   1.180 +        System.err.println("    -startAt <subdir of sourceBase>");
   1.181 +        System.err.println("    -additionalFile <file not in database but " +
   1.182 +                           "which should show up in project file, like " +
   1.183 +                           "includeDB_core>");
   1.184 +        System.err.println("    -additionalGeneratedFile <absolute path to " +
   1.185 +                           "directory containing file; no trailing slash> " +
   1.186 +                           "<name of file generated later in the build process>");
   1.187 +        throw new IllegalArgumentException();
   1.188 +    }
   1.189 +
   1.190 +
   1.191 +    public void addPerFileLine(Hashtable table,
   1.192 +                               String fileName,
   1.193 +                               String line) {
   1.194 +        Vector v = (Vector) table.get(fileName);
   1.195 +        if (v != null) {
   1.196 +            v.add(line);
   1.197 +        } else {
   1.198 +            v = new Vector();
   1.199 +            v.add(line);
   1.200 +            table.put(fileName, v);
   1.201 +        }
   1.202 +    }
   1.203 +
   1.204 +    protected static class PerFileCondData {
   1.205 +        public String releaseString;
   1.206 +        public String debugString;
   1.207 +    }
   1.208 +
   1.209 +    protected void addConditionalPerFileLine(Hashtable table,
   1.210 +                                           String fileName,
   1.211 +                                           String releaseLine,
   1.212 +                                           String debugLine) {
   1.213 +        PerFileCondData data = new PerFileCondData();
   1.214 +        data.releaseString = releaseLine;
   1.215 +        data.debugString = debugLine;
   1.216 +        Vector v = (Vector) table.get(fileName);
   1.217 +        if (v != null) {
   1.218 +            v.add(data);
   1.219 +        } else {
   1.220 +            v = new Vector();
   1.221 +            v.add(data);
   1.222 +            table.put(fileName, v);
   1.223 +        }
   1.224 +    }
   1.225 +
   1.226 +    protected static class PrelinkCommandData {
   1.227 +      String description;
   1.228 +      String commands;
   1.229 +    }
   1.230 +
   1.231 +    protected void addPrelinkCommand(Hashtable table,
   1.232 +                                     String build,
   1.233 +                                     String description,
   1.234 +                                     String commands) {
   1.235 +      PrelinkCommandData data = new PrelinkCommandData();
   1.236 +      data.description = description;
   1.237 +      data.commands = commands;
   1.238 +      table.put(build, data);
   1.239 +    }
   1.240 +
   1.241 +    public boolean findString(Vector v, String s) {
   1.242 +        for (Iterator iter = v.iterator(); iter.hasNext(); ) {
   1.243 +            if (((String) iter.next()).equals(s)) {
   1.244 +                return true;
   1.245 +            }
   1.246 +        }
   1.247 +
   1.248 +        return false;
   1.249 +    }
   1.250 +
   1.251 +    /* This returns a String containing the full path to the passed
   1.252 +       file name, or null if an error occurred. If the file was not
   1.253 +       found or was a duplicate and couldn't be resolved using the
   1.254 +       preferred paths, the file name is added to the appropriate
   1.255 +       Vector of Strings. */
   1.256 +    private String findFileInDirectory(String fileName,
   1.257 +                                       DirectoryTree directory,
   1.258 +                                       Vector preferredPaths,
   1.259 +                                       Vector filesNotFound,
   1.260 +                                       Vector filesDuplicate) {
   1.261 +        List locationsInTree = directory.findFile(fileName);
   1.262 +        int  rootNameLength = directory.getRootNodeName().length();
   1.263 +        String name = null;
   1.264 +        if ((locationsInTree == null) ||
   1.265 +            (locationsInTree.size() == 0)) {
   1.266 +            filesNotFound.add(fileName);
   1.267 +        } else if (locationsInTree.size() > 1) {
   1.268 +            // We shouldn't have duplicate file names in our workspace.
   1.269 +            System.err.println();
   1.270 +            System.err.println("There are multiple files named as: " + fileName);
   1.271 +            System.exit(-1);
   1.272 +            // The following code could be safely removed if we don't need duplicate
   1.273 +            // file names.
   1.274 +
   1.275 +            // Iterate through them, trying to find one with a
   1.276 +            // preferred path
   1.277 +        search:
   1.278 +            {
   1.279 +                for (Iterator locIter = locationsInTree.iterator();
   1.280 +                     locIter.hasNext(); ) {
   1.281 +                    DirectoryTreeNode node =
   1.282 +                        (DirectoryTreeNode) locIter.next();
   1.283 +                    String tmpName = node.getName();
   1.284 +                    for (Iterator prefIter = preferredPaths.iterator();
   1.285 +                         prefIter.hasNext(); ) {
   1.286 +                        // We need to make sure the preferred path is
   1.287 +                        // found from the file path not including the root node name.
   1.288 +                        if (tmpName.indexOf((String)prefIter.next(),
   1.289 +                                            rootNameLength) != -1) {
   1.290 +                            name = tmpName;
   1.291 +                            break search;
   1.292 +                        }
   1.293 +                    }
   1.294 +                }
   1.295 +            }
   1.296 +
   1.297 +            if (name == null) {
   1.298 +                filesDuplicate.add(fileName);
   1.299 +            }
   1.300 +        } else {
   1.301 +            name = ((DirectoryTreeNode) locationsInTree.get(0)).getName();
   1.302 +        }
   1.303 +
   1.304 +        return name;
   1.305 +    }
   1.306 +
   1.307 +    protected boolean databaseAllFilesEqual(Database previousDB,
   1.308 +                                            Database currentDB) {
   1.309 +        Iterator i1 = previousDB.getAllFiles().iterator();
   1.310 +        Iterator i2 = currentDB.getAllFiles().iterator();
   1.311 +
   1.312 +        while (i1.hasNext() && i2.hasNext()) {
   1.313 +            FileList fl1 = (FileList) i1.next();
   1.314 +            FileList fl2 = (FileList) i2.next();
   1.315 +            if (!fl1.getName().equals(fl2.getName())) {
   1.316 +                return false;
   1.317 +            }
   1.318 +        }
   1.319 +
   1.320 +        if (i1.hasNext() != i2.hasNext()) {
   1.321 +            // Different lengths
   1.322 +            return false;
   1.323 +        }
   1.324 +
   1.325 +        return true;
   1.326 +    }
   1.327 +
   1.328 +    protected String envVarPrefixedFileName(String fileName,
   1.329 +                                            int sourceBaseLen,
   1.330 +                                            DirectoryTree tree,
   1.331 +                                            Vector preferredPaths,
   1.332 +                                            Vector filesNotFound,
   1.333 +                                            Vector filesDuplicate) {
   1.334 +        String fullName = findFileInDirectory(fileName,
   1.335 +                                              tree,
   1.336 +                                              preferredPaths,
   1.337 +                                              filesNotFound,
   1.338 +                                              filesDuplicate);
   1.339 +        return fullName;
   1.340 +    }
   1.341 +
   1.342 +     String getProjectName(String fullPath, String extension)
   1.343 +        throws IllegalArgumentException, IOException {
   1.344 +        File file = new File(fullPath).getCanonicalFile();
   1.345 +        fullPath = file.getCanonicalPath();
   1.346 +        String parent = file.getParent();
   1.347 +
   1.348 +        if (!fullPath.endsWith(extension)) {
   1.349 +            throw new IllegalArgumentException("project file name \"" +
   1.350 +                                               fullPath +
   1.351 +                                               "\" does not end in "+extension);
   1.352 +        }
   1.353 +
   1.354 +        if ((parent != null) &&
   1.355 +            (!fullPath.startsWith(parent))) {
   1.356 +            throw new RuntimeException(
   1.357 +                "Internal error: parent of file name \"" + parent +
   1.358 +                "\" does not match file name \"" + fullPath + "\""
   1.359 +            );
   1.360 +        }
   1.361 +
   1.362 +        int len = parent.length();
   1.363 +        if (!parent.endsWith(Util.sep)) {
   1.364 +            len += Util.sep.length();
   1.365 +        }
   1.366 +
   1.367 +        int end = fullPath.length() - extension.length();
   1.368 +
   1.369 +        if (len == end) {
   1.370 +            throw new RuntimeException(
   1.371 +                "Internal error: file name was empty"
   1.372 +            );
   1.373 +        }
   1.374 +
   1.375 +        return fullPath.substring(len, end);
   1.376 +    }
   1.377 +
   1.378 +    protected abstract String getProjectExt();
   1.379 +
   1.380 +    public void writePlatformSpecificFiles(Database previousDB,
   1.381 +                                           Database currentDB, String[] args)
   1.382 +        throws IllegalArgumentException, IOException {
   1.383 +
   1.384 +        parseArguments(args);
   1.385 +
   1.386 +        String projectFileName = BuildConfig.getFieldString(null, "ProjectFileName");
   1.387 +        String ext = getProjectExt();
   1.388 +
   1.389 +        // Compare contents of allFiles of previousDB and includeDB.
   1.390 +        // If these haven't changed, then skip writing the .vcproj file.
   1.391 +        if (false && databaseAllFilesEqual(previousDB, currentDB) &&
   1.392 +            new File(projectFileName).exists()) {
   1.393 +            System.out.println(
   1.394 +                               "    Databases unchanged; skipping overwrite of "+ext+" file."
   1.395 +                               );
   1.396 +            return;
   1.397 +        }
   1.398 +
   1.399 +        String projectName = getProjectName(projectFileName, ext);
   1.400 +
   1.401 +        writeProjectFile(projectFileName, projectName, createAllConfigs());
   1.402 +    }
   1.403 +
   1.404 +    protected void writePrologue(String[] args) {
   1.405 +        System.err.println("WinGammaPlatform platform-specific arguments:");
   1.406 +        for (int i = 0; i < args.length; i++) {
   1.407 +            System.err.print(args[i] + " ");
   1.408 +        }
   1.409 +        System.err.println();
   1.410 +    }
   1.411 +
   1.412 +
   1.413 +    void setInclFileTemplate(FileName val) {
   1.414 +        this.inclFileTemplate = val;
   1.415 +    }
   1.416 +
   1.417 +    void setGIFileTemplate(FileName val) {
   1.418 +        this.giFileTemplate = val;
   1.419 +    }
   1.420 +
   1.421 +
   1.422 +    void parseArguments(String[] args) {
   1.423 +        new ArgsParser(args,
   1.424 +                       new ArgRule[]
   1.425 +            {
   1.426 +                new HsArgRule("-sourceBase",
   1.427 +                              "SourceBase",
   1.428 +                              "   (Did you set the HotSpotWorkSpace environment variable?)",
   1.429 +                              HsArgHandler.STRING
   1.430 +                              ),
   1.431 +
   1.432 +                new HsArgRule("-buildBase",
   1.433 +                              "BuildBase",
   1.434 +                              "   (Did you set the HotSpotBuildSpace environment variable?)",
   1.435 +                              HsArgHandler.STRING
   1.436 +                              ),
   1.437 +
   1.438 +                new HsArgRule("-projectFileName",
   1.439 +                              "ProjectFileName",
   1.440 +                              null,
   1.441 +                              HsArgHandler.STRING
   1.442 +                              ),
   1.443 +
   1.444 +                new HsArgRule("-jdkTargetRoot",
   1.445 +                              "JdkTargetRoot",
   1.446 +                              "   (Did you set the HotSpotJDKDist environment variable?)",
   1.447 +                              HsArgHandler.STRING
   1.448 +                              ),
   1.449 +
   1.450 +                new HsArgRule("-compiler",
   1.451 +                              "CompilerVersion",
   1.452 +                              "   (Did you set the VcVersion correctly?)",
   1.453 +                              HsArgHandler.STRING
   1.454 +                              ),
   1.455 +
   1.456 +                new HsArgRule("-platform",
   1.457 +                              "Platform",
   1.458 +                              null,
   1.459 +                              HsArgHandler.STRING
   1.460 +                              ),
   1.461 +
   1.462 +                new HsArgRule("-absoluteInclude",
   1.463 +                              "AbsoluteInclude",
   1.464 +                              null,
   1.465 +                              HsArgHandler.VECTOR
   1.466 +                              ),
   1.467 +
   1.468 +                new HsArgRule("-relativeInclude",
   1.469 +                              "RelativeInclude",
   1.470 +                              null,
   1.471 +                              HsArgHandler.VECTOR
   1.472 +                              ),
   1.473 +
   1.474 +                new HsArgRule("-define",
   1.475 +                              "Define",
   1.476 +                              null,
   1.477 +                              HsArgHandler.VECTOR
   1.478 +                              ),
   1.479 +
   1.480 +                new HsArgRule("-useToGeneratePch",
   1.481 +                              "UseToGeneratePch",
   1.482 +                              null,
   1.483 +                              HsArgHandler.STRING
   1.484 +                              ),
   1.485 +
   1.486 +                new ArgRuleSpecific("-perFileLine",
   1.487 +                            new HsArgHandler() {
   1.488 +                                public void handle(ArgIterator it) {
   1.489 +                                    String cfg = getCfg(it.get());
   1.490 +                                    if (nextNotKey(it)) {
   1.491 +                                        String fileName = it.get();
   1.492 +                                        if (nextNotKey(it)) {
   1.493 +                                            String line = it.get();
   1.494 +                                            BuildConfig.putFieldHash(cfg, "PerFileLine", fileName, line);
   1.495 +                                            it.next();
   1.496 +                                            return;
   1.497 +                                        }
   1.498 +                                    }
   1.499 +                                    empty(null, "** Error: wrong number of args to -perFileLine");
   1.500 +                                }
   1.501 +                            }
   1.502 +                            ),
   1.503 +
   1.504 +                new ArgRuleSpecific("-conditionalPerFileLine",
   1.505 +                            new HsArgHandler() {
   1.506 +                                public void handle(ArgIterator it) {
   1.507 +                                    String cfg = getCfg(it.get());
   1.508 +                                    if (nextNotKey(it)) {
   1.509 +                                        String fileName = it.get();
   1.510 +                                        if (nextNotKey(it)) {
   1.511 +                                            String productLine = it.get();
   1.512 +                                            if (nextNotKey(it)) {
   1.513 +                                                String debugLine = it.get();
   1.514 +                                                BuildConfig.putFieldHash(cfg+"_debug", "CondPerFileLine",
   1.515 +                                                                         fileName, debugLine);
   1.516 +                                                BuildConfig.putFieldHash(cfg+"_product", "CondPerFileLine",
   1.517 +                                                                         fileName, productLine);
   1.518 +                                                it.next();
   1.519 +                                                return;
   1.520 +                                            }
   1.521 +                                        }
   1.522 +                                    }
   1.523 +
   1.524 +                                    empty(null, "** Error: wrong number of args to -conditionalPerFileLine");
   1.525 +                                }
   1.526 +                            }
   1.527 +                            ),
   1.528 +
   1.529 +                new HsArgRule("-disablePch",
   1.530 +                              "DisablePch",
   1.531 +                              null,
   1.532 +                              HsArgHandler.HASH
   1.533 +                              ),
   1.534 +
   1.535 +                new ArgRule("-startAt",
   1.536 +                            new HsArgHandler() {
   1.537 +                                public void handle(ArgIterator it) {
   1.538 +                                    if (BuildConfig.getField(null, "StartAt") != null) {
   1.539 +                                        empty(null, "** Error: multiple -startAt");
   1.540 +                                    }
   1.541 +                                    if (nextNotKey(it)) {
   1.542 +                                        BuildConfig.putField(null, "StartAt", it.get());
   1.543 +                                        it.next();
   1.544 +                                    } else {
   1.545 +                                        empty("-startAt", null);
   1.546 +                                    }
   1.547 +                                }
   1.548 +                            }
   1.549 +                            ),
   1.550 +
   1.551 +                new HsArgRule("-ignoreFile",
   1.552 +                                      "IgnoreFile",
   1.553 +                                      null,
   1.554 +                                      HsArgHandler.HASH
   1.555 +                                      ),
   1.556 +
   1.557 +                new HsArgRule("-additionalFile",
   1.558 +                              "AdditionalFile",
   1.559 +                              null,
   1.560 +                              HsArgHandler.VECTOR
   1.561 +                              ),
   1.562 +
   1.563 +                new ArgRuleSpecific("-additionalGeneratedFile",
   1.564 +                            new HsArgHandler() {
   1.565 +                                public void handle(ArgIterator it) {
   1.566 +                                    String cfg = getCfg(it.get());
   1.567 +                                    if (nextNotKey(it)) {
   1.568 +                                        String dir = it.get();
   1.569 +                                        if (nextNotKey(it)) {
   1.570 +                                            String fileName = it.get();
   1.571 +                                            // we ignore files that we know are generated, so we coudn't
   1.572 +                                            // find them in sources
   1.573 +                                            BuildConfig.putFieldHash(cfg, "IgnoreFile",  fileName, "1");
   1.574 +                                            BuildConfig.putFieldHash(cfg, "AdditionalGeneratedFile",
   1.575 +                                                                     Util.normalize(dir + Util.sep + fileName),
   1.576 +                                                                     fileName);
   1.577 +                                            it.next();
   1.578 +                                            return;
   1.579 +                                        }
   1.580 +                                    }
   1.581 +                                    empty(null, "** Error: wrong number of args to -additionalGeneratedFile");
   1.582 +                                }
   1.583 +                            }
   1.584 +                            ),
   1.585 +
   1.586 +                new HsArgRule("-includeDB",
   1.587 +                              "IncludeDB",
   1.588 +                              null,
   1.589 +                              HsArgHandler.STRING
   1.590 +                              ),
   1.591 +
   1.592 +                new ArgRule("-prelink",
   1.593 +                            new HsArgHandler() {
   1.594 +                                public void handle(ArgIterator it) {
   1.595 +                                    if (nextNotKey(it)) {
   1.596 +                                        String build = it.get();
   1.597 +                                        if (nextNotKey(it)) {
   1.598 +                                            String description = it.get();
   1.599 +                                            if (nextNotKey(it)) {
   1.600 +                                                String command = it.get();
   1.601 +                                                BuildConfig.putField(null, "PrelinkDescription", description);
   1.602 +                                                BuildConfig.putField(null, "PrelinkCommand", command);
   1.603 +                                                it.next();
   1.604 +                                                return;
   1.605 +                                            }
   1.606 +                                        }
   1.607 +                                    }
   1.608 +
   1.609 +                                    empty(null,  "** Error: wrong number of args to -prelink");
   1.610 +                                }
   1.611 +                            }
   1.612 +                            )
   1.613 +            },
   1.614 +                                       new ArgHandler() {
   1.615 +                                           public void handle(ArgIterator it) {
   1.616 +
   1.617 +                                               throw new RuntimeException("Arg Parser: unrecognized option "+it.get());
   1.618 +                                           }
   1.619 +                                       }
   1.620 +                                       );
   1.621 +        if (BuildConfig.getField(null, "SourceBase") == null      ||
   1.622 +            BuildConfig.getField(null, "BuildBase") == null       ||
   1.623 +            BuildConfig.getField(null, "ProjectFileName") == null ||
   1.624 +            BuildConfig.getField(null, "CompilerVersion") == null) {
   1.625 +            usage();
   1.626 +        }
   1.627 +
   1.628 +        if (BuildConfig.getField(null, "UseToGeneratePch") == null) {
   1.629 +            throw new RuntimeException("ERROR: need to specify one file to compute PCH, with -useToGeneratePch flag");
   1.630 +        }
   1.631 +
   1.632 +        BuildConfig.putField(null, "PlatformObject", this);
   1.633 +    }
   1.634 +
   1.635 +    Vector createAllConfigs() {
   1.636 +        Vector allConfigs = new Vector();
   1.637 +
   1.638 +        allConfigs.add(new C1DebugConfig());
   1.639 +
   1.640 +        boolean b = true;
   1.641 +        if (b) {
   1.642 +            allConfigs.add(new C1FastDebugConfig());
   1.643 +            allConfigs.add(new C1ProductConfig());
   1.644 +
   1.645 +            allConfigs.add(new C2DebugConfig());
   1.646 +            allConfigs.add(new C2FastDebugConfig());
   1.647 +            allConfigs.add(new C2ProductConfig());
   1.648 +
   1.649 +            allConfigs.add(new TieredDebugConfig());
   1.650 +            allConfigs.add(new TieredFastDebugConfig());
   1.651 +            allConfigs.add(new TieredProductConfig());
   1.652 +
   1.653 +            allConfigs.add(new CoreDebugConfig());
   1.654 +            allConfigs.add(new CoreFastDebugConfig());
   1.655 +            allConfigs.add(new CoreProductConfig());
   1.656 +
   1.657 +            allConfigs.add(new KernelDebugConfig());
   1.658 +            allConfigs.add(new KernelFastDebugConfig());
   1.659 +            allConfigs.add(new KernelProductConfig());
   1.660 +        }
   1.661 +
   1.662 +        return allConfigs;
   1.663 +    }
   1.664 +
   1.665 +    class FileAttribute {
   1.666 +        int     numConfigs;
   1.667 +        Vector  configs;
   1.668 +        String  shortName;
   1.669 +        boolean noPch, pchRoot;
   1.670 +
   1.671 +        FileAttribute(String shortName, BuildConfig cfg, int numConfigs) {
   1.672 +            this.shortName = shortName;
   1.673 +            this.noPch =  (cfg.lookupHashFieldInContext("DisablePch", shortName) != null);
   1.674 +            this.pchRoot = shortName.equals(BuildConfig.getFieldString(null, "UseToGeneratePch"));
   1.675 +            this.numConfigs = numConfigs;
   1.676 +
   1.677 +            configs = new Vector();
   1.678 +            add(cfg.get("Name"));
   1.679 +        }
   1.680 +
   1.681 +        void add(String confName) {
   1.682 +            configs.add(confName);
   1.683 +
   1.684 +            // if presented in all configs
   1.685 +            if (configs.size() == numConfigs) {
   1.686 +                configs = null;
   1.687 +            }
   1.688 +        }
   1.689 +    }
   1.690 +
   1.691 +    class FileInfo implements Comparable {
   1.692 +        String        full;
   1.693 +        FileAttribute attr;
   1.694 +
   1.695 +        FileInfo(String full, FileAttribute  attr) {
   1.696 +            this.full = full;
   1.697 +            this.attr = attr;
   1.698 +        }
   1.699 +
   1.700 +        public int compareTo(Object o) {
   1.701 +            FileInfo oo = (FileInfo)o;
   1.702 +            // Don't squelch identical short file names where the full
   1.703 +            // paths are different
   1.704 +            if (!attr.shortName.equals(oo.attr.shortName))
   1.705 +              return attr.shortName.compareTo(oo.attr.shortName);
   1.706 +            return full.compareTo(oo.full);
   1.707 +        }
   1.708 +
   1.709 +        boolean isHeader() {
   1.710 +            return attr.shortName.endsWith(".h") || attr.shortName.endsWith(".hpp");
   1.711 +        }
   1.712 +    }
   1.713 +
   1.714 +
   1.715 +    TreeSet sortFiles(Hashtable allFiles) {
   1.716 +        TreeSet rv = new TreeSet();
   1.717 +        Enumeration e = allFiles.keys();
   1.718 +        while (e.hasMoreElements()) {
   1.719 +            String fullPath = (String)e.nextElement();
   1.720 +            rv.add(new FileInfo(fullPath, (FileAttribute)allFiles.get(fullPath)));
   1.721 +        }
   1.722 +        return rv;
   1.723 +    }
   1.724 +
   1.725 +    Hashtable computeAttributedFiles(Vector allConfigs) {
   1.726 +        Hashtable ht = new Hashtable();
   1.727 +        int numConfigs = allConfigs.size();
   1.728 +
   1.729 +        for (Iterator i = allConfigs.iterator(); i.hasNext(); ) {
   1.730 +            BuildConfig bc = (BuildConfig)i.next();
   1.731 +            Hashtable  confFiles = (Hashtable)bc.getSpecificField("AllFilesHash");
   1.732 +            String confName = bc.get("Name");
   1.733 +
   1.734 +            for (Enumeration e=confFiles.keys(); e.hasMoreElements(); ) {
   1.735 +                String filePath = (String)e.nextElement();
   1.736 +                FileAttribute fa = (FileAttribute)ht.get(filePath);
   1.737 +
   1.738 +                if (fa == null) {
   1.739 +                    fa = new FileAttribute((String)confFiles.get(filePath), bc, numConfigs);
   1.740 +                    ht.put(filePath, fa);
   1.741 +                } else {
   1.742 +                    fa.add(confName);
   1.743 +                }
   1.744 +            }
   1.745 +        }
   1.746 +
   1.747 +        return ht;
   1.748 +    }
   1.749 +
   1.750 +     Hashtable computeAttributedFiles(BuildConfig bc) {
   1.751 +        Hashtable ht = new Hashtable();
   1.752 +        Hashtable confFiles = (Hashtable)bc.getSpecificField("AllFilesHash");
   1.753 +
   1.754 +        for (Enumeration e = confFiles.keys(); e.hasMoreElements(); ) {
   1.755 +            String filePath = (String)e.nextElement();
   1.756 +            ht.put(filePath,  new FileAttribute((String)confFiles.get(filePath), bc, 1));
   1.757 +        }
   1.758 +
   1.759 +        return ht;
   1.760 +    }
   1.761 +
   1.762 +    PrintWriter printWriter;
   1.763 +
   1.764 +    public void writeProjectFile(String projectFileName, String projectName,
   1.765 +                                 Vector allConfigs) throws IOException {
   1.766 +        throw new RuntimeException("use compiler version specific version");
   1.767 +    }
   1.768 +}

mercurial