jib-profiles.js revision 2455:688a3863c00e
1129198Scognet/*
2129198Scognet * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3139735Simp * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4129198Scognet *
5129198Scognet * This code is free software; you can redistribute it and/or modify it
6129198Scognet * under the terms of the GNU General Public License version 2 only, as
7129198Scognet * published by the Free Software Foundation.  Oracle designates this
8129198Scognet * particular file as subject to the "Classpath" exception as provided
9129198Scognet * by Oracle in the LICENSE file that accompanied this code.
10129198Scognet *
11129198Scognet * This code is distributed in the hope that it will be useful, but WITHOUT
12129198Scognet * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13129198Scognet * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14129198Scognet * version 2 for more details (a copy is included in the LICENSE file that
15129198Scognet * accompanied this code).
16129198Scognet *
17129198Scognet * You should have received a copy of the GNU General Public License version
18129198Scognet * 2 along with this work; if not, write to the Free Software Foundation,
19129198Scognet * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20129198Scognet *
21129198Scognet * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22129198Scognet * or visit www.oracle.com if you need additional information or have any
23129198Scognet * questions.
24129198Scognet */
25129198Scognet
26129198Scognet/*
27129198Scognet * This file defines build profiles for the JIB tool and others.
28129198Scognet *
29129198Scognet * A build profile defines a set of configuration options and external
30129198Scognet * dependencies that we for some reason or other care about specifically.
31129198Scognet * Typically, build profiles are defined for the build configurations we
32129198Scognet * build regularly.
33129198Scognet *
34129198Scognet * Contract against this file from the tools that use it, is to provide
35129198Scognet * a function on the form:
36129198Scognet *
37129198Scognet * getJibProfiles(input)
38129198Scognet *
39129198Scognet * which returns an object graph describing the profiles and their
40129198Scognet * dependencies. The name of the function is based on the name of this
41129198Scognet * file, minus the extension and the '-', camel cased and prefixed with
42129198Scognet * 'get'.
43129198Scognet *
44129198Scognet *
45129198Scognet * The parameter 'input' is an object that optionally contains  some data.
46129198Scognet * Optionally because a tool may read the configuration for different purposes.
47129198Scognet * To initially get a list of available profiles, the active profile may not
48129198Scognet * yet be known for instance.
49129198Scognet *
50129198Scognet * Data that may be set on the input object:
51129198Scognet *
52136382Scognet * input.profile = <name of active profile>
53136382Scognet *
54129198Scognet * If the active profile is set, the following data from it must also
55129198Scognet * be provided:
56129198Scognet *
57129198Scognet * input.profile
58129198Scognet * input.build_id
59129198Scognet * input.target_os
60129198Scognet * input.target_cpu
61129198Scognet * input.build_os
62129198Scognet * input.build_cpu
63129198Scognet * input.target_platform
64129198Scognet * input.build_platform
65129198Scognet * // The build_osenv_* variables describe the unix layer on Windows systems,
66129198Scognet * // i.e. Cygwin, which may also be 32 or 64 bit.
67129198Scognet * input.build_osenv
68129198Scognet * input.build_osenv_cpu
69129198Scognet * input.build_osenv_platform
70129198Scognet *
71129198Scognet * For more complex nested attributes, there is a method "get":
72129198Scognet *
73129198Scognet * input.get("<dependency>", "<attribute>")
74135666Scognet *
75129198Scognet * Valid attributes are:
76129198Scognet * install_path
77129198Scognet * download_path
78129198Scognet * download_dir
79129198Scognet *
80129198Scognet *
81129198Scognet * The output data generated by this configuration file has the following
82129198Scognet * format:
83129198Scognet *
84129198Scognet * data: {
85129198Scognet *   // Identifies the version of this format to the tool reading it
86129198Scognet *   format_version: "1.0",
87129198Scognet *
88129198Scognet *   // Name of base outputdir. JIB assumes the actual output dir is formed
89129198Scognet *   // by adding the configuration name: <output_basedir>/<config-name>
90129198Scognet *   output_basedir: "build",
91129198Scognet *   // Configure argument to use to specify configuration name
92129198Scognet *   configuration_configure_arg:
93129198Scognet *   // Make argument to use to specify configuration name
94129198Scognet *   configuration_make_arg:
95129198Scognet *
96129198Scognet *   profiles: {
97129198Scognet *     <profile-name>: {
98129198Scognet *       // Name of os the profile is built to run on
99129198Scognet *       target_os; <string>
100129198Scognet *       // Name of cpu the profile is built to run on
101129198Scognet *       target_cpu; <string>
102129198Scognet *       // Combination of target_os and target_cpu for convenience
103135666Scognet *       target_platform; <string>
104135666Scognet *       // Name of os the profile is built on
105135666Scognet *       build_os; <string>
106129198Scognet *       // Name of cpu the profile is built on
107129198Scognet *       build_cpu; <string>
108129198Scognet *       // Combination of build_os and build_cpu for convenience
109129198Scognet *       build_platform; <string>
110129198Scognet *
111129198Scognet *       // List of dependencies needed to build this profile
112129198Scognet *       dependencies: <Array of strings>
113129198Scognet *
114129198Scognet *       // List of configure args to use for this profile
115129198Scognet *       configure_args: <Array of strings>
116129198Scognet *
117129198Scognet *       // List of free form labels describing aspects of this profile
118129198Scognet *       labels: <Array of strings>
119129198Scognet *     }
120129198Scognet *   }
121129198Scognet *
122129198Scognet *   // Dependencies use a Maven like deployment structure
123129198Scognet *   dependencies: {
124129198Scognet *     <dependency-name>: {
125129198Scognet *       // Organization part of path defining this dependency
126129198Scognet *       organization: <string>
127129198Scognet *       // File extension for this dependency
128129198Scognet *       ext: <string>
129129198Scognet *       // Module part of path for defining this dependency,
130129198Scognet *       // defaults to <dependency-name>
131129198Scognet *       module: <string>
132129198Scognet *       // Revision part of path for defining this dependency
133129198Scognet *       revision: <string>
134129198Scognet *
135129198Scognet *       // List of configure args to add when using this dependency,
136136382Scognet *       // defaults to
137139022Scognet *       // "--with-<dependency-name>=input.get("<dependency-name", "install_path")"
138136382Scognet *       configure_args: <array of strings>
139129198Scognet *
140129198Scognet *       // Name of environment variable to set when using this dependency
141129198Scognet *       // when running make
142129198Scognet *       environment_name: <string>
143129198Scognet *       // Value of environment variable to set when using this dependency
144129198Scognet *       // when running make
145129198Scognet *       environment_value: <string>
146129198Scognet *
147129198Scognet *       // Value to add to the PATH variable when using this dependency,
148129198Scognet *       // applies to both make and configure
149129198Scognet *       environment_path: <string>
150129198Scognet *     }
151129198Scognet *
152129198Scognet *     <dependency-name>: {
153129198Scognet *       // For certain dependencies where a legacy distribution mechanism is
154129198Scognet *       // already in place, the "javare" server layout is also supported
155129198Scognet *       // Indicate that an alternate server source and layout should be used
156129198Scognet *       server: "javare"
157129198Scognet *
158129198Scognet *       // For "javare", a combination of module, revision,
159129198Scognet *       // build number (optional), files and checksum file is possible for
160129198Scognet *       // artifacts following the standard layout.
161129198Scognet *       module: <string>
162129198Scognet *       revision: <string>
163135666Scognet *       build_number: <string>
164135666Scognet *       checksum_file: <string>
165135666Scognet *       file: <string>
166135666Scognet *
167135666Scognet *       // For other files, use checksum path and path instead
168135666Scognet *       checksum_path: <string>
169135666Scognet *       path: <string>
170135666Scognet *     }
171135666Scognet *   }
172135666Scognet * }
173135666Scognet */
174135666Scognet
175135666Scognet/**
176129198Scognet * Main entry to generate the profile configuration
177129198Scognet *
178129198Scognet * @param input External data to use for generating the configuration
179129198Scognet * @returns {{}} Profile configuration
180129198Scognet */
181129198Scognetvar getJibProfiles = function (input) {
182129198Scognet
183129198Scognet    var data = {};
184129198Scognet
185129198Scognet    // Identifies the version of this format to the tool reading it.
186129198Scognet    // 1.1 signifies that the publish, publish-src and get-src features are usable.
187129198Scognet    data.format_version = "1.1";
188129198Scognet
189135666Scognet    // Organization, product and version are used when uploading/publishing build results
190129198Scognet    data.organization = "";
191129198Scognet    data.product = "jdk";
192129198Scognet    data.version = getVersion();
193129198Scognet
194129198Scognet    // The base directory for the build output. JIB will assume that the
195129198Scognet    // actual build directory will be <output_basedir>/<configuration>
196129198Scognet    data.output_basedir = "build";
197129198Scognet    // The configure argument to use to specify the name of the configuration
198129198Scognet    data.configuration_configure_arg = "--with-conf-name=";
199129198Scognet    // The make argument to use to specify the name of the configuration
200129198Scognet    data.configuration_make_arg = "CONF_NAME=";
201129198Scognet
202129198Scognet    // Exclude list to use when Jib creates a source bundle
203129198Scognet    data.src_bundle_excludes = "./build webrev .hg */.hg */*/.hg */*/*/.hg";
204129198Scognet    // Include list to use when creating a minimal jib source bundle which
205129198Scognet    // contains just the jib configuration files.
206129198Scognet    data.conf_bundle_includes = "*/conf/jib-profiles.* common/autoconf/version-numbers"
207129198Scognet
208129198Scognet    // Define some common values
209129198Scognet    var common = getJibProfilesCommon(input, data);
210129198Scognet    // Generate the profiles part of the configuration
211129198Scognet    data.profiles = getJibProfilesProfiles(input, common, data);
212129198Scognet    // Generate the dependencies part of the configuration
213129198Scognet    data.dependencies = getJibProfilesDependencies(input, common, data);
214129198Scognet
215129198Scognet    return data;
216129198Scognet};
217129198Scognet
218129198Scognet/**
219129198Scognet * Generates some common values
220129198Scognet *
221129198Scognet * @param input External data to use for generating the configuration
222129198Scognet * @returns Common values
223129198Scognet */
224136382Scognetvar getJibProfilesCommon = function (input, data) {
225129198Scognet    var common = {};
226129198Scognet
227129198Scognet    common.organization = "jpg.infra.builddeps";
228129198Scognet    common.build_id = getBuildId(input);
229129198Scognet    common.build_number = input.build_number != null ? input.build_number : "0";
230129198Scognet
231129198Scognet    // List of the main profile names used for iteration
232129198Scognet    common.main_profile_names = [
233129198Scognet        "linux-x64", "linux-x86", "macosx-x64", "solaris-x64",
234129198Scognet        "solaris-sparcv9", "windows-x64", "windows-x86"
235129198Scognet    ];
236129198Scognet
237129198Scognet    // These are the base setttings for all the main build profiles.
238129198Scognet    common.main_profile_base = {
239129198Scognet        dependencies: ["boot_jdk", "gnumake", "jtreg"],
240129198Scognet        default_make_targets: ["product-bundles", "test-bundles"],
241129198Scognet        configure_args: [
242129198Scognet            "--with-version-opt=" + common.build_id,
243129198Scognet            "--enable-jtreg-failure-handler",
244129198Scognet            "--with-version-build=" + common.build_number
245129198Scognet        ]
246129198Scognet    };
247129198Scognet    // Extra settings for debug profiles
248129198Scognet    common.debug_suffix = "-debug";
249129198Scognet    common.debug_profile_base = {
250129198Scognet        configure_args: ["--enable-debug"],
251129198Scognet        labels: "debug"
252129198Scognet    };
253129198Scognet    // Extra settings for slowdebug profiles
254129198Scognet    common.slowdebug_suffix = "-slowdebug";
255129198Scognet    common.slowdebug_profile_base = {
256129198Scognet        configure_args: ["--with-debug-level=slowdebug"],
257129198Scognet        labels: "slowdebug"
258129198Scognet    };
259129198Scognet    // Extra settings for openjdk only profiles
260129198Scognet    common.open_suffix = "-open";
261129198Scognet    common.open_profile_base = {
262129198Scognet        configure_args: ["--enable-openjdk-only"],
263129198Scognet        labels: "open"
264129198Scognet    };
265129198Scognet
266129198Scognet    common.configure_args_64bit = ["--with-target-bits=64"];
267129198Scognet    common.configure_args_32bit = ["--with-target-bits=32"];
268129198Scognet
269129198Scognet    /**
270129198Scognet     * Define common artifacts template for all main profiles
271129198Scognet     * @param pf - Name of platform in bundle names
272129198Scognet     * @param demo_ext - Type of extension for demo bundle
273129198Scognet     */
274129198Scognet    common.main_profile_artifacts = function (pf, demo_ext) {
275129198Scognet        return {
276129198Scognet            artifacts: {
277137912Sdas                jdk: {
278129198Scognet                    local: "bundles/\\(jdk.*bin.tar.gz\\)",
279129198Scognet                    remote: [
280129198Scognet                        "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin.tar.gz",
281129198Scognet                        "bundles/" + pf + "/\\1"
282129198Scognet                    ],
283129198Scognet                    subdir: "jdk-" + data.version,
284129198Scognet                    exploded: "images/jdk"
285129198Scognet                },
286129198Scognet                jre: {
287129198Scognet                    local: "bundles/\\(jre.*bin.tar.gz\\)",
288129198Scognet                    remote: [
289129198Scognet                        "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin.tar.gz",
290129198Scognet                        "bundles/" + pf + "/\\1"
291129198Scognet                    ],
292129198Scognet                    subdir: "jre-" + data.version,
293129198Scognet                    exploded: "images/jre"
294129198Scognet                },
295129198Scognet                test: {
296129198Scognet                    local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
297129198Scognet                    remote: [
298129198Scognet                        "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-tests.tar.gz",
299129198Scognet                        "bundles/" + pf + "/\\1"
300129198Scognet                    ],
301135666Scognet                    exploded: "images/test"
302135666Scognet                },
303129198Scognet                jdk_symbols: {
304129198Scognet                    local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
305129198Scognet                    remote: [
306129198Scognet                        "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-symbols.tar.gz",
307129198Scognet                        "bundles/" + pf + "/\\1"
308129198Scognet                    ],
309129198Scognet                    subdir: "jdk-" + data.version,
310129198Scognet                    exploded: "images/jdk"
311129198Scognet                },
312129198Scognet                jre_symbols: {
313129198Scognet                    local: "bundles/\\(jre.*bin-symbols.tar.gz\\)",
314129198Scognet                    remote: [
315136382Scognet                        "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin-symbols.tar.gz",
316129198Scognet                        "bundles/" + pf + "/\\1"
317129198Scognet                    ],
318129198Scognet                    subdir: "jre-" + data.version,
319129198Scognet                    exploded: "images/jre"
320129198Scognet                },
321129198Scognet                demo: {
322129198Scognet                    local: "bundles/\\(jdk.*demo." + demo_ext + "\\)",
323129198Scognet                    remote: [
324129198Scognet                        "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_demo." + demo_ext,
325129198Scognet                        "bundles/" + pf + "/\\1"
326129198Scognet                    ],
327129198Scognet                }
328129198Scognet            }
329129198Scognet        };
330129198Scognet    };
331129198Scognet
332129198Scognet
333129198Scognet    /**
334129198Scognet     * Define common artifacts template for all debug profiles
335129198Scognet     * @param pf - Name of platform in bundle names
336129198Scognet     */
337129198Scognet    common.debug_profile_artifacts = function (pf) {
338129198Scognet        return {
339129198Scognet            artifacts: {
340129198Scognet                jdk: {
341129198Scognet                    local: "bundles/\\(jdk.*bin-debug.tar.gz\\)",
342129198Scognet                    remote: [
343129198Scognet                        "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-debug.tar.gz",
344129198Scognet                        "bundles/" + pf + "/\\1"
345129198Scognet                    ],
346129198Scognet                    subdir: "jdk-" + data.version,
347129198Scognet                    exploded: "images/jdk"
348129198Scognet                },
349129198Scognet                jre: {
350129198Scognet                    local: "bundles/\\(jre.*bin-debug.tar.gz\\)",
351129198Scognet                    remote: [
352129198Scognet                        "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin-debug.tar.gz",
353130645Scognet                        "bundles/" + pf + "/\\1"
354129198Scognet                    ],
355129198Scognet                    subdir: "jre-" + data.version,
356129198Scognet                    exploded: "images/jre"
357129198Scognet                },
358129198Scognet                test: {
359129198Scognet                    local: "bundles/\\(jdk.*bin-tests-debug.tar.gz\\)",
360129198Scognet                    remote: [
361129198Scognet                        "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-tests-debug.tar.gz",
362129198Scognet                        "bundles/" + pf + "/\\1"
363129198Scognet                    ],
364129198Scognet                    exploded: "images/test"
365129198Scognet                },
366129198Scognet                jdk_symbols: {
367129198Scognet                    local: "bundles/\\(jdk.*bin-debug-symbols.tar.gz\\)",
368129198Scognet                    remote: [
369129198Scognet                        "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-debug-symbols.tar.gz",
370129198Scognet                        "bundles/" + pf + "/\\1"
371129198Scognet                    ],
372129198Scognet                    subdir: "jdk-" + data.version,
373129198Scognet                    exploded: "images/jdk"
374129198Scognet                },
375129198Scognet                jre_symbols: {
376129198Scognet                    local: "bundles/\\(jre.*bin-debug-symbols.tar.gz\\)",
377129198Scognet                    remote: [
378129198Scognet                        "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin-debug-symbols.tar.gz",
379129198Scognet                        "bundles/" + pf + "/\\1"
380129198Scognet                    ],
381129198Scognet                    subdir: "jre-" + data.version,
382129198Scognet                    exploded: "images/jre"
383129198Scognet                }
384129198Scognet            }
385129198Scognet        };
386129198Scognet    };
387134791Sjulian
388129198Scognet    var boot_jdk_revision = "8";
389129198Scognet    var boot_jdk_subdirpart = "1.8.0";
390129198Scognet    // JDK 8 does not work on sparc M7 cpus, need a newer update when building
391129198Scognet    // on such hardware.
392129198Scognet    if (input.build_cpu == "sparcv9") {
393129198Scognet       var cpu_brand = $EXEC("bash -c \"kstat -m cpu_info | grep brand | head -n1 | awk '{ print \$2 }'\"");
394129198Scognet       if (cpu_brand.trim() == 'SPARC-M7') {
395129198Scognet           boot_jdk_revision = "8u20";
396129198Scognet           boot_jdk_subdirpart = "1.8.0_20";
397129198Scognet       }
398129198Scognet    }
399129198Scognet    common.boot_jdk_revision = boot_jdk_revision;
400129198Scognet    common.boot_jdk_subdirpart = boot_jdk_subdirpart;
401135666Scognet    common.boot_jdk_home = input.get("boot_jdk", "home_path") + "/jdk"
402129198Scognet        + common.boot_jdk_subdirpart
403139022Scognet        + (input.build_os == "macosx" ? ".jdk/Contents/Home" : "");
404135666Scognet
405129198Scognet    return common;
406129198Scognet};
407129198Scognet
408129198Scognet/**
409129198Scognet * Generates the profiles part of the configuration.
410139022Scognet *
411129198Scognet * @param input External data to use for generating the configuration
412129198Scognet * @param common The common values
413129198Scognet * @returns {{}} Profiles part of the configuration
414129198Scognet */
415129198Scognetvar getJibProfilesProfiles = function (input, common, data) {
416129198Scognet    // Main SE profiles
417129198Scognet    var profiles = {
418135666Scognet
419129198Scognet        "linux-x64": {
420137939Scognet            target_os: "linux",
421137939Scognet            target_cpu: "x64",
422129198Scognet            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" ],
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" ],
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", 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
919    return dependencies;
920};
921
922/**
923 * Generate the missing platform attributes for profiles
924 *
925 * @param profiles Profiles map to generate attributes on
926 * @returns {{}} New profiles map with platform attributes fully filled in
927 */
928var generatePlatformAttributes = function (profiles) {
929    var ret = concatObjects(profiles, {});
930    for (var profile in profiles) {
931        if (ret[profile].build_os == null) {
932            ret[profile].build_os = ret[profile].target_os;
933        }
934        if (ret[profile].build_cpu == null) {
935            ret[profile].build_cpu = ret[profile].target_cpu;
936        }
937        ret[profile].target_platform = ret[profile].target_os + "_" + ret[profile].target_cpu;
938        ret[profile].build_platform = ret[profile].build_os + "_" + ret[profile].build_cpu;
939    }
940    return ret;
941};
942
943/**
944 * The default_make_targets attribute on a profile is not a real Jib attribute.
945 * This function rewrites that attribute into the corresponding configure arg.
946 * Calling this function multiple times on the same profiles object is safe.
947 *
948 * @param common Common values
949 * @param profiles Profiles map to rewrite profiles for
950 * @returns {{}} New map of profiles with the make targets converted
951 */
952var generateDefaultMakeTargetsConfigureArg = function (common, profiles) {
953    var ret = concatObjects(profiles, {});
954    for (var profile in ret) {
955        if (ret[profile]["default_make_targets"] != null) {
956            var targetsString = concat(ret[profile].default_make_targets).join(" ");
957            // Iterate over all configure args and see if --with-default-make-target
958            // is already there and change it, otherwise add it.
959            var found = false;
960            for (var i in ret[profile].configure_args) {
961                var arg = ret[profile].configure_args[i];
962                if (arg != null && arg.startsWith("--with-default-make-target=")) {
963                    found = true;
964                    ret[profile].configure_args[i]
965                        = "--with-default-make-target=" + targetsString;
966                }
967            }
968            if (!found) {
969                ret[profile].configure_args = concat(
970                    ret[profile].configure_args,
971                    "--with-default-make-target=" + targetsString);
972            }
973        }
974    }
975    return ret;
976}
977
978var getBuildId = function (input) {
979    if (input.build_id != null) {
980        return input.build_id;
981    } else {
982        var topdir = new java.io.File(__DIR__, "../..").getCanonicalFile().getName();
983        var userName = java.lang.System.getProperty("user.name");
984        return userName + "." + topdir;
985    }
986}
987
988/**
989 * Deep clones an object tree.
990 *
991 * @param o Object to clone
992 * @returns {{}} Clone of o
993 */
994var clone = function (o) {
995    return JSON.parse(JSON.stringify(o));
996};
997
998/**
999 * Concatenates all arguments into a new array
1000 *
1001 * @returns {Array.<T>} New array containing all arguments
1002 */
1003var concat = function () {
1004    return Array.prototype.concat.apply([], arguments);
1005};
1006
1007/**
1008 * Takes a String or Array of Strings and does a replace operation on each
1009 * of them.
1010 *
1011 * @param pattern Pattern to look for
1012 * @param replacement Replacement text to insert
1013 * @param a String or Array of Strings to replace
1014 * @returns {Array} Either a new array or a new string depending on the input
1015 */
1016var replaceAll = function (pattern, replacement, a) {
1017    // If a is an array
1018    if (Array === a.constructor) {
1019    var newA = [];
1020    for (var i in a) {
1021            newA.push(a[i].replace(pattern, replacement));
1022        }
1023        return newA;
1024        } else {
1025        return a.replace(pattern, replacement);
1026    }
1027};
1028
1029/**
1030 * Deep concatenation of two objects. For each node encountered, merge
1031 * the contents with the corresponding node in the other object tree,
1032 * treating all strings as array elements.
1033 *
1034 * @param o1 Object to concatenate
1035 * @param o2 Object to concatenate
1036 * @returns {{}} New object tree containing the concatenation of o1 and o2
1037 */
1038var concatObjects = function (o1, o2) {
1039    if (o1 == null) {
1040        return clone(o2);
1041    }
1042    if (o2 == null) {
1043        return clone(o1);
1044    }
1045    var ret = {};
1046    for (var a in o1) {
1047        if (o2[a] == null) {
1048            ret[a] = clone(o1[a]);
1049        }
1050    }
1051    for (var a in o2) {
1052        if (o1[a] == null) {
1053            ret[a] = clone(o2[a]);
1054        } else {
1055            if (typeof o1[a] == 'string') {
1056                ret[a] = clone([o1[a]].concat(o2[a]));
1057            } else if (Array.isArray(o1[a])) {
1058                ret[a] = clone(o1[a].concat(o2[a]));
1059            } else if (typeof o1[a] == 'object') {
1060                ret[a] = concatObjects(o1[a], o2[a]);
1061            }
1062        }
1063    }
1064    return ret;
1065};
1066
1067/**
1068 * Constructs the numeric version string from reading the
1069 * common/autoconf/version-numbers file and removing all trailing ".0".
1070 *
1071 * @param major Override major version
1072 * @param minor Override minor version
1073 * @param security Override security version
1074 * @param patch Override patch version
1075 * @returns {String} The numeric version string
1076 */
1077var getVersion = function (major, minor, security, patch) {
1078    var version_numbers = getVersionNumbers();
1079    var version = (major != null ? major : version_numbers.get("DEFAULT_VERSION_MAJOR"))
1080        + "." + (minor != null ? minor : version_numbers.get("DEFAULT_VERSION_MINOR"))
1081        + "." + (security != null ? security :  version_numbers.get("DEFAULT_VERSION_SECURITY"))
1082        + "." + (patch != null ? patch : version_numbers.get("DEFAULT_VERSION_PATCH"));
1083    while (version.match(".*\.0$")) {
1084        version = version.substring(0, version.length - 2);
1085    }
1086    return version;
1087};
1088
1089// Properties representation of the common/autoconf/version-numbers file. Lazily
1090// initiated by the function below.
1091var version_numbers;
1092
1093/**
1094 * Read the common/autoconf/version-numbers file into a Properties object.
1095 *
1096 * @returns {java.utilProperties}
1097 */
1098var getVersionNumbers = function () {
1099    // Read version information from common/autoconf/version-numbers
1100    if (version_numbers == null) {
1101        version_numbers = new java.util.Properties();
1102        var stream = new java.io.FileInputStream(__DIR__ + "/../../common/autoconf/version-numbers");
1103        version_numbers.load(stream);
1104        stream.close();
1105    }
1106    return version_numbers;
1107}
1108