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