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