1 /*
   2  * Copyright (c) 2015, 2017, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /*
  27  * This file defines build profiles for the JIB tool and others.
  28  *
  29  * A build profile defines a set of configuration options and external
  30  * dependencies that we for some reason or other care about specifically.
  31  * Typically, build profiles are defined for the build configurations we
  32  * build regularly.
  33  *
  34  * Contract against this file from the tools that use it, is to provide
  35  * a function on the form:
  36  *
  37  * getJibProfiles(input)
  38  *
  39  * which returns an object graph describing the profiles and their
  40  * dependencies. The name of the function is based on the name of this
  41  * file, minus the extension and the '-', camel cased and prefixed with
  42  * 'get'.
  43  *
  44  *
  45  * The parameter 'input' is an object that optionally contains  some data.
  46  * Optionally because a tool may read the configuration for different purposes.
  47  * To initially get a list of available profiles, the active profile may not
  48  * yet be known for instance.
  49  *
  50  * Data that may be set on the input object:
  51  *
  52  * input.profile = <name of active profile>
  53  *
  54  * If the active profile is set, the following data from it must also
  55  * be provided:
  56  *
  57  * input.profile
  58  * input.build_id
  59  * input.target_os
  60  * input.target_cpu
  61  * input.build_os
  62  * input.build_cpu
  63  * input.target_platform
  64  * input.build_platform
  65  * // The build_osenv_* variables describe the unix layer on Windows systems,
  66  * // i.e. Cygwin, which may also be 32 or 64 bit.
  67  * input.build_osenv
  68  * input.build_osenv_cpu
  69  * input.build_osenv_platform
  70  *
  71  * For more complex nested attributes, there is a method "get":
  72  *
  73  * input.get("<dependency>", "<attribute>")
  74  *
  75  * Valid attributes are:
  76  * install_path
  77  * download_path
  78  * download_dir
  79  *
  80  *
  81  * The output data generated by this configuration file has the following
  82  * format:
  83  *
  84  * data: {
  85  *   // Identifies the version of this format to the tool reading it
  86  *   format_version: "1.0",
  87  *
  88  *   // Name of base outputdir. JIB assumes the actual output dir is formed
  89  *   // by adding the configuration name: <output_basedir>/<config-name>
  90  *   output_basedir: "build",
  91  *   // Configure argument to use to specify configuration name
  92  *   configuration_configure_arg:
  93  *   // Make argument to use to specify configuration name
  94  *   configuration_make_arg:
  95  *
  96  *   profiles: {
  97  *     <profile-name>: {
  98  *       // Name of os the profile is built to run on
  99  *       target_os; <string>
 100  *       // Name of cpu the profile is built to run on
 101  *       target_cpu; <string>
 102  *       // Combination of target_os and target_cpu for convenience
 103  *       target_platform; <string>
 104  *       // Name of os the profile is built on
 105  *       build_os; <string>
 106  *       // Name of cpu the profile is built on
 107  *       build_cpu; <string>
 108  *       // Combination of build_os and build_cpu for convenience
 109  *       build_platform; <string>
 110  *
 111  *       // List of dependencies needed to build this profile
 112  *       dependencies: <Array of strings>
 113  *
 114  *       // List of configure args to use for this profile
 115  *       configure_args: <Array of strings>
 116  *
 117  *       // List of free form labels describing aspects of this profile
 118  *       labels: <Array of strings>
 119  *     }
 120  *   }
 121  *
 122  *   // Dependencies use a Maven like deployment structure
 123  *   dependencies: {
 124  *     <dependency-name>: {
 125  *       // Organization part of path defining this dependency
 126  *       organization: <string>
 127  *       // File extension for this dependency
 128  *       ext: <string>
 129  *       // Module part of path for defining this dependency,
 130  *       // defaults to <dependency-name>
 131  *       module: <string>
 132  *       // Revision part of path for defining this dependency
 133  *       revision: <string>
 134  *
 135  *       // List of configure args to add when using this dependency,
 136  *       // defaults to
 137  *       // "--with-<dependency-name>=input.get("<dependency-name", "install_path")"
 138  *       configure_args: <array of strings>
 139  *
 140  *       // Name of environment variable to set when using this dependency
 141  *       // when running make
 142  *       environment_name: <string>
 143  *       // Value of environment variable to set when using this dependency
 144  *       // when running make
 145  *       environment_value: <string>
 146  *
 147  *       // Value to add to the PATH variable when using this dependency,
 148  *       // applies to both make and configure
 149  *       environment_path: <string>
 150  *     }
 151  *
 152  *     <dependency-name>: {
 153  *       // For certain dependencies where a legacy distribution mechanism is
 154  *       // already in place, the "javare" server layout is also supported
 155  *       // Indicate that an alternate server source and layout should be used
 156  *       server: "javare"
 157  *
 158  *       // For "javare", a combination of module, revision,
 159  *       // build number (optional), files and checksum file is possible for
 160  *       // artifacts following the standard layout.
 161  *       module: <string>
 162  *       revision: <string>
 163  *       build_number: <string>
 164  *       checksum_file: <string>
 165  *       file: <string>
 166  *
 167  *       // For other files, use checksum path and path instead
 168  *       checksum_path: <string>
 169  *       path: <string>
 170  *     }
 171  *   }
 172  * }
 173  */
 174 
 175 /**
 176  * Main entry to generate the profile configuration
 177  *
 178  * @param input External data to use for generating the configuration
 179  * @returns {{}} Profile configuration
 180  */
 181 var getJibProfiles = function (input) {
 182 
 183     var data = {};
 184 
 185     // Identifies the version of this format to the tool reading it.
 186     // 1.1 signifies that the publish, publish-src and get-src features are usable.
 187     data.format_version = "1.1";
 188 
 189     // Organization, product and version are used when uploading/publishing build results
 190     data.organization = "";
 191     data.product = "jdk";
 192     data.version = getVersion();
 193 
 194     // The base directory for the build output. JIB will assume that the
 195     // actual build directory will be <output_basedir>/<configuration>
 196     data.output_basedir = "build";
 197     // The configure argument to use to specify the name of the configuration
 198     data.configuration_configure_arg = "--with-conf-name=";
 199     // The make argument to use to specify the name of the configuration
 200     data.configuration_make_arg = "CONF_NAME=";
 201 
 202     // Exclude list to use when Jib creates a source bundle
 203     data.src_bundle_excludes = "./build webrev* */webrev* */*/webrev* */*/*/webrev* .hg */.hg */*/.hg */*/*/.hg";
 204     // Include list to use when creating a minimal jib source bundle which
 205     // contains just the jib configuration files.
 206     data.conf_bundle_includes = "*/conf/jib-profiles.* make/autoconf/version-numbers"
 207 
 208     // Define some common values
 209     var common = getJibProfilesCommon(input, data);
 210     // Generate the profiles part of the configuration
 211     data.profiles = getJibProfilesProfiles(input, common, data);
 212     // Generate the dependencies part of the configuration
 213     data.dependencies = getJibProfilesDependencies(input, common, data);
 214 
 215     return data;
 216 };
 217 
 218 /**
 219  * Generates some common values
 220  *
 221  * @param input External data to use for generating the configuration
 222  * @returns Common values
 223  */
 224 var getJibProfilesCommon = function (input, data) {
 225     var common = {};
 226 
 227     common.organization = "jpg.infra.builddeps";
 228     common.build_id = getBuildId(input);
 229     common.build_number = input.build_number != null ? input.build_number : "0";
 230 
 231     // List of the main profile names used for iteration
 232     common.main_profile_names = [
 233         "linux-x64", "linux-x86", "macosx-x64", "solaris-x64",
 234         "solaris-sparcv9", "windows-x64", "windows-x86",
 235         "linux-arm64", "linux-arm-vfp-hflt", "linux-arm-vfp-hflt-dyn"
 236     ];
 237 
 238     // These are the base setttings for all the main build profiles.
 239     common.main_profile_base = {
 240         dependencies: ["boot_jdk", "gnumake", "jtreg", "jib"],
 241         default_make_targets: ["product-bundles", "test-bundles"],
 242         configure_args: concat(["--enable-jtreg-failure-handler"],
 243                                versionArgs(input, common))
 244     };
 245     // Extra settings for debug profiles
 246     common.debug_suffix = "-debug";
 247     common.debug_profile_base = {
 248         configure_args: ["--enable-debug"],
 249         labels: "debug"
 250     };
 251     // Extra settings for slowdebug profiles
 252     common.slowdebug_suffix = "-slowdebug";
 253     common.slowdebug_profile_base = {
 254         configure_args: ["--with-debug-level=slowdebug"],
 255         labels: "slowdebug"
 256     };
 257     // Extra settings for openjdk only profiles
 258     common.open_suffix = "-open";
 259     common.open_profile_base = {
 260         configure_args: ["--enable-openjdk-only"],
 261         labels: "open"
 262     };
 263 
 264     common.configure_args_64bit = ["--with-target-bits=64"];
 265     common.configure_args_32bit = ["--with-target-bits=32"];
 266 
 267     /**
 268      * Define common artifacts template for all main profiles
 269      * @param o - Object containing data for artifacts
 270      */
 271     common.main_profile_artifacts = function (o) {
 272         var jdk_subdir = (o.jdk_subdir != null ? o.jdk_subdir : "jdk-" + data.version);
 273         var jre_subdir = (o.jre_subdir != null ? o.jre_subdir : "jre-" + data.version);
 274         var pf = o.platform
 275         return {
 276             artifacts: {
 277                 jdk: {
 278                     local: "bundles/\\(jdk.*bin.tar.gz\\)",
 279                     remote: [
 280                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin.tar.gz",
 281                         "bundles/" + pf + "/\\1"
 282                     ],
 283                     subdir: jdk_subdir,
 284                     exploded: "images/jdk"
 285                 },
 286                 jre: {
 287                     local: "bundles/\\(jre.*bin.tar.gz\\)",
 288                     remote: [
 289                         "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin.tar.gz",
 290                         "bundles/" + pf + "/\\1"
 291                     ],
 292                     subdir: jre_subdir,
 293                     exploded: "images/jre"
 294                 },
 295                 test: {
 296                     local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
 297                     remote: [
 298                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-tests.tar.gz",
 299                         "bundles/" + pf + "/\\1"
 300                     ],
 301                     exploded: "images/test"
 302                 },
 303                 test_demos: {
 304                     local: "bundles/\\(jdk.*bin-tests-demos.tar.gz\\)",
 305                     remote: [
 306                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-tests-demos.tar.gz",
 307                         "bundles/" + pf + "/\\1"
 308                     ],
 309                     exploded: "images/test"
 310                 },
 311                 jdk_symbols: {
 312                     local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
 313                     remote: [
 314                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-symbols.tar.gz",
 315                         "bundles/" + pf + "/\\1"
 316                     ],
 317                     subdir: jdk_subdir,
 318                     exploded: "images/jdk"
 319                 },
 320                 jre_symbols: {
 321                     local: "bundles/\\(jre.*bin-symbols.tar.gz\\)",
 322                     remote: [
 323                         "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin-symbols.tar.gz",
 324                         "bundles/" + pf + "/\\1"
 325                     ],
 326                     subdir: jre_subdir,
 327                     exploded: "images/jre"
 328                 }
 329             }
 330         };
 331     };
 332 
 333 
 334     /**
 335      * Define common artifacts template for all debug profiles
 336      * @param o - Object containing data for artifacts
 337      */
 338     common.debug_profile_artifacts = function (o) {
 339         var jdk_subdir = "jdk-" + data.version + "/fastdebug";
 340         var jre_subdir = "jre-" + data.version + "/fastdebug";
 341         var pf = o.platform
 342         return {
 343             artifacts: {
 344                 jdk: {
 345                     local: "bundles/\\(jdk.*bin-debug.tar.gz\\)",
 346                     remote: [
 347                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-debug.tar.gz",
 348                         "bundles/" + pf + "/\\1"
 349                     ],
 350                     subdir: jdk_subdir,
 351                     exploded: "images/jdk"
 352                 },
 353                 jre: {
 354                     local: "bundles/\\(jre.*bin-debug.tar.gz\\)",
 355                     remote: [
 356                         "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin-debug.tar.gz",
 357                         "bundles/" + pf + "/\\1"
 358                     ],
 359                     subdir: jre_subdir,
 360                     exploded: "images/jre"
 361                 },
 362                 test: {
 363                     local: "bundles/\\(jdk.*bin-tests-debug.tar.gz\\)",
 364                     remote: [
 365                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-tests-debug.tar.gz",
 366                         "bundles/" + pf + "/\\1"
 367                     ],
 368                     exploded: "images/test"
 369                 },
 370                 jdk_symbols: {
 371                     local: "bundles/\\(jdk.*bin-debug-symbols.tar.gz\\)",
 372                     remote: [
 373                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-debug-symbols.tar.gz",
 374                         "bundles/" + pf + "/\\1"
 375                     ],
 376                     subdir: jdk_subdir,
 377                     exploded: "images/jdk"
 378                 },
 379                 jre_symbols: {
 380                     local: "bundles/\\(jre.*bin-debug-symbols.tar.gz\\)",
 381                     remote: [
 382                         "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin-debug-symbols.tar.gz",
 383                         "bundles/" + pf + "/\\1"
 384                     ],
 385                     subdir: jre_subdir,
 386                     exploded: "images/jre"
 387                 }
 388             }
 389         };
 390     };
 391 
 392     common.boot_jdk_version = "9";
 393     common.boot_jdk_home = input.get("boot_jdk", "home_path") + "/jdk-"
 394         + common.boot_jdk_version
 395         + (input.build_os == "macosx" ? ".jdk/Contents/Home" : "");
 396 
 397     return common;
 398 };
 399 
 400 /**
 401  * Generates the profiles part of the configuration.
 402  *
 403  * @param input External data to use for generating the configuration
 404  * @param common The common values
 405  * @returns {{}} Profiles part of the configuration
 406  */
 407 var getJibProfilesProfiles = function (input, common, data) {
 408     // Main SE profiles
 409     var profiles = {
 410 
 411         "linux-x64": {
 412             target_os: "linux",
 413             target_cpu: "x64",
 414             dependencies: ["devkit", "graphviz", "pandoc"],
 415             configure_args: concat(common.configure_args_64bit,
 416                 "--enable-full-docs", "--with-zlib=system"),
 417             default_make_targets: ["docs-bundles"],
 418         },
 419 
 420         "linux-x86": {
 421             target_os: "linux",
 422             target_cpu: "x86",
 423             build_cpu: "x64",
 424             dependencies: ["devkit"],
 425             configure_args: concat(common.configure_args_32bit,
 426                 "--with-jvm-variants=minimal,server", "--with-zlib=system"),
 427         },
 428 
 429         "macosx-x64": {
 430             target_os: "macosx",
 431             target_cpu: "x64",
 432             dependencies: ["devkit", "freetype"],
 433             configure_args: concat(common.configure_args_64bit, "--with-zlib=system",
 434                 "--with-macosx-version-max=10.7.0"),
 435         },
 436 
 437         "solaris-x64": {
 438             target_os: "solaris",
 439             target_cpu: "x64",
 440             dependencies: ["devkit", "cups"],
 441             configure_args: concat(common.configure_args_64bit,
 442                 "--with-zlib=system", "--enable-dtrace"),
 443         },
 444 
 445         "solaris-sparcv9": {
 446             target_os: "solaris",
 447             target_cpu: "sparcv9",
 448             dependencies: ["devkit", "cups"],
 449             configure_args: concat(common.configure_args_64bit,
 450                 "--with-zlib=system", "--enable-dtrace"),
 451         },
 452 
 453         "windows-x64": {
 454             target_os: "windows",
 455             target_cpu: "x64",
 456             dependencies: ["devkit", "freetype"],
 457             configure_args: concat(common.configure_args_64bit),
 458         },
 459 
 460         "windows-x86": {
 461             target_os: "windows",
 462             target_cpu: "x86",
 463             build_cpu: "x64",
 464             dependencies: ["devkit", "freetype"],
 465             configure_args: concat(common.configure_args_32bit),
 466         },
 467 
 468         "linux-arm64": {
 469             target_os: "linux",
 470             target_cpu: "aarch64",
 471             build_cpu: "x64",
 472             dependencies: ["devkit", "build_devkit", "cups", "headless_stubs"],
 473             configure_args: [
 474                 "--with-cpu-port=arm64",
 475                 "--with-jvm-variants=server",
 476                 "--openjdk-target=aarch64-linux-gnu",
 477                 "--enable-headless-only"
 478             ],
 479         },
 480 
 481         "linux-arm-vfp-hflt": {
 482             target_os: "linux",
 483             target_cpu: "arm",
 484             build_cpu: "x64",
 485             dependencies: ["devkit", "build_devkit", "cups"],
 486             configure_args: [
 487                 "--with-jvm-variants=minimal1,client",
 488                 "--with-x=" + input.get("devkit", "install_path") + "/arm-linux-gnueabihf/libc/usr/X11R6-PI",
 489                 "--openjdk-target=arm-linux-gnueabihf",
 490                 "--with-abi-profile=arm-vfp-hflt"
 491             ],
 492         },
 493 
 494         // Special version of the SE profile adjusted to be testable on arm64 hardware.
 495         "linux-arm-vfp-hflt-dyn": {
 496             configure_args: "--with-stdc++lib=dynamic"
 497         }
 498     };
 499     // Let linux-arm-vfp-hflt-dyn inherit everything from linux-arm-vfp-hflt
 500     profiles["linux-arm-vfp-hflt-dyn"] = concatObjects(
 501         profiles["linux-arm-vfp-hflt-dyn"], profiles["linux-arm-vfp-hflt"]);
 502 
 503     // Add the base settings to all the main profiles
 504     common.main_profile_names.forEach(function (name) {
 505         profiles[name] = concatObjects(common.main_profile_base, profiles[name]);
 506     });
 507 
 508     // Generate debug versions of all the main profiles
 509     common.main_profile_names.forEach(function (name) {
 510         var debugName = name + common.debug_suffix;
 511         profiles[debugName] = concatObjects(profiles[name],
 512                                             common.debug_profile_base);
 513     });
 514     // Generate slowdebug versions of all the main profiles
 515     common.main_profile_names.forEach(function (name) {
 516         var debugName = name + common.slowdebug_suffix;
 517         profiles[debugName] = concatObjects(profiles[name],
 518                                             common.slowdebug_profile_base);
 519     });
 520 
 521     // Profiles for building the zero jvm variant. These are used for verification
 522     // in JPRT.
 523     var zeroProfiles = {
 524         "linux-x64-zero": {
 525             target_os: "linux",
 526             target_cpu: "x64",
 527             dependencies: ["devkit"],
 528             configure_args: concat(common.configure_args_64bit, [
 529                 "--with-zlib=system",
 530                 "--with-jvm-variants=zero",
 531                 "--enable-libffi-bundling"
 532             ])
 533         },
 534 
 535         "linux-x86-zero": {
 536             target_os: "linux",
 537             target_cpu: "x86",
 538             build_cpu: "x64",
 539             dependencies: ["devkit"],
 540             configure_args:  concat(common.configure_args_32bit, [
 541                 "--with-zlib=system",
 542                 "--with-jvm-variants=zero",
 543                 "--enable-libffi-bundling"
 544             ])
 545         }
 546     }
 547     profiles = concatObjects(profiles, zeroProfiles);
 548 
 549     // Add the base settings to the zero profiles and generate debug profiles
 550     Object.keys(zeroProfiles).forEach(function (name) {
 551         var debugName = name + common.debug_suffix;
 552         profiles[name] = concatObjects(common.main_profile_base, profiles[name]);
 553         profiles[debugName] = concatObjects(profiles[name], common.debug_profile_base);
 554     });
 555 
 556     //
 557     // Define artifacts for profiles
 558     //
 559     // Macosx bundles are named osx
 560     // tar.gz.
 561     var artifactData = {
 562         "linux-x64": {
 563             platform: "linux-x64",
 564         },
 565         "linux-x86": {
 566             platform: "linux-x86",
 567         },
 568         "macosx-x64": {
 569             platform: "osx-x64",
 570             jdk_subdir: "jdk-" + data.version +  ".jdk/Contents/Home",
 571             jre_subdir: "jre-" + data.version +  ".jre/Contents/Home"
 572         },
 573         "solaris-x64": {
 574             platform: "solaris-x64",
 575         },
 576         "solaris-sparcv9": {
 577             platform: "solaris-sparcv9",
 578         },
 579         "windows-x64": {
 580             platform: "windows-x64",
 581         },
 582         "windows-x86": {
 583             platform: "windows-x86",
 584         },
 585        "linux-arm64": {
 586             platform: "linux-arm64-vfp-hflt",
 587         },
 588         "linux-arm-vfp-hflt": {
 589             platform: "linux-arm32-vfp-hflt",
 590         },
 591         "linux-arm-vfp-hflt-dyn": {
 592             platform: "linux-arm32-vfp-hflt-dyn",
 593         }
 594     }
 595     // Generate common artifacts for all main profiles
 596     Object.keys(artifactData).forEach(function (name) {
 597         profiles[name] = concatObjects(profiles[name],
 598             common.main_profile_artifacts(artifactData[name]));
 599     });
 600 
 601     // Generate common artifacts for all debug profiles
 602     Object.keys(artifactData).forEach(function (name) {
 603         var debugName = name + common.debug_suffix;
 604         profiles[debugName] = concatObjects(profiles[debugName],
 605             common.debug_profile_artifacts(artifactData[name]));
 606     });
 607 
 608     profilesArtifacts = {
 609         "linux-x64": {
 610             artifacts: {
 611                 doc_api_spec: {
 612                     local: "bundles/\\(jdk.*doc-api-spec.tar.gz\\)",
 613                     remote: [
 614                         "bundles/common/jdk-" + data.version + "_doc-api-spec.tar.gz",
 615                         "bundles/linux-x64/\\1"
 616                     ],
 617                 },
 618             }
 619         }
 620     };
 621     profiles = concatObjects(profiles, profilesArtifacts);
 622 
 623     // Generate open only profiles for all the main and debug profiles.
 624     // Rewrite artifact remote paths by adding "openjdk/GPL".
 625     common.main_profile_names.forEach(function (name) {
 626         var openName = name + common.open_suffix;
 627         profiles[openName] = concatObjects(profiles[name],
 628             common.open_profile_base);
 629         for (artifactName in profiles[openName].artifacts) {
 630             var artifact = profiles[openName].artifacts[artifactName];
 631             artifact.remote = replaceAll(
 632                 "bundles\/", "bundles/openjdk/GPL/",
 633                 (artifact.remote != null ? artifact.remote : artifact.local));
 634         }
 635         var debugName = name + common.debug_suffix;
 636         var openDebugName = name + common.open_suffix + common.debug_suffix;
 637         profiles[openDebugName] = concatObjects(profiles[debugName],
 638             common.open_profile_base);
 639         for (artifactName in profiles[openDebugName].artifacts) {
 640             var artifact = profiles[openDebugName].artifacts[artifactName];
 641             artifact.remote = replaceAll(
 642                 "bundles\/", "bundles/openjdk/GPL/",
 643                 (artifact.remote != null ? artifact.remote : artifact.local));
 644         }
 645     });
 646 
 647     // Define the reference implementation profiles. These are basically the same
 648     // as the open profiles, but upload artifacts to a different location.
 649     common.main_profile_names.forEach(function (name) {
 650         var riName = name + "-ri";
 651         var riDebugName = riName + common.debug_suffix;
 652         var openName = name + common.open_suffix;
 653         var openDebugName = openName + common.debug_suffix;
 654         profiles[riName] = clone(profiles[openName]);
 655         profiles[riDebugName] = clone(profiles[openDebugName]);
 656         // Rewrite all remote dirs to "bundles/openjdk/BCL/..."
 657         for (artifactName in profiles[riName].artifacts) {
 658             var artifact = profiles[riName].artifacts[artifactName];
 659             artifact.remote = replaceAll(
 660                 "\/GPL\/", "/BCL/",
 661                 (artifact.remote != null ? artifact.remote : artifact.local));
 662         }
 663     });
 664 
 665     // Profiles used to run tests. Used in JPRT and Mach 5.
 666     var testOnlyProfiles = {
 667         "run-test-jprt": {
 668             target_os: input.build_os,
 669             target_cpu: input.build_cpu,
 670             dependencies: [ "jtreg", "gnumake", "boot_jdk", "devkit", "jib" ],
 671             labels: "test",
 672             environment: {
 673                 "JT_JAVA": common.boot_jdk_home
 674             }
 675         },
 676 
 677         "run-test": {
 678             target_os: input.build_os,
 679             target_cpu: input.build_cpu,
 680             dependencies: [ "jtreg", "gnumake", "boot_jdk", "devkit", "jib" ],
 681             labels: "test",
 682             environment: {
 683                 "JT_JAVA": common.boot_jdk_home
 684             }
 685         }
 686     };
 687     profiles = concatObjects(profiles, testOnlyProfiles);
 688 
 689     // Profiles used to run tests using Jib for internal dependencies.
 690     var testedProfile = input.testedProfile;
 691     if (testedProfile == null) {
 692         testedProfile = input.build_os + "-" + input.build_cpu;
 693     }
 694     var testOnlyProfilesPrebuilt = {
 695         "run-test-prebuilt": {
 696             target_os: input.build_os,
 697             target_cpu: input.build_cpu,
 698             src: "src.conf",
 699             dependencies: [ "jtreg", "gnumake", "boot_jdk", "jib", testedProfile + ".jdk",
 700                 testedProfile + ".test", "src.full"
 701             ],
 702             work_dir: input.get("src.full", "install_path") + "/test",
 703             environment: {
 704                 "JT_JAVA": common.boot_jdk_home,
 705                 "PRODUCT_HOME": input.get(testedProfile + ".jdk", "home_path"),
 706                 "TEST_IMAGE_DIR": input.get(testedProfile + ".test", "home_path"),
 707                 "TEST_OUTPUT_DIR": input.src_top_dir
 708             },
 709             labels: "test"
 710         }
 711     };
 712 
 713     // If actually running the run-test-prebuilt profile, verify that the input
 714     // variable is valid and if so, add the appropriate target_* values from
 715     // the tested profile.
 716     if (input.profile == "run-test-prebuilt") {
 717         if (profiles[testedProfile] == null) {
 718             error("testedProfile is not defined: " + testedProfile);
 719         }
 720     }
 721     if (profiles[testedProfile] != null) {
 722         testOnlyProfilesPrebuilt["run-test-prebuilt"]["target_os"]
 723             = profiles[testedProfile]["target_os"];
 724         testOnlyProfilesPrebuilt["run-test-prebuilt"]["target_cpu"]
 725             = profiles[testedProfile]["target_cpu"];
 726     }
 727     profiles = concatObjects(profiles, testOnlyProfilesPrebuilt);
 728 
 729     // On macosx add the devkit bin dir to the path in all the run-test profiles.
 730     // This gives us a guaranteed working version of lldb for the jtreg failure handler.
 731     if (input.build_os == "macosx") {
 732         macosxRunTestExtra = {
 733             dependencies: [ "devkit" ],
 734             environment_path: input.get("devkit", "install_path")
 735                 + "/Xcode.app/Contents/Developer/usr/bin"
 736         }
 737         profiles["run-test"] = concatObjects(profiles["run-test"], macosxRunTestExtra);
 738         profiles["run-test-jprt"] = concatObjects(profiles["run-test-jprt"], macosxRunTestExtra);
 739         profiles["run-test-prebuilt"] = concatObjects(profiles["run-test-prebuilt"], macosxRunTestExtra);
 740     }
 741 
 742     // Generate the missing platform attributes
 743     profiles = generatePlatformAttributes(profiles);
 744     profiles = generateDefaultMakeTargetsConfigureArg(common, profiles);
 745     return profiles;
 746 };
 747 
 748 /**
 749  * Generate the dependencies part of the configuration
 750  *
 751  * @param input External data to use for generating the configuration
 752  * @param common The common values
 753  * @returns {{}} Dependencies part of configuration
 754  */
 755 var getJibProfilesDependencies = function (input, common) {
 756 
 757     var devkit_platform_revisions = {
 758         linux_x64: "gcc4.9.2-OEL6.4+1.2",
 759         macosx_x64: "Xcode6.3-MacOSX10.9+1.0",
 760         solaris_x64: "SS12u4-Solaris11u1+1.0",
 761         solaris_sparcv9: "SS12u4-Solaris11u1+1.0",
 762         windows_x64: "VS2013SP4+1.0",
 763         linux_aarch64: "gcc-linaro-aarch64-linux-gnu-4.8-2013.11_linux+1.0",
 764         linux_arm: (input.profile != null && input.profile.indexOf("hflt") >= 0
 765                     ? "gcc-linaro-arm-linux-gnueabihf-raspbian-2012.09-20120921_linux+1.0"
 766                     : "arm-linaro-4.7+1.0")
 767     };
 768 
 769     var devkit_platform = (input.target_cpu == "x86"
 770         ? input.target_os + "_x64"
 771         : input.target_platform);
 772 
 773     var boot_jdk_platform = (input.build_os == "macosx" ? "osx" : input.build_os)
 774         + "-" + input.build_cpu;
 775 
 776     var freetype_version = {
 777         windows_x64: "2.7.1-v120+1.1",
 778         windows_x86: "2.7.1-v120+1.1",
 779         macosx_x64: "2.7.1-Xcode6.3-MacOSX10.9+1.0"
 780     }[input.target_platform];
 781 
 782     var dependencies = {
 783 
 784         boot_jdk: {
 785             server: "jpg",
 786             product: "jdk",
 787             version: common.boot_jdk_version,
 788             build_number: "181",
 789             file: "bundles/" + boot_jdk_platform + "/jdk-" + common.boot_jdk_version + "_"
 790                 + boot_jdk_platform + "_bin.tar.gz",
 791             configure_args: "--with-boot-jdk=" + common.boot_jdk_home,
 792             environment_path: common.boot_jdk_home + "/bin"
 793         },
 794 
 795         devkit: {
 796             organization: common.organization,
 797             ext: "tar.gz",
 798             module: "devkit-" + devkit_platform,
 799             revision: devkit_platform_revisions[devkit_platform]
 800         },
 801 
 802         build_devkit: {
 803             organization: common.organization,
 804             ext: "tar.gz",
 805             module: "devkit-" + input.build_platform,
 806             revision: devkit_platform_revisions[input.build_platform]
 807         },
 808 
 809         cups: {
 810             organization: common.organization,
 811             ext: "tar.gz",
 812             revision: "1.0118+1.0"
 813         },
 814 
 815         jtreg: {
 816             server: "javare",
 817             revision: "4.2",
 818             build_number: "b10",
 819             checksum_file: "MD5_VALUES",
 820             file: "jtreg_bin-4.2.zip",
 821             environment_name: "JT_HOME",
 822             environment_path: input.get("jtreg", "install_path") + "/jtreg/bin"
 823         },
 824 
 825         gnumake: {
 826             organization: common.organization,
 827             ext: "tar.gz",
 828             revision: "4.0+1.0",
 829 
 830             module: (input.build_os == "windows"
 831                 ? "gnumake-" + input.build_osenv_platform
 832                 : "gnumake-" + input.build_platform),
 833 
 834             configure_args: (input.build_os == "windows"
 835                 ? "MAKE=" + input.get("gnumake", "install_path") + "/cygwin/bin/make"
 836                 : "MAKE=" + input.get("gnumake", "install_path") + "/bin/make"),
 837 
 838             environment_path: (input.build_os == "windows"
 839                 ? input.get("gnumake", "install_path") + "/cygwin/bin"
 840                 : input.get("gnumake", "install_path") + "/bin")
 841         },
 842 
 843         freetype: {
 844             organization: common.organization,
 845             ext: "tar.gz",
 846             revision: freetype_version,
 847             module: "freetype-" + input.target_platform
 848         },
 849 
 850         graphviz: {
 851             organization: common.organization,
 852             ext: "tar.gz",
 853             revision: "2.38.0-1+1.1",
 854             module: "graphviz-" + input.target_platform,
 855             configure_args: "DOT=" + input.get("graphviz", "install_path") + "/dot",
 856             environment_path: input.get("graphviz", "install_path")
 857         },
 858 
 859         pandoc: {
 860             organization: common.organization,
 861             ext: "tar.gz",
 862             revision: "1.17.2+1.0",
 863             module: "pandoc-" + input.target_platform,
 864             configure_args: "PANDOC=" + input.get("pandoc", "install_path") + "/pandoc/pandoc",
 865             environment_path: input.get("pandoc", "install_path") + "/pandoc"
 866         },
 867         // This adds java jib as a dependency for the test artifacts resolver
 868         jib: {
 869             organization: "com.oracle.java.jib",
 870             ext: "zip",
 871             classifier: "distribution",
 872             revision: "3.0-SNAPSHOT",
 873             environment_name: "JIB_JAR",
 874             environment_value: input.get("jib", "install_path")
 875                 + "/jib-3.0-SNAPSHOT-distribution/lib/jib-3.0-SNAPSHOT.jar"
 876        }
 877     };
 878 
 879     // Need to add a value for the Visual Studio tools variable to make
 880     // jaot be able to pick up the Visual Studio linker in testing.
 881     if (input.target_os == "windows") {
 882         dependencies.devkit.environment = {
 883             VS120COMNTOOLS: input.get("devkit", "install_path") + "/Common7/Tools"
 884         };
 885     }
 886 
 887     return dependencies;
 888 };
 889 
 890 /**
 891  * Generate the missing platform attributes for profiles
 892  *
 893  * @param profiles Profiles map to generate attributes on
 894  * @returns {{}} New profiles map with platform attributes fully filled in
 895  */
 896 var generatePlatformAttributes = function (profiles) {
 897     var ret = concatObjects(profiles, {});
 898     for (var profile in profiles) {
 899         if (ret[profile].build_os == null) {
 900             ret[profile].build_os = ret[profile].target_os;
 901         }
 902         if (ret[profile].build_cpu == null) {
 903             ret[profile].build_cpu = ret[profile].target_cpu;
 904         }
 905         ret[profile].target_platform = ret[profile].target_os + "_" + ret[profile].target_cpu;
 906         ret[profile].build_platform = ret[profile].build_os + "_" + ret[profile].build_cpu;
 907     }
 908     return ret;
 909 };
 910 
 911 /**
 912  * The default_make_targets attribute on a profile is not a real Jib attribute.
 913  * This function rewrites that attribute into the corresponding configure arg.
 914  * Calling this function multiple times on the same profiles object is safe.
 915  *
 916  * @param common Common values
 917  * @param profiles Profiles map to rewrite profiles for
 918  * @returns {{}} New map of profiles with the make targets converted
 919  */
 920 var generateDefaultMakeTargetsConfigureArg = function (common, profiles) {
 921     var ret = concatObjects(profiles, {});
 922     for (var profile in ret) {
 923         if (ret[profile]["default_make_targets"] != null) {
 924             var targetsString = concat(ret[profile].default_make_targets).join(" ");
 925             // Iterate over all configure args and see if --with-default-make-target
 926             // is already there and change it, otherwise add it.
 927             var found = false;
 928             for (var i in ret[profile].configure_args) {
 929                 var arg = ret[profile].configure_args[i];
 930                 if (arg != null && arg.startsWith("--with-default-make-target=")) {
 931                     found = true;
 932                     ret[profile].configure_args[i]
 933                         = "--with-default-make-target=" + targetsString;
 934                 }
 935             }
 936             if (!found) {
 937                 ret[profile].configure_args = concat(
 938                     ret[profile].configure_args,
 939                     "--with-default-make-target=" + targetsString);
 940             }
 941         }
 942     }
 943     return ret;
 944 }
 945 
 946 var getBuildId = function (input) {
 947     if (input.build_id != null) {
 948         return input.build_id;
 949     } else {
 950         var topdir = new java.io.File(__DIR__, "../..").getCanonicalFile().getName();
 951         var userName = java.lang.System.getProperty("user.name");
 952         return userName + "." + topdir;
 953     }
 954 }
 955 
 956 /**
 957  * Deep clones an object tree.
 958  *
 959  * @param o Object to clone
 960  * @returns {{}} Clone of o
 961  */
 962 var clone = function (o) {
 963     return JSON.parse(JSON.stringify(o));
 964 };
 965 
 966 /**
 967  * Concatenates all arguments into a new array
 968  *
 969  * @returns {Array.<T>} New array containing all arguments
 970  */
 971 var concat = function () {
 972     return Array.prototype.concat.apply([], arguments);
 973 };
 974 
 975 /**
 976  * Takes a String or Array of Strings and does a replace operation on each
 977  * of them.
 978  *
 979  * @param pattern Pattern to look for
 980  * @param replacement Replacement text to insert
 981  * @param a String or Array of Strings to replace
 982  * @returns {Array} Either a new array or a new string depending on the input
 983  */
 984 var replaceAll = function (pattern, replacement, a) {
 985     // If a is an array
 986     if (Array === a.constructor) {
 987     var newA = [];
 988     for (var i in a) {
 989             newA.push(a[i].replace(pattern, replacement));
 990         }
 991         return newA;
 992         } else {
 993         return a.replace(pattern, replacement);
 994     }
 995 };
 996 
 997 /**
 998  * Deep concatenation of two objects. For each node encountered, merge
 999  * the contents with the corresponding node in the other object tree,
1000  * treating all strings as array elements.
1001  *
1002  * @param o1 Object to concatenate
1003  * @param o2 Object to concatenate
1004  * @returns {{}} New object tree containing the concatenation of o1 and o2
1005  */
1006 var concatObjects = function (o1, o2) {
1007     if (o1 == null) {
1008         return clone(o2);
1009     }
1010     if (o2 == null) {
1011         return clone(o1);
1012     }
1013     var ret = {};
1014     for (var a in o1) {
1015         if (o2[a] == null) {
1016             ret[a] = clone(o1[a]);
1017         }
1018     }
1019     for (var a in o2) {
1020         if (o1[a] == null) {
1021             ret[a] = clone(o2[a]);
1022         } else {
1023             if (typeof o1[a] == 'string') {
1024                 ret[a] = clone([o1[a]].concat(o2[a]));
1025             } else if (Array.isArray(o1[a])) {
1026                 ret[a] = clone(o1[a].concat(o2[a]));
1027             } else if (typeof o1[a] == 'object') {
1028                 ret[a] = concatObjects(o1[a], o2[a]);
1029             }
1030         }
1031     }
1032     return ret;
1033 };
1034 
1035 /**
1036  * Constructs the numeric version string from reading the
1037  * make/autoconf/version-numbers file and removing all trailing ".0".
1038  *
1039  * @param major Override major version
1040  * @param minor Override minor version
1041  * @param security Override security version
1042  * @param patch Override patch version
1043  * @returns {String} The numeric version string
1044  */
1045 var getVersion = function (major, minor, security, patch) {
1046     var version_numbers = getVersionNumbers();
1047     var version = (major != null ? major : version_numbers.get("DEFAULT_VERSION_MAJOR"))
1048         + "." + (minor != null ? minor : version_numbers.get("DEFAULT_VERSION_MINOR"))
1049         + "." + (security != null ? security :  version_numbers.get("DEFAULT_VERSION_SECURITY"))
1050         + "." + (patch != null ? patch : version_numbers.get("DEFAULT_VERSION_PATCH"));
1051     while (version.match(".*\\.0$")) {
1052         version = version.substring(0, version.length - 2);
1053     }
1054     return version;
1055 };
1056 
1057 /**
1058  * Constructs the common version configure args based on build type and
1059  * other version inputs
1060  */
1061 var versionArgs = function(input, common) {
1062     var args = ["--with-version-build=" + common.build_number];
1063     if (input.build_type == "promoted") {
1064         args = concat(args,
1065                       // This needs to be changed when we start building release candidates
1066                       "--with-version-pre=ea",
1067                       "--without-version-opt");
1068     } else {
1069         args = concat(args, "--with-version-opt=" + common.build_id);
1070     }
1071     return args;
1072 }
1073 
1074 // Properties representation of the make/autoconf/version-numbers file. Lazily
1075 // initiated by the function below.
1076 var version_numbers;
1077 
1078 /**
1079  * Read the make/autoconf/version-numbers file into a Properties object.
1080  *
1081  * @returns {java.utilProperties}
1082  */
1083 var getVersionNumbers = function () {
1084     // Read version information from make/autoconf/version-numbers
1085     if (version_numbers == null) {
1086         version_numbers = new java.util.Properties();
1087         var stream = new java.io.FileInputStream(__DIR__ + "/../autoconf/version-numbers");
1088         version_numbers.load(stream);
1089         stream.close();
1090     }
1091     return version_numbers;
1092 }