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