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"],
 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"]
 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-x86-zero": {
 592             target_os: "linux",
 593             target_cpu: "x86",
 594             build_cpu: "x64",
 595             dependencies: ["devkit", "gtest"],
 596             configure_args:  concat(common.configure_args_32bit, [
 597                 "--with-zlib=system",
 598                 "--with-jvm-variants=zero",
 599                 "--enable-libffi-bundling"
 600             ])
 601         }
 602     }
 603     profiles = concatObjects(profiles, zeroProfiles);
 604 
 605     // Add the base settings to the zero profiles and generate debug profiles
 606     Object.keys(zeroProfiles).forEach(function (name) {
 607         var debugName = name + common.debug_suffix;
 608         profiles[name] = concatObjects(common.main_profile_base, profiles[name]);
 609         profiles[debugName] = concatObjects(profiles[name], common.debug_profile_base);
 610     });
 611 
 612     // Define a profile with precompiled headers disabled. This is just used for
 613     // verfication of this build configuration.
 614     var noPchProfiles = {
 615         "linux-x64-debug-nopch": {
 616             target_os: "linux",
 617             target_cpu: "x64",
 618             dependencies: ["devkit", "gtest"],
 619             configure_args: concat(common.configure_args_64bit,
 620                 "--with-zlib=system", "--disable-precompiled-headers"),
 621         },
 622     };
 623     profiles = concatObjects(profiles, noPchProfiles);
 624     // Add base settings to noPch profiles
 625     Object.keys(noPchProfiles).forEach(function (name) {
 626         profiles[name] = concatObjects(common.main_profile_base, profiles[name]);
 627         profiles[name] = concatObjects(common.debug_profile_base, profiles[name]);
 628         // Override default make target with hotspot as that's the only part of
 629         // the build using precompiled headers.
 630         profiles[name].default_make_targets = ["hotspot"];
 631     });
 632 
 633     // Bootcycle profiles runs the build with itself as the boot jdk. This can
 634     // be done in two ways. Either using the builtin bootcycle target in the
 635     // build system. Or by supplying the main jdk build as bootjdk to configure.
 636     [ "linux-x64", "macosx-x64", "windows-x64", "linux-aarch64" ]
 637         .forEach(function (name) {
 638             var bootcycleName = name + "-bootcycle";
 639             var bootcyclePrebuiltName = name + "-bootcycle-prebuilt";
 640             // The base bootcycle profile just changes the default target
 641             // compared to the base profile
 642             profiles[bootcycleName] = clone(profiles[name]);
 643             profiles[bootcycleName].default_make_targets = [ "bootcycle-images" ];
 644             // The prebuilt bootcycle variant modifies the boot jdk argument
 645             var bootcyclePrebuiltBase = {
 646                 dependencies: [ name + ".jdk" ],
 647                 configure_args: [
 648                     "--with-boot-jdk=" + input.get(name + ".jdk", "home_path"),
 649                 ]
 650             }
 651             profiles[bootcyclePrebuiltName] = concatObjects(profiles[name],
 652                 bootcyclePrebuiltBase);
 653             var bootJdkIndex = profiles[bootcyclePrebuiltName].dependencies.indexOf("boot_jdk");
 654             delete profiles[bootcyclePrebuiltName].dependencies[bootJdkIndex];
 655             profiles[bootcyclePrebuiltName].default_make_targets = [ "product-images" ];
 656         });
 657 
 658     // JCov profiles build JCov-instrumented JDK image based on images provided through dependencies.
 659     [ "linux-aarch64", "linux-x64", "macosx-x64", "macosx-aarch64", "windows-x64" ]
 660         .forEach(function (name) {
 661             var jcovName = name + "-jcov";
 662             profiles[jcovName] = clone(common.main_profile_base);
 663             profiles[jcovName].target_os = profiles[name].target_os
 664             profiles[jcovName].target_cpu = profiles[name].target_cpu
 665             profiles[jcovName].default_make_targets = [ "jcov-bundles" ];
 666             profiles[jcovName].dependencies = concat(profiles[jcovName].dependencies,
 667                 [ name + ".jdk", "devkit" ]);
 668             profiles[jcovName].configure_args = concat(profiles[jcovName].configure_args,
 669                 ["--with-jcov-input-jdk=" + input.get(name + ".jdk", "home_path")]);
 670         });
 671 
 672     // Define artifacts for profiles
 673     var artifactData = {
 674         "linux-x64": {
 675             platform: "linux-x64",
 676         },
 677         "linux-x86": {
 678             platform: "linux-x86",
 679         },
 680         "macosx-x64": {
 681             platform: "macos-x64",
 682             jdk_subdir: "jdk-" + data.version +  ".jdk/Contents/Home",
 683         },
 684         "macosx-aarch64": {
 685             platform: "macos-aarch64",
 686             jdk_subdir: "jdk-" + data.version + ".jdk/Contents/Home",
 687         },
 688         "windows-x64": {
 689             platform: "windows-x64",
 690             jdk_suffix: "zip",
 691         },
 692         "windows-x86": {
 693             platform: "windows-x86",
 694             jdk_suffix: "zip",
 695         },
 696         "windows-aarch64": {
 697             platform: "windows-aarch64",
 698             jdk_suffix: "zip",
 699         },
 700        "linux-aarch64": {
 701             platform: "linux-aarch64",
 702         },
 703        "linux-arm32": {
 704             platform: "linux-arm32",
 705         },
 706        "linux-ppc64le": {
 707             platform: "linux-ppc64le",
 708         },
 709        "linux-s390x": {
 710             platform: "linux-s390x",
 711         }
 712     }
 713     // Generate common artifacts for all main profiles
 714     Object.keys(artifactData).forEach(function (name) {
 715         profiles[name] = concatObjects(profiles[name],
 716             common.main_profile_artifacts(artifactData[name]));
 717     });
 718 
 719     // Generate common artifacts for all debug profiles
 720     Object.keys(artifactData).forEach(function (name) {
 721         var debugName = name + common.debug_suffix;
 722         profiles[debugName] = concatObjects(profiles[debugName],
 723             common.debug_profile_artifacts(artifactData[name]));
 724     });
 725 
 726     buildJdkDep = input.build_os + "-" + input.build_cpu + ".jdk";
 727     docsProfiles = {
 728         "docs": {
 729             target_os: input.build_os,
 730             target_cpu: input.build_cpu,
 731             dependencies: [
 732                 "boot_jdk", "devkit", "graphviz", "pandoc", buildJdkDep,
 733             ],
 734             configure_args: concat(
 735                 "--enable-full-docs",
 736                 versionArgs(input, common),
 737                 "--with-build-jdk=" + input.get(buildJdkDep, "home_path"),
 738                 // Provide an explicit JDK for the docs-reference target to
 739                 // mimic the running conditions of when it's run for real as
 740                 // closely as possible.
 741                 "--with-docs-reference-jdk=" + input.get(buildJdkDep, "home_path")
 742             ),
 743             default_make_targets: ["all-docs-bundles"],
 744             artifacts: {
 745                 doc_api_spec: {
 746                     local: "bundles/\\(jdk-" + data.version + ".*doc-api-spec.tar.gz\\)",
 747                     remote: [
 748                         "bundles/common/jdk-" + data.version + "_doc-api-spec.tar.gz",
 749                         "bundles/common/\\1"
 750                     ],
 751                 },
 752                 javase_doc_api_spec: {
 753                     local: "bundles/\\(javase-" + data.version + ".*doc-api-spec.tar.gz\\)",
 754                     remote: [
 755                         "bundles/common/javase-" + data.version + "_doc-api-spec.tar.gz",
 756                         "bundles/common/\\1"
 757                     ],
 758                 },
 759                 reference_doc_api_spec: {
 760                     local: "bundles/\\(jdk-reference-" + data.version + ".*doc-api-spec.tar.gz\\)",
 761                     remote: [
 762                         "bundles/common/jdk-reference-" + data.version + "_doc-api-spec.tar.gz",
 763                         "bundles/common/\\1"
 764                     ],
 765                 },
 766             }
 767         }
 768     };
 769     profiles = concatObjects(profiles, docsProfiles);
 770 
 771     // Generate open only profiles for all the main and debug profiles.
 772     // Rewrite artifact remote paths by adding "openjdk/GPL".
 773     common.main_profile_names.forEach(function (name) {
 774         var openName = name + common.open_suffix;
 775         profiles[openName] = concatObjects(profiles[name],
 776             common.open_profile_base);
 777         for (artifactName in profiles[openName].artifacts) {
 778             var artifact = profiles[openName].artifacts[artifactName];
 779             artifact.remote = replaceAll(
 780                 "bundles\/", "bundles/openjdk/GPL/",
 781                 (artifact.remote != null ? artifact.remote : artifact.local));
 782         }
 783         var debugName = name + common.debug_suffix;
 784         var openDebugName = name + common.open_suffix + common.debug_suffix;
 785         profiles[openDebugName] = concatObjects(profiles[debugName],
 786             common.open_profile_base);
 787         for (artifactName in profiles[openDebugName].artifacts) {
 788             var artifact = profiles[openDebugName].artifacts[artifactName];
 789             artifact.remote = replaceAll(
 790                 "bundles\/", "bundles/openjdk/GPL/",
 791                 (artifact.remote != null ? artifact.remote : artifact.local));
 792         }
 793     });
 794 
 795     // Define the reference implementation profiles. These are basically the same
 796     // as the open profiles, but upload artifacts to a different location.
 797     common.main_profile_names.forEach(function (name) {
 798         var riName = name + "-ri";
 799         var riDebugName = riName + common.debug_suffix;
 800         var openName = name + common.open_suffix;
 801         var openDebugName = openName + common.debug_suffix;
 802         profiles[riName] = clone(profiles[openName]);
 803         profiles[riDebugName] = clone(profiles[openDebugName]);
 804         // Rewrite all remote dirs to "bundles/openjdk/BCL/..."
 805         for (artifactName in profiles[riName].artifacts) {
 806             var artifact = profiles[riName].artifacts[artifactName];
 807             artifact.remote = replaceAll(
 808                 "\/GPL\/", "/BCL/",
 809                 (artifact.remote != null ? artifact.remote : artifact.local));
 810         }
 811     });
 812 
 813     // For open profiles, the non-debug jdk bundles, need an "open" prefix on the
 814     // remote bundle names, forming the word "openjdk". See JDK-8188789.
 815     common.main_profile_names.forEach(function (name) {
 816         var openName = name + common.open_suffix;
 817         profiles[openName].artifacts["jdk"].remote = replaceAll(
 818             "\/jdk-", "/openjdk-",
 819             replaceAll("\/\\1", "/open\\1",
 820                        profiles[openName].artifacts["jdk"].remote));
 821     });
 822 
 823     // Generate cmp-baseline profiles for each main profile and their
 824     // corresponding debug profile. This profile does a compare build run with no
 825     // changes to verify that the compare script has a clean baseline
 826     common.main_profile_names.forEach(function (name) {
 827         [ "", common.open_suffix ].forEach(function (suffix) {
 828             var cmpBaselineName = name + suffix + "-cmp-baseline";
 829             profiles[cmpBaselineName] = clone(profiles[name + suffix]);
 830             // Only compare the images target. This should pressumably be expanded
 831             // to include more build targets when possible.
 832             profiles[cmpBaselineName].default_make_targets = [ "images", "test-image" ];
 833             if (name == "linux-x64") {
 834                 profiles[cmpBaselineName].default_make_targets
 835                     = concat(profiles[cmpBaselineName].default_make_targets, "docs");
 836             }
 837             profiles[cmpBaselineName].make_args = [ "COMPARE_BUILD=CONF=" ];
 838             profiles[cmpBaselineName].configure_args = concat(
 839                 profiles[cmpBaselineName].configure_args,
 840                 "--with-hotspot-build-time=n/a",
 841                 "--disable-precompiled-headers");
 842             // Do not inherit artifact definitions from base profile
 843             delete profiles[cmpBaselineName].artifacts;
 844         });
 845     });
 846 
 847     // After creating all derived profiles, we can add the release profile base
 848     // to the main profiles
 849     common.main_profile_names.forEach(function (name) {
 850         profiles[name] = concatObjects(profiles[name],
 851             common.release_profile_base);
 852     });
 853 
 854     // Artifacts of JCov profiles
 855     [ "linux-aarch64", "linux-x64", "macosx-x64", "macosx-aarch64", "windows-x64" ]
 856         .forEach(function (name) {
 857             var o = artifactData[name]
 858             var jdk_subdir = (o.jdk_subdir != null ? o.jdk_subdir : "jdk-" + data.version);
 859             var jdk_suffix = (o.jdk_suffix != null ? o.jdk_suffix : "tar.gz");
 860             var pf = o.platform
 861             var jcovName = name + "-jcov";
 862             profiles[jcovName].artifacts = {
 863                 jdk: {
 864                     local: "bundles/\\(jdk-jcov.*bin." + jdk_suffix + "\\)",
 865                     remote: [
 866                         "bundles/" + pf + "/jdk-jcov-" + data.version + "_" + pf + "_bin." + jdk_suffix
 867                     ],
 868                     subdir: jdk_subdir,
 869                     exploded: "images/jdk-jcov"
 870                 }
 871             };
 872         });
 873 
 874     // Artifacts of gcov (native-code-coverage) profiles
 875     [ "linux-aarch64", "linux-x64", "macosx-x64", "macosx-aarch64" ].forEach(function (name) {
 876         var o = artifactData[name]
 877         var pf = o.platform
 878         var jdk_subdir = (o.jdk_subdir != null ? o.jdk_subdir : "jdk-" + data.version);
 879         var jdk_suffix = (o.jdk_suffix != null ? o.jdk_suffix : "tar.gz");
 880         var gcovName = name + "-gcov";
 881         profiles[gcovName].artifacts = {
 882             jdk: {
 883                 local: "bundles/\\(jdk.*bin." + jdk_suffix + "\\)",
 884                 remote: [
 885                     "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-gcov." + jdk_suffix,
 886                 ],
 887                 subdir: jdk_subdir,
 888                 exploded: "images/jdk",
 889             },
 890             test: {
 891                     local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
 892                     remote: [
 893                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-gcov-tests.tar.gz",
 894                     ],
 895                     exploded: "images/test"
 896             },
 897             jdk_symbols: {
 898                     local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
 899                     remote: [
 900                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-gcov-symbols.tar.gz",
 901                     ],
 902                     subdir: jdk_subdir,
 903                     exploded: "images/jdk"
 904                 },
 905             };
 906     });
 907 
 908     // Profiles used to run tests.
 909     var testOnlyProfiles = {
 910         "run-test": {
 911             target_os: input.build_os,
 912             target_cpu: input.build_cpu,
 913             dependencies: [ "jtreg", "gnumake", "boot_jdk", "devkit", "jib" ],
 914             labels: "test",
 915             environment: {
 916                 "JT_JAVA": common.boot_jdk_home
 917             }
 918         }
 919     };
 920     profiles = concatObjects(profiles, testOnlyProfiles);
 921 
 922     // Profiles used to run tests using Jib for internal dependencies.
 923     var testedProfile = input.testedProfile;
 924     if (testedProfile == null) {
 925         testedProfile = input.build_os + "-" + input.build_cpu;
 926     }
 927     var testedProfileJdk = testedProfile + ".jdk";
 928     // Make it possible to use the test image from a different profile
 929     var testImageProfile;
 930     if (input.testImageProfile != null) {
 931         testImageProfile = input.testImageProfile;
 932     } else if (testedProfile.endsWith("-jcov")) {
 933         testImageProfile = testedProfile.substring(0, testedProfile.length - "-jcov".length);
 934     } else {
 935         testImageProfile = testedProfile;
 936     }
 937     var testedProfileTest = testImageProfile + ".test"
 938     var testOnlyMake = [ "test-prebuilt", "LOG_CMDLINES=true", "JTREG_VERBOSE=fail,error,time" ];
 939     if (testedProfile.endsWith("-gcov")) {
 940         testOnlyMake = concat(testOnlyMake, "GCOV_ENABLED=true")
 941     }
 942     var testOnlyProfilesPrebuilt = {
 943         "run-test-prebuilt": {
 944             target_os: input.build_os,
 945             target_cpu: input.build_cpu,
 946             dependencies: [
 947                 "jtreg", "gnumake", "boot_jdk", "devkit", "jib", "jcov", testedProfileJdk,
 948                 testedProfileTest
 949             ],
 950             src: "src.conf",
 951             make_args: testOnlyMake,
 952             environment: {
 953                 "BOOT_JDK": common.boot_jdk_home,
 954                 "JT_HOME": input.get("jtreg", "home_path"),
 955                 "JDK_IMAGE_DIR": input.get(testedProfileJdk, "home_path"),
 956                 "TEST_IMAGE_DIR": input.get(testedProfileTest, "home_path")
 957             },
 958             labels: "test"
 959         }
 960     };
 961 
 962     // If actually running the run-test-prebuilt profile, verify that the input
 963     // variable is valid and if so, add the appropriate target_* values from
 964     // the tested profile. Use testImageProfile value as backup.
 965     if (input.profile == "run-test-prebuilt") {
 966         if (profiles[testedProfile] == null && profiles[testImageProfile] == null) {
 967             error("testedProfile is not defined: " + testedProfile + " " + testImageProfile);
 968         }
 969     }
 970     if (profiles[testedProfile] != null) {
 971         testOnlyProfilesPrebuilt["run-test-prebuilt"]["target_os"]
 972             = profiles[testedProfile]["target_os"];
 973         testOnlyProfilesPrebuilt["run-test-prebuilt"]["target_cpu"]
 974             = profiles[testedProfile]["target_cpu"];
 975     } else if (profiles[testImageProfile] != null) {
 976         testOnlyProfilesPrebuilt["run-test-prebuilt"]["target_os"]
 977             = profiles[testImageProfile]["target_os"];
 978         testOnlyProfilesPrebuilt["run-test-prebuilt"]["target_cpu"]
 979             = profiles[testImageProfile]["target_cpu"];
 980     }
 981     profiles = concatObjects(profiles, testOnlyProfilesPrebuilt);
 982 
 983     // On macosx add the devkit bin dir to the path in all the run-test profiles.
 984     // This gives us a guaranteed working version of lldb for the jtreg failure handler.
 985     if (input.build_os == "macosx") {
 986         macosxRunTestExtra = {
 987             dependencies: [ "lldb" ],
 988             environment_path: [
 989                 input.get("gnumake", "install_path") + "/bin",
 990                 input.get("lldb", "install_path") + "/Xcode.app/Contents/Developer/usr/bin",
 991             ],
 992         };
 993         profiles["run-test"] = concatObjects(profiles["run-test"], macosxRunTestExtra);
 994         profiles["run-test-prebuilt"] = concatObjects(profiles["run-test-prebuilt"], macosxRunTestExtra);
 995     }
 996     // On windows we want the debug symbols available at test time
 997     if (input.build_os == "windows") {
 998         windowsRunTestPrebuiltExtra = {
 999             dependencies: [ testedProfile + ".jdk_symbols" ],
1000             environment: {
1001                 "SYMBOLS_IMAGE_DIR": input.get(testedProfile + ".jdk_symbols", "home_path"),
1002             }
1003         };
1004         profiles["run-test-prebuilt"] = concatObjects(profiles["run-test-prebuilt"],
1005             windowsRunTestPrebuiltExtra);
1006     }
1007 
1008     // The profile run-test-prebuilt defines src.conf as the src bundle. When
1009     // running in Mach 5, this reduces the time it takes to populate the
1010     // considerably. But with just src.conf, we cannot actually run any tests,
1011     // so if running from a workspace with just src.conf in it, we need to also
1012     // get src.full as a dependency, and define the work_dir (where make gets
1013     // run) to be in the src.full install path. By running in the install path,
1014     // the same cached installation of the full src can be reused for multiple
1015     // test tasks. Care must however be taken not to polute that work dir by
1016     // setting the appropriate make variables to control output directories.
1017     //
1018     // Use the existance of the top level README.md as indication of if this is
1019     // the full source or just src.conf.
1020     if (!new java.io.File(__DIR__, "../../README.md").exists()) {
1021         var runTestPrebuiltSrcFullExtra = {
1022             dependencies: "src.full",
1023             work_dir: input.get("src.full", "install_path"),
1024         }
1025         profiles["run-test-prebuilt"] = concatObjects(profiles["run-test-prebuilt"],
1026             runTestPrebuiltSrcFullExtra);
1027     }
1028 
1029     // Generate the missing platform attributes
1030     profiles = generatePlatformAttributes(profiles);
1031     profiles = generateDefaultMakeTargetsConfigureArg(common, profiles);
1032     return profiles;
1033 };
1034 
1035 /**
1036  * Generate the dependencies part of the configuration
1037  *
1038  * @param input External data to use for generating the configuration
1039  * @param common The common values
1040  * @returns {{}} Dependencies part of configuration
1041  */
1042 var getJibProfilesDependencies = function (input, common) {
1043 
1044     var devkit_platform_revisions = {
1045         linux_x64: "gcc10.3.0-OL6.4+1.0",
1046         macosx: "Xcode12.4+1.0",
1047         windows_x64: "VS2019-16.9.3+1.0",
1048         linux_aarch64: "gcc10.3.0-OL7.6+1.0",
1049         linux_arm: "gcc8.2.0-Fedora27+1.0",
1050         linux_ppc64le: "gcc8.2.0-Fedora27+1.0",
1051         linux_s390x: "gcc8.2.0-Fedora27+1.0"
1052     };
1053 
1054     var devkit_platform = (input.target_cpu == "x86"
1055         ? input.target_os + "_x64"
1056         : input.target_platform);
1057     if (input.target_platform == "windows_aarch64") {
1058         devkit_platform = "windows_x64";
1059     } else if (input.target_os == "macosx") {
1060         devkit_platform = "macosx";
1061     }
1062     var devkit_cross_prefix = "";
1063     if (!(input.target_os == "windows")) {
1064         if (input.build_platform != input.target_platform
1065            && input.build_platform != devkit_platform) {
1066             devkit_cross_prefix = input.build_platform + "-to-";
1067         }
1068     }
1069     var boot_jdk_os = input.build_os;
1070     if (input.build_os == "macosx") {
1071         boot_jdk_os = "macos";
1072     }
1073     var boot_jdk_platform = boot_jdk_os + "-" + input.build_cpu;
1074     var boot_jdk_ext = (input.build_os == "windows" ? ".zip" : ".tar.gz")
1075     // If running in WSL and building for Windows, it will look like Linux,
1076     // but we need a Windows boot JDK.
1077     if (isWsl(input) && input.target_os == "windows") {
1078         boot_jdk_platform = "windows-" + input.build_cpu;
1079         boot_jdk_ext = ".zip";
1080     }
1081     var boot_jdk = {
1082         server: "jpg",
1083         product: "jdk",
1084         version: common.boot_jdk_version,
1085         build_number: common.boot_jdk_build_number,
1086         file: "bundles/" + boot_jdk_platform + "/jdk-" + common.boot_jdk_version + "_"
1087             + boot_jdk_platform + "_bin" + boot_jdk_ext,
1088         configure_args: "--with-boot-jdk=" + common.boot_jdk_home,
1089         environment_path: common.boot_jdk_home + "/bin"
1090     }
1091 
1092     var makeBinDir = (input.build_os == "windows"
1093         ? input.get("gnumake", "install_path") + "/cygwin/bin"
1094         : input.get("gnumake", "install_path") + "/bin");
1095 
1096     var dependencies = {
1097         boot_jdk: boot_jdk,
1098 
1099         devkit: {
1100             organization: common.organization,
1101             ext: "tar.gz",
1102             module: "devkit-" + devkit_cross_prefix + devkit_platform,
1103             revision: devkit_platform_revisions[devkit_platform],
1104             environment: {
1105                 "DEVKIT_HOME": input.get("devkit", "home_path"),
1106             }
1107         },
1108 
1109         build_devkit: {
1110             organization: common.organization,
1111             ext: "tar.gz",
1112             module: "devkit-" + input.build_platform,
1113             revision: devkit_platform_revisions[input.build_platform],
1114             // Only set --with-build-devkit when cross compiling.
1115             configure_args: (input.build_cpu == input.target_cpu ? false
1116                 : "--with-build-devkit=" + input.get("build_devkit", "home_path"))
1117         },
1118 
1119         lldb: {
1120             organization: common.organization,
1121             ext: "tar.gz",
1122             module: "devkit-macosx" + (input.build_cpu == "x64" ? "_x64" : ""),
1123             revision: (input.build_cpu == "x64" ? "Xcode11.3.1-MacOSX10.15+1.1" : devkit_platform_revisions[devkit_platform])
1124         },
1125 
1126         cups: {
1127             organization: common.organization,
1128             ext: "tar.gz",
1129             revision: "1.0118+1.0"
1130         },
1131 
1132         jtreg: {
1133             server: "jpg",
1134             product: "jtreg",
1135             version: "6",
1136             build_number: "1",
1137             file: "bundles/jtreg-6+1.zip",
1138             environment_name: "JT_HOME",
1139             environment_path: input.get("jtreg", "home_path") + "/bin",
1140             configure_args: "--with-jtreg=" + input.get("jtreg", "home_path"),
1141         },
1142 
1143         jmh: {
1144             organization: common.organization,
1145             ext: "tar.gz",
1146             revision: "1.28+1.0"
1147         },
1148 
1149         jcov: {
1150             // Use custom build of JCov
1151             // See CODETOOLS-7902734 for more info.
1152             // server: "jpg",
1153             // product: "jcov",
1154             // version: "3.0",
1155             // build_number: "b07",
1156             // file: "bundles/jcov-3_0.zip",
1157             organization: common.organization,
1158             revision: "3.0-9-jdk-asm+1.0",
1159             ext: "zip",
1160             environment_name: "JCOV_HOME",
1161         },
1162 
1163         gnumake: {
1164             organization: common.organization,
1165             ext: "tar.gz",
1166             revision: "4.0+1.0",
1167 
1168             module: (input.build_os == "windows"
1169                 ? "gnumake-" + input.build_osenv_platform
1170                 : "gnumake-" + input.build_platform),
1171 
1172             configure_args: "MAKE=" + makeBinDir + "/make",
1173 
1174             environment: {
1175                 "MAKE": makeBinDir + "/make"
1176             },
1177 
1178             environment_path: makeBinDir
1179         },
1180 
1181         autoconf: {
1182             organization: common.organization,
1183             ext: "tar.gz",
1184             revision: "2.69+1.0.1",
1185             module: (input.build_os == "windows"
1186                 ? "autoconf-" + input.build_osenv_platform
1187                 : "autoconf-" + input.build_platform),
1188             configure_args: "",
1189             environment_path: input.get("autoconf", "install_path")
1190         },
1191 
1192         graphviz: {
1193             organization: common.organization,
1194             ext: "tar.gz",
1195             revision: "2.38.0-1+1.1",
1196             module: "graphviz-" + input.target_platform,
1197             configure_args: "DOT=" + input.get("graphviz", "install_path") + "/dot",
1198             environment_path: input.get("graphviz", "install_path")
1199         },
1200 
1201         pandoc: {
1202             organization: common.organization,
1203             ext: "tar.gz",
1204             revision: (input.build_cpu == 'aarch64' ? "2.5+1.0" : "2.3.1+1.0"),
1205             module: "pandoc-" + input.build_platform,
1206             configure_args: "PANDOC=" + input.get("pandoc", "install_path") + "/pandoc/pandoc",
1207             environment_path: input.get("pandoc", "install_path") + "/pandoc"
1208         },
1209 
1210         // This adds java jib as a dependency for the test artifacts resolver
1211         jib: {
1212             organization: "com.oracle.java.jib",
1213             ext: "zip",
1214             classifier: "distribution",
1215             revision: "3.0-SNAPSHOT",
1216             environment_name: "JIB_HOME",
1217             environment_value: input.get("jib", "home_path")
1218         },
1219 
1220         ant: {
1221             organization: common.organization,
1222             ext: "zip",
1223             revision: "1.7.1+1.0",
1224             configure_args: "",
1225         },
1226 
1227         gtest: {
1228             organization: common.organization,
1229             ext: "tar.gz",
1230             revision: "1.8.1"
1231         },
1232     };
1233 
1234     return dependencies;
1235 };
1236 
1237 /**
1238  * Generate the missing platform attributes for profiles
1239  *
1240  * @param profiles Profiles map to generate attributes on
1241  * @returns {{}} New profiles map with platform attributes fully filled in
1242  */
1243 var generatePlatformAttributes = function (profiles) {
1244     var ret = concatObjects(profiles, {});
1245     for (var profile in profiles) {
1246         if (ret[profile].build_os == null) {
1247             ret[profile].build_os = ret[profile].target_os;
1248         }
1249         if (ret[profile].build_cpu == null) {
1250             ret[profile].build_cpu = ret[profile].target_cpu;
1251         }
1252         ret[profile].target_platform = ret[profile].target_os + "_" + ret[profile].target_cpu;
1253         ret[profile].build_platform = ret[profile].build_os + "_" + ret[profile].build_cpu;
1254     }
1255     return ret;
1256 };
1257 
1258 /**
1259  * The default_make_targets attribute on a profile is not a real Jib attribute.
1260  * This function rewrites that attribute into the corresponding configure arg.
1261  * Calling this function multiple times on the same profiles object is safe.
1262  *
1263  * @param common Common values
1264  * @param profiles Profiles map to rewrite profiles for
1265  * @returns {{}} New map of profiles with the make targets converted
1266  */
1267 var generateDefaultMakeTargetsConfigureArg = function (common, profiles) {
1268     var ret = concatObjects(profiles, {});
1269     for (var profile in ret) {
1270         if (ret[profile]["default_make_targets"] != null) {
1271             var targetsString = concat(ret[profile].default_make_targets).join(" ");
1272             // Iterate over all configure args and see if --with-default-make-target
1273             // is already there and change it, otherwise add it.
1274             var found = false;
1275             for (var i in ret[profile].configure_args) {
1276                 var arg = ret[profile].configure_args[i];
1277                 if (arg != null && arg.startsWith("--with-default-make-target=")) {
1278                     found = true;
1279                     ret[profile].configure_args[i]
1280                         = "--with-default-make-target=" + targetsString;
1281                 }
1282             }
1283             if (!found) {
1284                 ret[profile].configure_args = concat(
1285                     ret[profile].configure_args,
1286                     "--with-default-make-target=" + targetsString);
1287             }
1288         }
1289     }
1290     return ret;
1291 }
1292 
1293 var getBuildId = function (input) {
1294     if (input.build_id != null) {
1295         return input.build_id;
1296     } else {
1297         var topdir = new java.io.File(__DIR__, "../..").getCanonicalFile().getName();
1298         var userName = java.lang.System.getProperty("user.name");
1299         return userName + "." + topdir;
1300     }
1301 }
1302 
1303 /**
1304  * Deep clones an object tree.
1305  *
1306  * @param o Object to clone
1307  * @returns {{}} Clone of o
1308  */
1309 var clone = function (o) {
1310     return JSON.parse(JSON.stringify(o));
1311 };
1312 
1313 /**
1314  * Concatenates all arguments into a new array
1315  *
1316  * @returns {Array.<T>} New array containing all arguments
1317  */
1318 var concat = function () {
1319     return Array.prototype.concat.apply([], arguments);
1320 };
1321 
1322 /**
1323  * Takes a String or Array of Strings and does a replace operation on each
1324  * of them.
1325  *
1326  * @param pattern Pattern to look for
1327  * @param replacement Replacement text to insert
1328  * @param a String or Array of Strings to replace
1329  * @returns {Array} Either a new array or a new string depending on the input
1330  */
1331 var replaceAll = function (pattern, replacement, a) {
1332     // If a is an array
1333     if (Array === a.constructor) {
1334     var newA = [];
1335     for (var i in a) {
1336             newA.push(a[i].replace(pattern, replacement));
1337         }
1338         return newA;
1339         } else {
1340         return a.replace(pattern, replacement);
1341     }
1342 };
1343 
1344 /**
1345  * Deep concatenation of two objects. For each node encountered, merge
1346  * the contents with the corresponding node in the other object tree,
1347  * treating all strings as array elements.
1348  *
1349  * @param o1 Object to concatenate
1350  * @param o2 Object to concatenate
1351  * @returns {{}} New object tree containing the concatenation of o1 and o2
1352  */
1353 var concatObjects = function (o1, o2) {
1354     if (o1 == null) {
1355         return clone(o2);
1356     }
1357     if (o2 == null) {
1358         return clone(o1);
1359     }
1360     var ret = {};
1361     for (var a in o1) {
1362         if (o2[a] == null) {
1363             ret[a] = clone(o1[a]);
1364         }
1365     }
1366     for (var a in o2) {
1367         if (o1[a] == null) {
1368             ret[a] = clone(o2[a]);
1369         } else {
1370             if (typeof o1[a] == 'string') {
1371                 ret[a] = clone([o1[a]].concat(o2[a]));
1372             } else if (Array.isArray(o1[a])) {
1373                 ret[a] = clone(o1[a].concat(o2[a]));
1374             } else if (typeof o1[a] == 'object') {
1375                 ret[a] = concatObjects(o1[a], o2[a]);
1376             }
1377         }
1378     }
1379     return ret;
1380 };
1381 
1382 /**
1383  * Constructs the numeric version string from reading the
1384  * make/conf/version-numbers.conf file and removing all trailing ".0".
1385  *
1386  * @param feature Override feature version
1387  * @param interim Override interim version
1388  * @param update Override update version
1389  * @param patch Override patch version
1390  * @returns {String} The numeric version string
1391  */
1392 var getVersion = function (feature, interim, update, patch, extra1, extra2, extra3) {
1393     var version_numbers = getVersionNumbers();
1394     var version = (feature != null ? feature : version_numbers.get("DEFAULT_VERSION_FEATURE"))
1395         + "." + (interim != null ? interim : version_numbers.get("DEFAULT_VERSION_INTERIM"))
1396         + "." + (update != null ? update :  version_numbers.get("DEFAULT_VERSION_UPDATE"))
1397         + "." + (patch != null ? patch : version_numbers.get("DEFAULT_VERSION_PATCH"))
1398         + "." + (extra1 != null ? extra1 : version_numbers.get("DEFAULT_VERSION_EXTRA1"))
1399         + "." + (extra2 != null ? extra2 : version_numbers.get("DEFAULT_VERSION_EXTRA2"))
1400         + "." + (extra3 != null ? extra3 : version_numbers.get("DEFAULT_VERSION_EXTRA3"));
1401     while (version.match(".*\\.0$")) {
1402         version = version.substring(0, version.length - 2);
1403     }
1404     return version;
1405 };
1406 
1407 /**
1408  * Constructs the common version configure args based on build type and
1409  * other version inputs
1410  */
1411 var versionArgs = function(input, common) {
1412     var args = ["--with-version-build=" + common.build_number];
1413     if (input.build_type == "promoted") {
1414         args = concat(args,
1415                       "--with-version-pre=" + version_numbers.get("DEFAULT_PROMOTED_VERSION_PRE"),
1416                       "--without-version-opt");
1417     } else if (input.build_type == "ci") {
1418         var ciBuildNumber = input.build_id_data.ciBuildNumber;
1419         var preString = input.build_id_data.projectName;
1420         if (preString == "jdk") {
1421             preString = version_numbers.get("DEFAULT_PROMOTED_VERSION_PRE");
1422         }
1423         args = concat(args, "--with-version-pre=" + preString,
1424                       "--with-version-opt=" + ciBuildNumber);
1425         if (input.target_os == "macosx") {
1426             args = concat(args, "--with-macosx-bundle-build-version="
1427                           + common.build_number + "." + ciBuildNumber);
1428         }
1429     } else {
1430         args = concat(args, "--with-version-pre=" + version_numbers.get("DEFAULT_PROMOTED_VERSION_PRE"));
1431         args = concat(args, "--with-version-opt=" + common.build_id);
1432     }
1433     return args;
1434 }
1435 
1436 // Properties representation of the make/conf/version-numbers.conf file. Lazily
1437 // initiated by the function below.
1438 var version_numbers;
1439 
1440 /**
1441  * Read the make/conf/version-numbers.conf file into a Properties object.
1442  *
1443  * @returns {java.utilProperties}
1444  */
1445 var getVersionNumbers = function () {
1446     // Read version information from make/conf/version-numbers.conf
1447     if (version_numbers == null) {
1448         version_numbers = new java.util.Properties();
1449         var stream = new java.io.FileInputStream(__DIR__ + "/version-numbers.conf");
1450         version_numbers.load(stream);
1451         stream.close();
1452     }
1453     return version_numbers;
1454 }
1455 
1456 /**
1457  * Returns true if running in Windows Subsystem for Linux. Jib does not yet
1458  * detect wsl as osenv, so fall back on linux with version containing Microsoft.
1459  */
1460 var isWsl = function (input) {
1461     return ( input.build_osenv == "wsl"
1462              || (input.build_os == "linux"
1463                  && java.lang.System.getProperty("os.version").contains("Microsoft")));
1464 }
1465 
1466 var error = function (s) {
1467     java.lang.System.err.println("[ERROR] " + s);
1468     exit(1);
1469 };