1 /*
   2  * Copyright (c) 2015, 2019, 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  * home_path
  80  *
  81  *
  82  * The output data generated by this configuration file has the following
  83  * format:
  84  *
  85  * data: {
  86  *   // Identifies the version of this format to the tool reading it
  87  *   format_version: "1.0",
  88  *
  89  *   // Name of base outputdir. JIB assumes the actual output dir is formed
  90  *   // by adding the configuration name: <output_basedir>/<config-name>
  91  *   output_basedir: "build",
  92  *   // Configure argument to use to specify configuration name
  93  *   configuration_configure_arg:
  94  *   // Make argument to use to specify configuration name
  95  *   configuration_make_arg:
  96  *
  97  *   profiles: {
  98  *     <profile-name>: {
  99  *       // Name of os the profile is built to run on
 100  *       target_os; <string>
 101  *       // Name of cpu the profile is built to run on
 102  *       target_cpu; <string>
 103  *       // Combination of target_os and target_cpu for convenience
 104  *       target_platform; <string>
 105  *       // Name of os the profile is built on
 106  *       build_os; <string>
 107  *       // Name of cpu the profile is built on
 108  *       build_cpu; <string>
 109  *       // Combination of build_os and build_cpu for convenience
 110  *       build_platform; <string>
 111  *
 112  *       // List of dependencies needed to build this profile
 113  *       dependencies: <Array of strings>
 114  *
 115  *       // List of configure args to use for this profile
 116  *       configure_args: <Array of strings>
 117  *
 118  *       // List of free form labels describing aspects of this profile
 119  *       labels: <Array of strings>
 120  *     }
 121  *   }
 122  *
 123  *   // Dependencies use a Maven like deployment structure
 124  *   dependencies: {
 125  *     <dependency-name>: {
 126  *       // Organization part of path defining this dependency
 127  *       organization: <string>
 128  *       // File extension for this dependency
 129  *       ext: <string>
 130  *       // Module part of path for defining this dependency,
 131  *       // defaults to <dependency-name>
 132  *       module: <string>
 133  *       // Revision part of path for defining this dependency
 134  *       revision: <string>
 135  *
 136  *       // List of configure args to add when using this dependency,
 137  *       // defaults to
 138  *       // "--with-<dependency-name>=input.get("<dependency-name", "install_path")"
 139  *       configure_args: <array of strings>
 140  *
 141  *       // Name of environment variable to set when using this dependency
 142  *       // when running make
 143  *       environment_name: <string>
 144  *       // Value of environment variable to set when using this dependency
 145  *       // when running make
 146  *       environment_value: <string>
 147  *
 148  *       // Value to add to the PATH variable when using this dependency,
 149  *       // applies to both make and configure
 150  *       environment_path: <string>
 151  *     }
 152  *
 153  *     <dependency-name>: {
 154  *       // For certain dependencies where a legacy distribution mechanism is
 155  *       // already in place, the "javare" server layout is also supported
 156  *       // Indicate that an alternate server source and layout should be used
 157  *       server: "javare"
 158  *
 159  *       // For "javare", a combination of module, revision,
 160  *       // build number (optional), files and checksum file is possible for
 161  *       // artifacts following the standard layout.
 162  *       module: <string>
 163  *       revision: <string>
 164  *       build_number: <string>
 165  *       checksum_file: <string>
 166  *       file: <string>
 167  *
 168  *       // For other files, use checksum path and path instead
 169  *       checksum_path: <string>
 170  *       path: <string>
 171  *     }
 172  *   }
 173  * }
 174  */
 175 
 176 /**
 177  * Main entry to generate the profile configuration
 178  *
 179  * @param input External data to use for generating the configuration
 180  * @returns {{}} Profile configuration
 181  */
 182 var getJibProfiles = function (input) {
 183 
 184     var data = {};
 185 
 186     // Identifies the version of this format to the tool reading it.
 187     // 1.1 signifies that the publish, publish-src and get-src features are usable.
 188     // 1.2 signifies that artifact uploads should fail on missing artifacts by default.
 189     // 1.3 input.get(<dep>, "home_path") automatically goes down into a single top
 190     //     dir just like default configure_args and environment_path variables.
 191     data.format_version = "1.3";
 192 
 193     // Organization, product and version are used when uploading/publishing build results
 194     data.organization = "";
 195     data.product = "jdk";
 196     data.version = getVersion();
 197 
 198     // The base directory for the build output. JIB will assume that the
 199     // actual build directory will be <output_basedir>/<configuration>
 200     data.output_basedir = "build";
 201     // The configure argument to use to specify the name of the configuration
 202     data.configuration_configure_arg = "--with-conf-name=";
 203     // The make argument to use to specify the name of the configuration
 204     data.configuration_make_arg = "CONF_NAME=";
 205 
 206     // Exclude list to use when Jib creates a source bundle
 207     data.src_bundle_excludes = [
 208         "build", "{,**/}webrev*", "{,**/}.hg", "{,**/}JTwork", "{,**/}JTreport",
 209         "{,**/}.git"
 210     ];
 211     // Include list to use when creating a minimal jib source bundle which
 212     // contains just the jib configuration files.
 213     data.conf_bundle_includes = [
 214         "make/autoconf/version-numbers",
 215     ];
 216 
 217     // Define some common values
 218     var common = getJibProfilesCommon(input, data);
 219     // Generate the profiles part of the configuration
 220     data.profiles = getJibProfilesProfiles(input, common, data);
 221     // Generate the dependencies part of the configuration
 222     data.dependencies = getJibProfilesDependencies(input, common, data);
 223 
 224     return data;
 225 };
 226 
 227 /**
 228  * Generates some common values
 229  *
 230  * @param input External data to use for generating the configuration
 231  * @returns Common values
 232  */
 233 var getJibProfilesCommon = function (input, data) {
 234     var common = {};
 235 
 236     common.organization = "jpg.infra.builddeps";
 237     common.build_id = getBuildId(input);
 238     common.build_number = input.build_number != null ? input.build_number : "0";
 239 
 240     // List of the main profile names used for iteration
 241     common.main_profile_names = [
 242         "linux-x64", "linux-x86", "macosx-x64", "solaris-x64",
 243         "solaris-sparcv9", "windows-x64", "windows-x86",
 244         "linux-aarch64", "linux-arm32", "linux-ppc64le", "linux-s390x"
 245     ];
 246 
 247     // These are the base setttings for all the main build profiles.
 248     common.main_profile_base = {
 249         dependencies: ["boot_jdk", "gnumake", "jtreg", "jib", "autoconf", "jmh", "jcov"],
 250         default_make_targets: ["product-bundles", "test-bundles"],
 251         configure_args: concat(["--enable-jtreg-failure-handler"],
 252             "--with-exclude-translations=de,es,fr,it,ko,pt_BR,sv,ca,tr,cs,sk,ja_JP_A,ja_JP_HA,ja_JP_HI,ja_JP_I,zh_TW,zh_HK",
 253             "--disable-manpages",
 254             "--with-jvm-features=-shenandoahgc",
 255             versionArgs(input, common))
 256     };
 257     // Extra settings for debug profiles
 258     common.debug_suffix = "-debug";
 259     common.debug_profile_base = {
 260         configure_args: ["--enable-debug"],
 261         labels: "debug"
 262     };
 263     // Extra settings for slowdebug profiles
 264     common.slowdebug_suffix = "-slowdebug";
 265     common.slowdebug_profile_base = {
 266         configure_args: ["--with-debug-level=slowdebug"],
 267         labels: "slowdebug"
 268     };
 269     // Extra settings for openjdk only profiles
 270     common.open_suffix = "-open";
 271     common.open_profile_base = {
 272         configure_args: ["--enable-openjdk-only"],
 273         labels: "open"
 274     };
 275 
 276     common.configure_args_64bit = ["--with-target-bits=64"];
 277     common.configure_args_32bit = ["--with-target-bits=32"];
 278 
 279     /**
 280      * Define common artifacts template for all main profiles
 281      * @param o - Object containing data for artifacts
 282      */
 283     common.main_profile_artifacts = function (o) {
 284         var jdk_subdir = (o.jdk_subdir != null ? o.jdk_subdir : "jdk-" + data.version);
 285         var jdk_suffix = (o.jdk_suffix != null ? o.jdk_suffix : "tar.gz");
 286         var pf = o.platform
 287         return {
 288             artifacts: {
 289                 jdk: {
 290                     local: "bundles/\\(jdk.*bin." + jdk_suffix + "\\)",
 291                     remote: [
 292                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin." + jdk_suffix,
 293                         "bundles/" + pf + "/\\1"
 294                     ],
 295                     subdir: jdk_subdir,
 296                     exploded: "images/jdk"
 297                 },
 298                 test: {
 299                     local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
 300                     remote: [
 301                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-tests.tar.gz",
 302                         "bundles/" + pf + "/\\1"
 303                     ],
 304                     exploded: "images/test"
 305                 },
 306                 test_demos: {
 307                     local: "bundles/\\(jdk.*bin-tests-demos.tar.gz\\)",
 308                     remote: [
 309                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-tests-demos.tar.gz",
 310                         "bundles/" + pf + "/\\1"
 311                     ],
 312                     exploded: "images/test"
 313                 },
 314                 jdk_symbols: {
 315                     local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
 316                     remote: [
 317                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-symbols.tar.gz",
 318                         "bundles/" + pf + "/\\1"
 319                     ],
 320                     subdir: jdk_subdir,
 321                     exploded: "images/jdk"
 322                 },
 323             }
 324         };
 325     };
 326 
 327 
 328     /**
 329      * Define common artifacts template for all debug profiles
 330      * @param o - Object containing data for artifacts
 331      */
 332     common.debug_profile_artifacts = function (o) {
 333         var jdk_subdir = "jdk-" + data.version + "/fastdebug";
 334         var jdk_suffix = (o.jdk_suffix != null ? o.jdk_suffix : "tar.gz");
 335         var pf = o.platform
 336         return {
 337             artifacts: {
 338                 jdk: {
 339                     local: "bundles/\\(jdk.*bin-debug." + jdk_suffix + "\\)",
 340                     remote: [
 341                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-debug." + jdk_suffix,
 342                         "bundles/" + pf + "/\\1"
 343                     ],
 344                     subdir: jdk_subdir,
 345                     exploded: "images/jdk"
 346                 },
 347                 test: {
 348                     local: "bundles/\\(jdk.*bin-tests-debug.tar.gz\\)",
 349                     remote: [
 350                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-tests-debug.tar.gz",
 351                         "bundles/" + pf + "/\\1"
 352                     ],
 353                     exploded: "images/test"
 354                 },
 355                 jdk_symbols: {
 356                     local: "bundles/\\(jdk.*bin-debug-symbols.tar.gz\\)",
 357                     remote: [
 358                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-debug-symbols.tar.gz",
 359                         "bundles/" + pf + "/\\1"
 360                     ],
 361                     subdir: jdk_subdir,
 362                     exploded: "images/jdk"
 363                 },
 364             }
 365         };
 366     };
 367 
 368     common.boot_jdk_version = "11";
 369     common.boot_jdk_home = input.get("boot_jdk", "install_path") + "/jdk-"
 370         + common.boot_jdk_version
 371         + (input.build_os == "macosx" ? ".jdk/Contents/Home" : "");
 372 
 373     return common;
 374 };
 375 
 376 /**
 377  * Generates the profiles part of the configuration.
 378  *
 379  * @param input External data to use for generating the configuration
 380  * @param common The common values
 381  * @returns {{}} Profiles part of the configuration
 382  */
 383 var getJibProfilesProfiles = function (input, common, data) {
 384     // Main SE profiles
 385     var profiles = {
 386 
 387         "linux-x64": {
 388             target_os: "linux",
 389             target_cpu: "x64",
 390             dependencies: ["devkit", "graphviz", "pandoc", "graalunit_lib"],
 391             configure_args: concat(common.configure_args_64bit,
 392                 "--enable-full-docs", "--with-zlib=system",
 393                 (isWsl(input) ? [ "--host=x86_64-unknown-linux-gnu",
 394                     "--build=x86_64-unknown-linux-gnu" ] : [])),
 395             default_make_targets: ["docs-bundles"],
 396         },
 397 
 398         "linux-x86": {
 399             target_os: "linux",
 400             target_cpu: "x86",
 401             build_cpu: "x64",
 402             dependencies: ["devkit"],
 403             configure_args: concat(common.configure_args_32bit,
 404                 "--with-jvm-variants=minimal,server", "--with-zlib=system"),
 405         },
 406 
 407         "macosx-x64": {
 408             target_os: "macosx",
 409             target_cpu: "x64",
 410             dependencies: ["devkit", "pandoc", "graalunit_lib"],
 411             configure_args: concat(common.configure_args_64bit, "--with-zlib=system",
 412                 "--with-macosx-version-max=10.9.0"),
 413         },
 414 
 415         "solaris-x64": {
 416             target_os: "solaris",
 417             target_cpu: "x64",
 418             dependencies: ["devkit", "cups"],
 419             configure_args: concat(common.configure_args_64bit,
 420                 "--with-zlib=system", "--enable-dtrace"),
 421         },
 422 
 423         "solaris-sparcv9": {
 424             target_os: "solaris",
 425             target_cpu: "sparcv9",
 426             dependencies: ["devkit", "cups"],
 427             configure_args: concat(common.configure_args_64bit,
 428                 "--with-zlib=system", "--enable-dtrace"),
 429         },
 430 
 431         "windows-x64": {
 432             target_os: "windows",
 433             target_cpu: "x64",
 434             dependencies: ["devkit", "pandoc", "graalunit_lib"],
 435             configure_args: concat(common.configure_args_64bit),
 436         },
 437 
 438         "windows-x86": {
 439             target_os: "windows",
 440             target_cpu: "x86",
 441             build_cpu: "x64",
 442             dependencies: ["devkit"],
 443             configure_args: concat(common.configure_args_32bit),
 444         },
 445 
 446         "linux-aarch64": {
 447             target_os: "linux",
 448             target_cpu: "aarch64",
 449             build_cpu: "x64",
 450             dependencies: ["devkit", "build_devkit", "cups"],
 451             configure_args: [
 452                 "--openjdk-target=aarch64-linux-gnu", "--with-freetype=bundled",
 453                 "--disable-warnings-as-errors"
 454             ],
 455         },
 456 
 457         "linux-arm32": {
 458             target_os: "linux",
 459             target_cpu: "arm",
 460             build_cpu: "x64",
 461             dependencies: ["devkit", "build_devkit", "cups"],
 462             configure_args: [
 463                 "--openjdk-target=arm-linux-gnueabihf", "--with-freetype=bundled",
 464                 "--with-abi-profile=arm-vfp-hflt", "--disable-warnings-as-errors"
 465             ],
 466         },
 467 
 468         "linux-ppc64le": {
 469             target_os: "linux",
 470             target_cpu: "ppc64le",
 471             build_cpu: "x64",
 472             dependencies: ["devkit", "build_devkit", "cups"],
 473             configure_args: [
 474                 "--openjdk-target=ppc64le-linux-gnu", "--with-freetype=bundled",
 475                 "--disable-warnings-as-errors"
 476             ],
 477         },
 478 
 479         "linux-s390x": {
 480             target_os: "linux",
 481             target_cpu: "s390x",
 482             build_cpu: "x64",
 483             dependencies: ["devkit", "build_devkit", "cups"],
 484             configure_args: [
 485                 "--openjdk-target=s390x-linux-gnu", "--with-freetype=bundled",
 486                 "--disable-warnings-as-errors"
 487             ],
 488         },
 489     };
 490 
 491     // Add the base settings to all the main profiles
 492     common.main_profile_names.forEach(function (name) {
 493         profiles[name] = concatObjects(common.main_profile_base, profiles[name]);
 494     });
 495 
 496     // Generate debug versions of all the main profiles
 497     common.main_profile_names.forEach(function (name) {
 498         var debugName = name + common.debug_suffix;
 499         profiles[debugName] = concatObjects(profiles[name],
 500                                             common.debug_profile_base);
 501     });
 502     // Generate slowdebug versions of all the main profiles
 503     common.main_profile_names.forEach(function (name) {
 504         var debugName = name + common.slowdebug_suffix;
 505         profiles[debugName] = concatObjects(profiles[name],
 506                                             common.slowdebug_profile_base);
 507     });
 508     // Generate testmake profiles for the main profile of each build host
 509     // platform. This profile only runs the makefile tests.
 510     // Ant is needed to run the idea project generator test.
 511     var testmakeBase = {
 512         dependencies: [ "ant" ],
 513         environment: {
 514             "ANT_HOME": input.get("ant", "home_path")
 515         }
 516     };
 517     [ "linux-x64", "macosx-x64", "solaris-sparcv9", "solaris-x64", "windows-x64"]
 518         .forEach(function (name) {
 519             var maketestName = name + "-testmake";
 520             profiles[maketestName] = concatObjects(profiles[name], testmakeBase);
 521             profiles[maketestName].default_make_targets = [ "test-make" ];
 522         });
 523 
 524     // Generate -gcov profiles
 525     [ "linux-x64", "macosx-x64" ].forEach(function (name) {
 526         var gcovName = name + "-gcov";
 527         profiles[gcovName] = clone(profiles[name]);
 528         profiles[gcovName].default_make_targets = ["product-bundles", "test-bundles"];
 529         profiles[gcovName].configure_args = concat(profiles[gcovName].configure_args,
 530             ["--enable-native-coverage", "--disable-warnings-as-errors"]);
 531     });
 532 
 533     // Profiles for building the zero jvm variant. These are used for verification.
 534     var zeroProfiles = {
 535         "linux-x64-zero": {
 536             target_os: "linux",
 537             target_cpu: "x64",
 538             dependencies: ["devkit"],
 539             configure_args: concat(common.configure_args_64bit, [
 540                 "--with-zlib=system",
 541                 "--with-jvm-variants=zero",
 542                 "--enable-libffi-bundling"
 543             ])
 544         },
 545 
 546         "linux-x86-zero": {
 547             target_os: "linux",
 548             target_cpu: "x86",
 549             build_cpu: "x64",
 550             dependencies: ["devkit"],
 551             configure_args:  concat(common.configure_args_32bit, [
 552                 "--with-zlib=system",
 553                 "--with-jvm-variants=zero",
 554                 "--enable-libffi-bundling"
 555             ])
 556         }
 557     }
 558     profiles = concatObjects(profiles, zeroProfiles);
 559 
 560     // Add the base settings to the zero profiles and generate debug profiles
 561     Object.keys(zeroProfiles).forEach(function (name) {
 562         var debugName = name + common.debug_suffix;
 563         profiles[name] = concatObjects(common.main_profile_base, profiles[name]);
 564         profiles[debugName] = concatObjects(profiles[name], common.debug_profile_base);
 565     });
 566 
 567     // Define a profile with precompiled headers disabled. This is just used for
 568     // verfication of this build configuration.
 569     var noPchProfiles = {
 570         "linux-x64-debug-nopch": {
 571             target_os: "linux",
 572             target_cpu: "x64",
 573             dependencies: ["devkit"],
 574             configure_args: concat(common.configure_args_64bit,
 575                 "--with-zlib=system", "--disable-precompiled-headers"),
 576         },
 577     };
 578     profiles = concatObjects(profiles, noPchProfiles);
 579     // Add base settings to noPch profiles
 580     Object.keys(noPchProfiles).forEach(function (name) {
 581         profiles[name] = concatObjects(common.main_profile_base, profiles[name]);
 582         profiles[name] = concatObjects(common.debug_profile_base, profiles[name]);
 583         // Override default make target with hotspot as that's the only part of
 584         // the build using precompiled headers.
 585         profiles[name].default_make_targets = ["hotspot"];
 586     });
 587 
 588     // Bootcycle profiles runs the build with itself as the boot jdk. This can
 589     // be done in two ways. Either using the builtin bootcycle target in the
 590     // build system. Or by supplying the main jdk build as bootjdk to configure.
 591     [ "linux-x64", "macosx-x64", "solaris-sparcv9", "windows-x64"]
 592         .forEach(function (name) {
 593             var bootcycleName = name + "-bootcycle";
 594             var bootcyclePrebuiltName = name + "-bootcycle-prebuilt";
 595             // The base bootcycle profile just changes the default target
 596             // compared to the base profile
 597             profiles[bootcycleName] = clone(profiles[name]);
 598             profiles[bootcycleName].default_make_targets = [ "bootcycle-images" ];
 599             // The prebuilt bootcycle variant modifies the boot jdk argument
 600             var bootcyclePrebuiltBase = {
 601                 dependencies: [ name + ".jdk" ],
 602                 configure_args: "--with-boot-jdk=" + input.get(name + ".jdk", "home_path"),
 603             }
 604             profiles[bootcyclePrebuiltName] = concatObjects(profiles[name],
 605                 bootcyclePrebuiltBase);
 606             var bootJdkIndex = profiles[bootcyclePrebuiltName].dependencies.indexOf("boot_jdk");
 607             delete profiles[bootcyclePrebuiltName].dependencies[bootJdkIndex];
 608             profiles[bootcyclePrebuiltName].default_make_targets = [ "product-images" ];
 609         });
 610 
 611     // JCov profiles build JCov-instrumented JDK image based on images provided through dependencies.
 612     [ "linux-x64", "macosx-x64", "solaris-sparcv9", "windows-x64"]
 613         .forEach(function (name) {
 614             var jcovName = name + "-jcov";
 615             profiles[jcovName] = clone(common.main_profile_base);
 616             profiles[jcovName].target_os = profiles[name].target_os
 617             profiles[jcovName].target_cpu = profiles[name].target_cpu
 618             profiles[jcovName].default_make_targets = [ "jcov-bundles" ];
 619             profiles[jcovName].dependencies = concat(profiles[jcovName].dependencies,
 620                 [ name + ".jdk", "devkit" ]);
 621             profiles[jcovName].configure_args = concat(profiles[jcovName].configure_args,
 622                 ["--with-jcov-input-jdk=" + input.get(name + ".jdk", "home_path")]);
 623         });
 624 
 625     //
 626     // Define artifacts for profiles
 627     //
 628     // Macosx bundles are named osx
 629     // tar.gz.
 630     var artifactData = {
 631         "linux-x64": {
 632             platform: "linux-x64",
 633         },
 634         "linux-x86": {
 635             platform: "linux-x86",
 636         },
 637         "macosx-x64": {
 638             platform: "osx-x64",
 639             jdk_subdir: "jdk-" + data.version +  ".jdk/Contents/Home",
 640         },
 641         "solaris-x64": {
 642             platform: "solaris-x64",
 643         },
 644         "solaris-sparcv9": {
 645             platform: "solaris-sparcv9",
 646         },
 647         "windows-x64": {
 648             platform: "windows-x64",
 649             jdk_suffix: "zip",
 650         },
 651         "windows-x86": {
 652             platform: "windows-x86",
 653             jdk_suffix: "zip",
 654         },
 655        "linux-aarch64": {
 656             platform: "linux-aarch64",
 657         },
 658        "linux-arm32": {
 659             platform: "linux-arm32",
 660         },
 661        "linux-ppc64le": {
 662             platform: "linux-ppc64le",
 663         },
 664        "linux-s390x": {
 665             platform: "linux-s390x",
 666         }
 667     }
 668     // Generate common artifacts for all main profiles
 669     Object.keys(artifactData).forEach(function (name) {
 670         profiles[name] = concatObjects(profiles[name],
 671             common.main_profile_artifacts(artifactData[name]));
 672     });
 673 
 674     // Generate common artifacts for all debug profiles
 675     Object.keys(artifactData).forEach(function (name) {
 676         var debugName = name + common.debug_suffix;
 677         profiles[debugName] = concatObjects(profiles[debugName],
 678             common.debug_profile_artifacts(artifactData[name]));
 679     });
 680 
 681     profilesArtifacts = {
 682         "linux-x64": {
 683             artifacts: {
 684                 doc_api_spec: {
 685                     local: "bundles/\\(jdk.*doc-api-spec.tar.gz\\)",
 686                     remote: [
 687                         "bundles/common/jdk-" + data.version + "_doc-api-spec.tar.gz",
 688                         "bundles/linux-x64/\\1"
 689                     ],
 690                 },
 691             }
 692         }
 693     };
 694     profiles = concatObjects(profiles, profilesArtifacts);
 695 
 696     // Generate open only profiles for all the main and debug profiles.
 697     // Rewrite artifact remote paths by adding "openjdk/GPL".
 698     common.main_profile_names.forEach(function (name) {
 699         var openName = name + common.open_suffix;
 700         profiles[openName] = concatObjects(profiles[name],
 701             common.open_profile_base);
 702         for (artifactName in profiles[openName].artifacts) {
 703             var artifact = profiles[openName].artifacts[artifactName];
 704             artifact.remote = replaceAll(
 705                 "bundles\/", "bundles/openjdk/GPL/",
 706                 (artifact.remote != null ? artifact.remote : artifact.local));
 707         }
 708         var debugName = name + common.debug_suffix;
 709         var openDebugName = name + common.open_suffix + common.debug_suffix;
 710         profiles[openDebugName] = concatObjects(profiles[debugName],
 711             common.open_profile_base);
 712         for (artifactName in profiles[openDebugName].artifacts) {
 713             var artifact = profiles[openDebugName].artifacts[artifactName];
 714             artifact.remote = replaceAll(
 715                 "bundles\/", "bundles/openjdk/GPL/",
 716                 (artifact.remote != null ? artifact.remote : artifact.local));
 717         }
 718     });
 719 
 720     // Define the reference implementation profiles. These are basically the same
 721     // as the open profiles, but upload artifacts to a different location.
 722     common.main_profile_names.forEach(function (name) {
 723         var riName = name + "-ri";
 724         var riDebugName = riName + common.debug_suffix;
 725         var openName = name + common.open_suffix;
 726         var openDebugName = openName + common.debug_suffix;
 727         profiles[riName] = clone(profiles[openName]);
 728         profiles[riDebugName] = clone(profiles[openDebugName]);
 729         // Rewrite all remote dirs to "bundles/openjdk/BCL/..."
 730         for (artifactName in profiles[riName].artifacts) {
 731             var artifact = profiles[riName].artifacts[artifactName];
 732             artifact.remote = replaceAll(
 733                 "\/GPL\/", "/BCL/",
 734                 (artifact.remote != null ? artifact.remote : artifact.local));
 735         }
 736     });
 737 
 738     // For open profiles, the non-debug jdk bundles, need an "open" prefix on the
 739     // remote bundle names, forming the word "openjdk". See JDK-8188789.
 740     common.main_profile_names.forEach(function (name) {
 741         var openName = name + common.open_suffix;
 742         profiles[openName].artifacts["jdk"].remote = replaceAll(
 743             "\/jdk-", "/openjdk-",
 744             replaceAll("\/\\1", "/open\\1",
 745                        profiles[openName].artifacts["jdk"].remote));
 746     });
 747 
 748     // Generate cmp-baseline profiles for each main profile and their
 749     // corresponding debug profile. This profile does a compare build run with no
 750     // changes to verify that the compare script has a clean baseline
 751     common.main_profile_names.forEach(function (name) {
 752         [ "", common.open_suffix ].forEach(function (suffix) {
 753             var cmpBaselineName = name + suffix + "-cmp-baseline";
 754             profiles[cmpBaselineName] = clone(profiles[name + suffix]);
 755             // Only compare the images target. This should pressumably be expanded
 756             // to include more build targets when possible.
 757             profiles[cmpBaselineName].default_make_targets = [ "images" ];
 758             profiles[cmpBaselineName].make_args = [ "COMPARE_BUILD=CONF=" ];
 759             // Do not inherit artifact definitions from base profile
 760             delete profiles[cmpBaselineName].artifacts;
 761         });
 762     });
 763 
 764     // Artifacts of JCov profiles
 765     [ "linux-x64", "macosx-x64", "solaris-sparcv9", "windows-x64"]
 766         .forEach(function (name) {
 767             var o = artifactData[name]
 768             var jdk_subdir = (o.jdk_subdir != null ? o.jdk_subdir : "jdk-" + data.version);
 769             var jdk_suffix = (o.jdk_suffix != null ? o.jdk_suffix : "tar.gz");
 770             var pf = o.platform
 771             var jcovName = name + "-jcov";
 772             profiles[jcovName].artifacts = {
 773                 jdk: {
 774                     local: "bundles/\\(jdk-jcov.*bin." + jdk_suffix + "\\)",
 775                     remote: [
 776                         "bundles/" + pf + "/jdk-jcov-" + data.version + "_" + pf + "_bin." + jdk_suffix
 777                     ],
 778                     subdir: jdk_subdir,
 779                     exploded: "images/jdk-jcov"
 780                 }
 781             };
 782         });
 783 
 784     // Artifacts of gcov (native-code-coverage) profiles
 785     [ "linux-x64", "macosx-x64" ].forEach(function (name) {
 786         var o = artifactData[name]
 787         var pf = o.platform
 788         var jdk_subdir = (o.jdk_subdir != null ? o.jdk_subdir : "jdk-" + data.version);
 789         var jdk_suffix = (o.jdk_suffix != null ? o.jdk_suffix : "tar.gz");
 790         var gcovName = name + "-gcov";
 791         profiles[gcovName].artifacts = {
 792             jdk: {
 793                 local: "bundles/\\(jdk.*bin." + jdk_suffix + "\\)",
 794                 remote: [
 795                     "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-gcov." + jdk_suffix,
 796                 ],
 797                 subdir: jdk_subdir,
 798                 exploded: "images/jdk",
 799             },
 800             test: {
 801                     local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
 802                     remote: [
 803                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-gcov-tests.tar.gz",
 804                     ],
 805                     exploded: "images/test"
 806             },
 807             jdk_symbols: {
 808                     local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
 809                     remote: [
 810                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-gcov-symbols.tar.gz",
 811                     ],
 812                     subdir: jdk_subdir,
 813                     exploded: "images/jdk"
 814                 },
 815             };
 816     });
 817 
 818     // Profiles used to run tests.
 819     var testOnlyProfiles = {
 820         "run-test": {
 821             target_os: input.build_os,
 822             target_cpu: input.build_cpu,
 823             dependencies: [ "jtreg", "gnumake", "boot_jdk", "devkit", "jib" ],
 824             labels: "test",
 825             environment: {
 826                 "JT_JAVA": common.boot_jdk_home
 827             }
 828         }
 829     };
 830     profiles = concatObjects(profiles, testOnlyProfiles);
 831 
 832     // Profiles used to run tests using Jib for internal dependencies.
 833     var testedProfile = input.testedProfile;
 834     if (testedProfile == null) {
 835         testedProfile = input.build_os + "-" + input.build_cpu;
 836     }
 837     var testedProfileJDK = testedProfile + ".jdk";
 838     var testedProfileTest = ""
 839     if (testedProfile.endsWith("-jcov")) {
 840         testedProfileTest = testedProfile.substring(0, testedProfile.length - "-jcov".length) + ".test";
 841     } else {
 842         testedProfileTest = testedProfile + ".test";
 843     }
 844     var testOnlyMake = [ "run-test-prebuilt", "LOG_CMDLINES=true", "JTREG_VERBOSE=fail,error,time" ];
 845     if (testedProfile.endsWith("-gcov")) {
 846         testOnlyMake = concat(testOnlyMake, "GCOV_ENABLED=true")
 847     }
 848     var testOnlyProfilesPrebuilt = {
 849         "run-test-prebuilt": {
 850             target_os: input.build_os,
 851             target_cpu: input.build_cpu,
 852             dependencies: [
 853                 "jtreg", "gnumake", "boot_jdk", "devkit", "jib", "jcov", testedProfileJDK,
 854                 testedProfileTest
 855             ],
 856             src: "src.conf",
 857             make_args: testOnlyMake,
 858             environment: {
 859                 "BOOT_JDK": common.boot_jdk_home,
 860                 "JDK_IMAGE_DIR": input.get(testedProfileJDK, "home_path"),
 861                 "TEST_IMAGE_DIR": input.get(testedProfileTest, "home_path")
 862             },
 863             labels: "test"
 864         }
 865     };
 866 
 867     // If actually running the run-test-prebuilt profile, verify that the input
 868     // variable is valid and if so, add the appropriate target_* values from
 869     // the tested profile.
 870     if (input.profile == "run-test-prebuilt") {
 871         if (profiles[testedProfile] == null) {
 872             error("testedProfile is not defined: " + testedProfile);
 873         }
 874     }
 875     if (profiles[testedProfile] != null) {
 876         testOnlyProfilesPrebuilt["run-test-prebuilt"]["target_os"]
 877             = profiles[testedProfile]["target_os"];
 878         testOnlyProfilesPrebuilt["run-test-prebuilt"]["target_cpu"]
 879             = profiles[testedProfile]["target_cpu"];
 880     }
 881     profiles = concatObjects(profiles, testOnlyProfilesPrebuilt);
 882 
 883     // On macosx add the devkit bin dir to the path in all the run-test profiles.
 884     // This gives us a guaranteed working version of lldb for the jtreg failure handler.
 885     if (input.build_os == "macosx") {
 886         macosxRunTestExtra = {
 887             environment_path: input.get("devkit", "install_path")
 888                 + "/Xcode.app/Contents/Developer/usr/bin"
 889         };
 890         profiles["run-test"] = concatObjects(profiles["run-test"], macosxRunTestExtra);
 891         profiles["run-test-prebuilt"] = concatObjects(profiles["run-test-prebuilt"], macosxRunTestExtra);
 892     }
 893     // On windows we want the debug symbols available at test time
 894     if (input.build_os == "windows") {
 895         windowsRunTestPrebuiltExtra = {
 896             dependencies: [ testedProfile + ".jdk_symbols" ],
 897             environment: {
 898                 "SYMBOLS_IMAGE_DIR": input.get(testedProfile + ".jdk_symbols", "home_path"),
 899             }
 900         };
 901         profiles["run-test-prebuilt"] = concatObjects(profiles["run-test-prebuilt"],
 902             windowsRunTestPrebuiltExtra);
 903     }
 904 
 905     // The profile run-test-prebuilt defines src.conf as the src bundle. When
 906     // running in Mach 5, this reduces the time it takes to populate the
 907     // considerably. But with just src.conf, we cannot actually run any tests,
 908     // so if running from a workspace with just src.conf in it, we need to also
 909     // get src.full as a dependency, and define the work_dir (where make gets
 910     // run) to be in the src.full install path. By running in the install path,
 911     // the same cached installation of the full src can be reused for multiple
 912     // test tasks. Care must however be taken not to polute that work dir by
 913     // setting the appropriate make variables to control output directories.
 914     //
 915     // Use the existance of the top level README as indication of if this is
 916     // the full source or just src.conf.
 917     if (!new java.io.File(__DIR__, "../../README").exists()) {
 918         var runTestPrebuiltSrcFullExtra = {
 919             dependencies: "src.full",
 920             work_dir: input.get("src.full", "install_path"),
 921         }
 922         profiles["run-test-prebuilt"] = concatObjects(profiles["run-test-prebuilt"],
 923             runTestPrebuiltSrcFullExtra);
 924     }
 925 
 926     // Generate the missing platform attributes
 927     profiles = generatePlatformAttributes(profiles);
 928     profiles = generateDefaultMakeTargetsConfigureArg(common, profiles);
 929     return profiles;
 930 };
 931 
 932 /**
 933  * Generate the dependencies part of the configuration
 934  *
 935  * @param input External data to use for generating the configuration
 936  * @param common The common values
 937  * @returns {{}} Dependencies part of configuration
 938  */
 939 var getJibProfilesDependencies = function (input, common) {
 940 
 941     var devkit_platform_revisions = {
 942         linux_x64: "gcc7.3.0-OEL6.4+1.2",
 943         macosx_x64: "Xcode9.4-MacOSX10.13+1.0",
 944         solaris_x64: "SS12u4-Solaris11u1+1.0",
 945         solaris_sparcv9: "SS12u6-Solaris11u3+1.0",
 946         windows_x64: "VS2017-15.5.5+1.0",
 947         linux_aarch64: "gcc7.3.0-Fedora27+1.2",
 948         linux_arm: "gcc7.3.0-Fedora27+1.2",
 949         linux_ppc64le: "gcc7.3.0-Fedora27+1.0",
 950         linux_s390x: "gcc7.3.0-Fedora27+1.0"
 951     };
 952 
 953     var devkit_platform = (input.target_cpu == "x86"
 954         ? input.target_os + "_x64"
 955         : input.target_platform);
 956 
 957     var boot_jdk_platform = (input.build_os == "macosx" ? "osx" : input.build_os)
 958         + "-" + input.build_cpu;
 959     var boot_jdk_ext = (input.build_os == "windows" ? ".zip" : ".tar.gz")
 960     // If running in WSL and building for Windows, it will look like Linux,
 961     // but we need a Windows boot JDK.
 962     if (isWsl(input) && input.target_os == "windows") {
 963         boot_jdk_platform = "windows-" + input.build_cpu;
 964         boot_jdk_ext = ".zip";
 965     }
 966 
 967     var makeBinDir = (input.build_os == "windows"
 968         ? input.get("gnumake", "install_path") + "/cygwin/bin"
 969         : input.get("gnumake", "install_path") + "/bin");
 970 
 971     var dependencies = {
 972 
 973         boot_jdk: {
 974             server: "jpg",
 975             product: "jdk",
 976             version: common.boot_jdk_version,
 977             build_number: "28",
 978             file: "bundles/" + boot_jdk_platform + "/jdk-" + common.boot_jdk_version + "_"
 979                 + boot_jdk_platform + "_bin" + boot_jdk_ext,
 980             configure_args: "--with-boot-jdk=" + common.boot_jdk_home,
 981             environment_path: common.boot_jdk_home + "/bin"
 982         },
 983 
 984         devkit: {
 985             organization: common.organization,
 986             ext: "tar.gz",
 987             module: "devkit-" + devkit_platform,
 988             revision: devkit_platform_revisions[devkit_platform],
 989             environment: {
 990                 "DEVKIT_HOME": input.get("devkit", "home_path"),
 991             }
 992         },
 993 
 994         build_devkit: {
 995             organization: common.organization,
 996             ext: "tar.gz",
 997             module: "devkit-" + input.build_platform,
 998             revision: devkit_platform_revisions[input.build_platform]
 999         },
1000 
1001         cups: {
1002             organization: common.organization,
1003             ext: "tar.gz",
1004             revision: "1.0118+1.0"
1005         },
1006 
1007         jtreg: {
1008             server: "javare",
1009             revision: "4.2",
1010             build_number: "b14",
1011             checksum_file: "MD5_VALUES",
1012             file: "jtreg_bin-4.2.zip",
1013             environment_name: "JT_HOME",
1014             environment_path: input.get("jtreg", "install_path") + "/jtreg/bin"
1015         },
1016 
1017         jmh: {
1018             organization: common.organization,
1019             ext: "tar.gz",
1020             revision: "1.21+1.0"
1021         },
1022 
1023         jcov: {
1024             // Until an official build of JCov is available, use custom
1025             // build to support classfile version 57.
1026             // See CODETOOLS-7902358 for more info.
1027             // server: "jpg",
1028             // product: "jcov",
1029             // version: "3.0",
1030             // build_number: "b07",
1031             // file: "bundles/jcov-3_0.zip",
1032             organization: common.organization,
1033             revision: "3.0-57-support+1.0",
1034             ext: "zip",
1035             environment_name: "JCOV_HOME",
1036         },
1037 
1038         gnumake: {
1039             organization: common.organization,
1040             ext: "tar.gz",
1041             revision: "4.0+1.0",
1042 
1043             module: (input.build_os == "windows"
1044                 ? "gnumake-" + input.build_osenv_platform
1045                 : "gnumake-" + input.build_platform),
1046 
1047             configure_args: "MAKE=" + makeBinDir + "/make",
1048 
1049             environment: {
1050                 "MAKE": makeBinDir + "/make"
1051             },
1052 
1053             environment_path: makeBinDir
1054         },
1055 
1056         autoconf: {
1057             organization: common.organization,
1058             ext: "tar.gz",
1059             revision: "2.69+1.0.1",
1060             module: (input.build_os == "windows"
1061                 ? "autoconf-" + input.build_osenv_platform
1062                 : "autoconf-" + input.build_platform),
1063             configure_args: "",
1064             environment_path: input.get("autoconf", "install_path")
1065         },
1066 
1067         graphviz: {
1068             organization: common.organization,
1069             ext: "tar.gz",
1070             revision: "2.38.0-1+1.1",
1071             module: "graphviz-" + input.target_platform,
1072             configure_args: "DOT=" + input.get("graphviz", "install_path") + "/dot",
1073             environment_path: input.get("graphviz", "install_path")
1074         },
1075 
1076         pandoc: {
1077             organization: common.organization,
1078             ext: "tar.gz",
1079             revision: "2.3.1+1.0",
1080             module: "pandoc-" + input.build_platform,
1081             configure_args: "PANDOC=" + input.get("pandoc", "install_path") + "/pandoc/pandoc",
1082             environment_path: input.get("pandoc", "install_path") + "/pandoc"
1083         },
1084 
1085         // This adds java jib as a dependency for the test artifacts resolver
1086         jib: {
1087             organization: "com.oracle.java.jib",
1088             ext: "zip",
1089             classifier: "distribution",
1090             revision: "3.0-SNAPSHOT",
1091             environment_name: "JIB_HOME",
1092             environment_value: input.get("jib", "home_path")
1093         },
1094 
1095         ant: {
1096             organization: common.organization,
1097             ext: "zip",
1098             revision: "1.7.1+1.0",
1099             configure_args: "",
1100         },
1101 
1102         graalunit_lib: {
1103             organization: common.organization,
1104             ext: "zip",
1105             revision: "619_Apr_12_2018",
1106             module: "graalunit-lib",
1107             configure_args: "--with-graalunit-lib=" + input.get("graalunit_lib", "install_path"),
1108             environment_name: "GRAALUNIT_LIB"
1109         },
1110     };
1111 
1112     return dependencies;
1113 };
1114 
1115 /**
1116  * Generate the missing platform attributes for profiles
1117  *
1118  * @param profiles Profiles map to generate attributes on
1119  * @returns {{}} New profiles map with platform attributes fully filled in
1120  */
1121 var generatePlatformAttributes = function (profiles) {
1122     var ret = concatObjects(profiles, {});
1123     for (var profile in profiles) {
1124         if (ret[profile].build_os == null) {
1125             ret[profile].build_os = ret[profile].target_os;
1126         }
1127         if (ret[profile].build_cpu == null) {
1128             ret[profile].build_cpu = ret[profile].target_cpu;
1129         }
1130         ret[profile].target_platform = ret[profile].target_os + "_" + ret[profile].target_cpu;
1131         ret[profile].build_platform = ret[profile].build_os + "_" + ret[profile].build_cpu;
1132     }
1133     return ret;
1134 };
1135 
1136 /**
1137  * The default_make_targets attribute on a profile is not a real Jib attribute.
1138  * This function rewrites that attribute into the corresponding configure arg.
1139  * Calling this function multiple times on the same profiles object is safe.
1140  *
1141  * @param common Common values
1142  * @param profiles Profiles map to rewrite profiles for
1143  * @returns {{}} New map of profiles with the make targets converted
1144  */
1145 var generateDefaultMakeTargetsConfigureArg = function (common, profiles) {
1146     var ret = concatObjects(profiles, {});
1147     for (var profile in ret) {
1148         if (ret[profile]["default_make_targets"] != null) {
1149             var targetsString = concat(ret[profile].default_make_targets).join(" ");
1150             // Iterate over all configure args and see if --with-default-make-target
1151             // is already there and change it, otherwise add it.
1152             var found = false;
1153             for (var i in ret[profile].configure_args) {
1154                 var arg = ret[profile].configure_args[i];
1155                 if (arg != null && arg.startsWith("--with-default-make-target=")) {
1156                     found = true;
1157                     ret[profile].configure_args[i]
1158                         = "--with-default-make-target=" + targetsString;
1159                 }
1160             }
1161             if (!found) {
1162                 ret[profile].configure_args = concat(
1163                     ret[profile].configure_args,
1164                     "--with-default-make-target=" + targetsString);
1165             }
1166         }
1167     }
1168     return ret;
1169 }
1170 
1171 var getBuildId = function (input) {
1172     if (input.build_id != null) {
1173         return input.build_id;
1174     } else {
1175         var topdir = new java.io.File(__DIR__, "../..").getCanonicalFile().getName();
1176         var userName = java.lang.System.getProperty("user.name");
1177         return userName + "." + topdir;
1178     }
1179 }
1180 
1181 /**
1182  * Deep clones an object tree.
1183  *
1184  * @param o Object to clone
1185  * @returns {{}} Clone of o
1186  */
1187 var clone = function (o) {
1188     return JSON.parse(JSON.stringify(o));
1189 };
1190 
1191 /**
1192  * Concatenates all arguments into a new array
1193  *
1194  * @returns {Array.<T>} New array containing all arguments
1195  */
1196 var concat = function () {
1197     return Array.prototype.concat.apply([], arguments);
1198 };
1199 
1200 /**
1201  * Takes a String or Array of Strings and does a replace operation on each
1202  * of them.
1203  *
1204  * @param pattern Pattern to look for
1205  * @param replacement Replacement text to insert
1206  * @param a String or Array of Strings to replace
1207  * @returns {Array} Either a new array or a new string depending on the input
1208  */
1209 var replaceAll = function (pattern, replacement, a) {
1210     // If a is an array
1211     if (Array === a.constructor) {
1212     var newA = [];
1213     for (var i in a) {
1214             newA.push(a[i].replace(pattern, replacement));
1215         }
1216         return newA;
1217         } else {
1218         return a.replace(pattern, replacement);
1219     }
1220 };
1221 
1222 /**
1223  * Deep concatenation of two objects. For each node encountered, merge
1224  * the contents with the corresponding node in the other object tree,
1225  * treating all strings as array elements.
1226  *
1227  * @param o1 Object to concatenate
1228  * @param o2 Object to concatenate
1229  * @returns {{}} New object tree containing the concatenation of o1 and o2
1230  */
1231 var concatObjects = function (o1, o2) {
1232     if (o1 == null) {
1233         return clone(o2);
1234     }
1235     if (o2 == null) {
1236         return clone(o1);
1237     }
1238     var ret = {};
1239     for (var a in o1) {
1240         if (o2[a] == null) {
1241             ret[a] = clone(o1[a]);
1242         }
1243     }
1244     for (var a in o2) {
1245         if (o1[a] == null) {
1246             ret[a] = clone(o2[a]);
1247         } else {
1248             if (typeof o1[a] == 'string') {
1249                 ret[a] = clone([o1[a]].concat(o2[a]));
1250             } else if (Array.isArray(o1[a])) {
1251                 ret[a] = clone(o1[a].concat(o2[a]));
1252             } else if (typeof o1[a] == 'object') {
1253                 ret[a] = concatObjects(o1[a], o2[a]);
1254             }
1255         }
1256     }
1257     return ret;
1258 };
1259 
1260 /**
1261  * Constructs the numeric version string from reading the
1262  * make/autoconf/version-numbers file and removing all trailing ".0".
1263  *
1264  * @param feature Override feature version
1265  * @param interim Override interim version
1266  * @param update Override update version
1267  * @param patch Override patch version
1268  * @returns {String} The numeric version string
1269  */
1270 var getVersion = function (feature, interim, update, patch) {
1271     var version_numbers = getVersionNumbers();
1272     var version = (feature != null ? feature : version_numbers.get("DEFAULT_VERSION_FEATURE"))
1273         + "." + (interim != null ? interim : version_numbers.get("DEFAULT_VERSION_INTERIM"))
1274         + "." + (update != null ? update :  version_numbers.get("DEFAULT_VERSION_UPDATE"))
1275         + "." + (patch != null ? patch : version_numbers.get("DEFAULT_VERSION_PATCH"));
1276     while (version.match(".*\\.0$")) {
1277         version = version.substring(0, version.length - 2);
1278     }
1279     return version;
1280 };
1281 
1282 /**
1283  * Constructs the common version configure args based on build type and
1284  * other version inputs
1285  */
1286 var versionArgs = function(input, common) {
1287     var args = ["--with-version-build=" + common.build_number];
1288     if (input.build_type == "promoted") {
1289         args = concat(args,
1290                       // This needs to be changed when we start building release candidates
1291                       // with-version-pre must be set to ea for 'ea' and empty for fcs build
1292                       "--with-version-pre=ea",
1293                       "--without-version-opt");
1294     } else {
1295         args = concat(args, "--with-version-opt=" + common.build_id);
1296     }
1297     return args;
1298 }
1299 
1300 // Properties representation of the make/autoconf/version-numbers file. Lazily
1301 // initiated by the function below.
1302 var version_numbers;
1303 
1304 /**
1305  * Read the make/autoconf/version-numbers file into a Properties object.
1306  *
1307  * @returns {java.utilProperties}
1308  */
1309 var getVersionNumbers = function () {
1310     // Read version information from make/autoconf/version-numbers
1311     if (version_numbers == null) {
1312         version_numbers = new java.util.Properties();
1313         var stream = new java.io.FileInputStream(__DIR__ + "/../autoconf/version-numbers");
1314         version_numbers.load(stream);
1315         stream.close();
1316     }
1317     return version_numbers;
1318 }
1319 
1320 /**
1321  * Returns true if running in Windows Subsystem for Linux. Jib does not yet
1322  * detect wsl as osenv, so fall back on linux with version containing Microsoft.
1323  */
1324 var isWsl = function (input) {
1325     return ( input.build_osenv == "wsl"
1326              || (input.build_os == "linux"
1327                  && java.lang.System.getProperty("os.version").contains("Microsoft")));
1328 }