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