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