comparison src/share/tools/ProjectCreator/BuildConfig.java @ 6801:1a9b9cfcef41

7163863: Updated projectcreator Summary: Enable source browsing for all platform dependent code Reviewed-by: brutisso, coleenp
author neliasso
date Thu, 29 Mar 2012 16:43:21 +0200
parents 2eeebe4b4213
children e522a00b91aa 6b748c9e1845
comparison
equal deleted inserted replaced
6800:9191895df19d 6801:1a9b9cfcef41
20 * or visit www.oracle.com if you need additional information or have any 20 * or visit www.oracle.com if you need additional information or have any
21 * questions. 21 * questions.
22 * 22 *
23 */ 23 */
24 24
25 import java.io.File;
26 import java.util.Enumeration; 25 import java.util.Enumeration;
27 import java.util.Hashtable; 26 import java.util.Hashtable;
28 import java.util.Iterator;
29 import java.util.Vector; 27 import java.util.Vector;
30 28
31 class BuildConfig { 29 class BuildConfig {
30 @SuppressWarnings("rawtypes")
32 Hashtable vars; 31 Hashtable vars;
33 Vector basicNames, basicPaths; 32 Vector<String> basicNames, basicPaths;
34 String[] context; 33 String[] context;
35 34
36 static CompilerInterface ci; 35 static CompilerInterface ci;
37 static CompilerInterface getCI() { 36 static CompilerInterface getCI() {
38 if (ci == null) { 37 if (ci == null) {
45 } 44 }
46 } 45 }
47 return ci; 46 return ci;
48 } 47 }
49 48
49 @SuppressWarnings("rawtypes")
50 protected void initNames(String flavour, String build, String outDll) { 50 protected void initNames(String flavour, String build, String outDll) {
51 if (vars == null) vars = new Hashtable(); 51 if (vars == null) vars = new Hashtable();
52 52
53 String flavourBuild = flavour + "_" + build; 53 String flavourBuild = flavour + "_" + build;
54 String platformName = getFieldString(null, "PlatformName"); 54 String platformName = getFieldString(null, "PlatformName");
61 put("PlatformName", platformName); 61 put("PlatformName", platformName);
62 62
63 // ones mentioned above were needed to expand format 63 // ones mentioned above were needed to expand format
64 String buildBase = expandFormat(getFieldString(null, "BuildBase")); 64 String buildBase = expandFormat(getFieldString(null, "BuildBase"));
65 String sourceBase = getFieldString(null, "SourceBase"); 65 String sourceBase = getFieldString(null, "SourceBase");
66 String buildSpace = getFieldString(null, "BuildSpace");
66 String outDir = buildBase; 67 String outDir = buildBase;
67 68
68 put("Id", flavourBuild); 69 put("Id", flavourBuild);
69 put("OutputDir", outDir); 70 put("OutputDir", outDir);
70 put("SourceBase", sourceBase); 71 put("SourceBase", sourceBase);
71 put("BuildBase", buildBase); 72 put("BuildBase", buildBase);
73 put("BuildSpace", buildSpace);
72 put("OutputDll", outDir + Util.sep + outDll); 74 put("OutputDll", outDir + Util.sep + outDll);
73 75
74 context = new String [] {flavourBuild, flavour, build, null}; 76 context = new String [] {flavourBuild, flavour, build, null};
75 } 77 }
76 78
77 protected void init(Vector includes, Vector defines) { 79 protected void init(Vector<String> includes, Vector<String> defines) {
78 initDefaultDefines(defines); 80 initDefaultDefines(defines);
79 initDefaultCompilerFlags(includes); 81 initDefaultCompilerFlags(includes);
80 initDefaultLinkerFlags(); 82 initDefaultLinkerFlags();
81 handleDB(); 83 //handleDB();
82 } 84 }
83 85
84 86
85 protected void initDefaultCompilerFlags(Vector includes) { 87 protected void initDefaultCompilerFlags(Vector<String> includes) {
86 Vector compilerFlags = new Vector(); 88 Vector compilerFlags = new Vector();
87 89
88 compilerFlags.addAll(getCI().getBaseCompilerFlags(getV("Define"), 90 compilerFlags.addAll(getCI().getBaseCompilerFlags(getV("Define"),
89 includes, 91 includes,
90 get("OutputDir"))); 92 get("OutputDir")));
98 linkerFlags.addAll(getCI().getBaseLinkerFlags( get("OutputDir"), get("OutputDll"), get("PlatformName"))); 100 linkerFlags.addAll(getCI().getBaseLinkerFlags( get("OutputDir"), get("OutputDll"), get("PlatformName")));
99 101
100 put("LinkerFlags", linkerFlags); 102 put("LinkerFlags", linkerFlags);
101 } 103 }
102 104
103 DirectoryTree getSourceTree(String sourceBase, String startAt) { 105 public boolean matchesIgnoredPath(String path) {
104 DirectoryTree tree = new DirectoryTree(); 106 Vector<String> rv = new Vector<String>();
105
106 tree.addSubdirToIgnore("Codemgr_wsdata");
107 tree.addSubdirToIgnore("deleted_files");
108 tree.addSubdirToIgnore("SCCS");
109 tree.setVerbose(true);
110 if (startAt != null) {
111 tree.readDirectory(sourceBase + File.separator + startAt);
112 } else {
113 tree.readDirectory(sourceBase);
114 }
115
116 return tree;
117 }
118
119
120 Vector getPreferredPaths() {
121 Vector preferredPaths = new Vector();
122
123 // In the case of multiple files with the same name in
124 // different subdirectories, prefer these versions
125 preferredPaths.add("windows");
126 preferredPaths.add("x86");
127 preferredPaths.add("closed");
128
129 // Also prefer "opto" over "adlc" for adlcVMDeps.hpp
130 preferredPaths.add("opto");
131
132 return preferredPaths;
133 }
134
135
136 void handleDB() {
137 WinGammaPlatform platform = (WinGammaPlatform)getField(null, "PlatformObject");
138
139 putSpecificField("AllFilesHash", computeAllFiles(platform));
140 }
141
142
143 private boolean matchesIgnoredPath(String prefixedName) {
144 Vector rv = new Vector();
145 collectRelevantVectors(rv, "IgnorePath"); 107 collectRelevantVectors(rv, "IgnorePath");
146 for (Iterator i = rv.iterator(); i.hasNext(); ) { 108 for (String pathPart : rv) {
147 String pathPart = (String) i.next(); 109 if (path.contains(pathPart)) {
148 if (prefixedName.contains(Util.normalize(pathPart))) {
149 return true; 110 return true;
150 } 111 }
151 } 112 }
152 return false; 113 return false;
153 } 114 }
154 115
155 void addAll(Iterator i, Hashtable hash, 116 public boolean matchesHidePath(String path) {
156 WinGammaPlatform platform, DirectoryTree tree, 117 Vector<String> rv = new Vector<String>();
157 Vector preferredPaths, Vector filesNotFound, Vector filesDuplicate) { 118 collectRelevantVectors(rv, "HidePath");
158 for (; i.hasNext(); ) { 119 for (String pathPart : rv) {
159 String fileName = (String) i.next(); 120 if (path.contains(Util.normalize(pathPart))) {
160 if (lookupHashFieldInContext("IgnoreFile", fileName) == null) { 121 return true;
161 String prefixedName = platform.envVarPrefixedFileName(fileName, 122 }
162 0, /* ignored */ 123 }
163 tree, 124 return false;
164 preferredPaths, 125 }
165 filesNotFound, 126
166 filesDuplicate); 127 public Vector<String> matchesAdditionalGeneratedPath(String fullPath) {
167 if (prefixedName != null) { 128 Vector<String> rv = new Vector<String>();
168 prefixedName = Util.normalize(prefixedName); 129 Hashtable<String, String> v = (Hashtable<String, String>)BuildConfig.getField(this.toString(), "AdditionalGeneratedFile");
169 if (!matchesIgnoredPath(prefixedName)) { 130 if (v != null) {
170 addTo(hash, prefixedName, fileName); 131 for (Enumeration<String> e=v.keys(); e.hasMoreElements(); ) {
171 } 132 String key = e.nextElement();
133 String val = v.get(key);
134
135 if (fullPath.endsWith(expandFormat(key))) {
136 rv.add(expandFormat(val));
172 } 137 }
173 } 138 }
174 } 139 }
140 return rv;
175 } 141 }
176 142
177 void addTo(Hashtable ht, String key, String value) { 143 void addTo(Hashtable ht, String key, String value) {
178 ht.put(expandFormat(key), expandFormat(value)); 144 ht.put(expandFormat(key), expandFormat(value));
179 }
180
181 Hashtable computeAllFiles(WinGammaPlatform platform) {
182 Hashtable rv = new Hashtable();
183 DirectoryTree tree = getSourceTree(get("SourceBase"), getFieldString(null, "StartAt"));
184 Vector preferredPaths = getPreferredPaths();
185
186 // Hold errors until end
187 Vector filesNotFound = new Vector();
188 Vector filesDuplicate = new Vector();
189
190 Vector includedFiles = new Vector();
191
192 // find all files
193 Vector dirs = getSourceIncludes();
194 for (Iterator i = dirs.iterator(); i.hasNext(); ) {
195 String dir = (String)i.next();
196 DirectoryTree subtree = getSourceTree(dir, null);
197 for (Iterator fi = subtree.getFileIterator(); fi.hasNext(); ) {
198 String name = ((File)fi.next()).getName();
199 includedFiles.add(name);
200 }
201 }
202 addAll(includedFiles.iterator(), rv,
203 platform, tree,
204 preferredPaths, filesNotFound, filesDuplicate);
205
206 Vector addFiles = new Vector();
207 collectRelevantVectors(addFiles, "AdditionalFile");
208 addAll(addFiles.iterator(), rv,
209 platform, tree,
210 preferredPaths, filesNotFound, filesDuplicate);
211
212 collectRelevantHashes(rv, "AdditionalGeneratedFile");
213
214 if ((filesNotFound.size() != 0) ||
215 (filesDuplicate.size() != 0)) {
216 System.err.println("Error: some files were not found or " +
217 "appeared in multiple subdirectories of " +
218 "directory " + get("SourceBase") + " and could not " +
219 "be resolved with os_family and arch.");
220 if (filesNotFound.size() != 0) {
221 System.err.println("Files not found:");
222 for (Iterator iter = filesNotFound.iterator();
223 iter.hasNext(); ) {
224 System.err.println(" " + (String) iter.next());
225 }
226 }
227 if (filesDuplicate.size() != 0) {
228 System.err.println("Duplicate files:");
229 for (Iterator iter = filesDuplicate.iterator();
230 iter.hasNext(); ) {
231 System.err.println(" " + (String) iter.next());
232 }
233 }
234 throw new RuntimeException();
235 }
236
237 return rv;
238 } 145 }
239 146
240 void initDefaultDefines(Vector defines) { 147 void initDefaultDefines(Vector defines) {
241 Vector sysDefines = new Vector(); 148 Vector sysDefines = new Vector();
242 sysDefines.add("WIN32"); 149 sysDefines.add("WIN32");
322 void putSpecificField(String field, Object value) { 229 void putSpecificField(String field, Object value) {
323 putField(get("Id"), field, value); 230 putField(get("Id"), field, value);
324 } 231 }
325 232
326 void collectRelevantVectors(Vector rv, String field) { 233 void collectRelevantVectors(Vector rv, String field) {
327 for (int i = 0; i < context.length; i++) { 234 for (String ctx : context) {
328 Vector v = getFieldVector(context[i], field); 235 Vector<String> v = getFieldVector(ctx, field);
329 if (v != null) { 236 if (v != null) {
330 for (Iterator j=v.iterator(); j.hasNext(); ) { 237 for (String val : v) {
331 String val = (String)j.next(); 238 rv.add(expandFormat(val).replace('/', '\\'));
332 rv.add(expandFormat(val));
333 } 239 }
334 } 240 }
335 } 241 }
336 } 242 }
337 243
338 void collectRelevantHashes(Hashtable rv, String field) { 244 void collectRelevantHashes(Hashtable rv, String field) {
339 for (int i = 0; i < context.length; i++) { 245 for (String ctx : context) {
340 Hashtable v = (Hashtable)getField(context[i], field); 246 Hashtable v = (Hashtable)getField(ctx, field);
341 if (v != null) { 247 if (v != null) {
342 for (Enumeration e=v.keys(); e.hasMoreElements(); ) { 248 for (Enumeration e=v.keys(); e.hasMoreElements(); ) {
343 String key = (String)e.nextElement(); 249 String key = (String)e.nextElement();
344 String val = (String)v.get(key); 250 String val = (String)v.get(key);
345 addTo(rv, key, val); 251 addTo(rv, key, val);
355 return rv; 261 return rv;
356 } 262 }
357 263
358 Vector getIncludes() { 264 Vector getIncludes() {
359 Vector rv = new Vector(); 265 Vector rv = new Vector();
360
361 collectRelevantVectors(rv, "AbsoluteInclude"); 266 collectRelevantVectors(rv, "AbsoluteInclude");
362
363 rv.addAll(getSourceIncludes()); 267 rv.addAll(getSourceIncludes());
364
365 return rv; 268 return rv;
366 } 269 }
367 270
368 private Vector getSourceIncludes() { 271 private Vector getSourceIncludes() {
369 Vector rv = new Vector(); 272 Vector<String> rv = new Vector<String>();
370 Vector ri = new Vector(); 273 Vector<String> ri = new Vector<String>();
371 String sourceBase = getFieldString(null, "SourceBase"); 274 String sourceBase = getFieldString(null, "SourceBase");
372 collectRelevantVectors(ri, "RelativeInclude"); 275 collectRelevantVectors(ri, "RelativeInclude");
373 for (Iterator i = ri.iterator(); i.hasNext(); ) { 276 for (String f : ri) {
374 String f = (String)i.next();
375 rv.add(sourceBase + Util.sep + f); 277 rv.add(sourceBase + Util.sep + f);
376 } 278 }
377 return rv; 279 return rv;
378 } 280 }
379 281
602 initNames("tiered", "fastdebug", "jvm.dll"); 504 initNames("tiered", "fastdebug", "jvm.dll");
603 init(getIncludes(), getDefines()); 505 init(getIncludes(), getDefines());
604 } 506 }
605 } 507 }
606 508
607
608 abstract class ProductConfig extends BuildConfig { 509 abstract class ProductConfig extends BuildConfig {
609 protected void init(Vector includes, Vector defines) { 510 protected void init(Vector includes, Vector defines) {
610 defines.add("NDEBUG"); 511 defines.add("NDEBUG");
611 defines.add("PRODUCT"); 512 defines.add("PRODUCT");
612 513
636 initNames("tiered", "product", "jvm.dll"); 537 initNames("tiered", "product", "jvm.dll");
637 init(getIncludes(), getDefines()); 538 init(getIncludes(), getDefines());
638 } 539 }
639 } 540 }
640 541
641
642 class CoreDebugConfig extends GenericDebugNonKernelConfig { 542 class CoreDebugConfig extends GenericDebugNonKernelConfig {
643 String getOptFlag() { 543 String getOptFlag() {
644 return getCI().getNoOptFlag(); 544 return getCI().getNoOptFlag();
645 } 545 }
646 546
648 initNames("core", "debug", "jvm.dll"); 548 initNames("core", "debug", "jvm.dll");
649 init(getIncludes(), getDefines()); 549 init(getIncludes(), getDefines());
650 } 550 }
651 } 551 }
652 552
653
654 class CoreFastDebugConfig extends GenericDebugNonKernelConfig { 553 class CoreFastDebugConfig extends GenericDebugNonKernelConfig {
655 String getOptFlag() { 554 String getOptFlag() {
656 return getCI().getOptFlag(); 555 return getCI().getOptFlag();
657 } 556 }
658 557
659 CoreFastDebugConfig() { 558 CoreFastDebugConfig() {
660 initNames("core", "fastdebug", "jvm.dll"); 559 initNames("core", "fastdebug", "jvm.dll");
661 init(getIncludes(), getDefines()); 560 init(getIncludes(), getDefines());
662 } 561 }
663 } 562 }
664
665 563
666 class CoreProductConfig extends ProductConfig { 564 class CoreProductConfig extends ProductConfig {
667 CoreProductConfig() { 565 CoreProductConfig() {
668 initNames("core", "product", "jvm.dll"); 566 initNames("core", "product", "jvm.dll");
669 init(getIncludes(), getDefines()); 567 init(getIncludes(), getDefines());
698 KernelProductConfig() { 596 KernelProductConfig() {
699 initNames("kernel", "product", "jvm.dll"); 597 initNames("kernel", "product", "jvm.dll");
700 init(getIncludes(), getDefines()); 598 init(getIncludes(), getDefines());
701 } 599 }
702 } 600 }
601
703 abstract class CompilerInterface { 602 abstract class CompilerInterface {
704 abstract Vector getBaseCompilerFlags(Vector defines, Vector includes, String outDir); 603 abstract Vector getBaseCompilerFlags(Vector defines, Vector includes, String outDir);
705 abstract Vector getBaseLinkerFlags(String outDir, String outDll, String platformName); 604 abstract Vector getBaseLinkerFlags(String outDir, String outDll, String platformName);
706 abstract Vector getDebugCompilerFlags(String opt); 605 abstract Vector getDebugCompilerFlags(String opt);
707 abstract Vector getDebugLinkerFlags(); 606 abstract Vector getDebugLinkerFlags();