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

1502         args = concat(args, "--with-version-opt=" + common.build_id);
1503     }
1504     var sourceDate
1505     if (input.build_id_data && input.build_id_data.creationTime) {
1506         sourceDate = Math.floor(Date.parse(input.build_id_data.creationTime)/1000);
1507     } else {
1508         sourceDate = "current";
1509     }
1510     args = concat(args, "--with-source-date=" + sourceDate);
1511 
1512     return args;
1513 }
1514 
1515 // Properties representation of the make/conf/version-numbers.conf file. Lazily
1516 // initiated by the function below.
1517 var version_numbers;
1518 
1519 /**
1520  * Read the make/conf/version-numbers.conf file into a Properties object.
1521  *
1522  * @returns {java.utilProperties}
1523  */
1524 var getVersionNumbers = function () {
1525     // Read version information from make/conf/version-numbers.conf
1526     if (version_numbers == null) {
1527         version_numbers = new java.util.Properties();
1528         var stream = new java.io.FileInputStream(__DIR__ + "/version-numbers.conf");
1529         version_numbers.load(stream);
1530         stream.close();
1531     }
1532     return version_numbers;
1533 }
1534 
1535 /**
1536  * Returns true if running in Windows Subsystem for Linux. Jib does not yet
1537  * detect wsl as osenv, so fall back on linux with version containing Microsoft.
1538  */
1539 var isWsl = function (input) {
1540     return ( input.build_osenv == "wsl"
1541              || (input.build_os == "linux"
1542                  && java.lang.System.getProperty("os.version").toLowerCase().contains("microsoft")));
1543 }
1544 
1545 var error = function (s) {
1546     java.lang.System.err.println("[ERROR] " + s);
1547     exit(1);
1548 };
--- EOF ---