src/share/tools/ProjectCreator/WinGammaPlatform.java

Print this page


   1 /*
   2  * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 100         }
 101     }
 102 
 103     SpecificHsArgHandler(String argKey, String valKey, String message, int type) {
 104         this.argKey = argKey;
 105         this.valKey = valKey;
 106         this.message = message;
 107         this.type = type;
 108     }
 109 }
 110 
 111 
 112 class HsArgRule extends ArgRuleSpecific {
 113 
 114     HsArgRule(String argKey, String valKey, String message, int type) {
 115         super(argKey, new SpecificHsArgHandler(argKey, valKey, message, type));
 116     }
 117 
 118 }
 119 
 120 public abstract class WinGammaPlatform extends Platform {
 121     public void setupFileTemplates() {
 122         inclFileTemplate = new FileName(this,
 123             "incls\\", "_", "",                      ".incl", "", ""
 124         );
 125         giFileTemplate = new FileName(this,
 126             "incls\\", "",  "_precompiled", ".incl", "", ""
 127         );
 128         gdFileTemplate = new FileName(this,
 129             "", "",  "Dependencies",         "",      "", ""
 130         );
 131     }
 132 
 133     private static String[] suffixes = { ".cpp", ".c" };
 134 
 135     public String[] outerSuffixes() {
 136         return suffixes;
 137     }
 138 
 139     public String objFileSuffix() {
 140         return ".obj";
 141     }
 142 
 143     public String asmFileSuffix() {
 144         return ".i";
 145     }
 146 
 147     public String dependentPrefix() {
 148         return "$(VM_PATH)";
 149     }
 150 
 151     public boolean includeGIInEachIncl() {
 152         return false;
 153     }
 154 
 155     public boolean fileNameStringEquality(String s1, String s2) {
 156         return s1.equalsIgnoreCase(s2);
 157     }
 158 
 159     static void usage() throws IllegalArgumentException {
 160         System.err.println("WinGammaPlatform platform-specific options:");
 161         System.err.println("  -sourceBase <path to directory (workspace) " +
 162                            "containing source files; no trailing slash>");
 163         System.err.println("  -projectFileName <full pathname to which project file " +
 164                            "will be written; all parent directories must " +
 165                            "already exist>");
 166         System.err.println("  If any of the above are specified, "+
 167                            "they must all be.");
 168         System.err.println("  Additional, optional arguments, which can be " +
 169                            "specified multiple times:");
 170         System.err.println("    -absoluteInclude <string containing absolute " +
 171                            "path to include directory>");
 172         System.err.println("    -relativeInclude <string containing include " +
 173                            "directory relative to -sourceBase>");
 174         System.err.println("    -define <preprocessor flag to be #defined " +
 175                            "(note: doesn't yet support " +
 176                            "#define (flag) (value))>");
 177         System.err.println("    -startAt <subdir of sourceBase>");
 178         System.err.println("    -additionalFile <file not in database but " +
 179                            "which should show up in project file, like " +
 180                            "includeDB_core>");
 181         System.err.println("    -additionalGeneratedFile <absolute path to " +
 182                            "directory containing file; no trailing slash> " +
 183                            "<name of file generated later in the build process>");
 184         throw new IllegalArgumentException();
 185     }
 186 
 187 
 188     public void addPerFileLine(Hashtable table,
 189                                String fileName,
 190                                String line) {
 191         Vector v = (Vector) table.get(fileName);
 192         if (v != null) {
 193             v.add(line);
 194         } else {
 195             v = new Vector();
 196             v.add(line);
 197             table.put(fileName, v);
 198         }
 199     }
 200 


 284                         // found from the file path not including the root node name.
 285                         if (tmpName.indexOf((String)prefIter.next(),
 286                                             rootNameLength) != -1) {
 287                             name = tmpName;
 288                             break search;
 289                         }
 290                     }
 291                 }
 292             }
 293 
 294             if (name == null) {
 295                 filesDuplicate.add(fileName);
 296             }
 297         } else {
 298             name = ((DirectoryTreeNode) locationsInTree.get(0)).getName();
 299         }
 300 
 301         return name;
 302     }
 303 
 304     protected boolean databaseAllFilesEqual(Database previousDB,
 305                                             Database currentDB) {
 306         Iterator i1 = previousDB.getAllFiles().iterator();
 307         Iterator i2 = currentDB.getAllFiles().iterator();
 308 
 309         while (i1.hasNext() && i2.hasNext()) {
 310             FileList fl1 = (FileList) i1.next();
 311             FileList fl2 = (FileList) i2.next();
 312             if (!fl1.getName().equals(fl2.getName())) {
 313                 return false;
 314             }
 315         }
 316 
 317         if (i1.hasNext() != i2.hasNext()) {
 318             // Different lengths
 319             return false;
 320         }
 321 
 322         return true;
 323     }
 324 
 325     protected String envVarPrefixedFileName(String fileName,
 326                                             int sourceBaseLen,
 327                                             DirectoryTree tree,
 328                                             Vector preferredPaths,
 329                                             Vector filesNotFound,
 330                                             Vector filesDuplicate) {
 331         String fullName = findFileInDirectory(fileName,
 332                                               tree,
 333                                               preferredPaths,
 334                                               filesNotFound,
 335                                               filesDuplicate);
 336         return fullName;
 337     }
 338 
 339      String getProjectName(String fullPath, String extension)
 340         throws IllegalArgumentException, IOException {
 341         File file = new File(fullPath).getCanonicalFile();
 342         fullPath = file.getCanonicalPath();
 343         String parent = file.getParent();
 344 


 357         }
 358 
 359         int len = parent.length();
 360         if (!parent.endsWith(Util.sep)) {
 361             len += Util.sep.length();
 362         }
 363 
 364         int end = fullPath.length() - extension.length();
 365 
 366         if (len == end) {
 367             throw new RuntimeException(
 368                 "Internal error: file name was empty"
 369             );
 370         }
 371 
 372         return fullPath.substring(len, end);
 373     }
 374 
 375     protected abstract String getProjectExt();
 376 
 377     public void writePlatformSpecificFiles(Database previousDB,
 378                                            Database currentDB, String[] args)
 379         throws IllegalArgumentException, IOException {
 380 
 381         parseArguments(args);
 382 
 383         String projectFileName = BuildConfig.getFieldString(null, "ProjectFileName");
 384         String ext = getProjectExt();
 385 
 386         // Compare contents of allFiles of previousDB and includeDB.
 387         // If these haven't changed, then skip writing the .vcproj file.
 388         if (false && databaseAllFilesEqual(previousDB, currentDB) &&
 389             new File(projectFileName).exists()) {
 390             System.out.println(
 391                                "    Databases unchanged; skipping overwrite of "+ext+" file."
 392                                );
 393             return;
 394         }
 395 
 396         String projectName = getProjectName(projectFileName, ext);
 397 
 398         writeProjectFile(projectFileName, projectName, createAllConfigs());
 399     }
 400 
 401     protected void writePrologue(String[] args) {
 402         System.err.println("WinGammaPlatform platform-specific arguments:");
 403         for (int i = 0; i < args.length; i++) {
 404             System.err.print(args[i] + " ");
 405         }
 406         System.err.println();
 407     }
 408 
 409 
 410     void setInclFileTemplate(FileName val) {
 411         this.inclFileTemplate = val;
 412     }
 413 
 414     void setGIFileTemplate(FileName val) {
 415         this.giFileTemplate = val;
 416     }
 417 
 418 
 419     void parseArguments(String[] args) {
 420         new ArgsParser(args,
 421                        new ArgRule[]
 422             {
 423                 new HsArgRule("-sourceBase",
 424                               "SourceBase",
 425                               "   (Did you set the HotSpotWorkSpace environment variable?)",
 426                               HsArgHandler.STRING
 427                               ),
 428 
 429                 new HsArgRule("-buildBase",
 430                               "BuildBase",
 431                               "   (Did you set the HotSpotBuildSpace environment variable?)",
 432                               HsArgHandler.STRING
 433                               ),
 434 
 435                 new HsArgRule("-projectFileName",
 436                               "ProjectFileName",
 437                               null,
 438                               HsArgHandler.STRING


 534                                 public void handle(ArgIterator it) {
 535                                     if (BuildConfig.getField(null, "StartAt") != null) {
 536                                         empty(null, "** Error: multiple -startAt");
 537                                     }
 538                                     if (nextNotKey(it)) {
 539                                         BuildConfig.putField(null, "StartAt", it.get());
 540                                         it.next();
 541                                     } else {
 542                                         empty("-startAt", null);
 543                                     }
 544                                 }
 545                             }
 546                             ),
 547 
 548                 new HsArgRule("-ignoreFile",
 549                                       "IgnoreFile",
 550                                       null,
 551                                       HsArgHandler.HASH
 552                                       ),
 553 






 554                 new HsArgRule("-additionalFile",
 555                               "AdditionalFile",
 556                               null,
 557                               HsArgHandler.VECTOR
 558                               ),
 559 
 560                 new ArgRuleSpecific("-additionalGeneratedFile",
 561                             new HsArgHandler() {
 562                                 public void handle(ArgIterator it) {
 563                                     String cfg = getCfg(it.get());
 564                                     if (nextNotKey(it)) {
 565                                         String dir = it.get();
 566                                         if (nextNotKey(it)) {
 567                                             String fileName = it.get();
 568                                             // we ignore files that we know are generated, so we coudn't
 569                                             // find them in sources
 570                                             BuildConfig.putFieldHash(cfg, "IgnoreFile",  fileName, "1");
 571                                             BuildConfig.putFieldHash(cfg, "AdditionalGeneratedFile",
 572                                                                      Util.normalize(dir + Util.sep + fileName),
 573                                                                      fileName);
 574                                             it.next();
 575                                             return;
 576                                         }
 577                                     }
 578                                     empty(null, "** Error: wrong number of args to -additionalGeneratedFile");
 579                                 }
 580                             }
 581                             ),
 582 
 583                 new HsArgRule("-includeDB",
 584                               "IncludeDB",
 585                               null,
 586                               HsArgHandler.STRING
 587                               ),
 588 
 589                 new ArgRule("-prelink",
 590                             new HsArgHandler() {
 591                                 public void handle(ArgIterator it) {
 592                                     if (nextNotKey(it)) {
 593                                         String build = it.get();
 594                                         if (nextNotKey(it)) {
 595                                             String description = it.get();
 596                                             if (nextNotKey(it)) {
 597                                                 String command = it.get();
 598                                                 BuildConfig.putField(null, "PrelinkDescription", description);
 599                                                 BuildConfig.putField(null, "PrelinkCommand", command);
 600                                                 it.next();
 601                                                 return;
 602                                             }
 603                                         }
 604                                     }
 605 
 606                                     empty(null,  "** Error: wrong number of args to -prelink");
 607                                 }
 608                             }


   1 /*
   2  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 100         }
 101     }
 102 
 103     SpecificHsArgHandler(String argKey, String valKey, String message, int type) {
 104         this.argKey = argKey;
 105         this.valKey = valKey;
 106         this.message = message;
 107         this.type = type;
 108     }
 109 }
 110 
 111 
 112 class HsArgRule extends ArgRuleSpecific {
 113 
 114     HsArgRule(String argKey, String valKey, String message, int type) {
 115         super(argKey, new SpecificHsArgHandler(argKey, valKey, message, type));
 116     }
 117 
 118 }
 119 
 120 public abstract class WinGammaPlatform {

































 121     
 122     public boolean fileNameStringEquality(String s1, String s2) {
 123         return s1.equalsIgnoreCase(s2);
 124     }
 125 
 126     static void usage() throws IllegalArgumentException {
 127         System.err.println("WinGammaPlatform platform-specific options:");
 128         System.err.println("  -sourceBase <path to directory (workspace) " +
 129                            "containing source files; no trailing slash>");
 130         System.err.println("  -projectFileName <full pathname to which project file " +
 131                            "will be written; all parent directories must " +
 132                            "already exist>");
 133         System.err.println("  If any of the above are specified, "+
 134                            "they must all be.");
 135         System.err.println("  Additional, optional arguments, which can be " +
 136                            "specified multiple times:");
 137         System.err.println("    -absoluteInclude <string containing absolute " +
 138                            "path to include directory>");
 139         System.err.println("    -relativeInclude <string containing include " +
 140                            "directory relative to -sourceBase>");
 141         System.err.println("    -define <preprocessor flag to be #defined " +
 142                            "(note: doesn't yet support " +
 143                            "#define (flag) (value))>");
 144         System.err.println("    -startAt <subdir of sourceBase>");
 145         System.err.println("    -additionalFile <file not in database but " +
 146                            "which should show up in project file>");

 147         System.err.println("    -additionalGeneratedFile <absolute path to " +
 148                            "directory containing file; no trailing slash> " +
 149                            "<name of file generated later in the build process>");
 150         throw new IllegalArgumentException();
 151     }
 152 
 153 
 154     public void addPerFileLine(Hashtable table,
 155                                String fileName,
 156                                String line) {
 157         Vector v = (Vector) table.get(fileName);
 158         if (v != null) {
 159             v.add(line);
 160         } else {
 161             v = new Vector();
 162             v.add(line);
 163             table.put(fileName, v);
 164         }
 165     }
 166 


 250                         // found from the file path not including the root node name.
 251                         if (tmpName.indexOf((String)prefIter.next(),
 252                                             rootNameLength) != -1) {
 253                             name = tmpName;
 254                             break search;
 255                         }
 256                     }
 257                 }
 258             }
 259 
 260             if (name == null) {
 261                 filesDuplicate.add(fileName);
 262             }
 263         } else {
 264             name = ((DirectoryTreeNode) locationsInTree.get(0)).getName();
 265         }
 266 
 267         return name;
 268     }
 269 





















 270     protected String envVarPrefixedFileName(String fileName,
 271                                             int sourceBaseLen,
 272                                             DirectoryTree tree,
 273                                             Vector preferredPaths,
 274                                             Vector filesNotFound,
 275                                             Vector filesDuplicate) {
 276         String fullName = findFileInDirectory(fileName,
 277                                               tree,
 278                                               preferredPaths,
 279                                               filesNotFound,
 280                                               filesDuplicate);
 281         return fullName;
 282     }
 283 
 284      String getProjectName(String fullPath, String extension)
 285         throws IllegalArgumentException, IOException {
 286         File file = new File(fullPath).getCanonicalFile();
 287         fullPath = file.getCanonicalPath();
 288         String parent = file.getParent();
 289 


 302         }
 303 
 304         int len = parent.length();
 305         if (!parent.endsWith(Util.sep)) {
 306             len += Util.sep.length();
 307         }
 308 
 309         int end = fullPath.length() - extension.length();
 310 
 311         if (len == end) {
 312             throw new RuntimeException(
 313                 "Internal error: file name was empty"
 314             );
 315         }
 316 
 317         return fullPath.substring(len, end);
 318     }
 319 
 320     protected abstract String getProjectExt();
 321 
 322     public void createVcproj(String[] args)

 323         throws IllegalArgumentException, IOException {
 324 
 325         parseArguments(args);
 326 
 327         String projectFileName = BuildConfig.getFieldString(null, "ProjectFileName");
 328         String ext = getProjectExt();
 329 










 330         String projectName = getProjectName(projectFileName, ext);
 331 
 332         writeProjectFile(projectFileName, projectName, createAllConfigs());
 333     }
 334 
 335     protected void writePrologue(String[] args) {
 336         System.err.println("WinGammaPlatform platform-specific arguments:");
 337         for (int i = 0; i < args.length; i++) {
 338             System.err.print(args[i] + " ");
 339         }
 340         System.err.println();
 341     }
 342 
 343 









 344     void parseArguments(String[] args) {
 345         new ArgsParser(args,
 346                        new ArgRule[]
 347             {
 348                 new HsArgRule("-sourceBase",
 349                               "SourceBase",
 350                               "   (Did you set the HotSpotWorkSpace environment variable?)",
 351                               HsArgHandler.STRING
 352                               ),
 353 
 354                 new HsArgRule("-buildBase",
 355                               "BuildBase",
 356                               "   (Did you set the HotSpotBuildSpace environment variable?)",
 357                               HsArgHandler.STRING
 358                               ),
 359 
 360                 new HsArgRule("-projectFileName",
 361                               "ProjectFileName",
 362                               null,
 363                               HsArgHandler.STRING


 459                                 public void handle(ArgIterator it) {
 460                                     if (BuildConfig.getField(null, "StartAt") != null) {
 461                                         empty(null, "** Error: multiple -startAt");
 462                                     }
 463                                     if (nextNotKey(it)) {
 464                                         BuildConfig.putField(null, "StartAt", it.get());
 465                                         it.next();
 466                                     } else {
 467                                         empty("-startAt", null);
 468                                     }
 469                                 }
 470                             }
 471                             ),
 472 
 473                 new HsArgRule("-ignoreFile",
 474                                       "IgnoreFile",
 475                                       null,
 476                                       HsArgHandler.HASH
 477                                       ),
 478 
 479                 new HsArgRule("-ignorePath",
 480                               "IgnorePath",
 481                               null,
 482                               HsArgHandler.VECTOR
 483                               ),
 484 
 485                 new HsArgRule("-additionalFile",
 486                               "AdditionalFile",
 487                               null,
 488                               HsArgHandler.VECTOR
 489                               ),
 490 
 491                 new ArgRuleSpecific("-additionalGeneratedFile",
 492                             new HsArgHandler() {
 493                                 public void handle(ArgIterator it) {
 494                                     String cfg = getCfg(it.get());
 495                                     if (nextNotKey(it)) {
 496                                         String dir = it.get();
 497                                         if (nextNotKey(it)) {
 498                                             String fileName = it.get();



 499                                             BuildConfig.putFieldHash(cfg, "AdditionalGeneratedFile",
 500                                                                      Util.normalize(dir + Util.sep + fileName),
 501                                                                      fileName);
 502                                             it.next();
 503                                             return;
 504                                         }
 505                                     }
 506                                     empty(null, "** Error: wrong number of args to -additionalGeneratedFile");
 507                                 }
 508                             }
 509                             ),
 510 






 511                 new ArgRule("-prelink",
 512                             new HsArgHandler() {
 513                                 public void handle(ArgIterator it) {
 514                                     if (nextNotKey(it)) {
 515                                         String build = it.get();
 516                                         if (nextNotKey(it)) {
 517                                             String description = it.get();
 518                                             if (nextNotKey(it)) {
 519                                                 String command = it.get();
 520                                                 BuildConfig.putField(null, "PrelinkDescription", description);
 521                                                 BuildConfig.putField(null, "PrelinkCommand", command);
 522                                                 it.next();
 523                                                 return;
 524                                             }
 525                                         }
 526                                     }
 527 
 528                                     empty(null,  "** Error: wrong number of args to -prelink");
 529                                 }
 530                             }