1 /*
   2  * Copyright (c) 2015, 2021, 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/conf/version-numbers.conf",
 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", "macosx-aarch64",
 243         "windows-x64", "windows-x86", "windows-aarch64",
 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", "static-libs-bundles"],
 251         configure_args: concat("--enable-jtreg-failure-handler",
 252             "--with-exclude-translations=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             "--disable-jvm-feature-shenandoahgc",
 255             versionArgs(input, common))
 256     };
 257     // Extra settings for release profiles
 258     common.release_profile_base = {
 259         configure_args: [
 260             "--enable-reproducible-build",
 261             "--with-source-date=current",
 262         ],
 263     };
 264     // Extra settings for debug profiles
 265     common.debug_suffix = "-debug";
 266     common.debug_profile_base = {
 267         configure_args: ["--enable-debug"],
 268         labels: "debug"
 269     };
 270     // Extra settings for slowdebug profiles
 271     common.slowdebug_suffix = "-slowdebug";
 272     common.slowdebug_profile_base = {
 273         configure_args: ["--with-debug-level=slowdebug"],
 274         labels: "slowdebug"
 275     };
 276     // Extra settings for optimized profiles
 277     common.optimized_suffix = "-optimized";
 278     common.optimized_profile_base = {
 279         configure_args: ["--with-debug-level=optimized"],
 280         labels: "optimized",
 281     };
 282     // Extra settings for openjdk only profiles
 283     common.open_suffix = "-open";
 284     common.open_profile_base = {
 285         configure_args: ["--enable-openjdk-only"],
 286         labels: "open"
 287     };
 288 
 289     common.configure_args_64bit = ["--with-target-bits=64"];
 290     common.configure_args_32bit = ["--with-target-bits=32"];
 291 
 292     /**
 293      * Define common artifacts template for all main profiles
 294      * @param o - Object containing data for artifacts
 295      */
 296     common.main_profile_artifacts = function (o) {
 297         var jdk_subdir = (o.jdk_subdir != null ? o.jdk_subdir : "jdk-" + data.version);
 298         var jdk_suffix = (o.jdk_suffix != null ? o.jdk_suffix : "tar.gz");
 299         var pf = o.platform
 300         return {
 301             artifacts: {
 302                 jdk: {
 303                     local: "bundles/\\(jdk.*bin." + jdk_suffix + "\\)",
 304                     remote: [
 305                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin." + jdk_suffix,
 306                         "bundles/" + pf + "/\\1"
 307                     ],
 308                     subdir: jdk_subdir,
 309                     exploded: "images/jdk"
 310                 },
 311                 test: {
 312                     local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
 313                     remote: [
 314                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-tests.tar.gz",
 315                         "bundles/" + pf + "/\\1"
 316                     ],
 317                     exploded: "images/test"
 318                 },
 319                 test_demos: {
 320                     local: "bundles/\\(jdk.*bin-tests-demos.tar.gz\\)",
 321                     remote: [
 322                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-tests-demos.tar.gz",
 323                         "bundles/" + pf + "/\\1"
 324                     ],
 325                     exploded: "images/test"
 326                 },
 327                 jdk_symbols: {
 328                     local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
 329                     remote: [
 330                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-symbols.tar.gz",
 331                         "bundles/" + pf + "/\\1"
 332                     ],
 333                     subdir: jdk_subdir,
 334                     exploded: "images/jdk"
 335                 },
 336                 static_libs: {
 337                     local: "bundles/\\(jdk.*bin-static-libs.tar.gz\\)",
 338                     remote: [
 339                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-static-libs.tar.gz",
 340                         "bundles/" + pf + "/\\1"
 341                     ],
 342                     subdir: jdk_subdir,
 343                 },
 344             }
 345         };
 346     };
 347 
 348 
 349     /**
 350      * Define common artifacts template for all debug profiles
 351      * @param o - Object containing data for artifacts
 352      */
 353     common.debug_profile_artifacts = function (o) {
 354         var jdk_subdir = "jdk-" + data.version + "/fastdebug";
 355         var jdk_suffix = (o.jdk_suffix != null ? o.jdk_suffix : "tar.gz");
 356         var pf = o.platform
 357         return {
 358             artifacts: {
 359                 jdk: {
 360                     local: "bundles/\\(jdk.*bin-debug." + jdk_suffix + "\\)",
 361                     remote: [
 362                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-debug." + jdk_suffix,
 363                         "bundles/" + pf + "/\\1"
 364                     ],
 365                     subdir: jdk_subdir,
 366                     exploded: "images/jdk"
 367                 },
 368                 test: {
 369                     local: "bundles/\\(jdk.*bin-tests-debug.tar.gz\\)",
 370                     remote: [
 371                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-tests-debug.tar.gz",
 372                         "bundles/" + pf + "/\\1"
 373                     ],
 374                     exploded: "images/test"
 375                 },
 376                 jdk_symbols: {
 377                     local: "bundles/\\(jdk.*bin-debug-symbols.tar.gz\\)",
 378                     remote: [
 379                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-debug-symbols.tar.gz",
 380                         "bundles/" + pf + "/\\1"
 381                     ],
 382                     subdir: jdk_subdir,
 383                     exploded: "images/jdk"
 384                 },
 385                 static_libs: {
 386                     local: "bundles/\\(jdk.*bin-static-libs-debug.tar.gz\\)",
 387                     remote: [
 388                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-static-libs-debug.tar.gz",
 389                         "bundles/" + pf + "/\\1"
 390                     ],
 391                     subdir: jdk_subdir,
 392                 },
 393             }
 394         };
 395     };
 396 
 397     common.boot_jdk_version = "17";
 398     common.boot_jdk_build_number = "35";
 399     common.boot_jdk_home = input.get("boot_jdk", "install_path") + "/jdk-"
 400         + common.boot_jdk_version
 401         + (input.build_os == "macosx" ? ".jdk/Contents/Home" : "");
 402 
 403     return common;
 404 };
 405 
 406 /**
 407  * Generates the profiles part of the configuration.
 408  *
 409  * @param input External data to use for generating the configuration
 410  * @param common The common values
 411  * @returns {{}} Profiles part of the configuration
 412  */
 413 var getJibProfilesProfiles = function (input, common, data) {
 414     // Main SE profiles
 415     var profiles = {
 416 
 417         "linux-x64": {
 418             target_os: "linux",
 419             target_cpu: "x64",
 420             dependencies: ["devkit", "gtest", "build_devkit", "graphviz", "pandoc"],
 421             configure_args: concat(
 422                 (input.build_cpu == "x64" ? common.configure_args_64bit
 423                  : "--openjdk-target=x86_64-linux-gnu"),
 424                 "--with-zlib=system", "--disable-dtrace",
 425                 (isWsl(input) ? [ "--host=x86_64-unknown-linux-gnu",
 426                     "--build=x86_64-unknown-linux-gnu" ] : [])),
 427         },
 428 
 429         "linux-x86": {
 430             target_os: "linux",
 431             target_cpu: "x86",
 432             build_cpu: "x64",
 433             dependencies: ["devkit", "gtest"],
 434             configure_args: concat(common.configure_args_32bit,
 435                 "--with-jvm-variants=minimal,server", "--with-zlib=system"),
 436         },
 437 
 438         "macosx-x64": {
 439             target_os: "macosx",
 440             target_cpu: "x64",
 441             dependencies: ["devkit", "gtest", "pandoc"],
 442             configure_args: concat(common.configure_args_64bit, "--with-zlib=system",
 443                 "--with-macosx-version-max=10.12.00",
 444                 "--enable-compatible-cds-alignment",
 445                 // Use system SetFile instead of the one in the devkit as the
 446                 // devkit one may not work on Catalina.
 447                 "SETFILE=/usr/bin/SetFile"),
 448         },
 449 
 450         "macosx-aarch64": {
 451             target_os: "macosx",
 452             target_cpu: "aarch64",
 453             dependencies: ["devkit", "gtest", "pandoc"],
 454             configure_args: concat(common.configure_args_64bit, "--with-zlib=system",
 455                 "--with-macosx-version-max=11.00.00"),
 456         },
 457 
 458         "windows-x64": {
 459             target_os: "windows",
 460             target_cpu: "x64",
 461             dependencies: ["devkit", "gtest", "pandoc"],
 462             configure_args: concat(common.configure_args_64bit),
 463         },
 464 
 465         "windows-x86": {
 466             target_os: "windows",
 467             target_cpu: "x86",
 468             build_cpu: "x64",
 469             dependencies: ["devkit", "gtest"],
 470             configure_args: concat(common.configure_args_32bit),
 471         },
 472 
 473         "windows-aarch64": {
 474             target_os: "windows",
 475             target_cpu: "aarch64",
 476             dependencies: ["devkit", "gtest", "build_devkit"],
 477             configure_args: [
 478                 "--openjdk-target=aarch64-unknown-cygwin",
 479             ],
 480         },
 481 
 482         "linux-aarch64": {
 483             target_os: "linux",
 484             target_cpu: "aarch64",
 485             build_cpu: "x64",
 486             dependencies: ["devkit", "gtest", "build_devkit", "pandoc"],
 487             configure_args: [
 488                 "--openjdk-target=aarch64-linux-gnu",
 489                 "--with-zlib=system",
 490                 "--disable-dtrace",
 491 		"--enable-compatible-cds-alignment",
 492             ],
 493         },
 494 
 495         "linux-arm32": {
 496             target_os: "linux",
 497             target_cpu: "arm",
 498             build_cpu: "x64",
 499             dependencies: ["devkit", "gtest", "build_devkit"],
 500             configure_args: [
 501                 "--openjdk-target=arm-linux-gnueabihf", "--with-freetype=bundled",
 502                 "--with-abi-profile=arm-vfp-hflt", "--disable-warnings-as-errors"
 503             ],
 504         },
 505 
 506         "linux-ppc64le": {
 507             target_os: "linux",
 508             target_cpu: "ppc64le",
 509             build_cpu: "x64",
 510             dependencies: ["devkit", "gtest", "build_devkit"],
 511             configure_args: [
 512                 "--openjdk-target=ppc64le-linux-gnu", "--with-freetype=bundled",
 513                 "--disable-warnings-as-errors"
 514             ],
 515         },
 516 
 517         "linux-s390x": {
 518             target_os: "linux",
 519             target_cpu: "s390x",
 520             build_cpu: "x64",
 521             dependencies: ["devkit", "gtest", "build_devkit"],
 522             configure_args: [
 523                 "--openjdk-target=s390x-linux-gnu", "--with-freetype=bundled",
 524                 "--disable-warnings-as-errors"
 525             ],
 526         },
 527     };
 528 
 529     // Add the base settings to all the main profiles
 530     common.main_profile_names.forEach(function (name) {
 531         profiles[name] = concatObjects(common.main_profile_base, profiles[name]);
 532     });
 533 
 534     // Generate debug versions of all the main profiles
 535     common.main_profile_names.forEach(function (name) {
 536         var debugName = name + common.debug_suffix;
 537         profiles[debugName] = concatObjects(profiles[name],
 538                                             common.debug_profile_base);
 539     });
 540     // Generate slowdebug versions of all the main profiles
 541     common.main_profile_names.forEach(function (name) {
 542         var debugName = name + common.slowdebug_suffix;
 543         profiles[debugName] = concatObjects(profiles[name],
 544                                             common.slowdebug_profile_base);
 545     });
 546     // Generate optimized versions of all the main profiles
 547     common.main_profile_names.forEach(function (name) {
 548         var optName = name + common.optimized_suffix;
 549         profiles[optName] = concatObjects(profiles[name],
 550                                           common.optimized_profile_base);
 551         profiles[optName].default_make_targets = [ "hotspot" ];
 552     });
 553     // Generate testmake profiles for the main profile of each build host
 554     // platform. This profile only runs the makefile tests.
 555     // Ant is needed to run the idea project generator test.
 556     var testmakeBase = {
 557         dependencies: [ "ant" ],
 558         environment: {
 559             "ANT_HOME": input.get("ant", "home_path")
 560         }
 561     };
 562     [ "linux-x64", "macosx-x64", "windows-x64", "linux-aarch64"]
 563         .forEach(function (name) {
 564             var maketestName = name + "-testmake";
 565             profiles[maketestName] = concatObjects(profiles[name], testmakeBase);
 566             profiles[maketestName].default_make_targets = [ "test-make" ];
 567         });
 568 
 569     // Generate -gcov profiles
 570     [ "linux-aarch64", "linux-x64", "macosx-x64", "macosx-aarch64" ].forEach(function (name) {
 571         var gcovName = name + "-gcov";
 572         profiles[gcovName] = clone(profiles[name]);
 573         profiles[gcovName].default_make_targets = ["product-bundles", "test-bundles"];
 574         profiles[gcovName].configure_args = concat(profiles[gcovName].configure_args,
 575             ["--enable-native-coverage", "--disable-warnings-as-errors"]);
 576     });
 577 
 578     // Profiles for building the zero jvm variant. These are used for verification.
 579     var zeroProfiles = {
 580         "linux-x64-zero": {
 581             target_os: "linux",
 582             target_cpu: "x64",
 583             dependencies: ["devkit", "gtest"],
 584             configure_args: concat(common.configure_args_64bit, [
 585                 "--with-zlib=system",
 586                 "--with-jvm-variants=zero",
 587                 "--enable-libffi-bundling"
 588             ])
 589         },
 590 
 591         "linux-aarch64-zero": {
 592             target_os: "linux",
 593             target_cpu: "aarch64",
 594             dependencies: ["devkit", "gtest"],
 595             configure_args: concat(common.configure_args_64bit, [
 596                 "--with-zlib=system",
 597                 "--with-jvm-variants=zero",
 598                 "--enable-libffi-bundling"
 599             ])
 600         },
 601 
 602         "linux-x86-zero": {
 603             target_os: "linux",
 604             target_cpu: "x86",
 605             build_cpu: "x64",
 606             dependencies: ["devkit", "gtest"],
 607             configure_args:  concat(common.configure_args_32bit, [
 608                 "--with-zlib=system",
 609                 "--with-jvm-variants=zero",
 610                 "--enable-libffi-bundling"
 611             ])
 612         }
 613     }
 614     profiles = concatObjects(profiles, zeroProfiles);
 615 
 616     // Add the base settings to the zero profiles and generate debug profiles
 617     Object.keys(zeroProfiles).forEach(function (name) {
 618         var debugName = name + common.debug_suffix;
 619         profiles[name] = concatObjects(common.main_profile_base, profiles[name]);
 620         profiles[debugName] = concatObjects(profiles[name], common.debug_profile_base);
 621     });
 622 
 623     // Define a profile with precompiled headers disabled. This is just used for
 624     // verfication of this build configuration.
 625     var noPchProfiles = {
 626         "linux-x64-debug-nopch": {
 627             target_os: "linux",
 628             target_cpu: "x64",
 629             dependencies: ["devkit", "gtest"],
 630             configure_args: concat(common.configure_args_64bit,
 631                 "--with-zlib=system", "--disable-precompiled-headers"),
 632         },
 633     };
 634     profiles = concatObjects(profiles, noPchProfiles);
 635     // Add base settings to noPch profiles
 636     Object.keys(noPchProfiles).forEach(function (name) {
 637         profiles[name] = concatObjects(common.main_profile_base, profiles[name]);
 638         profiles[name] = concatObjects(common.debug_profile_base, profiles[name]);
 639         // Override default make target with hotspot as that's the only part of
 640         // the build using precompiled headers.
 641         profiles[name].default_make_targets = ["hotspot"];
 642     });
 643 
 644     // Bootcycle profiles runs the build with itself as the boot jdk. This can
 645     // be done in two ways. Either using the builtin bootcycle target in the
 646     // build system. Or by supplying the main jdk build as bootjdk to configure.
 647     [ "linux-x64", "macosx-x64", "windows-x64", "linux-aarch64" ]
 648         .forEach(function (name) {
 649             var bootcycleName = name + "-bootcycle";
 650             var bootcyclePrebuiltName = name + "-bootcycle-prebuilt";
 651             // The base bootcycle profile just changes the default target
 652             // compared to the base profile
 653             profiles[bootcycleName] = clone(profiles[name]);
 654             profiles[bootcycleName].default_make_targets = [ "bootcycle-images" ];
 655             // The prebuilt bootcycle variant modifies the boot jdk argument
 656             var bootcyclePrebuiltBase = {
 657                 dependencies: [ name + ".jdk" ],
 658                 configure_args: [
 659                     "--with-boot-jdk=" + input.get(name + ".jdk", "home_path"),
 660                 ]
 661             }
 662             profiles[bootcyclePrebuiltName] = concatObjects(profiles[name],
 663                 bootcyclePrebuiltBase);
 664             var bootJdkIndex = profiles[bootcyclePrebuiltName].dependencies.indexOf("boot_jdk");
 665             delete profiles[bootcyclePrebuiltName].dependencies[bootJdkIndex];
 666             profiles[bootcyclePrebuiltName].default_make_targets = [ "product-images" ];
 667         });
 668 
 669     // JCov profiles build JCov-instrumented JDK image based on images provided through dependencies.
 670     [ "linux-aarch64", "linux-x64", "macosx-x64", "macosx-aarch64", "windows-x64" ]
 671         .forEach(function (name) {
 672             var jcovName = name + "-jcov";
 673             profiles[jcovName] = clone(common.main_profile_base);
 674             profiles[jcovName].target_os = profiles[name].target_os
 675             profiles[jcovName].target_cpu = profiles[name].target_cpu
 676             profiles[jcovName].default_make_targets = [ "jcov-bundles" ];
 677             profiles[jcovName].dependencies = concat(profiles[jcovName].dependencies,
 678                 [ name + ".jdk", "devkit" ]);
 679             profiles[jcovName].configure_args = concat(profiles[jcovName].configure_args,
 680                 ["--with-jcov-input-jdk=" + input.get(name + ".jdk", "home_path")]);
 681         });
 682 
 683     // Define artifacts for profiles
 684     var artifactData = {
 685         "linux-x64": {
 686             platform: "linux-x64",
 687         },
 688         "linux-x86": {
 689             platform: "linux-x86",
 690         },
 691         "macosx-x64": {
 692             platform: "macos-x64",
 693             jdk_subdir: "jdk-" + data.version +  ".jdk/Contents/Home",
 694         },
 695         "macosx-aarch64": {
 696             platform: "macos-aarch64",
 697             jdk_subdir: "jdk-" + data.version + ".jdk/Contents/Home",
 698         },
 699         "windows-x64": {
 700             platform: "windows-x64",
 701             jdk_suffix: "zip",
 702         },
 703         "windows-x86": {
 704             platform: "windows-x86",
 705             jdk_suffix: "zip",
 706         },
 707         "windows-aarch64": {
 708             platform: "windows-aarch64",
 709             jdk_suffix: "zip",
 710         },
 711        "linux-aarch64": {
 712             platform: "linux-aarch64",
 713         },
 714        "linux-arm32": {
 715             platform: "linux-arm32",
 716         },
 717        "linux-ppc64le": {
 718             platform: "linux-ppc64le",
 719         },
 720        "linux-s390x": {
 721             platform: "linux-s390x",
 722         }
 723     }
 724     // Generate common artifacts for all main profiles
 725     Object.keys(artifactData).forEach(function (name) {
 726         profiles[name] = concatObjects(profiles[name],
 727             common.main_profile_artifacts(artifactData[name]));
 728     });
 729 
 730     // Generate common artifacts for all debug profiles
 731     Object.keys(artifactData).forEach(function (name) {
 732         var debugName = name + common.debug_suffix;
 733         profiles[debugName] = concatObjects(profiles[debugName],
 734             common.debug_profile_artifacts(artifactData[name]));
 735     });
 736 
 737     buildJdkDep = input.build_os + "-" + input.build_cpu + ".jdk";
 738     docsProfiles = {
 739         "docs": {
 740             target_os: input.build_os,
 741             target_cpu: input.build_cpu,
 742             dependencies: [
 743                 "boot_jdk", "devkit", "graphviz", "pandoc", buildJdkDep,
 744             ],
 745             configure_args: concat(
 746                 "--enable-full-docs",
 747                 versionArgs(input, common),
 748                 "--with-build-jdk=" + input.get(buildJdkDep, "home_path"),
 749                 // Provide an explicit JDK for the docs-reference target to
 750                 // mimic the running conditions of when it's run for real as
 751                 // closely as possible.
 752                 "--with-docs-reference-jdk=" + input.get(buildJdkDep, "home_path")
 753             ),
 754             default_make_targets: ["all-docs-bundles"],
 755             artifacts: {
 756                 doc_api_spec: {
 757                     local: "bundles/\\(jdk-" + data.version + ".*doc-api-spec.tar.gz\\)",
 758                     remote: [
 759                         "bundles/common/jdk-" + data.version + "_doc-api-spec.tar.gz",
 760                         "bundles/common/\\1"
 761                     ],
 762                 },
 763                 javase_doc_api_spec: {
 764                     local: "bundles/\\(javase-" + data.version + ".*doc-api-spec.tar.gz\\)",
 765                     remote: [
 766                         "bundles/common/javase-" + data.version + "_doc-api-spec.tar.gz",
 767                         "bundles/common/\\1"
 768                     ],
 769                 },
 770                 reference_doc_api_spec: {
 771                     local: "bundles/\\(jdk-reference-" + data.version + ".*doc-api-spec.tar.gz\\)",
 772                     remote: [
 773                         "bundles/common/jdk-reference-" + data.version + "_doc-api-spec.tar.gz",
 774                         "bundles/common/\\1"
 775                     ],
 776                 },
 777             }
 778         }
 779     };
 780     profiles = concatObjects(profiles, docsProfiles);
 781 
 782     // Generate open only profiles for all the main and debug profiles.
 783     // Rewrite artifact remote paths by adding "openjdk/GPL".
 784     common.main_profile_names.forEach(function (name) {
 785         var openName = name + common.open_suffix;
 786         profiles[openName] = concatObjects(profiles[name],
 787             common.open_profile_base);
 788         for (artifactName in profiles[openName].artifacts) {
 789             var artifact = profiles[openName].artifacts[artifactName];
 790             artifact.remote = replaceAll(
 791                 "bundles\/", "bundles/openjdk/GPL/",
 792                 (artifact.remote != null ? artifact.remote : artifact.local));
 793         }
 794         var debugName = name + common.debug_suffix;
 795         var openDebugName = name + common.open_suffix + common.debug_suffix;
 796         profiles[openDebugName] = concatObjects(profiles[debugName],
 797             common.open_profile_base);
 798         for (artifactName in profiles[openDebugName].artifacts) {
 799             var artifact = profiles[openDebugName].artifacts[artifactName];
 800             artifact.remote = replaceAll(
 801                 "bundles\/", "bundles/openjdk/GPL/",
 802                 (artifact.remote != null ? artifact.remote : artifact.local));
 803         }
 804     });
 805 
 806     // Define the reference implementation profiles. These are basically the same
 807     // as the open profiles, but upload artifacts to a different location.
 808     common.main_profile_names.forEach(function (name) {
 809         var riName = name + "-ri";
 810         var riDebugName = riName + common.debug_suffix;
 811         var openName = name + common.open_suffix;
 812         var openDebugName = openName + common.debug_suffix;
 813         profiles[riName] = clone(profiles[openName]);
 814         profiles[riDebugName] = clone(profiles[openDebugName]);
 815         // Rewrite all remote dirs to "bundles/openjdk/BCL/..."
 816         for (artifactName in profiles[riName].artifacts) {
 817             var artifact = profiles[riName].artifacts[artifactName];
 818             artifact.remote = replaceAll(
 819                 "\/GPL\/", "/BCL/",
 820                 (artifact.remote != null ? artifact.remote : artifact.local));
 821         }
 822     });
 823 
 824     // For open profiles, the non-debug jdk bundles, need an "open" prefix on the
 825     // remote bundle names, forming the word "openjdk". See JDK-8188789.
 826     common.main_profile_names.forEach(function (name) {
 827         var openName = name + common.open_suffix;
 828         profiles[openName].artifacts["jdk"].remote = replaceAll(
 829             "\/jdk-", "/openjdk-",
 830             replaceAll("\/\\1", "/open\\1",
 831                        profiles[openName].artifacts["jdk"].remote));
 832     });
 833 
 834     // Generate cmp-baseline profiles for each main profile and their
 835     // corresponding debug profile. This profile does a compare build run with no
 836     // changes to verify that the compare script has a clean baseline
 837     common.main_profile_names.forEach(function (name) {
 838         [ "", common.open_suffix ].forEach(function (suffix) {
 839             var cmpBaselineName = name + suffix + "-cmp-baseline";
 840             profiles[cmpBaselineName] = clone(profiles[name + suffix]);
 841             // Only compare the images target. This should pressumably be expanded
 842             // to include more build targets when possible.
 843             profiles[cmpBaselineName].default_make_targets = [ "images", "test-image" ];
 844             if (name == "linux-x64") {
 845                 profiles[cmpBaselineName].default_make_targets
 846                     = concat(profiles[cmpBaselineName].default_make_targets, "docs");
 847             }
 848             profiles[cmpBaselineName].make_args = [ "COMPARE_BUILD=CONF=" ];
 849             profiles[cmpBaselineName].configure_args = concat(
 850                 profiles[cmpBaselineName].configure_args,
 851                 "--with-hotspot-build-time=n/a",
 852                 "--disable-precompiled-headers");
 853             // Do not inherit artifact definitions from base profile
 854             delete profiles[cmpBaselineName].artifacts;
 855         });
 856     });
 857 
 858     // After creating all derived profiles, we can add the release profile base
 859     // to the main profiles
 860     common.main_profile_names.forEach(function (name) {
 861         profiles[name] = concatObjects(profiles[name],
 862             common.release_profile_base);
 863     });
 864 
 865     // Artifacts of JCov profiles
 866     [ "linux-aarch64", "linux-x64", "macosx-x64", "macosx-aarch64", "windows-x64" ]
 867         .forEach(function (name) {
 868             var o = artifactData[name]
 869             var jdk_subdir = (o.jdk_subdir != null ? o.jdk_subdir : "jdk-" + data.version);
 870             var jdk_suffix = (o.jdk_suffix != null ? o.jdk_suffix : "tar.gz");
 871             var pf = o.platform
 872             var jcovName = name + "-jcov";
 873             profiles[jcovName].artifacts = {
 874                 jdk: {
 875                     local: "bundles/\\(jdk-jcov.*bin." + jdk_suffix + "\\)",
 876                     remote: [
 877                         "bundles/" + pf + "/jdk-jcov-" + data.version + "_" + pf + "_bin." + jdk_suffix
 878                     ],
 879                     subdir: jdk_subdir,
 880                     exploded: "images/jdk-jcov"
 881                 }
 882             };
 883         });
 884 
 885     // Artifacts of gcov (native-code-coverage) profiles
 886     [ "linux-aarch64", "linux-x64", "macosx-x64", "macosx-aarch64" ].forEach(function (name) {
 887         var o = artifactData[name]
 888         var pf = o.platform
 889         var jdk_subdir = (o.jdk_subdir != null ? o.jdk_subdir : "jdk-" + data.version);
 890         var jdk_suffix = (o.jdk_suffix != null ? o.jdk_suffix : "tar.gz");
 891         var gcovName = name + "-gcov";
 892         profiles[gcovName].artifacts = {
 893             jdk: {
 894                 local: "bundles/\\(jdk.*bin." + jdk_suffix + "\\)",
 895                 remote: [
 896                     "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-gcov." + jdk_suffix,
 897                 ],
 898                 subdir: jdk_subdir,
 899                 exploded: "images/jdk",
 900             },
 901             test: {
 902                     local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
 903                     remote: [
 904                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-gcov-tests.tar.gz",
 905                     ],
 906                     exploded: "images/test"
 907             },
 908             jdk_symbols: {
 909                     local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
 910                     remote: [
 911                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-gcov-symbols.tar.gz",
 912                     ],
 913                     subdir: jdk_subdir,
 914                     exploded: "images/jdk"
 915                 },
 916             };
 917     });
 918 
 919     // Profiles used to run tests.
 920     var testOnlyProfiles = {
 921         "run-test": {
 922             target_os: input.build_os,
 923             target_cpu: input.build_cpu,
 924             dependencies: [ "jtreg", "gnumake", "boot_jdk", "devkit", "jib" ],
 925             labels: "test",
 926             environment: {
 927                 "JT_JAVA": common.boot_jdk_home
 928             }
 929         }
 930     };
 931     profiles = concatObjects(profiles, testOnlyProfiles);
 932 
 933     // Profiles used to run tests using Jib for internal dependencies.
 934     var testedProfile = input.testedProfile;
 935     if (testedProfile == null) {
 936         testedProfile = input.build_os + "-" + input.build_cpu;
 937     }
 938     var testedProfileJdk = testedProfile + ".jdk";
 939     // Make it possible to use the test image from a different profile
 940     var testImageProfile;
 941     if (input.testImageProfile != null) {
 942         testImageProfile = input.testImageProfile;
 943     } else if (testedProfile.endsWith("-jcov")) {
 944         testImageProfile = testedProfile.substring(0, testedProfile.length - "-jcov".length);
 945     } else {
 946         testImageProfile = testedProfile;
 947     }
 948     var testedProfileTest = testImageProfile + ".test"
 949     var testOnlyMake = [ "test-prebuilt", "LOG_CMDLINES=true", "JTREG_VERBOSE=fail,error,time" ];
 950     if (testedProfile.endsWith("-gcov")) {
 951         testOnlyMake = concat(testOnlyMake, "GCOV_ENABLED=true")
 952     }
 953     var testOnlyProfilesPrebuilt = {
 954         "run-test-prebuilt": {
 955             target_os: input.build_os,
 956             target_cpu: input.build_cpu,
 957             dependencies: [
 958                 "jtreg", "gnumake", "boot_jdk", "devkit", "jib", "jcov", testedProfileJdk,
 959                 testedProfileTest
 960             ],
 961             src: "src.conf",
 962             make_args: testOnlyMake,
 963             environment: {
 964                 "BOOT_JDK": common.boot_jdk_home,
 965                 "JT_HOME": input.get("jtreg", "home_path"),
 966                 "JDK_IMAGE_DIR": input.get(testedProfileJdk, "home_path"),
 967                 "TEST_IMAGE_DIR": input.get(testedProfileTest, "home_path")
 968             },
 969             labels: "test"
 970         }
 971     };
 972 
 973     // If actually running the run-test-prebuilt profile, verify that the input
 974     // variable is valid and if so, add the appropriate target_* values from
 975     // the tested profile. Use testImageProfile value as backup.
 976     if (input.profile == "run-test-prebuilt") {
 977         if (profiles[testedProfile] == null && profiles[testImageProfile] == null) {
 978             error("testedProfile is not defined: " + testedProfile + " " + testImageProfile);
 979         }
 980     }
 981     if (profiles[testedProfile] != null) {
 982         testOnlyProfilesPrebuilt["run-test-prebuilt"]["target_os"]
 983             = profiles[testedProfile]["target_os"];
 984         testOnlyProfilesPrebuilt["run-test-prebuilt"]["target_cpu"]
 985             = profiles[testedProfile]["target_cpu"];
 986     } else if (profiles[testImageProfile] != null) {
 987         testOnlyProfilesPrebuilt["run-test-prebuilt"]["target_os"]
 988             = profiles[testImageProfile]["target_os"];
 989         testOnlyProfilesPrebuilt["run-test-prebuilt"]["target_cpu"]
 990             = profiles[testImageProfile]["target_cpu"];
 991     }
 992     profiles = concatObjects(profiles, testOnlyProfilesPrebuilt);
 993 
 994     // On macosx add the devkit bin dir to the path in all the run-test profiles.
 995     // This gives us a guaranteed working version of lldb for the jtreg failure handler.
 996     if (input.build_os == "macosx") {
 997         macosxRunTestExtra = {
 998             dependencies: [ "lldb" ],
 999             environment_path: [
1000                 input.get("gnumake", "install_path") + "/bin",
1001                 input.get("lldb", "install_path") + "/Xcode.app/Contents/Developer/usr/bin",
1002             ],
1003         };
1004         profiles["run-test"] = concatObjects(profiles["run-test"], macosxRunTestExtra);
1005         profiles["run-test-prebuilt"] = concatObjects(profiles["run-test-prebuilt"], macosxRunTestExtra);
1006     }
1007     // On windows we want the debug symbols available at test time
1008     if (input.build_os == "windows") {
1009         windowsRunTestPrebuiltExtra = {
1010             dependencies: [ testedProfile + ".jdk_symbols" ],
1011             environment: {
1012                 "SYMBOLS_IMAGE_DIR": input.get(testedProfile + ".jdk_symbols", "home_path"),
1013             }
1014         };
1015         profiles["run-test-prebuilt"] = concatObjects(profiles["run-test-prebuilt"],
1016             windowsRunTestPrebuiltExtra);
1017     }
1018 
1019     // The profile run-test-prebuilt defines src.conf as the src bundle. When
1020     // running in Mach 5, this reduces the time it takes to populate the
1021     // considerably. But with just src.conf, we cannot actually run any tests,
1022     // so if running from a workspace with just src.conf in it, we need to also
1023     // get src.full as a dependency, and define the work_dir (where make gets
1024     // run) to be in the src.full install path. By running in the install path,
1025     // the same cached installation of the full src can be reused for multiple
1026     // test tasks. Care must however be taken not to polute that work dir by
1027     // setting the appropriate make variables to control output directories.
1028     //
1029     // Use the existance of the top level README.md as indication of if this is
1030     // the full source or just src.conf.
1031     if (!new java.io.File(__DIR__, "../../README.md").exists()) {
1032         var runTestPrebuiltSrcFullExtra = {
1033             dependencies: "src.full",
1034             work_dir: input.get("src.full", "install_path"),
1035         }
1036         profiles["run-test-prebuilt"] = concatObjects(profiles["run-test-prebuilt"],
1037             runTestPrebuiltSrcFullExtra);
1038     }
1039 
1040     // Generate the missing platform attributes
1041     profiles = generatePlatformAttributes(profiles);
1042     profiles = generateDefaultMakeTargetsConfigureArg(common, profiles);
1043     return profiles;
1044 };
1045 
1046 /**
1047  * Generate the dependencies part of the configuration
1048  *
1049  * @param input External data to use for generating the configuration
1050  * @param common The common values
1051  * @returns {{}} Dependencies part of configuration
1052  */
1053 var getJibProfilesDependencies = function (input, common) {
1054 
1055     var devkit_platform_revisions = {
1056         linux_x64: "gcc10.3.0-OL6.4+1.0",
1057         macosx: "Xcode12.4+1.0",
1058         windows_x64: "VS2019-16.9.3+1.0",
1059         linux_aarch64: "gcc10.3.0-OL7.6+1.0",
1060         linux_arm: "gcc8.2.0-Fedora27+1.0",
1061         linux_ppc64le: "gcc8.2.0-Fedora27+1.0",
1062         linux_s390x: "gcc8.2.0-Fedora27+1.0"
1063     };
1064 
1065     var devkit_platform = (input.target_cpu == "x86"
1066         ? input.target_os + "_x64"
1067         : input.target_platform);
1068     if (input.target_platform == "windows_aarch64") {
1069         devkit_platform = "windows_x64";
1070     } else if (input.target_os == "macosx") {
1071         devkit_platform = "macosx";
1072     }
1073     var devkit_cross_prefix = "";
1074     if (!(input.target_os == "windows")) {
1075         if (input.build_platform != input.target_platform
1076            && input.build_platform != devkit_platform) {
1077             devkit_cross_prefix = input.build_platform + "-to-";
1078         }
1079     }
1080     var boot_jdk_os = input.build_os;
1081     if (input.build_os == "macosx") {
1082         boot_jdk_os = "macos";
1083     }
1084     var boot_jdk_platform = boot_jdk_os + "-" + input.build_cpu;
1085     var boot_jdk_ext = (input.build_os == "windows" ? ".zip" : ".tar.gz")
1086     // If running in WSL and building for Windows, it will look like Linux,
1087     // but we need a Windows boot JDK.
1088     if (isWsl(input) && input.target_os == "windows") {
1089         boot_jdk_platform = "windows-" + input.build_cpu;
1090         boot_jdk_ext = ".zip";
1091     }
1092     var boot_jdk = {
1093         server: "jpg",
1094         product: "jdk",
1095         version: common.boot_jdk_version,
1096         build_number: common.boot_jdk_build_number,
1097         file: "bundles/" + boot_jdk_platform + "/jdk-" + common.boot_jdk_version + "_"
1098             + boot_jdk_platform + "_bin" + boot_jdk_ext,
1099         configure_args: "--with-boot-jdk=" + common.boot_jdk_home,
1100         environment_path: common.boot_jdk_home + "/bin"
1101     }
1102 
1103     var pandoc_version;
1104     if (input.build_cpu == "aarch64") {
1105         if (input.build_os == "macosx") {
1106             pandoc_version = "2.14.0.2+1.0";
1107         } else {
1108             pandoc_version = "2.5+1.0";
1109         }
1110     } else {
1111         pandoc_version = "2.3.1+1.0";
1112     }
1113 
1114     var makeBinDir = (input.build_os == "windows"
1115         ? input.get("gnumake", "install_path") + "/cygwin/bin"
1116         : input.get("gnumake", "install_path") + "/bin");
1117 
1118     var dependencies = {
1119         boot_jdk: boot_jdk,
1120 
1121         devkit: {
1122             organization: common.organization,
1123             ext: "tar.gz",
1124             module: "devkit-" + devkit_cross_prefix + devkit_platform,
1125             revision: devkit_platform_revisions[devkit_platform],
1126             environment: {
1127                 "DEVKIT_HOME": input.get("devkit", "home_path"),
1128             }
1129         },
1130 
1131         build_devkit: {
1132             organization: common.organization,
1133             ext: "tar.gz",
1134             module: "devkit-" + input.build_platform,
1135             revision: devkit_platform_revisions[input.build_platform],
1136             // Only set --with-build-devkit when cross compiling.
1137             configure_args: (input.build_cpu == input.target_cpu ? false
1138                 : "--with-build-devkit=" + input.get("build_devkit", "home_path"))
1139         },
1140 
1141         lldb: {
1142             organization: common.organization,
1143             ext: "tar.gz",
1144             module: "devkit-macosx" + (input.build_cpu == "x64" ? "_x64" : ""),
1145             revision: (input.build_cpu == "x64" ? "Xcode11.3.1-MacOSX10.15+1.1" : devkit_platform_revisions[devkit_platform])
1146         },
1147 
1148         cups: {
1149             organization: common.organization,
1150             ext: "tar.gz",
1151             revision: "1.0118+1.0"
1152         },
1153 
1154         jtreg: {
1155             server: "jpg",
1156             product: "jtreg",
1157             version: "6.1",
1158             build_number: "1",
1159             file: "bundles/jtreg-6.1+1.zip",
1160             environment_name: "JT_HOME",
1161             environment_path: input.get("jtreg", "home_path") + "/bin",
1162             configure_args: "--with-jtreg=" + input.get("jtreg", "home_path"),
1163         },
1164 
1165         jmh: {
1166             organization: common.organization,
1167             ext: "tar.gz",
1168             revision: "1.33+1.0"
1169         },
1170 
1171         jcov: {
1172             // Use custom build of JCov
1173             // See CODETOOLS-7902734 for more info.
1174             // server: "jpg",
1175             // product: "jcov",
1176             // version: "3.0",
1177             // build_number: "b07",
1178             // file: "bundles/jcov-3_0.zip",
1179             organization: common.organization,
1180             revision: "3.0-9-jdk-asm+1.0",
1181             ext: "zip",
1182             environment_name: "JCOV_HOME",
1183         },
1184 
1185         gnumake: {
1186             organization: common.organization,
1187             ext: "tar.gz",
1188             revision: "4.0+1.0",
1189 
1190             module: (input.build_os == "windows"
1191                 ? "gnumake-" + input.build_osenv_platform
1192                 : "gnumake-" + input.build_platform),
1193 
1194             configure_args: "MAKE=" + makeBinDir + "/make",
1195 
1196             environment: {
1197                 "MAKE": makeBinDir + "/make"
1198             },
1199 
1200             environment_path: makeBinDir
1201         },
1202 
1203         autoconf: {
1204             organization: common.organization,
1205             ext: "tar.gz",
1206             revision: "2.69+1.0.1",
1207             module: (input.build_os == "windows"
1208                 ? "autoconf-" + input.build_osenv_platform
1209                 : "autoconf-" + input.build_platform),
1210             configure_args: "",
1211             environment_path: input.get("autoconf", "install_path")
1212         },
1213 
1214         graphviz: {
1215             organization: common.organization,
1216             ext: "tar.gz",
1217             revision: "2.38.0-1+1.1",
1218             module: "graphviz-" + input.target_platform,
1219             configure_args: "DOT=" + input.get("graphviz", "install_path") + "/dot",
1220             environment_path: input.get("graphviz", "install_path")
1221         },
1222 
1223         pandoc: {
1224             organization: common.organization,
1225             ext: "tar.gz",
1226             revision: pandoc_version,
1227             module: "pandoc-" + input.build_platform,
1228             configure_args: "PANDOC=" + input.get("pandoc", "install_path") + "/pandoc/pandoc",
1229             environment_path: input.get("pandoc", "install_path") + "/pandoc"
1230         },
1231 
1232         // This adds java jib as a dependency for the test artifacts resolver
1233         jib: {
1234             organization: "com.oracle.java.jib",
1235             ext: "zip",
1236             classifier: "distribution",
1237             revision: "3.0-SNAPSHOT",
1238             environment_name: "JIB_HOME",
1239             environment_value: input.get("jib", "home_path")
1240         },
1241 
1242         ant: {
1243             organization: common.organization,
1244             ext: "zip",
1245             revision: "1.7.1+1.0",
1246             configure_args: "",
1247         },
1248 
1249         gtest: {
1250             organization: common.organization,
1251             ext: "tar.gz",
1252             revision: "1.8.1"
1253         },
1254     };
1255 
1256     return dependencies;
1257 };
1258 
1259 /**
1260  * Generate the missing platform attributes for profiles
1261  *
1262  * @param profiles Profiles map to generate attributes on
1263  * @returns {{}} New profiles map with platform attributes fully filled in
1264  */
1265 var generatePlatformAttributes = function (profiles) {
1266     var ret = concatObjects(profiles, {});
1267     for (var profile in profiles) {
1268         if (ret[profile].build_os == null) {
1269             ret[profile].build_os = ret[profile].target_os;
1270         }
1271         if (ret[profile].build_cpu == null) {
1272             ret[profile].build_cpu = ret[profile].target_cpu;
1273         }
1274         ret[profile].target_platform = ret[profile].target_os + "_" + ret[profile].target_cpu;
1275         ret[profile].build_platform = ret[profile].build_os + "_" + ret[profile].build_cpu;
1276     }
1277     return ret;
1278 };
1279 
1280 /**
1281  * The default_make_targets attribute on a profile is not a real Jib attribute.
1282  * This function rewrites that attribute into the corresponding configure arg.
1283  * Calling this function multiple times on the same profiles object is safe.
1284  *
1285  * @param common Common values
1286  * @param profiles Profiles map to rewrite profiles for
1287  * @returns {{}} New map of profiles with the make targets converted
1288  */
1289 var generateDefaultMakeTargetsConfigureArg = function (common, profiles) {
1290     var ret = concatObjects(profiles, {});
1291     for (var profile in ret) {
1292         if (ret[profile]["default_make_targets"] != null) {
1293             var targetsString = concat(ret[profile].default_make_targets).join(" ");
1294             // Iterate over all configure args and see if --with-default-make-target
1295             // is already there and change it, otherwise add it.
1296             var found = false;
1297             for (var i in ret[profile].configure_args) {
1298                 var arg = ret[profile].configure_args[i];
1299                 if (arg != null && arg.startsWith("--with-default-make-target=")) {
1300                     found = true;
1301                     ret[profile].configure_args[i]
1302                         = "--with-default-make-target=" + targetsString;
1303                 }
1304             }
1305             if (!found) {
1306                 ret[profile].configure_args = concat(
1307                     ret[profile].configure_args,
1308                     "--with-default-make-target=" + targetsString);
1309             }
1310         }
1311     }
1312     return ret;
1313 }
1314 
1315 var getBuildId = function (input) {
1316     if (input.build_id != null) {
1317         return input.build_id;
1318     } else {
1319         var topdir = new java.io.File(__DIR__, "../..").getCanonicalFile().getName();
1320         var userName = java.lang.System.getProperty("user.name");
1321         return userName + "." + topdir;
1322     }
1323 }
1324 
1325 /**
1326  * Deep clones an object tree.
1327  *
1328  * @param o Object to clone
1329  * @returns {{}} Clone of o
1330  */
1331 var clone = function (o) {
1332     return JSON.parse(JSON.stringify(o));
1333 };
1334 
1335 /**
1336  * Concatenates all arguments into a new array
1337  *
1338  * @returns {Array.<T>} New array containing all arguments
1339  */
1340 var concat = function () {
1341     return Array.prototype.concat.apply([], arguments);
1342 };
1343 
1344 /**
1345  * Takes a String or Array of Strings and does a replace operation on each
1346  * of them.
1347  *
1348  * @param pattern Pattern to look for
1349  * @param replacement Replacement text to insert
1350  * @param a String or Array of Strings to replace
1351  * @returns {Array} Either a new array or a new string depending on the input
1352  */
1353 var replaceAll = function (pattern, replacement, a) {
1354     // If a is an array
1355     if (Array === a.constructor) {
1356     var newA = [];
1357     for (var i in a) {
1358             newA.push(a[i].replace(pattern, replacement));
1359         }
1360         return newA;
1361         } else {
1362         return a.replace(pattern, replacement);
1363     }
1364 };
1365 
1366 /**
1367  * Deep concatenation of two objects. For each node encountered, merge
1368  * the contents with the corresponding node in the other object tree,
1369  * treating all strings as array elements.
1370  *
1371  * @param o1 Object to concatenate
1372  * @param o2 Object to concatenate
1373  * @returns {{}} New object tree containing the concatenation of o1 and o2
1374  */
1375 var concatObjects = function (o1, o2) {
1376     if (o1 == null) {
1377         return clone(o2);
1378     }
1379     if (o2 == null) {
1380         return clone(o1);
1381     }
1382     var ret = {};
1383     for (var a in o1) {
1384         if (o2[a] == null) {
1385             ret[a] = clone(o1[a]);
1386         }
1387     }
1388     for (var a in o2) {
1389         if (o1[a] == null) {
1390             ret[a] = clone(o2[a]);
1391         } else {
1392             if (typeof o1[a] == 'string') {
1393                 ret[a] = clone([o1[a]].concat(o2[a]));
1394             } else if (Array.isArray(o1[a])) {
1395                 ret[a] = clone(o1[a].concat(o2[a]));
1396             } else if (typeof o1[a] == 'object') {
1397                 ret[a] = concatObjects(o1[a], o2[a]);
1398             }
1399         }
1400     }
1401     return ret;
1402 };
1403 
1404 /**
1405  * Constructs the numeric version string from reading the
1406  * make/conf/version-numbers.conf file and removing all trailing ".0".
1407  *
1408  * @param feature Override feature version
1409  * @param interim Override interim version
1410  * @param update Override update version
1411  * @param patch Override patch version
1412  * @returns {String} The numeric version string
1413  */
1414 var getVersion = function (feature, interim, update, patch, extra1, extra2, extra3) {
1415     var version_numbers = getVersionNumbers();
1416     var version = (feature != null ? feature : version_numbers.get("DEFAULT_VERSION_FEATURE"))
1417         + "." + (interim != null ? interim : version_numbers.get("DEFAULT_VERSION_INTERIM"))
1418         + "." + (update != null ? update :  version_numbers.get("DEFAULT_VERSION_UPDATE"))
1419         + "." + (patch != null ? patch : version_numbers.get("DEFAULT_VERSION_PATCH"))
1420         + "." + (extra1 != null ? extra1 : version_numbers.get("DEFAULT_VERSION_EXTRA1"))
1421         + "." + (extra2 != null ? extra2 : version_numbers.get("DEFAULT_VERSION_EXTRA2"))
1422         + "." + (extra3 != null ? extra3 : version_numbers.get("DEFAULT_VERSION_EXTRA3"));
1423     while (version.match(".*\\.0$")) {
1424         version = version.substring(0, version.length - 2);
1425     }
1426     return version;
1427 };
1428 
1429 /**
1430  * Constructs the common version configure args based on build type and
1431  * other version inputs
1432  */
1433 var versionArgs = function(input, common) {
1434     var args = ["--with-version-build=" + common.build_number];
1435     if (input.build_type == "promoted") {
1436         args = concat(args,
1437                       "--with-version-pre=" + version_numbers.get("DEFAULT_PROMOTED_VERSION_PRE"),
1438                       "--without-version-opt");
1439     } else if (input.build_type == "ci") {
1440         var ciBuildNumber = input.build_id_data.ciBuildNumber;
1441         var preString = input.build_id_data.projectName;
1442         if (preString == "jdk") {
1443             preString = version_numbers.get("DEFAULT_PROMOTED_VERSION_PRE");
1444         }
1445         args = concat(args, "--with-version-pre=" + preString,
1446                       "--with-version-opt=" + ciBuildNumber);
1447         if (input.target_os == "macosx") {
1448             args = concat(args, "--with-macosx-bundle-build-version="
1449                           + common.build_number + "." + ciBuildNumber);
1450         }
1451     } else {
1452         args = concat(args, "--with-version-opt=" + common.build_id);
1453     }
1454     return args;
1455 }
1456 
1457 // Properties representation of the make/conf/version-numbers.conf file. Lazily
1458 // initiated by the function below.
1459 var version_numbers;
1460 
1461 /**
1462  * Read the make/conf/version-numbers.conf file into a Properties object.
1463  *
1464  * @returns {java.utilProperties}
1465  */
1466 var getVersionNumbers = function () {
1467     // Read version information from make/conf/version-numbers.conf
1468     if (version_numbers == null) {
1469         version_numbers = new java.util.Properties();
1470         var stream = new java.io.FileInputStream(__DIR__ + "/version-numbers.conf");
1471         version_numbers.load(stream);
1472         stream.close();
1473     }
1474     return version_numbers;
1475 }
1476 
1477 /**
1478  * Returns true if running in Windows Subsystem for Linux. Jib does not yet
1479  * detect wsl as osenv, so fall back on linux with version containing Microsoft.
1480  */
1481 var isWsl = function (input) {
1482     return ( input.build_osenv == "wsl"
1483              || (input.build_os == "linux"
1484                  && java.lang.System.getProperty("os.version").contains("Microsoft")));
1485 }
1486 
1487 var error = function (s) {
1488     java.lang.System.err.println("[ERROR] " + s);
1489     exit(1);
1490 };