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