jib-profiles.js revision 2560:11153e2b9fbf
1356290Sjkim/*
296593Smarkm * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
396593Smarkm * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4142429Snectar *
596593Smarkm * This code is free software; you can redistribute it and/or modify it
696593Smarkm * under the terms of the GNU General Public License version 2 only, as
796593Smarkm * published by the Free Software Foundation.  Oracle designates this
896593Smarkm * particular file as subject to the "Classpath" exception as provided
996593Smarkm * by Oracle in the LICENSE file that accompanied this code.
1096593Smarkm *
1196593Smarkm * This code is distributed in the hope that it will be useful, but WITHOUT
1296593Smarkm * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1396593Smarkm * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1496593Smarkm * version 2 for more details (a copy is included in the LICENSE file that
1596593Smarkm * accompanied this code).
1696593Smarkm *
1796593Smarkm * You should have received a copy of the GNU General Public License version
1896593Smarkm * 2 along with this work; if not, write to the Free Software Foundation,
1996593Smarkm * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20215698Ssimon *
21215698Ssimon * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22215698Ssimon * or visit www.oracle.com if you need additional information or have any
23215698Ssimon * questions.
24215698Ssimon */
2596593Smarkm
2696593Smarkm/*
2796593Smarkm * This file defines build profiles for the JIB tool and others.
2896593Smarkm *
2996593Smarkm * A build profile defines a set of configuration options and external
3096593Smarkm * dependencies that we for some reason or other care about specifically.
3196593Smarkm * Typically, build profiles are defined for the build configurations we
3296593Smarkm * build regularly.
3396593Smarkm *
3496593Smarkm * Contract against this file from the tools that use it, is to provide
3596593Smarkm * a function on the form:
3696593Smarkm *
3796593Smarkm * getJibProfiles(input)
3896593Smarkm *
3996593Smarkm * which returns an object graph describing the profiles and their
4096593Smarkm * dependencies. The name of the function is based on the name of this
41276861Sjkim * file, minus the extension and the '-', camel cased and prefixed with
42276861Sjkim * 'get'.
4396593Smarkm *
4496593Smarkm *
45215698Ssimon * The parameter 'input' is an object that optionally contains  some data.
46215698Ssimon * Optionally because a tool may read the configuration for different purposes.
47215698Ssimon * To initially get a list of available profiles, the active profile may not
48215698Ssimon * yet be known for instance.
49312826Sjkim *
50215698Ssimon * Data that may be set on the input object:
51142429Snectar *
52142429Snectar * input.profile = <name of active profile>
53276861Sjkim *
54276861Sjkim * If the active profile is set, the following data from it must also
55276861Sjkim * be provided:
5696593Smarkm *
57344604Sjkim * input.profile
58344604Sjkim * input.build_id
59344604Sjkim * input.target_os
60344604Sjkim * input.target_cpu
61344604Sjkim * input.build_os
62344604Sjkim * input.build_cpu
63215698Ssimon * input.target_platform
64344604Sjkim * input.build_platform
65344604Sjkim * // The build_osenv_* variables describe the unix layer on Windows systems,
66344604Sjkim * // i.e. Cygwin, which may also be 32 or 64 bit.
67344604Sjkim * input.build_osenv
68276861Sjkim * input.build_osenv_cpu
69215698Ssimon * input.build_osenv_platform
70344604Sjkim *
7196593Smarkm * For more complex nested attributes, there is a method "get":
7296593Smarkm *
7396593Smarkm * input.get("<dependency>", "<attribute>")
7496593Smarkm *
7596593Smarkm * Valid attributes are:
7696593Smarkm * install_path
7796593Smarkm * download_path
7896593Smarkm * download_dir
7996593Smarkm *
8096593Smarkm *
8196593Smarkm * The output data generated by this configuration file has the following
8296593Smarkm * format:
8396593Smarkm *
8496593Smarkm * data: {
8596593Smarkm *   // Identifies the version of this format to the tool reading it
8696593Smarkm *   format_version: "1.0",
8796593Smarkm *
8896593Smarkm *   // Name of base outputdir. JIB assumes the actual output dir is formed
8996593Smarkm *   // by adding the configuration name: <output_basedir>/<config-name>
9096593Smarkm *   output_basedir: "build",
9196593Smarkm *   // Configure argument to use to specify configuration name
9296593Smarkm *   configuration_configure_arg:
9396593Smarkm *   // Make argument to use to specify configuration name
9496593Smarkm *   configuration_make_arg:
9596593Smarkm *
9696593Smarkm *   profiles: {
9796593Smarkm *     <profile-name>: {
9896593Smarkm *       // Name of os the profile is built to run on
9996593Smarkm *       target_os; <string>
10096593Smarkm *       // Name of cpu the profile is built to run on
10196593Smarkm *       target_cpu; <string>
10296593Smarkm *       // Combination of target_os and target_cpu for convenience
10396593Smarkm *       target_platform; <string>
10496593Smarkm *       // Name of os the profile is built on
10596593Smarkm *       build_os; <string>
10696593Smarkm *       // Name of cpu the profile is built on
10796593Smarkm *       build_cpu; <string>
10896593Smarkm *       // Combination of build_os and build_cpu for convenience
10996593Smarkm *       build_platform; <string>
11096593Smarkm *
11196593Smarkm *       // List of dependencies needed to build this profile
11296593Smarkm *       dependencies: <Array of strings>
11396593Smarkm *
11496593Smarkm *       // List of configure args to use for this profile
11596593Smarkm *       configure_args: <Array of strings>
11696593Smarkm *
11796593Smarkm *       // List of free form labels describing aspects of this profile
11896593Smarkm *       labels: <Array of strings>
11996593Smarkm *     }
12096593Smarkm *   }
12196593Smarkm *
12296593Smarkm *   // Dependencies use a Maven like deployment structure
12396593Smarkm *   dependencies: {
12496593Smarkm *     <dependency-name>: {
12596593Smarkm *       // Organization part of path defining this dependency
12696593Smarkm *       organization: <string>
12796593Smarkm *       // File extension for this dependency
12896593Smarkm *       ext: <string>
12996593Smarkm *       // Module part of path for defining this dependency,
13096593Smarkm *       // defaults to <dependency-name>
13196593Smarkm *       module: <string>
13296593Smarkm *       // Revision part of path for defining this dependency
133142429Snectar *       revision: <string>
13496593Smarkm *
135100946Snectar *       // List of configure args to add when using this dependency,
136356290Sjkim *       // defaults to
137215698Ssimon *       // "--with-<dependency-name>=input.get("<dependency-name", "install_path")"
138215698Ssimon *       configure_args: <array of strings>
139215698Ssimon *
140215698Ssimon *       // Name of environment variable to set when using this dependency
14196593Smarkm *       // when running make
142238405Sjkim *       environment_name: <string>
143238405Sjkim *       // Value of environment variable to set when using this dependency
144238405Sjkim *       // when running make
14596593Smarkm *       environment_value: <string>
14696593Smarkm *
14796593Smarkm *       // Value to add to the PATH variable when using this dependency,
14896593Smarkm *       // applies to both make and configure
14996593Smarkm *       environment_path: <string>
15096593Smarkm *     }
15196593Smarkm *
152215698Ssimon *     <dependency-name>: {
153238405Sjkim *       // For certain dependencies where a legacy distribution mechanism is
154238405Sjkim *       // already in place, the "javare" server layout is also supported
155238405Sjkim *       // Indicate that an alternate server source and layout should be used
156238405Sjkim *       server: "javare"
157238405Sjkim *
158238405Sjkim *       // For "javare", a combination of module, revision,
159238405Sjkim *       // build number (optional), files and checksum file is possible for
160238405Sjkim *       // artifacts following the standard layout.
161238405Sjkim *       module: <string>
162238405Sjkim *       revision: <string>
163238405Sjkim *       build_number: <string>
164238405Sjkim *       checksum_file: <string>
165238405Sjkim *       file: <string>
166238405Sjkim *
167238405Sjkim *       // For other files, use checksum path and path instead
168238405Sjkim *       checksum_path: <string>
169238405Sjkim *       path: <string>
170215698Ssimon *     }
17196593Smarkm *   }
172215698Ssimon * }
17396593Smarkm */
17496593Smarkm
175215698Ssimon/**
17696593Smarkm * Main entry to generate the profile configuration
17796593Smarkm *
17896593Smarkm * @param input External data to use for generating the configuration
17996593Smarkm * @returns {{}} Profile configuration
18096593Smarkm */
18196593Smarkmvar getJibProfiles = function (input) {
18296593Smarkm
183215698Ssimon    var data = {};
18496593Smarkm
185215698Ssimon    // Identifies the version of this format to the tool reading it.
18696593Smarkm    // 1.1 signifies that the publish, publish-src and get-src features are usable.
187215698Ssimon    data.format_version = "1.1";
18896593Smarkm
189215698Ssimon    // Organization, product and version are used when uploading/publishing build results
19096593Smarkm    data.organization = "";
191215698Ssimon    data.product = "jdk";
19296593Smarkm    data.version = getVersion();
193215698Ssimon
19496593Smarkm    // The base directory for the build output. JIB will assume that the
195215698Ssimon    // actual build directory will be <output_basedir>/<configuration>
19696593Smarkm    data.output_basedir = "build";
197215698Ssimon    // The configure argument to use to specify the name of the configuration
19896593Smarkm    data.configuration_configure_arg = "--with-conf-name=";
199215698Ssimon    // The make argument to use to specify the name of the configuration
20096593Smarkm    data.configuration_make_arg = "CONF_NAME=";
20196593Smarkm
20296593Smarkm    // Exclude list to use when Jib creates a source bundle
203331638Sjkim    data.src_bundle_excludes = "./build webrev .hg */.hg */*/.hg */*/*/.hg";
204331638Sjkim    // Include list to use when creating a minimal jib source bundle which
205238405Sjkim    // contains just the jib configuration files.
206331638Sjkim    data.conf_bundle_includes = "*/conf/jib-profiles.* common/autoconf/version-numbers"
207331638Sjkim
208331638Sjkim    // Define some common values
209331638Sjkim    var common = getJibProfilesCommon(input, data);
21096593Smarkm    // Generate the profiles part of the configuration
21196593Smarkm    data.profiles = getJibProfilesProfiles(input, common, data);
212110010Smarkm    // Generate the dependencies part of the configuration
21396593Smarkm    data.dependencies = getJibProfilesDependencies(input, common, data);
21496593Smarkm
21596593Smarkm    return data;
21696593Smarkm};
217344604Sjkim
21896593Smarkm/**
21996593Smarkm * Generates some common values
22096593Smarkm *
22196593Smarkm * @param input External data to use for generating the configuration
22296593Smarkm * @returns Common values
22396593Smarkm */
224238405Sjkimvar getJibProfilesCommon = function (input, data) {
225238405Sjkim    var common = {};
226344604Sjkim
227344604Sjkim    common.organization = "jpg.infra.builddeps";
228238405Sjkim    common.build_id = getBuildId(input);
229344604Sjkim    common.build_number = input.build_number != null ? input.build_number : "0";
230238405Sjkim
231238405Sjkim    // List of the main profile names used for iteration
232238405Sjkim    common.main_profile_names = [
233238405Sjkim        "linux-x64", "linux-x86", "macosx-x64", "solaris-x64",
23496593Smarkm        "solaris-sparcv9", "windows-x64", "windows-x86"
235344604Sjkim    ];
236238405Sjkim
237238405Sjkim    // These are the base setttings for all the main build profiles.
238344604Sjkim    common.main_profile_base = {
239238405Sjkim        dependencies: ["boot_jdk", "gnumake", "jtreg"],
240238405Sjkim        default_make_targets: ["product-bundles", "test-bundles"],
241344604Sjkim        configure_args: [
242344604Sjkim            "--with-version-opt=" + common.build_id,
243238405Sjkim            "--enable-jtreg-failure-handler",
244344604Sjkim            "--with-version-build=" + common.build_number
245238405Sjkim        ]
246344604Sjkim    };
247238405Sjkim    // Extra settings for debug profiles
248238405Sjkim    common.debug_suffix = "-debug";
249238405Sjkim    common.debug_profile_base = {
250238405Sjkim        configure_args: ["--enable-debug"],
251238405Sjkim        labels: "debug"
252238405Sjkim    };
25396593Smarkm    // Extra settings for slowdebug profiles
25496593Smarkm    common.slowdebug_suffix = "-slowdebug";
25596593Smarkm    common.slowdebug_profile_base = {
256215698Ssimon        configure_args: ["--with-debug-level=slowdebug"],
257215698Ssimon        labels: "slowdebug"
258215698Ssimon    };
259215698Ssimon    // Extra settings for openjdk only profiles
260215698Ssimon    common.open_suffix = "-open";
26196593Smarkm    common.open_profile_base = {
26296593Smarkm        configure_args: ["--enable-openjdk-only"],
26396593Smarkm        labels: "open"
26496593Smarkm    };
26596593Smarkm
26696593Smarkm    common.configure_args_64bit = ["--with-target-bits=64"];
26796593Smarkm    common.configure_args_32bit = ["--with-target-bits=32"];
26896593Smarkm
26996593Smarkm    /**
27096593Smarkm     * Define common artifacts template for all main profiles
27196593Smarkm     * @param pf - Name of platform in bundle names
27296593Smarkm     * @param demo_ext - Type of extension for demo bundle
27396593Smarkm     */
27496593Smarkm    common.main_profile_artifacts = function (pf, demo_ext) {
27596593Smarkm        return {
276344604Sjkim            artifacts: {
27796593Smarkm                jdk: {
27896593Smarkm                    local: "bundles/\\(jdk.*bin.tar.gz\\)",
279344604Sjkim                    remote: [
28096593Smarkm                        "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin.tar.gz",
28196593Smarkm                        "bundles/" + pf + "/\\1"
282344604Sjkim                    ],
28396593Smarkm                    subdir: "jdk-" + data.version,
284344604Sjkim                    exploded: "images/jdk"
28596593Smarkm                },
28696593Smarkm                jre: {
28796593Smarkm                    local: "bundles/\\(jre.*bin.tar.gz\\)",
28896593Smarkm                    remote: [
28996593Smarkm                        "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin.tar.gz",
29096593Smarkm                        "bundles/" + pf + "/\\1"
29196593Smarkm                    ],
29296593Smarkm                    subdir: "jre-" + data.version,
29396593Smarkm                    exploded: "images/jre"
29496593Smarkm                },
29596593Smarkm                test: {
29696593Smarkm                    local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
297344604Sjkim                    remote: [
29896593Smarkm                        "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-tests.tar.gz",
299344604Sjkim                        "bundles/" + pf + "/\\1"
30096593Smarkm                    ],
30196593Smarkm                    exploded: "images/test"
302160819Ssimon                },
303160819Ssimon                jdk_symbols: {
30496593Smarkm                    local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
30596593Smarkm                    remote: [
30696593Smarkm                        "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-symbols.tar.gz",
30796593Smarkm                        "bundles/" + pf + "/\\1"
30896593Smarkm                    ],
309160819Ssimon                    subdir: "jdk-" + data.version,
31096593Smarkm                    exploded: "images/jdk"
31196593Smarkm                },
31296593Smarkm                jre_symbols: {
31396593Smarkm                    local: "bundles/\\(jre.*bin-symbols.tar.gz\\)",
31496593Smarkm                    remote: [
315142429Snectar                        "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin-symbols.tar.gz",
31696593Smarkm                        "bundles/" + pf + "/\\1"
31796593Smarkm                    ],
31896593Smarkm                    subdir: "jre-" + data.version,
31996593Smarkm                    exploded: "images/jre"
32096593Smarkm                },
32196593Smarkm                demo: {
32296593Smarkm                    local: "bundles/\\(jdk.*demo." + demo_ext + "\\)",
32396593Smarkm                    remote: [
324344604Sjkim                        "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_demo." + demo_ext,
32596593Smarkm                        "bundles/" + pf + "/\\1"
326344604Sjkim                    ],
327142429Snectar                }
328238405Sjkim            }
329344604Sjkim        };
330344604Sjkim    };
331238405Sjkim
33296593Smarkm
33396593Smarkm    /**
334344604Sjkim     * Define common artifacts template for all debug profiles
335     * @param pf - Name of platform in bundle names
336     */
337    common.debug_profile_artifacts = function (pf) {
338        return {
339            artifacts: {
340                jdk: {
341                    local: "bundles/\\(jdk.*bin-debug.tar.gz\\)",
342                    remote: [
343                        "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-debug.tar.gz",
344                        "bundles/" + pf + "/\\1"
345                    ],
346                    subdir: "jdk-" + data.version,
347                    exploded: "images/jdk"
348                },
349                jre: {
350                    local: "bundles/\\(jre.*bin-debug.tar.gz\\)",
351                    remote: [
352                        "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin-debug.tar.gz",
353                        "bundles/" + pf + "/\\1"
354                    ],
355                    subdir: "jre-" + data.version,
356                    exploded: "images/jre"
357                },
358                test: {
359                    local: "bundles/\\(jdk.*bin-tests-debug.tar.gz\\)",
360                    remote: [
361                        "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-tests-debug.tar.gz",
362                        "bundles/" + pf + "/\\1"
363                    ],
364                    exploded: "images/test"
365                },
366                jdk_symbols: {
367                    local: "bundles/\\(jdk.*bin-debug-symbols.tar.gz\\)",
368                    remote: [
369                        "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-debug-symbols.tar.gz",
370                        "bundles/" + pf + "/\\1"
371                    ],
372                    subdir: "jdk-" + data.version,
373                    exploded: "images/jdk"
374                },
375                jre_symbols: {
376                    local: "bundles/\\(jre.*bin-debug-symbols.tar.gz\\)",
377                    remote: [
378                        "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin-debug-symbols.tar.gz",
379                        "bundles/" + pf + "/\\1"
380                    ],
381                    subdir: "jre-" + data.version,
382                    exploded: "images/jre"
383                }
384            }
385        };
386    };
387
388    var boot_jdk_revision = "8";
389    var boot_jdk_subdirpart = "1.8.0";
390    // JDK 8 does not work on sparc M7 cpus, need a newer update when building
391    // on such hardware.
392    if (input.build_cpu == "sparcv9") {
393       var cpu_brand = $EXEC("bash -c \"kstat -m cpu_info | grep brand | head -n1 | awk '{ print \$2 }'\"");
394       if (cpu_brand.trim() == 'SPARC-M7') {
395           boot_jdk_revision = "8u20";
396           boot_jdk_subdirpart = "1.8.0_20";
397       }
398    }
399    common.boot_jdk_revision = boot_jdk_revision;
400    common.boot_jdk_subdirpart = boot_jdk_subdirpart;
401    common.boot_jdk_home = input.get("boot_jdk", "home_path") + "/jdk"
402        + common.boot_jdk_subdirpart
403        + (input.build_os == "macosx" ? ".jdk/Contents/Home" : "");
404    common.boot_jdk_platform = input.build_os + "-"
405        + (input.build_cpu == "x86" ? "i586" : input.build_cpu);
406
407    return common;
408};
409
410/**
411 * Generates the profiles part of the configuration.
412 *
413 * @param input External data to use for generating the configuration
414 * @param common The common values
415 * @returns {{}} Profiles part of the configuration
416 */
417var getJibProfilesProfiles = function (input, common, data) {
418    // Main SE profiles
419    var profiles = {
420
421        "linux-x64": {
422            target_os: "linux",
423            target_cpu: "x64",
424            dependencies: ["devkit"],
425            configure_args: concat(common.configure_args_64bit, "--with-zlib=system"),
426            default_make_targets: ["docs-bundles"],
427        },
428
429        "linux-x86": {
430            target_os: "linux",
431            target_cpu: "x86",
432            build_cpu: "x64",
433            dependencies: ["devkit"],
434            configure_args: concat(common.configure_args_32bit,
435                "--with-jvm-variants=minimal,server", "--with-zlib=system"),
436        },
437
438        "macosx-x64": {
439            target_os: "macosx",
440            target_cpu: "x64",
441            dependencies: ["devkit"],
442            configure_args: concat(common.configure_args_64bit, "--with-zlib=system"),
443        },
444
445        "solaris-x64": {
446            target_os: "solaris",
447            target_cpu: "x64",
448            dependencies: ["devkit", "cups"],
449            configure_args: concat(common.configure_args_64bit,
450                "--with-zlib=system", "--enable-dtrace"),
451        },
452
453        "solaris-sparcv9": {
454            target_os: "solaris",
455            target_cpu: "sparcv9",
456            dependencies: ["devkit", "cups"],
457            configure_args: concat(common.configure_args_64bit,
458                "--with-zlib=system", "--enable-dtrace"),
459        },
460
461        "windows-x64": {
462            target_os: "windows",
463            target_cpu: "x64",
464            dependencies: ["devkit", "freetype"],
465            configure_args: concat(common.configure_args_64bit),
466        },
467
468        "windows-x86": {
469            target_os: "windows",
470            target_cpu: "x86",
471            build_cpu: "x64",
472            dependencies: ["devkit", "freetype"],
473            configure_args: concat(common.configure_args_32bit),
474        }
475    };
476    // Add the base settings to all the main profiles
477    common.main_profile_names.forEach(function (name) {
478        profiles[name] = concatObjects(common.main_profile_base, profiles[name]);
479    });
480
481    // Generate debug versions of all the main profiles
482    common.main_profile_names.forEach(function (name) {
483        var debugName = name + common.debug_suffix;
484        profiles[debugName] = concatObjects(profiles[name],
485                                            common.debug_profile_base);
486    });
487    // Generate slowdebug versions of all the main profiles
488    common.main_profile_names.forEach(function (name) {
489        var debugName = name + common.slowdebug_suffix;
490        profiles[debugName] = concatObjects(profiles[name],
491                                            common.slowdebug_profile_base);
492    });
493
494    // Generate open only profiles for all the main profiles for JPRT and reference
495    // implementation builds.
496    common.main_profile_names.forEach(function (name) {
497        var openName = name + common.open_suffix;
498        profiles[openName] = concatObjects(profiles[name],
499                                           common.open_profile_base);
500    });
501    // The open only profiles on linux are used for reference builds and should
502    // produce the compact profile images by default. This adds "profiles" as an
503    // extra default target.
504    var openOnlyProfilesExtra = {
505        "linux-x86-open": {
506            default_make_targets: "profiles-bundles",
507            configure_args: "--with-jvm-variants=client,server"
508        }
509    };
510    profiles = concatObjects(profiles, openOnlyProfilesExtra);
511
512    // Generate debug profiles for the open only profiles
513    common.main_profile_names.forEach(function (name) {
514        var openName = name + common.open_suffix;
515        var openDebugName = openName + common.debug_suffix;
516        profiles[openDebugName] = concatObjects(profiles[openName],
517                                                common.debug_profile_base);
518    });
519
520    // Profiles for building the zero jvm variant. These are used for verification
521    // in JPRT.
522    var zeroProfiles = {
523        "linux-x64-zero": {
524            target_os: "linux",
525            target_cpu: "x64",
526            dependencies: ["devkit"],
527            configure_args: concat(common.configure_args_64bit, [
528                "--with-zlib=system",
529                "--with-jvm-variants=zero",
530                "--enable-libffi-bundling"
531            ])
532        },
533
534        "linux-x86-zero": {
535            target_os: "linux",
536            target_cpu: "x86",
537            build_cpu: "x64",
538            dependencies: ["devkit"],
539            configure_args:  concat(common.configure_args_32bit, [
540                "--with-zlib=system",
541                "--with-jvm-variants=zero",
542                "--enable-libffi-bundling"
543            ])
544        }
545    }
546    profiles = concatObjects(profiles, zeroProfiles);
547
548    // Add the base settings to the zero profiles and generate debug profiles
549    Object.keys(zeroProfiles).forEach(function (name) {
550        var debugName = name + common.debug_suffix;
551        profiles[name] = concatObjects(common.main_profile_base, profiles[name]);
552        profiles[debugName] = concatObjects(profiles[name], common.debug_profile_base);
553    });
554
555    // Profiles used to run tests. Used in JPRT and Mach 5.
556    var testOnlyProfiles = {
557        "run-test-jprt": {
558            target_os: input.build_os,
559            target_cpu: input.build_cpu,
560            dependencies: [ "jtreg", "gnumake", "boot_jdk" ],
561            labels: "test",
562            environment: {
563                "JT_JAVA": common.boot_jdk_home
564            }
565        },
566
567        "run-test": {
568            target_os: input.build_os,
569            target_cpu: input.build_cpu,
570            dependencies: [ "jtreg", "gnumake", "boot_jdk" ],
571            labels: "test",
572            environment: {
573                "JT_JAVA": common.boot_jdk_home
574            }
575        }
576    };
577    profiles = concatObjects(profiles, testOnlyProfiles);
578
579    // Profiles used to run tests using Jib for internal dependencies.
580    var testedProfile = input.testedProfile;
581    if (testedProfile == null) {
582        testedProfile = input.build_os + "-" + input.build_cpu;
583    }
584    var testOnlyProfilesPrebuilt = {
585        "run-test-prebuilt": {
586            src: "src.conf",
587            dependencies: [ "jtreg", "gnumake", "boot_jdk", testedProfile + ".jdk",
588                testedProfile + ".test", "src.full"
589            ],
590            work_dir: input.get("src.full", "install_path") + "/test",
591            environment: {
592                "JT_JAVA": common.boot_jdk_home,
593                "PRODUCT_HOME": input.get(testedProfile + ".jdk", "home_path"),
594                "TEST_IMAGE_DIR": input.get(testedProfile + ".test", "home_path"),
595                "TEST_OUTPUT_DIR": input.src_top_dir
596            },
597            labels: "test"
598        }
599    };
600    // If actually running the run-test-prebuilt profile, verify that the input
601    // variable is valid and if so, add the appropriate target_* values from
602    // the tested profile.
603    if (input.profile == "run-test-prebuilt") {
604        if (profiles[testedProfile] == null) {
605            error("testedProfile is not defined: " + testedProfile);
606        } else {
607            testOnlyProfilesPrebuilt["run-test-prebuilt"]["target_os"]
608                = profiles[testedProfile]["target_os"];
609            testOnlyProfilesPrebuilt["run-test-prebuilt"]["target_cpu"]
610                = profiles[testedProfile]["target_cpu"];
611        }
612    }
613    profiles = concatObjects(profiles, testOnlyProfilesPrebuilt);
614
615    // On macosx add the devkit bin dir to the path in all the run-test profiles.
616    // This gives us a guaranteed working version of lldb for the jtreg failure handler.
617    if (input.build_os == "macosx") {
618        macosxRunTestExtra = {
619            dependencies: [ "devkit" ],
620            environment_path: input.get("devkit", "install_path")
621                + "/Xcode.app/Contents/Developer/usr/bin"
622        }
623        profiles["run-test"] = concatObjects(profiles["run-test"], macosxRunTestExtra);
624        profiles["run-test-jprt"] = concatObjects(profiles["run-test-jprt"], macosxRunTestExtra);
625        profiles["run-test-prebuilt"] = concatObjects(profiles["run-test-prebuilt"], macosxRunTestExtra);
626    }
627
628    //
629    // Define artifacts for profiles
630    //
631    // Macosx bundles are named osx and Windows demo bundles use zip instead of
632    // tar.gz.
633    var artifactData = {
634        "linux-x64": {
635            platform: "linux-x64",
636            demo_ext: "tar.gz"
637        },
638        "linux-x86": {
639            platform: "linux-x86",
640            demo_ext: "tar.gz"
641        },
642        "macosx-x64": {
643            platform: "osx-x64",
644            demo_ext: "tar.gz"
645        },
646        "solaris-x64": {
647            platform: "solaris-x64",
648            demo_ext: "tar.gz"
649        },
650        "solaris-sparcv9": {
651            platform: "solaris-sparcv9",
652            demo_ext: "tar.gz"
653        },
654        "windows-x64": {
655            platform: "windows-x64",
656            demo_ext: "zip"
657        },
658        "windows-x86": {
659            platform: "windows-x86",
660            demo_ext: "zip"
661        }
662    }
663    // Generate common artifacts for all main profiles
664    common.main_profile_names.forEach(function (name) {
665        profiles[name] = concatObjects(profiles[name],
666            common.main_profile_artifacts(artifactData[name].platform, artifactData[name].demo_ext));
667    });
668
669    // Generate common artifacts for all debug profiles
670    common.main_profile_names.forEach(function (name) {
671        var debugName = name + common.debug_suffix;
672        profiles[debugName] = concatObjects(profiles[debugName],
673            common.debug_profile_artifacts(artifactData[name].platform));
674    });
675
676    // Extra profile specific artifacts
677    profilesArtifacts = {
678        "linux-x64": {
679            artifacts: {
680                doc_api_spec: {
681                    local: "bundles/\\(jdk.*doc-api-spec.tar.gz\\)",
682                    remote: [
683                        "bundles/common/jdk-" + data.version + "_doc-api-spec.tar.gz",
684                        "bundles/linux-x64/\\1"
685                    ],
686                },
687            }
688        },
689
690        "linux-x64-open": {
691            artifacts: {
692                jdk: {
693                    local: "bundles/\\(jdk.*bin.tar.gz\\)",
694                    remote: "bundles/openjdk/GPL/linux-x64/\\1",
695                },
696                jre: {
697                    local: "bundles/\\(jre.*bin.tar.gz\\)",
698                    remote: "bundles/openjdk/GPL/linux-x64/\\1",
699                },
700                test: {
701                    local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
702                    remote: "bundles/openjdk/GPL/linux-x64/\\1",
703                },
704                jdk_symbols: {
705                    local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
706                    remote: "bundles/openjdk/GPL/linux-x64/\\1",
707                },
708                jre_symbols: {
709                    local: "bundles/\\(jre.*bin-symbols.tar.gz\\)",
710                    remote: "bundles/openjdk/GPL/linux-x64/\\1",
711                },
712                demo: {
713                    local: "bundles/\\(jdk.*demo.tar.gz\\)",
714                    remote: "bundles/openjdk/GPL/linux-x64/\\1",
715                },
716                doc_api_spec: {
717                    local: "bundles/\\(jdk.*doc-api-spec.tar.gz\\)",
718                    remote: "bundles/openjdk/GPL/linux-x64/\\1",
719                },
720            }
721        },
722
723        "linux-x86-open": {
724            artifacts: {
725                jdk: {
726                    local: "bundles/\\(jdk.*bin.tar.gz\\)",
727                    remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
728                },
729                jdk_symbols: {
730                    local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
731                    remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
732                },
733                jre: {
734                    // This regexp needs to not match the compact* files below
735                    local: "bundles/\\(jre.*[+][0-9]\\{1,\\}_linux-x86_bin.tar.gz\\)",
736                    remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
737                },
738                jre_compact1: {
739                    local: "bundles/\\(jre.*-compact1_linux-x86_bin.tar.gz\\)",
740                    remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
741                },
742                jre_compact2: {
743                    local: "bundles/\\(jre.*-compact2_linux-x86_bin.tar.gz\\)",
744                    remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
745                },
746                jre_compact3: {
747                    local: "bundles/\\(jre.*-compact3_linux-x86_bin.tar.gz\\)",
748                    remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
749                },
750            }
751        },
752
753        "windows-x86-open": {
754            artifacts: {
755                jdk: {
756                    local: "bundles/\\(jdk.*bin.tar.gz\\)",
757                    remote: "bundles/openjdk/GPL/windows-x86/\\1",
758                },
759                jre: {
760                    local: "bundles/\\(jre.*bin.tar.gz\\)",
761                    remote: "bundles/openjdk/GPL/windows-x86/\\1"
762                },
763                test: {
764                    local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
765                    remote: "bundles/openjdk/GPL/windows-x86/\\1",
766                },
767                jdk_symbols: {
768                    local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
769                    remote: "bundles/openjdk/GPL/windows-x86/\\1"
770                },
771                jre_symbols: {
772                    local: "bundles/\\(jre.*bin-symbols.tar.gz\\)",
773                    remote: "bundles/openjdk/GPL/windows-x86/\\1",
774                },
775                demo: {
776                    local: "bundles/\\(jdk.*demo.zip\\)",
777                    remote: "bundles/openjdk/GPL/windows-x86/\\1",
778                }
779            }
780        },
781
782        "linux-x86-open-debug": {
783            artifacts: {
784                jdk: {
785                    local: "bundles/\\(jdk.*bin-debug.tar.gz\\)",
786                    remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
787                },
788                jre: {
789                    local: "bundles/\\(jre.*bin-debug.tar.gz\\)",
790                    remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
791                },
792                jdk_symbols: {
793                    local: "bundles/\\(jdk.*bin-debug-symbols.tar.gz\\)",
794                    remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
795                },
796            }
797        },
798
799    };
800    profiles = concatObjects(profiles, profilesArtifacts);
801
802
803    // Define the reference implementation profiles. These are basically the same
804    // as the open profiles, but upload artifacts to a different location and
805    // are only defined for specific platforms.
806    profiles["linux-x64-ri"] = clone(profiles["linux-x64-open"]);
807    profiles["linux-x86-ri"] = clone(profiles["linux-x86-open"]);
808    profiles["linux-x86-ri-debug"] = clone(profiles["linux-x86-open-debug"]);
809    profiles["windows-x86-ri"] = clone(profiles["windows-x86-open"]);
810
811    // Generate artifacts for ri profiles
812    [ "linux-x64-ri", "linux-x86-ri", "linux-x86-ri-debug", "windows-x86-ri" ]
813        .forEach(function (name) {
814            // Rewrite all remote dirs to "bundles/openjdk/BCL/..."
815            for (artifactName in profiles[name].artifacts) {
816                var artifact = profiles[name].artifacts[artifactName];
817                artifact.remote = replaceAll("\/GPL\/", "/BCL/",
818                    (artifact.remote != null ? artifact.remote : artifact.local));
819            }
820        });
821
822    // Generate the missing platform attributes
823    profiles = generatePlatformAttributes(profiles);
824    profiles = generateDefaultMakeTargetsConfigureArg(common, profiles);
825    return profiles;
826};
827
828/**
829 * Generate the dependencies part of the configuration
830 *
831 * @param input External data to use for generating the configuration
832 * @param common The common values
833 * @returns {{}} Dependencies part of configuration
834 */
835var getJibProfilesDependencies = function (input, common) {
836
837    var devkit_platform_revisions = {
838        linux_x64: "gcc4.9.2-OEL6.4+1.1",
839        macosx_x64: "Xcode6.3-MacOSX10.9+1.0",
840        solaris_x64: "SS12u4-Solaris11u1+1.0",
841        solaris_sparcv9: "SS12u4-Solaris11u1+1.0",
842        windows_x64: "VS2013SP4+1.0"
843    };
844
845    var devkit_platform = (input.target_cpu == "x86"
846        ? input.target_os + "_x64"
847        : input.target_platform);
848
849    var dependencies = {
850
851        boot_jdk: {
852            server: "javare",
853            module: "jdk",
854            revision: common.boot_jdk_revision,
855            checksum_file: common.boot_jdk_platform + "/MD5_VALUES",
856            file: common.boot_jdk_platform + "/jdk-" + common.boot_jdk_revision
857                + "-" + common.boot_jdk_platform + ".tar.gz",
858            configure_args: "--with-boot-jdk=" + common.boot_jdk_home,
859            environment_path: common.boot_jdk_home + "/bin"
860        },
861
862        devkit: {
863            organization: common.organization,
864            ext: "tar.gz",
865            module: "devkit-" + devkit_platform,
866            revision: devkit_platform_revisions[devkit_platform]
867        },
868
869        build_devkit: {
870            organization: common.organization,
871            ext: "tar.gz",
872            module: "devkit-" + input.build_platform,
873            revision: devkit_platform_revisions[input.build_platform]
874        },
875
876        cups: {
877            organization: common.organization,
878            ext: "tar.gz",
879            revision: "1.0118+1.0"
880        },
881
882        jtreg: {
883            server: "javare",
884            revision: "4.2",
885            build_number: "b07",
886            checksum_file: "MD5_VALUES",
887            file: "jtreg_bin-4.2.zip",
888            environment_name: "JT_HOME",
889            environment_path: input.get("jtreg", "install_path") + "/jtreg/bin"
890        },
891
892        gnumake: {
893            organization: common.organization,
894            ext: "tar.gz",
895            revision: "4.0+1.0",
896
897            module: (input.build_os == "windows"
898                ? "gnumake-" + input.build_osenv_platform
899                : "gnumake-" + input.build_platform),
900
901            configure_args: (input.build_os == "windows"
902                ? "MAKE=" + input.get("gnumake", "install_path") + "/cygwin/bin/make"
903                : "MAKE=" + input.get("gnumake", "install_path") + "/bin/make"),
904
905            environment_path: (input.build_os == "windows"
906                ? input.get("gnumake", "install_path") + "/cygwin/bin"
907                : input.get("gnumake", "install_path") + "/bin")
908        },
909
910        freetype: {
911            organization: common.organization,
912            ext: "tar.gz",
913            revision: "2.7.1-v120+1.0",
914            module: "freetype-" + input.target_platform
915        }
916    };
917
918    return dependencies;
919};
920
921/**
922 * Generate the missing platform attributes for profiles
923 *
924 * @param profiles Profiles map to generate attributes on
925 * @returns {{}} New profiles map with platform attributes fully filled in
926 */
927var generatePlatformAttributes = function (profiles) {
928    var ret = concatObjects(profiles, {});
929    for (var profile in profiles) {
930        if (ret[profile].build_os == null) {
931            ret[profile].build_os = ret[profile].target_os;
932        }
933        if (ret[profile].build_cpu == null) {
934            ret[profile].build_cpu = ret[profile].target_cpu;
935        }
936        ret[profile].target_platform = ret[profile].target_os + "_" + ret[profile].target_cpu;
937        ret[profile].build_platform = ret[profile].build_os + "_" + ret[profile].build_cpu;
938    }
939    return ret;
940};
941
942/**
943 * The default_make_targets attribute on a profile is not a real Jib attribute.
944 * This function rewrites that attribute into the corresponding configure arg.
945 * Calling this function multiple times on the same profiles object is safe.
946 *
947 * @param common Common values
948 * @param profiles Profiles map to rewrite profiles for
949 * @returns {{}} New map of profiles with the make targets converted
950 */
951var generateDefaultMakeTargetsConfigureArg = function (common, profiles) {
952    var ret = concatObjects(profiles, {});
953    for (var profile in ret) {
954        if (ret[profile]["default_make_targets"] != null) {
955            var targetsString = concat(ret[profile].default_make_targets).join(" ");
956            // Iterate over all configure args and see if --with-default-make-target
957            // is already there and change it, otherwise add it.
958            var found = false;
959            for (var i in ret[profile].configure_args) {
960                var arg = ret[profile].configure_args[i];
961                if (arg != null && arg.startsWith("--with-default-make-target=")) {
962                    found = true;
963                    ret[profile].configure_args[i]
964                        = "--with-default-make-target=" + targetsString;
965                }
966            }
967            if (!found) {
968                ret[profile].configure_args = concat(
969                    ret[profile].configure_args,
970                    "--with-default-make-target=" + targetsString);
971            }
972        }
973    }
974    return ret;
975}
976
977var getBuildId = function (input) {
978    if (input.build_id != null) {
979        return input.build_id;
980    } else {
981        var topdir = new java.io.File(__DIR__, "../..").getCanonicalFile().getName();
982        var userName = java.lang.System.getProperty("user.name");
983        return userName + "." + topdir;
984    }
985}
986
987/**
988 * Deep clones an object tree.
989 *
990 * @param o Object to clone
991 * @returns {{}} Clone of o
992 */
993var clone = function (o) {
994    return JSON.parse(JSON.stringify(o));
995};
996
997/**
998 * Concatenates all arguments into a new array
999 *
1000 * @returns {Array.<T>} New array containing all arguments
1001 */
1002var concat = function () {
1003    return Array.prototype.concat.apply([], arguments);
1004};
1005
1006/**
1007 * Takes a String or Array of Strings and does a replace operation on each
1008 * of them.
1009 *
1010 * @param pattern Pattern to look for
1011 * @param replacement Replacement text to insert
1012 * @param a String or Array of Strings to replace
1013 * @returns {Array} Either a new array or a new string depending on the input
1014 */
1015var replaceAll = function (pattern, replacement, a) {
1016    // If a is an array
1017    if (Array === a.constructor) {
1018    var newA = [];
1019    for (var i in a) {
1020            newA.push(a[i].replace(pattern, replacement));
1021        }
1022        return newA;
1023        } else {
1024        return a.replace(pattern, replacement);
1025    }
1026};
1027
1028/**
1029 * Deep concatenation of two objects. For each node encountered, merge
1030 * the contents with the corresponding node in the other object tree,
1031 * treating all strings as array elements.
1032 *
1033 * @param o1 Object to concatenate
1034 * @param o2 Object to concatenate
1035 * @returns {{}} New object tree containing the concatenation of o1 and o2
1036 */
1037var concatObjects = function (o1, o2) {
1038    if (o1 == null) {
1039        return clone(o2);
1040    }
1041    if (o2 == null) {
1042        return clone(o1);
1043    }
1044    var ret = {};
1045    for (var a in o1) {
1046        if (o2[a] == null) {
1047            ret[a] = clone(o1[a]);
1048        }
1049    }
1050    for (var a in o2) {
1051        if (o1[a] == null) {
1052            ret[a] = clone(o2[a]);
1053        } else {
1054            if (typeof o1[a] == 'string') {
1055                ret[a] = clone([o1[a]].concat(o2[a]));
1056            } else if (Array.isArray(o1[a])) {
1057                ret[a] = clone(o1[a].concat(o2[a]));
1058            } else if (typeof o1[a] == 'object') {
1059                ret[a] = concatObjects(o1[a], o2[a]);
1060            }
1061        }
1062    }
1063    return ret;
1064};
1065
1066/**
1067 * Constructs the numeric version string from reading the
1068 * common/autoconf/version-numbers file and removing all trailing ".0".
1069 *
1070 * @param major Override major version
1071 * @param minor Override minor version
1072 * @param security Override security version
1073 * @param patch Override patch version
1074 * @returns {String} The numeric version string
1075 */
1076var getVersion = function (major, minor, security, patch) {
1077    var version_numbers = getVersionNumbers();
1078    var version = (major != null ? major : version_numbers.get("DEFAULT_VERSION_MAJOR"))
1079        + "." + (minor != null ? minor : version_numbers.get("DEFAULT_VERSION_MINOR"))
1080        + "." + (security != null ? security :  version_numbers.get("DEFAULT_VERSION_SECURITY"))
1081        + "." + (patch != null ? patch : version_numbers.get("DEFAULT_VERSION_PATCH"));
1082    while (version.match(".*\\.0$")) {
1083        version = version.substring(0, version.length - 2);
1084    }
1085    return version;
1086};
1087
1088// Properties representation of the common/autoconf/version-numbers file. Lazily
1089// initiated by the function below.
1090var version_numbers;
1091
1092/**
1093 * Read the common/autoconf/version-numbers file into a Properties object.
1094 *
1095 * @returns {java.utilProperties}
1096 */
1097var getVersionNumbers = function () {
1098    // Read version information from common/autoconf/version-numbers
1099    if (version_numbers == null) {
1100        version_numbers = new java.util.Properties();
1101        var stream = new java.io.FileInputStream(__DIR__ + "/../../common/autoconf/version-numbers");
1102        version_numbers.load(stream);
1103        stream.close();
1104    }
1105    return version_numbers;
1106}
1107