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