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

25 26 27
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
D
duke 已提交
28 29

class BuildConfig {
N
neliasso 已提交
30
    @SuppressWarnings("rawtypes")
D
duke 已提交
31
    Hashtable vars;
N
neliasso 已提交
32
    Vector<String> basicNames, basicPaths;
D
duke 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
    String[] context;

    static CompilerInterface ci;
    static CompilerInterface getCI() {
        if (ci == null) {
            String comp = (String)getField(null, "CompilerVersion");
            try {
                ci = (CompilerInterface)Class.forName("CompilerInterface" + comp).newInstance();
            } catch (Exception cnfe) {
                System.err.println("Cannot find support for compiler " + comp);
                throw new RuntimeException(cnfe.toString());
            }
        }
        return ci;
    }

N
neliasso 已提交
49
    @SuppressWarnings("rawtypes")
D
duke 已提交
50 51 52 53
    protected void initNames(String flavour, String build, String outDll) {
        if (vars == null) vars = new Hashtable();

        String flavourBuild =  flavour + "_" + build;
54
        String platformName = getFieldString(null, "PlatformName");
55 56 57
        System.out.println();
        System.out.println(flavourBuild);

58
        put("Name", getCI().makeCfgName(flavourBuild, platformName));
D
duke 已提交
59 60
        put("Flavour", flavour);
        put("Build", build);
61
        put("PlatformName", platformName);
D
duke 已提交
62 63 64 65

        // ones mentioned above were needed to expand format
        String buildBase = expandFormat(getFieldString(null, "BuildBase"));
        String sourceBase = getFieldString(null, "SourceBase");
N
neliasso 已提交
66
        String buildSpace = getFieldString(null, "BuildSpace");
D
duke 已提交
67 68 69 70 71 72
        String outDir = buildBase;

        put("Id", flavourBuild);
        put("OutputDir", outDir);
        put("SourceBase", sourceBase);
        put("BuildBase", buildBase);
N
neliasso 已提交
73
        put("BuildSpace", buildSpace);
74
        put("OutputDll", outDir + Util.sep + outDll);
D
duke 已提交
75 76 77 78

        context = new String [] {flavourBuild, flavour, build, null};
    }

N
neliasso 已提交
79
    protected void init(Vector<String> includes, Vector<String> defines) {
D
duke 已提交
80 81 82
        initDefaultDefines(defines);
        initDefaultCompilerFlags(includes);
        initDefaultLinkerFlags();
N
neliasso 已提交
83
        //handleDB();
D
duke 已提交
84 85 86
    }


N
neliasso 已提交
87
    protected void initDefaultCompilerFlags(Vector<String> includes) {
D
duke 已提交
88 89 90 91 92 93 94 95 96 97 98 99
        Vector compilerFlags = new Vector();

        compilerFlags.addAll(getCI().getBaseCompilerFlags(getV("Define"),
                                                          includes,
                                                          get("OutputDir")));

        put("CompilerFlags", compilerFlags);
    }

    protected void initDefaultLinkerFlags() {
        Vector linkerFlags = new Vector();

100
        linkerFlags.addAll(getCI().getBaseLinkerFlags( get("OutputDir"), get("OutputDll"), get("PlatformName")));
D
duke 已提交
101 102 103 104

        put("LinkerFlags", linkerFlags);
    }

N
neliasso 已提交
105 106
    public boolean matchesIgnoredPath(String path) {
        Vector<String> rv = new Vector<String>();
107
        collectRelevantVectors(rv, "IgnorePath");
N
neliasso 已提交
108 109
        for (String pathPart : rv) {
            if (path.contains(pathPart))  {
110 111 112 113 114 115
                return true;
            }
        }
        return false;
    }

N
neliasso 已提交
116 117 118 119 120 121
    public boolean matchesHidePath(String path) {
        Vector<String> rv = new Vector<String>();
        collectRelevantVectors(rv, "HidePath");
        for (String pathPart : rv) {
            if (path.contains(Util.normalize(pathPart)))  {
                return true;
D
duke 已提交
122 123
            }
        }
N
neliasso 已提交
124
        return false;
D
duke 已提交
125 126
    }

N
neliasso 已提交
127 128 129 130 131 132 133
   public Vector<String> matchesAdditionalGeneratedPath(String fullPath) {
        Vector<String> rv = new Vector<String>();
        Hashtable<String, String> v = (Hashtable<String, String>)BuildConfig.getField(this.toString(), "AdditionalGeneratedFile");
        if (v != null) {
            for (Enumeration<String> e=v.keys(); e.hasMoreElements(); ) {
                String key = e.nextElement();
                String val = v.get(key);
D
duke 已提交
134

N
neliasso 已提交
135 136
                if (fullPath.endsWith(expandFormat(key))) {
                    rv.add(expandFormat(val));
D
duke 已提交
137 138 139 140 141 142
                }
            }
        }
        return rv;
    }

N
neliasso 已提交
143 144 145 146
    void addTo(Hashtable ht, String key, String value) {
        ht.put(expandFormat(key), expandFormat(value));
    }

D
duke 已提交
147 148 149 150
    void initDefaultDefines(Vector defines) {
        Vector sysDefines = new Vector();
        sysDefines.add("WIN32");
        sysDefines.add("_WINDOWS");
151
        sysDefines.add("HOTSPOT_BUILD_USER=\\\""+System.getProperty("user.name")+"\\\"");
D
duke 已提交
152
        sysDefines.add("HOTSPOT_BUILD_TARGET=\\\""+get("Build")+"\\\"");
153
        sysDefines.add("INCLUDE_TRACE");
D
duke 已提交
154
        sysDefines.add("_JNI_IMPLEMENTATION_");
155 156 157 158 159
        if (vars.get("PlatformName").equals("Win32")) {
            sysDefines.add("HOTSPOT_LIB_ARCH=\\\"i386\\\"");
        } else {
            sysDefines.add("HOTSPOT_LIB_ARCH=\\\"amd64\\\"");
        }
D
duke 已提交
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233

        sysDefines.addAll(defines);

        put("Define", sysDefines);
    }

    String get(String key) {
        return (String)vars.get(key);
    }

    Vector getV(String key) {
        return (Vector)vars.get(key);
    }

    Object getO(String key) {
        return vars.get(key);
    }

    Hashtable getH(String key) {
        return (Hashtable)vars.get(key);
    }

    Object getFieldInContext(String field) {
        for (int i=0; i<context.length; i++) {
            Object rv = getField(context[i], field);
            if (rv != null) {
                return rv;
            }
        }
        return null;
    }

    Object lookupHashFieldInContext(String field, String key) {
        for (int i=0; i<context.length; i++) {
            Hashtable ht = (Hashtable)getField(context[i], field);
            if (ht != null) {
                Object rv = ht.get(key);
                if (rv != null) {
                    return rv;
                }
            }
        }
        return null;
    }

    void put(String key, String value) {
        vars.put(key, value);
    }

    void put(String key, Vector vvalue) {
        vars.put(key, vvalue);
    }

    void add(String key, Vector vvalue) {
        getV(key).addAll(vvalue);
    }

    String flavour() {
        return get("Flavour");
    }

    String build() {
        return get("Build");
    }

    Object getSpecificField(String field) {
        return getField(get("Id"), field);
    }

    void putSpecificField(String field, Object value) {
        putField(get("Id"), field, value);
    }

    void collectRelevantVectors(Vector rv, String field) {
N
neliasso 已提交
234 235
        for (String ctx : context) {
            Vector<String> v = getFieldVector(ctx, field);
D
duke 已提交
236
            if (v != null) {
N
neliasso 已提交
237 238
                for (String val : v) {
                    rv.add(expandFormat(val).replace('/', '\\'));
D
duke 已提交
239 240 241 242 243 244
                }
            }
        }
    }

    void collectRelevantHashes(Hashtable rv, String field) {
N
neliasso 已提交
245 246
        for (String ctx : context) {
            Hashtable v = (Hashtable)getField(ctx, field);
D
duke 已提交
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
            if (v != null) {
                for (Enumeration e=v.keys(); e.hasMoreElements(); ) {
                    String key = (String)e.nextElement();
                    String val =  (String)v.get(key);
                    addTo(rv, key, val);
                }
            }
        }
    }


    Vector getDefines() {
        Vector rv = new Vector();
        collectRelevantVectors(rv, "Define");
        return rv;
    }

    Vector getIncludes() {
        Vector rv = new Vector();
        collectRelevantVectors(rv, "AbsoluteInclude");
267 268 269 270 271
        rv.addAll(getSourceIncludes());
        return rv;
    }

    private Vector getSourceIncludes() {
N
neliasso 已提交
272 273
        Vector<String> rv = new Vector<String>();
        Vector<String> ri = new Vector<String>();
D
duke 已提交
274 275
        String sourceBase = getFieldString(null, "SourceBase");
        collectRelevantVectors(ri, "RelativeInclude");
N
neliasso 已提交
276
        for (String f : ri) {
D
duke 已提交
277 278 279 280 281 282 283 284 285 286 287 288 289 290
            rv.add(sourceBase + Util.sep + f);
        }
        return rv;
    }

    static Hashtable cfgData = new Hashtable();
    static Hashtable globalData = new Hashtable();

    static boolean appliesToTieredBuild(String cfg) {
        return (cfg != null &&
                (cfg.startsWith("compiler1") ||
                 cfg.startsWith("compiler2")));
    }

291 292
    // Filters out the IgnoreFile and IgnorePaths since they are
    // handled specially for tiered builds.
D
duke 已提交
293
    static boolean appliesToTieredBuild(String cfg, String key) {
294
        return (appliesToTieredBuild(cfg))&& (key != null && !key.startsWith("Ignore"));
D
duke 已提交
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
    }

    static String getTieredBuildCfg(String cfg) {
        assert appliesToTieredBuild(cfg) : "illegal configuration " + cfg;
        return "tiered" + cfg.substring(9);
    }

    static Object getField(String cfg, String field) {
        if (cfg == null) {
            return globalData.get(field);
        }

        Hashtable ht =  (Hashtable)cfgData.get(cfg);
        return ht == null ? null : ht.get(field);
    }

    static String getFieldString(String cfg, String field) {
        return (String)getField(cfg, field);
    }

    static Vector getFieldVector(String cfg, String field) {
        return (Vector)getField(cfg, field);
    }

    static void putField(String cfg, String field, Object value) {
        putFieldImpl(cfg, field, value);
        if (appliesToTieredBuild(cfg, field)) {
            putFieldImpl(getTieredBuildCfg(cfg), field, value);
        }
    }

    private static void putFieldImpl(String cfg, String field, Object value) {
        if (cfg == null) {
            globalData.put(field, value);
            return;
        }

        Hashtable ht = (Hashtable)cfgData.get(cfg);
        if (ht == null) {
            ht = new Hashtable();
            cfgData.put(cfg, ht);
        }

        ht.put(field, value);
    }

    static Object getFieldHash(String cfg, String field, String name) {
        Hashtable ht = (Hashtable)getField(cfg, field);

        return ht == null ? null : ht.get(name);
    }

    static void putFieldHash(String cfg, String field, String name, Object val) {
        putFieldHashImpl(cfg, field, name, val);
349
        if (appliesToTieredBuild(cfg, field)) {
D
duke 已提交
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
            putFieldHashImpl(getTieredBuildCfg(cfg), field, name, val);
        }
    }

    private static void putFieldHashImpl(String cfg, String field, String name, Object val) {
        Hashtable ht = (Hashtable)getField(cfg, field);

        if (ht == null) {
            ht = new Hashtable();
            putFieldImpl(cfg, field, ht);
        }

        ht.put(name, val);
    }

    static void addFieldVector(String cfg, String field, String element) {
        addFieldVectorImpl(cfg, field, element);
367
        if (appliesToTieredBuild(cfg, field)) {
D
duke 已提交
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
            addFieldVectorImpl(getTieredBuildCfg(cfg), field, element);
        }
    }

    private static void addFieldVectorImpl(String cfg, String field, String element) {
        Vector v = (Vector)getField(cfg, field);

        if (v == null) {
            v = new Vector();
            putFieldImpl(cfg, field, v);
        }

        v.add(element);
    }

    String expandFormat(String format) {
        if (format == null) {
            return null;
        }

        if (format.indexOf('%') == -1) {
            return format;
        }

        StringBuffer sb = new StringBuffer();
        int len = format.length();
        for (int i=0; i<len; i++) {
            char ch = format.charAt(i);
            if (ch == '%') {
                char ch1 = format.charAt(i+1);
                switch (ch1) {
                case '%':
                    sb.append(ch1);
                    break;
                case 'b':
                    sb.append(build());
                    break;
                case 'f':
                    sb.append(flavour());
                    break;
                default:
                    sb.append(ch);
                    sb.append(ch1);
                }
                i++;
            } else {
                sb.append(ch);
            }
        }

        return sb.toString();
    }
}

abstract class GenericDebugConfig extends BuildConfig {
    abstract String getOptFlag();

    protected void init(Vector includes, Vector defines) {
        defines.add("_DEBUG");
        defines.add("ASSERT");

        super.init(includes, defines);

        getV("CompilerFlags").addAll(getCI().getDebugCompilerFlags(getOptFlag()));
        getV("LinkerFlags").addAll(getCI().getDebugLinkerFlags());
   }
}

436 437 438 439 440 441 442 443
abstract class GenericDebugNonKernelConfig extends GenericDebugConfig {
    protected void init(Vector includes, Vector defines) {
        super.init(includes, defines);
        getCI().getAdditionalNonKernelLinkerFlags(getV("LinkerFlags"));
   }
}

class C1DebugConfig extends GenericDebugNonKernelConfig {
D
duke 已提交
444 445 446 447 448
    String getOptFlag() {
        return getCI().getNoOptFlag();
    }

    C1DebugConfig() {
449
        initNames("compiler1", "debug", "jvm.dll");
D
duke 已提交
450 451 452 453
        init(getIncludes(), getDefines());
    }
}

454
class C1FastDebugConfig extends GenericDebugNonKernelConfig {
D
duke 已提交
455 456 457 458 459
    String getOptFlag() {
        return getCI().getOptFlag();
    }

    C1FastDebugConfig() {
460
        initNames("compiler1", "fastdebug", "jvm.dll");
D
duke 已提交
461 462 463 464
        init(getIncludes(), getDefines());
    }
}

465
class C2DebugConfig extends GenericDebugNonKernelConfig {
D
duke 已提交
466 467 468 469 470
    String getOptFlag() {
        return getCI().getNoOptFlag();
    }

    C2DebugConfig() {
471
        initNames("compiler2", "debug", "jvm.dll");
D
duke 已提交
472 473 474 475
        init(getIncludes(), getDefines());
    }
}

476
class C2FastDebugConfig extends GenericDebugNonKernelConfig {
D
duke 已提交
477 478 479 480 481
    String getOptFlag() {
        return getCI().getOptFlag();
    }

    C2FastDebugConfig() {
482
        initNames("compiler2", "fastdebug", "jvm.dll");
D
duke 已提交
483 484 485 486
        init(getIncludes(), getDefines());
    }
}

487
class TieredDebugConfig extends GenericDebugNonKernelConfig {
D
duke 已提交
488 489 490 491 492
    String getOptFlag() {
        return getCI().getNoOptFlag();
    }

    TieredDebugConfig() {
493
        initNames("tiered", "debug", "jvm.dll");
D
duke 已提交
494 495 496 497
        init(getIncludes(), getDefines());
    }
}

498
class TieredFastDebugConfig extends GenericDebugNonKernelConfig {
D
duke 已提交
499 500 501 502 503
    String getOptFlag() {
        return getCI().getOptFlag();
    }

    TieredFastDebugConfig() {
504
        initNames("tiered", "fastdebug", "jvm.dll");
D
duke 已提交
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
        init(getIncludes(), getDefines());
    }
}

abstract class ProductConfig extends BuildConfig {
    protected void init(Vector includes, Vector defines) {
        defines.add("NDEBUG");
        defines.add("PRODUCT");

        super.init(includes, defines);

        getV("CompilerFlags").addAll(getCI().getProductCompilerFlags());
        getV("LinkerFlags").addAll(getCI().getProductLinkerFlags());
    }
}

class C1ProductConfig extends ProductConfig {
    C1ProductConfig() {
523
        initNames("compiler1", "product", "jvm.dll");
D
duke 已提交
524 525 526 527 528 529
        init(getIncludes(), getDefines());
    }
}

class C2ProductConfig extends ProductConfig {
    C2ProductConfig() {
530
        initNames("compiler2", "product", "jvm.dll");
D
duke 已提交
531 532 533 534 535 536
        init(getIncludes(), getDefines());
    }
}

class TieredProductConfig extends ProductConfig {
    TieredProductConfig() {
537
        initNames("tiered", "product", "jvm.dll");
D
duke 已提交
538 539 540 541
        init(getIncludes(), getDefines());
    }
}

542
class CoreDebugConfig extends GenericDebugNonKernelConfig {
D
duke 已提交
543 544 545 546 547
    String getOptFlag() {
        return getCI().getNoOptFlag();
    }

    CoreDebugConfig() {
548
        initNames("core", "debug", "jvm.dll");
D
duke 已提交
549 550 551 552
        init(getIncludes(), getDefines());
    }
}

553
class CoreFastDebugConfig extends GenericDebugNonKernelConfig {
D
duke 已提交
554 555 556 557 558
    String getOptFlag() {
        return getCI().getOptFlag();
    }

    CoreFastDebugConfig() {
559
        initNames("core", "fastdebug", "jvm.dll");
D
duke 已提交
560 561 562 563 564 565
        init(getIncludes(), getDefines());
    }
}

class CoreProductConfig extends ProductConfig {
    CoreProductConfig() {
566
        initNames("core", "product", "jvm.dll");
D
duke 已提交
567 568 569 570 571 572 573 574 575 576
        init(getIncludes(), getDefines());
    }
}

class KernelDebugConfig extends GenericDebugConfig {
    String getOptFlag() {
        return getCI().getNoOptFlag();
    }

    KernelDebugConfig() {
577
        initNames("kernel", "debug", "jvm.dll");
D
duke 已提交
578 579 580 581 582 583 584 585 586 587 588
        init(getIncludes(), getDefines());
    }
}


class KernelFastDebugConfig extends GenericDebugConfig {
    String getOptFlag() {
        return getCI().getOptFlag();
    }

    KernelFastDebugConfig() {
589
        initNames("kernel", "fastdebug", "jvm.dll");
D
duke 已提交
590 591 592 593 594 595 596
        init(getIncludes(), getDefines());
    }
}


class KernelProductConfig extends ProductConfig {
    KernelProductConfig() {
597
        initNames("kernel", "product", "jvm.dll");
D
duke 已提交
598 599 600
        init(getIncludes(), getDefines());
    }
}
N
neliasso 已提交
601

D
duke 已提交
602 603
abstract class CompilerInterface {
    abstract Vector getBaseCompilerFlags(Vector defines, Vector includes, String outDir);
604
    abstract Vector getBaseLinkerFlags(String outDir, String outDll, String platformName);
D
duke 已提交
605 606
    abstract Vector getDebugCompilerFlags(String opt);
    abstract Vector getDebugLinkerFlags();
607
    abstract void   getAdditionalNonKernelLinkerFlags(Vector rv);
D
duke 已提交
608 609 610 611
    abstract Vector getProductCompilerFlags();
    abstract Vector getProductLinkerFlags();
    abstract String getOptFlag();
    abstract String getNoOptFlag();
612
    abstract String makeCfgName(String flavourBuild, String platformName);
D
duke 已提交
613 614 615 616

    void addAttr(Vector receiver, String attr, String value) {
        receiver.add(attr); receiver.add(value);
    }
617 618 619 620 621 622 623 624 625 626
    void extAttr(Vector receiver, String attr, String value) {
        int attr_pos=receiver.indexOf(attr) ;
        if ( attr_pos == -1) {
          // If attr IS NOT present in the Vector - add it
          receiver.add(attr); receiver.add(value);
        } else {
          // If attr IS present in the Vector - append value to it
          receiver.set(attr_pos+1,receiver.get(attr_pos+1)+value);
        }
    }
D
duke 已提交
627
}