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