jib-profiles.js revision 2713:21142069b8ea
1364860Shselasky/*
2364860Shselasky * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
3364860Shselasky * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4364860Shselasky *
5364860Shselasky * This code is free software; you can redistribute it and/or modify it
6364860Shselasky * under the terms of the GNU General Public License version 2 only, as
7364860Shselasky * published by the Free Software Foundation.  Oracle designates this
8364860Shselasky * particular file as subject to the "Classpath" exception as provided
9364860Shselasky * by Oracle in the LICENSE file that accompanied this code.
10364860Shselasky *
11364860Shselasky * This code is distributed in the hope that it will be useful, but WITHOUT
12364860Shselasky * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13364860Shselasky * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14364860Shselasky * version 2 for more details (a copy is included in the LICENSE file that
15364860Shselasky * accompanied this code).
16364860Shselasky *
17364860Shselasky * You should have received a copy of the GNU General Public License version
18364860Shselasky * 2 along with this work; if not, write to the Free Software Foundation,
19364860Shselasky * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20364860Shselasky *
21364860Shselasky * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22364860Shselasky * or visit www.oracle.com if you need additional information or have any
23364860Shselasky * questions.
24364860Shselasky */
25364860Shselasky
26364860Shselasky/*
27364860Shselasky * This file defines build profiles for the JIB tool and others.
28364860Shselasky *
29364860Shselasky * A build profile defines a set of configuration options and external
30364860Shselasky * dependencies that we for some reason or other care about specifically.
31364860Shselasky * Typically, build profiles are defined for the build configurations we
32364860Shselasky * build regularly.
33364860Shselasky *
34364860Shselasky * Contract against this file from the tools that use it, is to provide
35364860Shselasky * a function on the form:
36364860Shselasky *
37364860Shselasky * getJibProfiles(input)
38364860Shselasky *
39364860Shselasky * which returns an object graph describing the profiles and their
40364860Shselasky * dependencies. The name of the function is based on the name of this
41364860Shselasky * file, minus the extension and the '-', camel cased and prefixed with
42364860Shselasky * 'get'.
43364860Shselasky *
44364860Shselasky *
45364860Shselasky * The parameter 'input' is an object that optionally contains  some data.
46364860Shselasky * Optionally because a tool may read the configuration for different purposes.
47364860Shselasky * To initially get a list of available profiles, the active profile may not
48364860Shselasky * yet be known for instance.
49364860Shselasky *
50364860Shselasky * Data that may be set on the input object:
51364860Shselasky *
52364860Shselasky * input.profile = <name of active profile>
53364860Shselasky *
54364860Shselasky * If the active profile is set, the following data from it must also
55364860Shselasky * be provided:
56364860Shselasky *
57364860Shselasky * input.profile
58364860Shselasky * input.build_id
59364860Shselasky * input.target_os
60364860Shselasky * input.target_cpu
61364860Shselasky * input.build_os
62364860Shselasky * input.build_cpu
63364860Shselasky * input.target_platform
64364860Shselasky * input.build_platform
65364860Shselasky * // The build_osenv_* variables describe the unix layer on Windows systems,
66364860Shselasky * // i.e. Cygwin, which may also be 32 or 64 bit.
67364860Shselasky * input.build_osenv
68364860Shselasky * input.build_osenv_cpu
69364860Shselasky * input.build_osenv_platform
70364860Shselasky *
71364860Shselasky * For more complex nested attributes, there is a method "get":
72364860Shselasky *
73364860Shselasky * input.get("<dependency>", "<attribute>")
74364860Shselasky *
75364860Shselasky * Valid attributes are:
76364860Shselasky * install_path
77364860Shselasky * download_path
78364860Shselasky * download_dir
79364860Shselasky *
80364860Shselasky *
81364860Shselasky * The output data generated by this configuration file has the following
82367557Shselasky * format:
83364860Shselasky *
84364860Shselasky * data: {
85364860Shselasky *   // Identifies the version of this format to the tool reading it
86364860Shselasky *   format_version: "1.0",
87364860Shselasky *
88364860Shselasky *   // Name of base outputdir. JIB assumes the actual output dir is formed
89364860Shselasky *   // by adding the configuration name: <output_basedir>/<config-name>
90364860Shselasky *   output_basedir: "build",
91364860Shselasky *   // Configure argument to use to specify configuration name
92364860Shselasky *   configuration_configure_arg:
93364860Shselasky *   // Make argument to use to specify configuration name
94364860Shselasky *   configuration_make_arg:
95364860Shselasky *
96364860Shselasky *   profiles: {
97364860Shselasky *     <profile-name>: {
98364860Shselasky *       // Name of os the profile is built to run on
99364860Shselasky *       target_os; <string>
100364860Shselasky *       // Name of cpu the profile is built to run on
101364860Shselasky *       target_cpu; <string>
102364860Shselasky *       // Combination of target_os and target_cpu for convenience
103364860Shselasky *       target_platform; <string>
104364860Shselasky *       // Name of os the profile is built on
105364860Shselasky *       build_os; <string>
106364860Shselasky *       // Name of cpu the profile is built on
107364860Shselasky *       build_cpu; <string>
108364860Shselasky *       // Combination of build_os and build_cpu for convenience
109364860Shselasky *       build_platform; <string>
110364860Shselasky *
111364860Shselasky *       // List of dependencies needed to build this profile
112364860Shselasky *       dependencies: <Array of strings>
113364860Shselasky *
114364860Shselasky *       // List of configure args to use for this profile
115364860Shselasky *       configure_args: <Array of strings>
116364860Shselasky *
117364860Shselasky *       // List of free form labels describing aspects of this profile
118364860Shselasky *       labels: <Array of strings>
119364860Shselasky *     }
120364860Shselasky *   }
121364860Shselasky *
122364860Shselasky *   // Dependencies use a Maven like deployment structure
123364860Shselasky *   dependencies: {
124364860Shselasky *     <dependency-name>: {
125364860Shselasky *       // Organization part of path defining this dependency
126364860Shselasky *       organization: <string>
127364860Shselasky *       // File extension for this dependency
128364860Shselasky *       ext: <string>
129364860Shselasky *       // Module part of path for defining this dependency,
130364860Shselasky *       // defaults to <dependency-name>
131364860Shselasky *       module: <string>
132364860Shselasky *       // Revision part of path for defining this dependency
133364860Shselasky *       revision: <string>
134364860Shselasky *
135364860Shselasky *       // List of configure args to add when using this dependency,
136364860Shselasky *       // defaults to
137364860Shselasky *       // "--with-<dependency-name>=input.get("<dependency-name", "install_path")"
138364860Shselasky *       configure_args: <array of strings>
139364860Shselasky *
140364860Shselasky *       // Name of environment variable to set when using this dependency
141364860Shselasky *       // when running make
142364860Shselasky *       environment_name: <string>
143364860Shselasky *       // Value of environment variable to set when using this dependency
144364860Shselasky *       // when running make
145364860Shselasky *       environment_value: <string>
146364860Shselasky *
147364860Shselasky *       // Value to add to the PATH variable when using this dependency,
148364860Shselasky *       // applies to both make and configure
149364860Shselasky *       environment_path: <string>
150364860Shselasky *     }
151364860Shselasky *
152364860Shselasky *     <dependency-name>: {
153364860Shselasky *       // For certain dependencies where a legacy distribution mechanism is
154364860Shselasky *       // already in place, the "javare" server layout is also supported
155364860Shselasky *       // Indicate that an alternate server source and layout should be used
156364860Shselasky *       server: "javare"
157364860Shselasky *
158364860Shselasky *       // For "javare", a combination of module, revision,
159364860Shselasky *       // build number (optional), files and checksum file is possible for
160364860Shselasky *       // artifacts following the standard layout.
161364860Shselasky *       module: <string>
162364860Shselasky *       revision: <string>
163364860Shselasky *       build_number: <string>
164364860Shselasky *       checksum_file: <string>
165364860Shselasky *       file: <string>
166364860Shselasky *
167364860Shselasky *       // For other files, use checksum path and path instead
168364860Shselasky *       checksum_path: <string>
169364860Shselasky *       path: <string>
170364860Shselasky *     }
171364860Shselasky *   }
172364860Shselasky * }
173364860Shselasky */
174364860Shselasky
175364860Shselasky/**
176364860Shselasky * Main entry to generate the profile configuration
177364860Shselasky *
178364860Shselasky * @param input External data to use for generating the configuration
179364860Shselasky * @returns {{}} Profile configuration
180364860Shselasky */
181364860Shselaskyvar getJibProfiles = function (input) {
182364860Shselasky
183364860Shselasky    var data = {};
184364860Shselasky
185364860Shselasky    // Identifies the version of this format to the tool reading it.
186364860Shselasky    // 1.1 signifies that the publish, publish-src and get-src features are usable.
187364860Shselasky    data.format_version = "1.1";
188364860Shselasky
189364860Shselasky    // Organization, product and version are used when uploading/publishing build results
190364860Shselasky    data.organization = "";
191364860Shselasky    data.product = "jdk";
192364860Shselasky    data.version = getVersion();
193364860Shselasky
194364860Shselasky    // The base directory for the build output. JIB will assume that the
195364860Shselasky    // actual build directory will be <output_basedir>/<configuration>
196364860Shselasky    data.output_basedir = "build";
197364860Shselasky    // The configure argument to use to specify the name of the configuration
198364860Shselasky    data.configuration_configure_arg = "--with-conf-name=";
199364860Shselasky    // The make argument to use to specify the name of the configuration
200364860Shselasky    data.configuration_make_arg = "CONF_NAME=";
201364860Shselasky
202364860Shselasky    // Exclude list to use when Jib creates a source bundle
203364860Shselasky    data.src_bundle_excludes = "./build webrev .hg */.hg */*/.hg */*/*/.hg";
204364860Shselasky    // Include list to use when creating a minimal jib source bundle which
205364860Shselasky    // contains just the jib configuration files.
206364860Shselasky    data.conf_bundle_includes = "*/conf/jib-profiles.* common/autoconf/version-numbers"
207364860Shselasky
208364860Shselasky    // Define some common values
209364860Shselasky    var common = getJibProfilesCommon(input, data);
210364860Shselasky    // Generate the profiles part of the configuration
211364860Shselasky    data.profiles = getJibProfilesProfiles(input, common, data);
212364860Shselasky    // Generate the dependencies part of the configuration
213364860Shselasky    data.dependencies = getJibProfilesDependencies(input, common, data);
214364860Shselasky
215364860Shselasky    return data;
216364860Shselasky};
217364860Shselasky
218364860Shselasky/**
219364860Shselasky * Generates some common values
220364860Shselasky *
221364860Shselasky * @param input External data to use for generating the configuration
222364860Shselasky * @returns Common values
223364860Shselasky */
224364860Shselaskyvar getJibProfilesCommon = function (input, data) {
225364860Shselasky    var common = {};
226364860Shselasky
227364860Shselasky    common.organization = "jpg.infra.builddeps";
228364860Shselasky    common.build_id = getBuildId(input);
229364860Shselasky    common.build_number = input.build_number != null ? input.build_number : "0";
230364860Shselasky
231364860Shselasky    // List of the main profile names used for iteration
232364860Shselasky    common.main_profile_names = [
233364860Shselasky        "linux-x64", "linux-x86", "macosx-x64", "solaris-x64",
234364860Shselasky        "solaris-sparcv9", "windows-x64", "windows-x86"
235364860Shselasky    ];
236364860Shselasky
237364860Shselasky    // These are the base setttings for all the main build profiles.
238364860Shselasky    common.main_profile_base = {
239364860Shselasky        dependencies: ["boot_jdk", "gnumake", "jtreg"],
240364860Shselasky        default_make_targets: ["product-bundles", "test-bundles"],
241364860Shselasky        configure_args: [
242364860Shselasky            "--with-version-opt=" + common.build_id,
243364860Shselasky            "--enable-jtreg-failure-handler",
244364860Shselasky            "--with-version-build=" + common.build_number
245364860Shselasky        ]
246364860Shselasky    };
247364860Shselasky    // Extra settings for debug profiles
248364860Shselasky    common.debug_suffix = "-debug";
249364860Shselasky    common.debug_profile_base = {
250364860Shselasky        configure_args: ["--enable-debug"],
251364860Shselasky        labels: "debug"
252364860Shselasky    };
253364860Shselasky    // Extra settings for slowdebug profiles
254364860Shselasky    common.slowdebug_suffix = "-slowdebug";
255364860Shselasky    common.slowdebug_profile_base = {
256364860Shselasky        configure_args: ["--with-debug-level=slowdebug"],
257364860Shselasky        labels: "slowdebug"
258364860Shselasky    };
259364860Shselasky    // Extra settings for openjdk only profiles
260364860Shselasky    common.open_suffix = "-open";
261364860Shselasky    common.open_profile_base = {
262364860Shselasky        configure_args: ["--enable-openjdk-only"],
263364860Shselasky        labels: "open"
264364860Shselasky    };
265364860Shselasky
266364860Shselasky    common.configure_args_64bit = ["--with-target-bits=64"];
267364860Shselasky    common.configure_args_32bit = ["--with-target-bits=32"];
268364860Shselasky
269364860Shselasky    /**
270364860Shselasky     * Define common artifacts template for all main profiles
271364860Shselasky     * @param pf - Name of platform in bundle names
272364860Shselasky     * @param demo_ext - Type of extension for demo bundle
273364860Shselasky     */
274364860Shselasky    common.main_profile_artifacts = function (pf, demo_ext) {
275364860Shselasky        return {
276364860Shselasky            artifacts: {
277364860Shselasky                jdk: {
278364860Shselasky                    local: "bundles/\\(jdk.*bin.tar.gz\\)",
279364860Shselasky                    remote: [
280364860Shselasky                        "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin.tar.gz",
281364860Shselasky                        "bundles/" + pf + "/\\1"
282364860Shselasky                    ],
283364860Shselasky                    subdir: "jdk-" + data.version,
284364860Shselasky                    exploded: "images/jdk"
285364860Shselasky                },
286364860Shselasky                jre: {
287364860Shselasky                    local: "bundles/\\(jre.*bin.tar.gz\\)",
288364860Shselasky                    remote: [
289364860Shselasky                        "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin.tar.gz",
290364860Shselasky                        "bundles/" + pf + "/\\1"
291364860Shselasky                    ],
292364860Shselasky                    subdir: "jre-" + data.version,
293364860Shselasky                    exploded: "images/jre"
294364860Shselasky                },
295364860Shselasky                test: {
296364860Shselasky                    local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
297364860Shselasky                    remote: [
298364860Shselasky                        "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-tests.tar.gz",
299364860Shselasky                        "bundles/" + pf + "/\\1"
300364860Shselasky                    ],
301364860Shselasky                    exploded: "images/test"
302364860Shselasky                },
303364860Shselasky                jdk_symbols: {
304364860Shselasky                    local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
305364860Shselasky                    remote: [
306364860Shselasky                        "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-symbols.tar.gz",
307364860Shselasky                        "bundles/" + pf + "/\\1"
308364860Shselasky                    ],
309364860Shselasky                    subdir: "jdk-" + data.version,
310364860Shselasky                    exploded: "images/jdk"
311364860Shselasky                },
312364860Shselasky                jre_symbols: {
313364860Shselasky                    local: "bundles/\\(jre.*bin-symbols.tar.gz\\)",
314364860Shselasky                    remote: [
315364860Shselasky                        "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin-symbols.tar.gz",
316364860Shselasky                        "bundles/" + pf + "/\\1"
317364860Shselasky                    ],
318364860Shselasky                    subdir: "jre-" + data.version,
319364860Shselasky                    exploded: "images/jre"
320364860Shselasky                },
321364860Shselasky                demo: {
322364860Shselasky                    local: "bundles/\\(jdk.*demo." + demo_ext + "\\)",
323364860Shselasky                    remote: [
324364860Shselasky                        "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_demo." + demo_ext,
325364860Shselasky                        "bundles/" + pf + "/\\1"
326364860Shselasky                    ],
327364860Shselasky                }
328364860Shselasky            }
329364860Shselasky        };
330364860Shselasky    };
331364860Shselasky
332364860Shselasky
333364860Shselasky    /**
334364860Shselasky     * Define common artifacts template for all debug profiles
335364860Shselasky     * @param pf - Name of platform in bundle names
336364860Shselasky     */
337364860Shselasky    common.debug_profile_artifacts = function (pf) {
338364860Shselasky        return {
339364860Shselasky            artifacts: {
340364860Shselasky                jdk: {
341364860Shselasky                    local: "bundles/\\(jdk.*bin-debug.tar.gz\\)",
342364860Shselasky                    remote: [
343364860Shselasky                        "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-debug.tar.gz",
344364860Shselasky                        "bundles/" + pf + "/\\1"
345364860Shselasky                    ],
346364860Shselasky                    subdir: "jdk-" + data.version,
347364860Shselasky                    exploded: "images/jdk"
348364860Shselasky                },
349364860Shselasky                jre: {
350364860Shselasky                    local: "bundles/\\(jre.*bin-debug.tar.gz\\)",
351364860Shselasky                    remote: [
352364860Shselasky                        "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin-debug.tar.gz",
353364860Shselasky                        "bundles/" + pf + "/\\1"
354364860Shselasky                    ],
355364860Shselasky                    subdir: "jre-" + data.version,
356364860Shselasky                    exploded: "images/jre"
357364860Shselasky                },
358364860Shselasky                test: {
359364860Shselasky                    local: "bundles/\\(jdk.*bin-tests-debug.tar.gz\\)",
360364860Shselasky                    remote: [
361364860Shselasky                        "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-tests-debug.tar.gz",
362364860Shselasky                        "bundles/" + pf + "/\\1"
363364860Shselasky                    ],
364364860Shselasky                    exploded: "images/test"
365364860Shselasky                },
366364860Shselasky                jdk_symbols: {
367364860Shselasky                    local: "bundles/\\(jdk.*bin-debug-symbols.tar.gz\\)",
368364860Shselasky                    remote: [
369364860Shselasky                        "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-debug-symbols.tar.gz",
370364860Shselasky                        "bundles/" + pf + "/\\1"
371364860Shselasky                    ],
372364860Shselasky                    subdir: "jdk-" + data.version,
373364860Shselasky                    exploded: "images/jdk"
374364860Shselasky                },
375364860Shselasky                jre_symbols: {
376364860Shselasky                    local: "bundles/\\(jre.*bin-debug-symbols.tar.gz\\)",
377364860Shselasky                    remote: [
378364860Shselasky                        "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin-debug-symbols.tar.gz",
379364860Shselasky                        "bundles/" + pf + "/\\1"
380364860Shselasky                    ],
381364860Shselasky                    subdir: "jre-" + data.version,
382364860Shselasky                    exploded: "images/jre"
383364860Shselasky                }
384364860Shselasky            }
385364860Shselasky        };
386364860Shselasky    };
387364860Shselasky
388364860Shselasky    var boot_jdk_revision = "8";
389364860Shselasky    var boot_jdk_subdirpart = "1.8.0";
390364860Shselasky    // JDK 8 does not work on sparc M7 cpus, need a newer update when building
391364860Shselasky    // on such hardware.
392    if (input.build_cpu == "sparcv9") {
393       var cpu_brand = $EXEC("bash -c \"kstat -m cpu_info | grep brand | head -n1 | awk '{ print \$2 }'\"");
394       if (cpu_brand.trim() == 'SPARC-M7') {
395           boot_jdk_revision = "8u20";
396           boot_jdk_subdirpart = "1.8.0_20";
397       }
398    }
399    common.boot_jdk_revision = boot_jdk_revision;
400    common.boot_jdk_subdirpart = boot_jdk_subdirpart;
401    common.boot_jdk_home = input.get("boot_jdk", "home_path") + "/jdk"
402        + common.boot_jdk_subdirpart
403        + (input.build_os == "macosx" ? ".jdk/Contents/Home" : "");
404
405    return common;
406};
407
408/**
409 * Generates the profiles part of the configuration.
410 *
411 * @param input External data to use for generating the configuration
412 * @param common The common values
413 * @returns {{}} Profiles part of the configuration
414 */
415var getJibProfilesProfiles = function (input, common, data) {
416    // Main SE profiles
417    var profiles = {
418
419        "linux-x64": {
420            target_os: "linux",
421            target_cpu: "x64",
422            dependencies: ["devkit"],
423            configure_args: concat(common.configure_args_64bit, "--with-zlib=system"),
424            default_make_targets: ["docs-bundles"],
425        },
426
427        "linux-x86": {
428            target_os: "linux",
429            target_cpu: "x86",
430            build_cpu: "x64",
431            dependencies: ["devkit"],
432            configure_args: concat(common.configure_args_32bit,
433                "--with-jvm-variants=minimal,server", "--with-zlib=system"),
434        },
435
436        "macosx-x64": {
437            target_os: "macosx",
438            target_cpu: "x64",
439            dependencies: ["devkit"],
440            configure_args: concat(common.configure_args_64bit, "--with-zlib=system"),
441        },
442
443        "solaris-x64": {
444            target_os: "solaris",
445            target_cpu: "x64",
446            dependencies: ["devkit", "cups"],
447            configure_args: concat(common.configure_args_64bit,
448                "--with-zlib=system", "--enable-dtrace"),
449        },
450
451        "solaris-sparcv9": {
452            target_os: "solaris",
453            target_cpu: "sparcv9",
454            dependencies: ["devkit", "cups"],
455            configure_args: concat(common.configure_args_64bit,
456                "--with-zlib=system", "--enable-dtrace"),
457        },
458
459        "windows-x64": {
460            target_os: "windows",
461            target_cpu: "x64",
462            dependencies: ["devkit", "freetype"],
463            configure_args: concat(common.configure_args_64bit),
464        },
465
466        "windows-x86": {
467            target_os: "windows",
468            target_cpu: "x86",
469            build_cpu: "x64",
470            dependencies: ["devkit", "freetype"],
471            configure_args: concat(common.configure_args_32bit),
472        }
473    };
474    // Add the base settings to all the main profiles
475    common.main_profile_names.forEach(function (name) {
476        profiles[name] = concatObjects(common.main_profile_base, profiles[name]);
477    });
478
479    // Generate debug versions of all the main profiles
480    common.main_profile_names.forEach(function (name) {
481        var debugName = name + common.debug_suffix;
482        profiles[debugName] = concatObjects(profiles[name],
483                                            common.debug_profile_base);
484    });
485    // Generate slowdebug versions of all the main profiles
486    common.main_profile_names.forEach(function (name) {
487        var debugName = name + common.slowdebug_suffix;
488        profiles[debugName] = concatObjects(profiles[name],
489                                            common.slowdebug_profile_base);
490    });
491
492    // Generate open only profiles for all the main profiles for JPRT and reference
493    // implementation builds.
494    common.main_profile_names.forEach(function (name) {
495        var openName = name + common.open_suffix;
496        profiles[openName] = concatObjects(profiles[name],
497                                           common.open_profile_base);
498    });
499    // The open only profiles on linux are used for reference builds and should
500    // produce the compact profile images by default. This adds "profiles" as an
501    // extra default target.
502    var openOnlyProfilesExtra = {
503        "linux-x86-open": {
504            default_make_targets: "profiles-bundles",
505            configure_args: "--with-jvm-variants=client,server"
506        }
507    };
508    profiles = concatObjects(profiles, openOnlyProfilesExtra);
509
510    // Generate debug profiles for the open only profiles
511    common.main_profile_names.forEach(function (name) {
512        var openName = name + common.open_suffix;
513        var openDebugName = openName + common.debug_suffix;
514        profiles[openDebugName] = concatObjects(profiles[openName],
515                                                common.debug_profile_base);
516    });
517
518    // Profiles for building the zero jvm variant. These are used for verification
519    // in JPRT.
520    var zeroProfiles = {
521        "linux-x64-zero": {
522            target_os: "linux",
523            target_cpu: "x64",
524            dependencies: ["devkit"],
525            configure_args: concat(common.configure_args_64bit, [
526                "--with-zlib=system",
527                "--with-jvm-variants=zero",
528                "--enable-libffi-bundling"
529            ])
530        },
531
532        "linux-x86-zero": {
533            target_os: "linux",
534            target_cpu: "x86",
535            build_cpu: "x64",
536            dependencies: ["devkit"],
537            configure_args:  concat(common.configure_args_32bit, [
538                "--with-zlib=system",
539                "--with-jvm-variants=zero",
540                "--enable-libffi-bundling"
541            ])
542        }
543    }
544    profiles = concatObjects(profiles, zeroProfiles);
545
546    // Add the base settings to the zero profiles and generate debug profiles
547    Object.keys(zeroProfiles).forEach(function (name) {
548        var debugName = name + common.debug_suffix;
549        profiles[name] = concatObjects(common.main_profile_base, profiles[name]);
550        profiles[debugName] = concatObjects(profiles[name], common.debug_profile_base);
551    });
552
553    // Profiles used to run tests. Used in JPRT and Mach 5.
554    var testOnlyProfiles = {
555        "run-test-jprt": {
556            target_os: input.build_os,
557            target_cpu: input.build_cpu,
558            dependencies: [ "jtreg", "gnumake", "boot_jdk", "devkit" ],
559            labels: "test",
560            environment: {
561                "JT_JAVA": common.boot_jdk_home
562            }
563        },
564
565        "run-test": {
566            target_os: input.build_os,
567            target_cpu: input.build_cpu,
568            dependencies: [ "jtreg", "gnumake", "boot_jdk", "devkit" ],
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    // Need to add a value for the Visual Studio tools variable to make
920    // jaot be able to pick up the Visual Studio linker in testing.
921    if (input.target_os == "windows") {
922        dependencies.devkit.environment = {
923            VS120COMNTOOLS: input.get("devkit", "install_path") + "/Common7/Tools"
924        };
925    }
926
927    return dependencies;
928};
929
930/**
931 * Generate the missing platform attributes for profiles
932 *
933 * @param profiles Profiles map to generate attributes on
934 * @returns {{}} New profiles map with platform attributes fully filled in
935 */
936var generatePlatformAttributes = function (profiles) {
937    var ret = concatObjects(profiles, {});
938    for (var profile in profiles) {
939        if (ret[profile].build_os == null) {
940            ret[profile].build_os = ret[profile].target_os;
941        }
942        if (ret[profile].build_cpu == null) {
943            ret[profile].build_cpu = ret[profile].target_cpu;
944        }
945        ret[profile].target_platform = ret[profile].target_os + "_" + ret[profile].target_cpu;
946        ret[profile].build_platform = ret[profile].build_os + "_" + ret[profile].build_cpu;
947    }
948    return ret;
949};
950
951/**
952 * The default_make_targets attribute on a profile is not a real Jib attribute.
953 * This function rewrites that attribute into the corresponding configure arg.
954 * Calling this function multiple times on the same profiles object is safe.
955 *
956 * @param common Common values
957 * @param profiles Profiles map to rewrite profiles for
958 * @returns {{}} New map of profiles with the make targets converted
959 */
960var generateDefaultMakeTargetsConfigureArg = function (common, profiles) {
961    var ret = concatObjects(profiles, {});
962    for (var profile in ret) {
963        if (ret[profile]["default_make_targets"] != null) {
964            var targetsString = concat(ret[profile].default_make_targets).join(" ");
965            // Iterate over all configure args and see if --with-default-make-target
966            // is already there and change it, otherwise add it.
967            var found = false;
968            for (var i in ret[profile].configure_args) {
969                var arg = ret[profile].configure_args[i];
970                if (arg != null && arg.startsWith("--with-default-make-target=")) {
971                    found = true;
972                    ret[profile].configure_args[i]
973                        = "--with-default-make-target=" + targetsString;
974                }
975            }
976            if (!found) {
977                ret[profile].configure_args = concat(
978                    ret[profile].configure_args,
979                    "--with-default-make-target=" + targetsString);
980            }
981        }
982    }
983    return ret;
984}
985
986var getBuildId = function (input) {
987    if (input.build_id != null) {
988        return input.build_id;
989    } else {
990        var topdir = new java.io.File(__DIR__, "../..").getCanonicalFile().getName();
991        var userName = java.lang.System.getProperty("user.name");
992        return userName + "." + topdir;
993    }
994}
995
996/**
997 * Deep clones an object tree.
998 *
999 * @param o Object to clone
1000 * @returns {{}} Clone of o
1001 */
1002var clone = function (o) {
1003    return JSON.parse(JSON.stringify(o));
1004};
1005
1006/**
1007 * Concatenates all arguments into a new array
1008 *
1009 * @returns {Array.<T>} New array containing all arguments
1010 */
1011var concat = function () {
1012    return Array.prototype.concat.apply([], arguments);
1013};
1014
1015/**
1016 * Takes a String or Array of Strings and does a replace operation on each
1017 * of them.
1018 *
1019 * @param pattern Pattern to look for
1020 * @param replacement Replacement text to insert
1021 * @param a String or Array of Strings to replace
1022 * @returns {Array} Either a new array or a new string depending on the input
1023 */
1024var replaceAll = function (pattern, replacement, a) {
1025    // If a is an array
1026    if (Array === a.constructor) {
1027    var newA = [];
1028    for (var i in a) {
1029            newA.push(a[i].replace(pattern, replacement));
1030        }
1031        return newA;
1032        } else {
1033        return a.replace(pattern, replacement);
1034    }
1035};
1036
1037/**
1038 * Deep concatenation of two objects. For each node encountered, merge
1039 * the contents with the corresponding node in the other object tree,
1040 * treating all strings as array elements.
1041 *
1042 * @param o1 Object to concatenate
1043 * @param o2 Object to concatenate
1044 * @returns {{}} New object tree containing the concatenation of o1 and o2
1045 */
1046var concatObjects = function (o1, o2) {
1047    if (o1 == null) {
1048        return clone(o2);
1049    }
1050    if (o2 == null) {
1051        return clone(o1);
1052    }
1053    var ret = {};
1054    for (var a in o1) {
1055        if (o2[a] == null) {
1056            ret[a] = clone(o1[a]);
1057        }
1058    }
1059    for (var a in o2) {
1060        if (o1[a] == null) {
1061            ret[a] = clone(o2[a]);
1062        } else {
1063            if (typeof o1[a] == 'string') {
1064                ret[a] = clone([o1[a]].concat(o2[a]));
1065            } else if (Array.isArray(o1[a])) {
1066                ret[a] = clone(o1[a].concat(o2[a]));
1067            } else if (typeof o1[a] == 'object') {
1068                ret[a] = concatObjects(o1[a], o2[a]);
1069            }
1070        }
1071    }
1072    return ret;
1073};
1074
1075/**
1076 * Constructs the numeric version string from reading the
1077 * common/autoconf/version-numbers file and removing all trailing ".0".
1078 *
1079 * @param major Override major version
1080 * @param minor Override minor version
1081 * @param security Override security version
1082 * @param patch Override patch version
1083 * @returns {String} The numeric version string
1084 */
1085var getVersion = function (major, minor, security, patch) {
1086    var version_numbers = getVersionNumbers();
1087    var version = (major != null ? major : version_numbers.get("DEFAULT_VERSION_MAJOR"))
1088        + "." + (minor != null ? minor : version_numbers.get("DEFAULT_VERSION_MINOR"))
1089        + "." + (security != null ? security :  version_numbers.get("DEFAULT_VERSION_SECURITY"))
1090        + "." + (patch != null ? patch : version_numbers.get("DEFAULT_VERSION_PATCH"));
1091    while (version.match(".*\\.0$")) {
1092        version = version.substring(0, version.length - 2);
1093    }
1094    return version;
1095};
1096
1097// Properties representation of the common/autoconf/version-numbers file. Lazily
1098// initiated by the function below.
1099var version_numbers;
1100
1101/**
1102 * Read the common/autoconf/version-numbers file into a Properties object.
1103 *
1104 * @returns {java.utilProperties}
1105 */
1106var getVersionNumbers = function () {
1107    // Read version information from common/autoconf/version-numbers
1108    if (version_numbers == null) {
1109        version_numbers = new java.util.Properties();
1110        var stream = new java.io.FileInputStream(__DIR__ + "/../../common/autoconf/version-numbers");
1111        version_numbers.load(stream);
1112        stream.close();
1113    }
1114    return version_numbers;
1115}
1116