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