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