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