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