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