1 /*
   2  * Copyright (c) 2015, 2019, 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  *
  80  *
  81  * The output data generated by this configuration file has the following
  82  * format:
  83  *
  84  * data: {
  85  *   // Identifies the version of this format to the tool reading it
  86  *   format_version: "1.0",
  87  *
  88  *   // Name of base outputdir. JIB assumes the actual output dir is formed
  89  *   // by adding the configuration name: <output_basedir>/<config-name>
  90  *   output_basedir: "build",
  91  *   // Configure argument to use to specify configuration name
  92  *   configuration_configure_arg:
  93  *   // Make argument to use to specify configuration name
  94  *   configuration_make_arg:
  95  *
  96  *   profiles: {
  97  *     <profile-name>: {
  98  *       // Name of os the profile is built to run on
  99  *       target_os; <string>
 100  *       // Name of cpu the profile is built to run on
 101  *       target_cpu; <string>
 102  *       // Combination of target_os and target_cpu for convenience
 103  *       target_platform; <string>
 104  *       // Name of os the profile is built on
 105  *       build_os; <string>
 106  *       // Name of cpu the profile is built on
 107  *       build_cpu; <string>
 108  *       // Combination of build_os and build_cpu for convenience
 109  *       build_platform; <string>
 110  *
 111  *       // List of dependencies needed to build this profile
 112  *       dependencies: <Array of strings>
 113  *
 114  *       // List of configure args to use for this profile
 115  *       configure_args: <Array of strings>
 116  *
 117  *       // List of free form labels describing aspects of this profile
 118  *       labels: <Array of strings>
 119  *     }
 120  *   }
 121  *
 122  *   // Dependencies use a Maven like deployment structure
 123  *   dependencies: {
 124  *     <dependency-name>: {
 125  *       // Organization part of path defining this dependency
 126  *       organization: <string>
 127  *       // File extension for this dependency
 128  *       ext: <string>
 129  *       // Module part of path for defining this dependency,
 130  *       // defaults to <dependency-name>
 131  *       module: <string>
 132  *       // Revision part of path for defining this dependency
 133  *       revision: <string>
 134  *
 135  *       // List of configure args to add when using this dependency,
 136  *       // defaults to
 137  *       // "--with-<dependency-name>=input.get("<dependency-name", "install_path")"
 138  *       configure_args: <array of strings>
 139  *
 140  *       // Name of environment variable to set when using this dependency
 141  *       // when running make
 142  *       environment_name: <string>
 143  *       // Value of environment variable to set when using this dependency
 144  *       // when running make
 145  *       environment_value: <string>
 146  *
 147  *       // Value to add to the PATH variable when using this dependency,
 148  *       // applies to both make and configure
 149  *       environment_path: <string>
 150  *     }
 151  *
 152  *     <dependency-name>: {
 153  *       // For certain dependencies where a legacy distribution mechanism is
 154  *       // already in place, the "javare" server layout is also supported
 155  *       // Indicate that an alternate server source and layout should be used
 156  *       server: "javare"
 157  *
 158  *       // For "javare", a combination of module, revision,
 159  *       // build number (optional), files and checksum file is possible for
 160  *       // artifacts following the standard layout.
 161  *       module: <string>
 162  *       revision: <string>
 163  *       build_number: <string>
 164  *       checksum_file: <string>
 165  *       file: <string>
 166  *
 167  *       // For other files, use checksum path and path instead
 168  *       checksum_path: <string>
 169  *       path: <string>
 170  *     }
 171  *   }
 172  * }
 173  */
 174 
 175 /**
 176  * Main entry to generate the profile configuration
 177  *
 178  * @param input External data to use for generating the configuration
 179  * @returns {{}} Profile configuration
 180  */
 181 var getJibProfiles = function (input) {
 182 
 183     var data = {};
 184 
 185     // Identifies the version of this format to the tool reading it.
 186     // 1.1 signifies that the publish, publish-src and get-src features are usable.
 187     // 1.2 signifies that artifact uploads should fail on missing artifacts by default.
 188     data.format_version = "1.2";
 189 
 190     // Organization, product and version are used when uploading/publishing build results
 191     data.organization = "";
 192     data.product = "jdk";
 193     data.version = getVersion();
 194 
 195     // The base directory for the build output. JIB will assume that the
 196     // actual build directory will be <output_basedir>/<configuration>
 197     data.output_basedir = "build";
 198     // The configure argument to use to specify the name of the configuration
 199     data.configuration_configure_arg = "--with-conf-name=";
 200     // The make argument to use to specify the name of the configuration
 201     data.configuration_make_arg = "CONF_NAME=";
 202 
 203     // Exclude list to use when Jib creates a source bundle
 204     data.src_bundle_excludes = [
 205         "build", "{,**/}webrev*", "{,**/}.hg", "{,**/}JTwork", "{,**/}JTreport",
 206         "{,**/}.git"
 207     ];
 208     // Include list to use when creating a minimal jib source bundle which
 209     // contains just the jib configuration files.
 210     data.conf_bundle_includes = [
 211         "make/autoconf/version-numbers",
 212     ];
 213 
 214     // Define some common values
 215     var common = getJibProfilesCommon(input, data);
 216     // Generate the profiles part of the configuration
 217     data.profiles = getJibProfilesProfiles(input, common, data);
 218     // Generate the dependencies part of the configuration
 219     data.dependencies = getJibProfilesDependencies(input, common, data);
 220 
 221     return data;
 222 };
 223 
 224 /**
 225  * Generates some common values
 226  *
 227  * @param input External data to use for generating the configuration
 228  * @returns Common values
 229  */
 230 var getJibProfilesCommon = function (input, data) {
 231     var common = {};
 232 
 233     common.organization = "jpg.infra.builddeps";
 234     common.build_id = getBuildId(input);
 235     common.build_number = input.build_number != null ? input.build_number : "0";
 236 
 237     // List of the main profile names used for iteration
 238     common.main_profile_names = [
 239         "linux-x64", "linux-x86", "macosx-x64", "solaris-x64",
 240         "solaris-sparcv9", "windows-x64", "windows-x86",
 241         "linux-aarch64", "linux-arm32"
 242     ];
 243 
 244     // These are the base setttings for all the main build profiles.
 245     common.main_profile_base = {
 246         dependencies: ["boot_jdk", "gnumake", "jtreg", "jib", "autoconf", "jmh", "jcov"],
 247         default_make_targets: ["product-bundles", "test-bundles"],
 248         configure_args: concat(["--enable-jtreg-failure-handler"],
 249             "--with-exclude-translations=de,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",
 250             "--disable-manpages",
 251             "--with-jvm-features=-shenandoahgc",
 252             versionArgs(input, common))
 253     };
 254     // Extra settings for debug profiles
 255     common.debug_suffix = "-debug";
 256     common.debug_profile_base = {
 257         configure_args: ["--enable-debug"],
 258         labels: "debug"
 259     };
 260     // Extra settings for slowdebug profiles
 261     common.slowdebug_suffix = "-slowdebug";
 262     common.slowdebug_profile_base = {
 263         configure_args: ["--with-debug-level=slowdebug"],
 264         labels: "slowdebug"
 265     };
 266     // Extra settings for openjdk only profiles
 267     common.open_suffix = "-open";
 268     common.open_profile_base = {
 269         configure_args: ["--enable-openjdk-only"],
 270         labels: "open"
 271     };
 272 
 273     common.configure_args_64bit = ["--with-target-bits=64"];
 274     common.configure_args_32bit = ["--with-target-bits=32"];
 275 
 276     /**
 277      * Define common artifacts template for all main profiles
 278      * @param o - Object containing data for artifacts
 279      */
 280     common.main_profile_artifacts = function (o) {
 281         var jdk_subdir = (o.jdk_subdir != null ? o.jdk_subdir : "jdk-" + data.version);
 282         var jdk_suffix = (o.jdk_suffix != null ? o.jdk_suffix : "tar.gz");
 283         var pf = o.platform
 284         return {
 285             artifacts: {
 286                 jdk: {
 287                     local: "bundles/\\(jdk.*bin." + jdk_suffix + "\\)",
 288                     remote: [
 289                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin." + jdk_suffix,
 290                         "bundles/" + pf + "/\\1"
 291                     ],
 292                     subdir: jdk_subdir,
 293                     exploded: "images/jdk"
 294                 },
 295                 test: {
 296                     local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
 297                     remote: [
 298                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-tests.tar.gz",
 299                         "bundles/" + pf + "/\\1"
 300                     ],
 301                     exploded: "images/test"
 302                 },
 303                 test_demos: {
 304                     local: "bundles/\\(jdk.*bin-tests-demos.tar.gz\\)",
 305                     remote: [
 306                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-tests-demos.tar.gz",
 307                         "bundles/" + pf + "/\\1"
 308                     ],
 309                     exploded: "images/test"
 310                 },
 311                 jdk_symbols: {
 312                     local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
 313                     remote: [
 314                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-symbols.tar.gz",
 315                         "bundles/" + pf + "/\\1"
 316                     ],
 317                     subdir: jdk_subdir,
 318                     exploded: "images/jdk"
 319                 },
 320             }
 321         };
 322     };
 323 
 324 
 325     /**
 326      * Define common artifacts template for all debug profiles
 327      * @param o - Object containing data for artifacts
 328      */
 329     common.debug_profile_artifacts = function (o) {
 330         var jdk_subdir = "jdk-" + data.version + "/fastdebug";
 331         var jdk_suffix = (o.jdk_suffix != null ? o.jdk_suffix : "tar.gz");
 332         var pf = o.platform
 333         return {
 334             artifacts: {
 335                 jdk: {
 336                     local: "bundles/\\(jdk.*bin-debug." + jdk_suffix + "\\)",
 337                     remote: [
 338                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-debug." + jdk_suffix,
 339                         "bundles/" + pf + "/\\1"
 340                     ],
 341                     subdir: jdk_subdir,
 342                     exploded: "images/jdk"
 343                 },
 344                 test: {
 345                     local: "bundles/\\(jdk.*bin-tests-debug.tar.gz\\)",
 346                     remote: [
 347                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-tests-debug.tar.gz",
 348                         "bundles/" + pf + "/\\1"
 349                     ],
 350                     exploded: "images/test"
 351                 },
 352                 jdk_symbols: {
 353                     local: "bundles/\\(jdk.*bin-debug-symbols.tar.gz\\)",
 354                     remote: [
 355                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-debug-symbols.tar.gz",
 356                         "bundles/" + pf + "/\\1"
 357                     ],
 358                     subdir: jdk_subdir,
 359                     exploded: "images/jdk"
 360                 },
 361             }
 362         };
 363     };
 364 
 365     common.boot_jdk_version = "11";
 366     common.boot_jdk_home = input.get("boot_jdk", "home_path") + "/jdk-"
 367         + common.boot_jdk_version
 368         + (input.build_os == "macosx" ? ".jdk/Contents/Home" : "");
 369 
 370     return common;
 371 };
 372 
 373 /**
 374  * Generates the profiles part of the configuration.
 375  *
 376  * @param input External data to use for generating the configuration
 377  * @param common The common values
 378  * @returns {{}} Profiles part of the configuration
 379  */
 380 var getJibProfilesProfiles = function (input, common, data) {
 381     // Main SE profiles
 382     var profiles = {
 383 
 384         "linux-x64": {
 385             target_os: "linux",
 386             target_cpu: "x64",
 387             dependencies: ["devkit", "graphviz", "pandoc", "graalunit_lib"],
 388             configure_args: concat(common.configure_args_64bit,
 389                 "--enable-full-docs", "--with-zlib=system",
 390                 (isWsl(input) ? [ "--host=x86_64-unknown-linux-gnu",
 391                     "--build=x86_64-unknown-linux-gnu" ] : [])),
 392             default_make_targets: ["docs-bundles"],
 393         },
 394 
 395         "linux-x86": {
 396             target_os: "linux",
 397             target_cpu: "x86",
 398             build_cpu: "x64",
 399             dependencies: ["devkit"],
 400             configure_args: concat(common.configure_args_32bit,
 401                 "--with-jvm-variants=minimal,server", "--with-zlib=system"),
 402         },
 403 
 404         "macosx-x64": {
 405             target_os: "macosx",
 406             target_cpu: "x64",
 407             dependencies: ["devkit", "pandoc", "graalunit_lib"],
 408             configure_args: concat(common.configure_args_64bit, "--with-zlib=system",
 409                 "--with-macosx-version-max=10.9.0"),
 410         },
 411 
 412         "solaris-x64": {
 413             target_os: "solaris",
 414             target_cpu: "x64",
 415             dependencies: ["devkit", "cups"],
 416             configure_args: concat(common.configure_args_64bit,
 417                 "--with-zlib=system", "--enable-dtrace"),
 418         },
 419 
 420         "solaris-sparcv9": {
 421             target_os: "solaris",
 422             target_cpu: "sparcv9",
 423             dependencies: ["devkit", "cups"],
 424             configure_args: concat(common.configure_args_64bit,
 425                 "--with-zlib=system", "--enable-dtrace"),
 426         },
 427 
 428         "windows-x64": {
 429             target_os: "windows",
 430             target_cpu: "x64",
 431             dependencies: ["devkit", "pandoc", "graalunit_lib"],
 432             configure_args: concat(common.configure_args_64bit),
 433         },
 434 
 435         "windows-x86": {
 436             target_os: "windows",
 437             target_cpu: "x86",
 438             build_cpu: "x64",
 439             dependencies: ["devkit"],
 440             configure_args: concat(common.configure_args_32bit),
 441         },
 442 
 443         "linux-aarch64": {
 444             target_os: "linux",
 445             target_cpu: "aarch64",
 446             build_cpu: "x64",
 447             dependencies: ["devkit", "build_devkit", "cups"],
 448             configure_args: [
 449                 "--openjdk-target=aarch64-linux-gnu", "--with-freetype=bundled",
 450                 "--disable-warnings-as-errors"
 451             ],
 452         },
 453 
 454         "linux-arm32": {
 455             target_os: "linux",
 456             target_cpu: "arm",
 457             build_cpu: "x64",
 458             dependencies: ["devkit", "build_devkit", "cups"],
 459             configure_args: [
 460                 "--openjdk-target=arm-linux-gnueabihf", "--with-freetype=bundled",
 461                 "--with-abi-profile=arm-vfp-hflt", "--disable-warnings-as-errors"
 462             ],
 463         },
 464     };
 465 
 466     // Add the base settings to all the main profiles
 467     common.main_profile_names.forEach(function (name) {
 468         profiles[name] = concatObjects(common.main_profile_base, profiles[name]);
 469     });
 470 
 471     // Generate debug versions of all the main profiles
 472     common.main_profile_names.forEach(function (name) {
 473         var debugName = name + common.debug_suffix;
 474         profiles[debugName] = concatObjects(profiles[name],
 475                                             common.debug_profile_base);
 476     });
 477     // Generate slowdebug versions of all the main profiles
 478     common.main_profile_names.forEach(function (name) {
 479         var debugName = name + common.slowdebug_suffix;
 480         profiles[debugName] = concatObjects(profiles[name],
 481                                             common.slowdebug_profile_base);
 482     });
 483     // Generate testmake profiles for the main profile of each build host
 484     // platform. This profile only runs the makefile tests.
 485     // Ant is needed to run the idea project generator test.
 486     var testmakeBase = {
 487         dependencies: [ "ant" ],
 488         environment: {
 489             "ANT_HOME": input.get("ant", "install_path") + "/apache-ant-1.7.1"
 490         }
 491     };
 492     [ "linux-x64", "macosx-x64", "solaris-sparcv9", "solaris-x64", "windows-x64"]
 493         .forEach(function (name) {
 494             var maketestName = name + "-testmake";
 495             profiles[maketestName] = concatObjects(profiles[name], testmakeBase);
 496             profiles[maketestName].default_make_targets = [ "test-make" ];
 497         });
 498 
 499     // Profiles for building the zero jvm variant. These are used for verification.
 500     var zeroProfiles = {
 501         "linux-x64-zero": {
 502             target_os: "linux",
 503             target_cpu: "x64",
 504             dependencies: ["devkit"],
 505             configure_args: concat(common.configure_args_64bit, [
 506                 "--with-zlib=system",
 507                 "--with-jvm-variants=zero",
 508                 "--enable-libffi-bundling"
 509             ])
 510         },
 511 
 512         "linux-x86-zero": {
 513             target_os: "linux",
 514             target_cpu: "x86",
 515             build_cpu: "x64",
 516             dependencies: ["devkit"],
 517             configure_args:  concat(common.configure_args_32bit, [
 518                 "--with-zlib=system",
 519                 "--with-jvm-variants=zero",
 520                 "--enable-libffi-bundling"
 521             ])
 522         }
 523     }
 524     profiles = concatObjects(profiles, zeroProfiles);
 525 
 526     // Add the base settings to the zero profiles and generate debug profiles
 527     Object.keys(zeroProfiles).forEach(function (name) {
 528         var debugName = name + common.debug_suffix;
 529         profiles[name] = concatObjects(common.main_profile_base, profiles[name]);
 530         profiles[debugName] = concatObjects(profiles[name], common.debug_profile_base);
 531     });
 532 
 533     // Define a profile with precompiled headers disabled. This is just used for
 534     // verfication of this build configuration.
 535     var noPchProfiles = {
 536         "linux-x64-debug-nopch": {
 537             target_os: "linux",
 538             target_cpu: "x64",
 539             dependencies: ["devkit"],
 540             configure_args: concat(common.configure_args_64bit,
 541                 "--with-zlib=system", "--disable-precompiled-headers"),
 542         },
 543     };
 544     profiles = concatObjects(profiles, noPchProfiles);
 545     // Add base settings to noPch profiles
 546     Object.keys(noPchProfiles).forEach(function (name) {
 547         profiles[name] = concatObjects(common.main_profile_base, profiles[name]);
 548         profiles[name] = concatObjects(common.debug_profile_base, profiles[name]);
 549         // Override default make target with hotspot as that's the only part of
 550         // the build using precompiled headers.
 551         profiles[name].default_make_targets = ["hotspot"];
 552     });
 553 
 554     // Bootcycle profiles runs the build with itself as the boot jdk. This can
 555     // be done in two ways. Either using the builtin bootcycle target in the
 556     // build system. Or by supplying the main jdk build as bootjdk to configure.
 557     [ "linux-x64", "macosx-x64", "solaris-sparcv9", "windows-x64"]
 558         .forEach(function (name) {
 559             var bootcycleName = name + "-bootcycle";
 560             var bootcyclePrebuiltName = name + "-bootcycle-prebuilt";
 561             // The base bootcycle profile just changes the default target
 562             // compared to the base profile
 563             profiles[bootcycleName] = clone(profiles[name]);
 564             profiles[bootcycleName].default_make_targets = [ "bootcycle-images" ];
 565             // The prebuilt bootcycle variant modifies the boot jdk argument
 566             var bootcyclePrebuiltBase = {
 567                 dependencies: [ name + ".jdk" ],
 568                 configure_args: "--with-boot-jdk=" + input.get(name + ".jdk", "home_path"),
 569             }
 570             profiles[bootcyclePrebuiltName] = concatObjects(profiles[name],
 571                 bootcyclePrebuiltBase);
 572             var bootJdkIndex = profiles[bootcyclePrebuiltName].dependencies.indexOf("boot_jdk");
 573             delete profiles[bootcyclePrebuiltName].dependencies[bootJdkIndex];
 574             profiles[bootcyclePrebuiltName].default_make_targets = [ "product-images" ];
 575         });
 576 
 577     // JCov profiles build JCov-instrumented JDK image based on images provided through dependencies.
 578     [ "linux-x64", "macosx-x64", "solaris-sparcv9", "windows-x64"]
 579         .forEach(function (name) {
 580             var jcovName = name + "-jcov";
 581             profiles[jcovName] = clone(common.main_profile_base);
 582             profiles[jcovName].target_os = profiles[name].target_os
 583             profiles[jcovName].target_cpu = profiles[name].target_cpu
 584             profiles[jcovName].default_make_targets = [ "jcov-bundles" ];
 585             profiles[jcovName].dependencies = concat(profiles[jcovName].dependencies,
 586                 [ name + ".jdk", "devkit" ]);
 587             profiles[jcovName].configure_args = concat(profiles[jcovName].configure_args,
 588                 ["--with-jcov-input-jdk=" + input.get(name + ".jdk", "home_path")]);
 589         });
 590 
 591     //
 592     // Define artifacts for profiles
 593     //
 594     // Macosx bundles are named osx
 595     // tar.gz.
 596     var artifactData = {
 597         "linux-x64": {
 598             platform: "linux-x64",
 599         },
 600         "linux-x86": {
 601             platform: "linux-x86",
 602         },
 603         "macosx-x64": {
 604             platform: "osx-x64",
 605             jdk_subdir: "jdk-" + data.version +  ".jdk/Contents/Home",
 606         },
 607         "solaris-x64": {
 608             platform: "solaris-x64",
 609         },
 610         "solaris-sparcv9": {
 611             platform: "solaris-sparcv9",
 612         },
 613         "windows-x64": {
 614             platform: "windows-x64",
 615             jdk_suffix: "zip",
 616         },
 617         "windows-x86": {
 618             platform: "windows-x86",
 619             jdk_suffix: "zip",
 620         },
 621        "linux-aarch64": {
 622             platform: "linux-aarch64",
 623         },
 624        "linux-arm32": {
 625             platform: "linux-arm32",
 626         }
 627     }
 628     // Generate common artifacts for all main profiles
 629     Object.keys(artifactData).forEach(function (name) {
 630         profiles[name] = concatObjects(profiles[name],
 631             common.main_profile_artifacts(artifactData[name]));
 632     });
 633 
 634     // Generate common artifacts for all debug profiles
 635     Object.keys(artifactData).forEach(function (name) {
 636         var debugName = name + common.debug_suffix;
 637         profiles[debugName] = concatObjects(profiles[debugName],
 638             common.debug_profile_artifacts(artifactData[name]));
 639     });
 640 
 641     profilesArtifacts = {
 642         "linux-x64": {
 643             artifacts: {
 644                 doc_api_spec: {
 645                     local: "bundles/\\(jdk.*doc-api-spec.tar.gz\\)",
 646                     remote: [
 647                         "bundles/common/jdk-" + data.version + "_doc-api-spec.tar.gz",
 648                         "bundles/linux-x64/\\1"
 649                     ],
 650                 },
 651             }
 652         }
 653     };
 654     profiles = concatObjects(profiles, profilesArtifacts);
 655 
 656     // Generate open only profiles for all the main and debug profiles.
 657     // Rewrite artifact remote paths by adding "openjdk/GPL".
 658     common.main_profile_names.forEach(function (name) {
 659         var openName = name + common.open_suffix;
 660         profiles[openName] = concatObjects(profiles[name],
 661             common.open_profile_base);
 662         for (artifactName in profiles[openName].artifacts) {
 663             var artifact = profiles[openName].artifacts[artifactName];
 664             artifact.remote = replaceAll(
 665                 "bundles\/", "bundles/openjdk/GPL/",
 666                 (artifact.remote != null ? artifact.remote : artifact.local));
 667         }
 668         var debugName = name + common.debug_suffix;
 669         var openDebugName = name + common.open_suffix + common.debug_suffix;
 670         profiles[openDebugName] = concatObjects(profiles[debugName],
 671             common.open_profile_base);
 672         for (artifactName in profiles[openDebugName].artifacts) {
 673             var artifact = profiles[openDebugName].artifacts[artifactName];
 674             artifact.remote = replaceAll(
 675                 "bundles\/", "bundles/openjdk/GPL/",
 676                 (artifact.remote != null ? artifact.remote : artifact.local));
 677         }
 678     });
 679 
 680     // Define the reference implementation profiles. These are basically the same
 681     // as the open profiles, but upload artifacts to a different location.
 682     common.main_profile_names.forEach(function (name) {
 683         var riName = name + "-ri";
 684         var riDebugName = riName + common.debug_suffix;
 685         var openName = name + common.open_suffix;
 686         var openDebugName = openName + common.debug_suffix;
 687         profiles[riName] = clone(profiles[openName]);
 688         profiles[riDebugName] = clone(profiles[openDebugName]);
 689         // Rewrite all remote dirs to "bundles/openjdk/BCL/..."
 690         for (artifactName in profiles[riName].artifacts) {
 691             var artifact = profiles[riName].artifacts[artifactName];
 692             artifact.remote = replaceAll(
 693                 "\/GPL\/", "/BCL/",
 694                 (artifact.remote != null ? artifact.remote : artifact.local));
 695         }
 696     });
 697 
 698     // For open profiles, the non-debug jdk bundles, need an "open" prefix on the
 699     // remote bundle names, forming the word "openjdk". See JDK-8188789.
 700     common.main_profile_names.forEach(function (name) {
 701         var openName = name + common.open_suffix;
 702         profiles[openName].artifacts["jdk"].remote = replaceAll(
 703             "\/jdk-", "/openjdk-",
 704             replaceAll("\/\\1", "/open\\1",
 705                        profiles[openName].artifacts["jdk"].remote));
 706     });
 707 
 708     // Generate cmp-baseline profiles for each main profile and their
 709     // corresponding debug profile. This profile does a compare build run with no
 710     // changes to verify that the compare script has a clean baseline
 711     common.main_profile_names.forEach(function (name) {
 712         [ "", common.open_suffix ].forEach(function (suffix) {
 713             var cmpBaselineName = name + suffix + "-cmp-baseline";
 714             profiles[cmpBaselineName] = clone(profiles[name + suffix]);
 715             // Only compare the images target. This should pressumably be expanded
 716             // to include more build targets when possible.
 717             profiles[cmpBaselineName].default_make_targets = [ "images" ];
 718             profiles[cmpBaselineName].make_args = [ "COMPARE_BUILD=CONF=" ];
 719             // Do not inherit artifact definitions from base profile
 720             delete profiles[cmpBaselineName].artifacts;
 721         });
 722     });
 723 
 724     // Artifacts of JCov profiles
 725     [ "linux-x64", "macosx-x64", "solaris-sparcv9", "windows-x64"]
 726         .forEach(function (name) {
 727             var o = artifactData[name]
 728             var jdk_subdir = (o.jdk_subdir != null ? o.jdk_subdir : "jdk-" + data.version);
 729             var jdk_suffix = (o.jdk_suffix != null ? o.jdk_suffix : "tar.gz");
 730             var pf = o.platform
 731             var jcovName = name + "-jcov";
 732             profiles[jcovName].artifacts = {
 733                 jdk: {
 734                     local: "bundles/\\(jdk-jcov.*bin." + jdk_suffix + "\\)",
 735                     remote: [
 736                         "bundles/" + pf + "/jdk-jcov-" + data.version + "_" + pf + "_bin." + jdk_suffix
 737                     ],
 738                     subdir: jdk_subdir,
 739                     exploded: "images/jdk-jcov"
 740                 }
 741             };
 742         });
 743 
 744     // Profiles used to run tests.
 745     var testOnlyProfiles = {
 746         "run-test": {
 747             target_os: input.build_os,
 748             target_cpu: input.build_cpu,
 749             dependencies: [ "jtreg", "gnumake", "boot_jdk", "devkit", "jib" ],
 750             labels: "test",
 751             environment: {
 752                 "JT_JAVA": common.boot_jdk_home
 753             }
 754         }
 755     };
 756     profiles = concatObjects(profiles, testOnlyProfiles);
 757 
 758     // Profiles used to run tests using Jib for internal dependencies.
 759     var testedProfile = input.testedProfile;
 760     if (testedProfile == null) {
 761         testedProfile = input.build_os + "-" + input.build_cpu;
 762     }
 763     var testOnlyProfilesPrebuilt = {
 764         "run-test-prebuilt": {
 765             target_os: input.build_os,
 766             target_cpu: input.build_cpu,
 767             dependencies: [
 768                 "jtreg", "gnumake", "boot_jdk", "devkit", "jib", testedProfile + ".jdk",
 769                 testedProfile + ".test"
 770             ],
 771             src: "src.conf",
 772             make_args: [ "run-test-prebuilt", "LOG_CMDLINES=true", "JTREG_VERBOSE=fail,error,time" ],
 773             environment: {
 774                 "BOOT_JDK": common.boot_jdk_home,
 775                 "JDK_IMAGE_DIR": input.get(testedProfile + ".jdk", "home_path"),
 776                 "TEST_IMAGE_DIR": input.get(testedProfile + ".test", "home_path")
 777             },
 778             labels: "test"
 779         }
 780     };
 781 
 782     // If actually running the run-test-prebuilt profile, verify that the input
 783     // variable is valid and if so, add the appropriate target_* values from
 784     // the tested profile.
 785     if (input.profile == "run-test-prebuilt") {
 786         if (profiles[testedProfile] == null) {
 787             error("testedProfile is not defined: " + testedProfile);
 788         }
 789     }
 790     if (profiles[testedProfile] != null) {
 791         testOnlyProfilesPrebuilt["run-test-prebuilt"]["target_os"]
 792             = profiles[testedProfile]["target_os"];
 793         testOnlyProfilesPrebuilt["run-test-prebuilt"]["target_cpu"]
 794             = profiles[testedProfile]["target_cpu"];
 795     }
 796     profiles = concatObjects(profiles, testOnlyProfilesPrebuilt);
 797 
 798     // On macosx add the devkit bin dir to the path in all the run-test profiles.
 799     // This gives us a guaranteed working version of lldb for the jtreg failure handler.
 800     if (input.build_os == "macosx") {
 801         macosxRunTestExtra = {
 802             environment_path: input.get("devkit", "install_path")
 803                 + "/Xcode.app/Contents/Developer/usr/bin"
 804         };
 805         profiles["run-test"] = concatObjects(profiles["run-test"], macosxRunTestExtra);
 806         profiles["run-test-prebuilt"] = concatObjects(profiles["run-test-prebuilt"], macosxRunTestExtra);
 807     }
 808     // On windows we want the debug symbols available at test time
 809     if (input.build_os == "windows") {
 810         windowsRunTestPrebuiltExtra = {
 811             dependencies: [ testedProfile + ".jdk_symbols" ],
 812             environment: {
 813                 "SYMBOLS_IMAGE_DIR": input.get(testedProfile + ".jdk_symbols", "home_path"),
 814             }
 815         };
 816         profiles["run-test-prebuilt"] = concatObjects(profiles["run-test-prebuilt"],
 817             windowsRunTestPrebuiltExtra);
 818     }
 819 
 820     // The profile run-test-prebuilt defines src.conf as the src bundle. When
 821     // running in Mach 5, this reduces the time it takes to populate the
 822     // considerably. But with just src.conf, we cannot actually run any tests,
 823     // so if running from a workspace with just src.conf in it, we need to also
 824     // get src.full as a dependency, and define the work_dir (where make gets
 825     // run) to be in the src.full install path. By running in the install path,
 826     // the same cached installation of the full src can be reused for multiple
 827     // test tasks. Care must however be taken not to polute that work dir by
 828     // setting the appropriate make variables to control output directories.
 829     //
 830     // Use the existance of the top level README as indication of if this is
 831     // the full source or just src.conf.
 832     if (!new java.io.File(__DIR__, "../../README").exists()) {
 833         var runTestPrebuiltSrcFullExtra = {
 834             dependencies: "src.full",
 835             work_dir: input.get("src.full", "install_path"),
 836         }
 837         profiles["run-test-prebuilt"] = concatObjects(profiles["run-test-prebuilt"],
 838             runTestPrebuiltSrcFullExtra);
 839     }
 840 
 841     // Generate the missing platform attributes
 842     profiles = generatePlatformAttributes(profiles);
 843     profiles = generateDefaultMakeTargetsConfigureArg(common, profiles);
 844     return profiles;
 845 };
 846 
 847 /**
 848  * Generate the dependencies part of the configuration
 849  *
 850  * @param input External data to use for generating the configuration
 851  * @param common The common values
 852  * @returns {{}} Dependencies part of configuration
 853  */
 854 var getJibProfilesDependencies = function (input, common) {
 855 
 856     var devkit_platform_revisions = {
 857         linux_x64: "gcc7.3.0-OEL6.4+1.1",
 858         macosx_x64: "Xcode9.4-MacOSX10.13+1.0",
 859         solaris_x64: "SS12u4-Solaris11u1+1.0",
 860         solaris_sparcv9: "SS12u6-Solaris11u3+1.0",
 861         windows_x64: "VS2017-15.5.5+1.0",
 862         linux_aarch64: "gcc7.3.0-Fedora27+1.1",
 863         linux_arm: "gcc7.3.0-Fedora27+1.1"
 864     };
 865 
 866     var devkit_platform = (input.target_cpu == "x86"
 867         ? input.target_os + "_x64"
 868         : input.target_platform);
 869 
 870     var boot_jdk_platform = (input.build_os == "macosx" ? "osx" : input.build_os)
 871         + "-" + input.build_cpu;
 872     var boot_jdk_ext = (input.build_os == "windows" ? ".zip" : ".tar.gz")
 873     // If running in WSL and building for Windows, it will look like Linux,
 874     // but we need a Windows boot JDK.
 875     if (isWsl(input) && input.target_os == "windows") {
 876         boot_jdk_platform = "windows-" + input.build_cpu;
 877         boot_jdk_ext = ".zip";
 878     }
 879 
 880     var makeBinDir = (input.build_os == "windows"
 881         ? input.get("gnumake", "install_path") + "/cygwin/bin"
 882         : input.get("gnumake", "install_path") + "/bin");
 883 
 884     var dependencies = {
 885 
 886         boot_jdk: {
 887             server: "jpg",
 888             product: "jdk",
 889             version: common.boot_jdk_version,
 890             build_number: "28",
 891             file: "bundles/" + boot_jdk_platform + "/jdk-" + common.boot_jdk_version + "_"
 892                 + boot_jdk_platform + "_bin" + boot_jdk_ext,
 893             configure_args: "--with-boot-jdk=" + common.boot_jdk_home,
 894             environment_path: common.boot_jdk_home + "/bin"
 895         },
 896 
 897         devkit: {
 898             organization: common.organization,
 899             ext: "tar.gz",
 900             module: "devkit-" + devkit_platform,
 901             revision: devkit_platform_revisions[devkit_platform],
 902             environment: {
 903                 "DEVKIT_HOME": input.get("devkit", "home_path"),
 904             }
 905         },
 906 
 907         build_devkit: {
 908             organization: common.organization,
 909             ext: "tar.gz",
 910             module: "devkit-" + input.build_platform,
 911             revision: devkit_platform_revisions[input.build_platform]
 912         },
 913 
 914         cups: {
 915             organization: common.organization,
 916             ext: "tar.gz",
 917             revision: "1.0118+1.0"
 918         },
 919 
 920         jtreg: {
 921             server: "javare",
 922             revision: "4.2",
 923             build_number: "b13",
 924             checksum_file: "MD5_VALUES",
 925             file: "jtreg_bin-4.2.zip",
 926             environment_name: "JT_HOME",
 927             environment_path: input.get("jtreg", "install_path") + "/jtreg/bin"
 928         },
 929 
 930         jmh: {
 931             organization: common.organization,
 932             ext: "tar.gz",
 933             revision: "1.21+1.0"
 934         },
 935 
 936         jcov: {
 937             server: "jpg",
 938             product: "jcov",
 939             version: "3.0",
 940             build_number: "b07",
 941             file: "bundles/jcov-3_0.zip",
 942         },
 943 
 944         gnumake: {
 945             organization: common.organization,
 946             ext: "tar.gz",
 947             revision: "4.0+1.0",
 948 
 949             module: (input.build_os == "windows"
 950                 ? "gnumake-" + input.build_osenv_platform
 951                 : "gnumake-" + input.build_platform),
 952 
 953             configure_args: "MAKE=" + makeBinDir + "/make",
 954 
 955             environment: {
 956                 "MAKE": makeBinDir + "/make"
 957             },
 958 
 959             environment_path: makeBinDir
 960         },
 961 
 962         autoconf: {
 963             organization: common.organization,
 964             ext: "tar.gz",
 965             revision: "2.69+1.0.1",
 966             module: (input.build_os == "windows"
 967                 ? "autoconf-" + input.build_osenv_platform
 968                 : "autoconf-" + input.build_platform),
 969             configure_args: "",
 970             environment_path: input.get("autoconf", "install_path")
 971         },
 972 
 973         graphviz: {
 974             organization: common.organization,
 975             ext: "tar.gz",
 976             revision: "2.38.0-1+1.1",
 977             module: "graphviz-" + input.target_platform,
 978             configure_args: "DOT=" + input.get("graphviz", "install_path") + "/dot",
 979             environment_path: input.get("graphviz", "install_path")
 980         },
 981 
 982         pandoc: {
 983             organization: common.organization,
 984             ext: "tar.gz",
 985             revision: "2.3.1+1.0",
 986             module: "pandoc-" + input.build_platform,
 987             configure_args: "PANDOC=" + input.get("pandoc", "install_path") + "/pandoc/pandoc",
 988             environment_path: input.get("pandoc", "install_path") + "/pandoc"
 989         },
 990 
 991         // This adds java jib as a dependency for the test artifacts resolver
 992         jib: {
 993             organization: "com.oracle.java.jib",
 994             ext: "zip",
 995             classifier: "distribution",
 996             revision: "3.0-SNAPSHOT",
 997             environment_name: "JIB_HOME",
 998             environment_value: input.get("jib", "install_path")
 999                 + "/jib-3.0-SNAPSHOT-distribution"
1000         },
1001 
1002         ant: {
1003             organization: common.organization,
1004             ext: "zip",
1005             revision: "1.7.1+1.0",
1006             configure_args: "",
1007         },
1008 
1009         graalunit_lib: {
1010             organization: common.organization,
1011             ext: "zip",
1012             revision: "619_Apr_12_2018",
1013             module: "graalunit-lib",
1014             configure_args: "--with-graalunit-lib=" + input.get("graalunit_lib", "install_path"),
1015             environment_name: "GRAALUNIT_LIB"
1016         },
1017     };
1018 
1019     return dependencies;
1020 };
1021 
1022 /**
1023  * Generate the missing platform attributes for profiles
1024  *
1025  * @param profiles Profiles map to generate attributes on
1026  * @returns {{}} New profiles map with platform attributes fully filled in
1027  */
1028 var generatePlatformAttributes = function (profiles) {
1029     var ret = concatObjects(profiles, {});
1030     for (var profile in profiles) {
1031         if (ret[profile].build_os == null) {
1032             ret[profile].build_os = ret[profile].target_os;
1033         }
1034         if (ret[profile].build_cpu == null) {
1035             ret[profile].build_cpu = ret[profile].target_cpu;
1036         }
1037         ret[profile].target_platform = ret[profile].target_os + "_" + ret[profile].target_cpu;
1038         ret[profile].build_platform = ret[profile].build_os + "_" + ret[profile].build_cpu;
1039     }
1040     return ret;
1041 };
1042 
1043 /**
1044  * The default_make_targets attribute on a profile is not a real Jib attribute.
1045  * This function rewrites that attribute into the corresponding configure arg.
1046  * Calling this function multiple times on the same profiles object is safe.
1047  *
1048  * @param common Common values
1049  * @param profiles Profiles map to rewrite profiles for
1050  * @returns {{}} New map of profiles with the make targets converted
1051  */
1052 var generateDefaultMakeTargetsConfigureArg = function (common, profiles) {
1053     var ret = concatObjects(profiles, {});
1054     for (var profile in ret) {
1055         if (ret[profile]["default_make_targets"] != null) {
1056             var targetsString = concat(ret[profile].default_make_targets).join(" ");
1057             // Iterate over all configure args and see if --with-default-make-target
1058             // is already there and change it, otherwise add it.
1059             var found = false;
1060             for (var i in ret[profile].configure_args) {
1061                 var arg = ret[profile].configure_args[i];
1062                 if (arg != null && arg.startsWith("--with-default-make-target=")) {
1063                     found = true;
1064                     ret[profile].configure_args[i]
1065                         = "--with-default-make-target=" + targetsString;
1066                 }
1067             }
1068             if (!found) {
1069                 ret[profile].configure_args = concat(
1070                     ret[profile].configure_args,
1071                     "--with-default-make-target=" + targetsString);
1072             }
1073         }
1074     }
1075     return ret;
1076 }
1077 
1078 var getBuildId = function (input) {
1079     if (input.build_id != null) {
1080         return input.build_id;
1081     } else {
1082         var topdir = new java.io.File(__DIR__, "../..").getCanonicalFile().getName();
1083         var userName = java.lang.System.getProperty("user.name");
1084         return userName + "." + topdir;
1085     }
1086 }
1087 
1088 /**
1089  * Deep clones an object tree.
1090  *
1091  * @param o Object to clone
1092  * @returns {{}} Clone of o
1093  */
1094 var clone = function (o) {
1095     return JSON.parse(JSON.stringify(o));
1096 };
1097 
1098 /**
1099  * Concatenates all arguments into a new array
1100  *
1101  * @returns {Array.<T>} New array containing all arguments
1102  */
1103 var concat = function () {
1104     return Array.prototype.concat.apply([], arguments);
1105 };
1106 
1107 /**
1108  * Takes a String or Array of Strings and does a replace operation on each
1109  * of them.
1110  *
1111  * @param pattern Pattern to look for
1112  * @param replacement Replacement text to insert
1113  * @param a String or Array of Strings to replace
1114  * @returns {Array} Either a new array or a new string depending on the input
1115  */
1116 var replaceAll = function (pattern, replacement, a) {
1117     // If a is an array
1118     if (Array === a.constructor) {
1119     var newA = [];
1120     for (var i in a) {
1121             newA.push(a[i].replace(pattern, replacement));
1122         }
1123         return newA;
1124         } else {
1125         return a.replace(pattern, replacement);
1126     }
1127 };
1128 
1129 /**
1130  * Deep concatenation of two objects. For each node encountered, merge
1131  * the contents with the corresponding node in the other object tree,
1132  * treating all strings as array elements.
1133  *
1134  * @param o1 Object to concatenate
1135  * @param o2 Object to concatenate
1136  * @returns {{}} New object tree containing the concatenation of o1 and o2
1137  */
1138 var concatObjects = function (o1, o2) {
1139     if (o1 == null) {
1140         return clone(o2);
1141     }
1142     if (o2 == null) {
1143         return clone(o1);
1144     }
1145     var ret = {};
1146     for (var a in o1) {
1147         if (o2[a] == null) {
1148             ret[a] = clone(o1[a]);
1149         }
1150     }
1151     for (var a in o2) {
1152         if (o1[a] == null) {
1153             ret[a] = clone(o2[a]);
1154         } else {
1155             if (typeof o1[a] == 'string') {
1156                 ret[a] = clone([o1[a]].concat(o2[a]));
1157             } else if (Array.isArray(o1[a])) {
1158                 ret[a] = clone(o1[a].concat(o2[a]));
1159             } else if (typeof o1[a] == 'object') {
1160                 ret[a] = concatObjects(o1[a], o2[a]);
1161             }
1162         }
1163     }
1164     return ret;
1165 };
1166 
1167 /**
1168  * Constructs the numeric version string from reading the
1169  * make/autoconf/version-numbers file and removing all trailing ".0".
1170  *
1171  * @param feature Override feature version
1172  * @param interim Override interim version
1173  * @param update Override update version
1174  * @param patch Override patch version
1175  * @returns {String} The numeric version string
1176  */
1177 var getVersion = function (feature, interim, update, patch) {
1178     var version_numbers = getVersionNumbers();
1179     var version = (feature != null ? feature : version_numbers.get("DEFAULT_VERSION_FEATURE"))
1180         + "." + (interim != null ? interim : version_numbers.get("DEFAULT_VERSION_INTERIM"))
1181         + "." + (update != null ? update :  version_numbers.get("DEFAULT_VERSION_UPDATE"))
1182         + "." + (patch != null ? patch : version_numbers.get("DEFAULT_VERSION_PATCH"));
1183     while (version.match(".*\\.0$")) {
1184         version = version.substring(0, version.length - 2);
1185     }
1186     return version;
1187 };
1188 
1189 /**
1190  * Constructs the common version configure args based on build type and
1191  * other version inputs
1192  */
1193 var versionArgs = function(input, common) {
1194     var args = ["--with-version-build=" + common.build_number];
1195     if (input.build_type == "promoted") {
1196         args = concat(args,
1197                       // This needs to be changed when we start building release candidates
1198                       // with-version-pre must be set to ea for 'ea' and empty for fcs build
1199                       "--with-version-pre=ea",
1200                       "--without-version-opt");
1201     } else {
1202         args = concat(args, "--with-version-opt=" + common.build_id);
1203     }
1204     return args;
1205 }
1206 
1207 // Properties representation of the make/autoconf/version-numbers file. Lazily
1208 // initiated by the function below.
1209 var version_numbers;
1210 
1211 /**
1212  * Read the make/autoconf/version-numbers file into a Properties object.
1213  *
1214  * @returns {java.utilProperties}
1215  */
1216 var getVersionNumbers = function () {
1217     // Read version information from make/autoconf/version-numbers
1218     if (version_numbers == null) {
1219         version_numbers = new java.util.Properties();
1220         var stream = new java.io.FileInputStream(__DIR__ + "/../autoconf/version-numbers");
1221         version_numbers.load(stream);
1222         stream.close();
1223     }
1224     return version_numbers;
1225 }
1226 
1227 /**
1228  * Returns true if running in Windows Subsystem for Linux. Jib does not yet
1229  * detect wsl as osenv, so fall back on linux with version containing Microsoft.
1230  */
1231 var isWsl = function (input) {
1232     return ( input.build_osenv == "wsl"
1233              || (input.build_os == "linux"
1234                  && java.lang.System.getProperty("os.version").contains("Microsoft")));
1235 }