jib-profiles.js revision 1961:f900d5afd9c8
164562Sgshapiro/* 2141858Sgshapiro * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 364562Sgshapiro * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 464562Sgshapiro * 564562Sgshapiro * This code is free software; you can redistribute it and/or modify it 664562Sgshapiro * under the terms of the GNU General Public License version 2 only, as 764562Sgshapiro * published by the Free Software Foundation. Oracle designates this 864562Sgshapiro * particular file as subject to the "Classpath" exception as provided 964562Sgshapiro * by Oracle in the LICENSE file that accompanied this code. 1064562Sgshapiro * 1164562Sgshapiro * This code is distributed in the hope that it will be useful, but WITHOUT 1264562Sgshapiro * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1364562Sgshapiro * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1464562Sgshapiro * version 2 for more details (a copy is included in the LICENSE file that 1590792Sgshapiro * accompanied this code). 1690792Sgshapiro * 1764562Sgshapiro * You should have received a copy of the GNU General Public License version 18203004Sgshapiro * 2 along with this work; if not, write to the Free Software Foundation, 1964562Sgshapiro * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2090792Sgshapiro * 2190792Sgshapiro * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2264562Sgshapiro * or visit www.oracle.com if you need additional information or have any 2364562Sgshapiro * questions. 2464562Sgshapiro */ 2564562Sgshapiro 2664562Sgshapiro/* 2764562Sgshapiro * This file defines build profiles for the JIB tool and others. 2864562Sgshapiro * 2964562Sgshapiro * A build profile defines a set of configuration options and external 3064562Sgshapiro * dependencies that we for some reason or other care about specifically. 3164562Sgshapiro * Typically, build profiles are defined for the build configurations we 3264562Sgshapiro * build regularly. 3364562Sgshapiro * 3464562Sgshapiro * Contract against this file from the tools that use it, is to provide 3564562Sgshapiro * a function on the form: 3664562Sgshapiro * 3764562Sgshapiro * getJibProfiles(input) 3864562Sgshapiro * 3964562Sgshapiro * which returns an object graph describing the profiles and their 4064562Sgshapiro * dependencies. The name of the function is based on the name of this 4164562Sgshapiro * file, minus the extension and the '-', camel cased and prefixed with 4264562Sgshapiro * 'get'. 4364562Sgshapiro * 4464562Sgshapiro * 4564562Sgshapiro * The parameter 'input' is an object that optionally contains some data. 4664562Sgshapiro * Optionally because a tool may read the configuration for different purposes. 4764562Sgshapiro * To initially get a list of available profiles, the active profile may not 4864562Sgshapiro * yet be known for instance. 4964562Sgshapiro * 5064562Sgshapiro * Data that may be set on the input object: 5164562Sgshapiro * 5264562Sgshapiro * input.profile = <name of active profile> 5364562Sgshapiro * 5464562Sgshapiro * If the active profile is set, the following data from it must also 5564562Sgshapiro * be provided: 5664562Sgshapiro * 5764562Sgshapiro * input.profile 5864562Sgshapiro * input.target_os 5964562Sgshapiro * input.target_cpu 6064562Sgshapiro * input.build_os 6198121Sgshapiro * input.build_cpu 6264562Sgshapiro * input.target_platform 6364562Sgshapiro * input.build_platform 6490792Sgshapiro * // The build_osenv_* variables describe the unix layer on Windows systems, 6564562Sgshapiro * // i.e. Cygwin, which may also be 32 or 64 bit. 6664562Sgshapiro * input.build_osenv 6790792Sgshapiro * input.build_osenv_cpu 6864562Sgshapiro * input.build_osenv_platform 6964562Sgshapiro * 7090792Sgshapiro * For more complex nested attributes, there is a method "get": 7164562Sgshapiro * 7264562Sgshapiro * input.get("<dependency>", "<attribute>") 7364562Sgshapiro * 7490792Sgshapiro * Valid attributes are: 7590792Sgshapiro * install_path 7664562Sgshapiro * download_path 7764562Sgshapiro * download_dir 7864562Sgshapiro * 7964562Sgshapiro * 8064562Sgshapiro * The output data generated by this configuration file has the following 8164562Sgshapiro * format: 8264562Sgshapiro * 8364562Sgshapiro * data: { 8464562Sgshapiro * // Identifies the version of this format to the tool reading it 8564562Sgshapiro * format_version: "1.0", 8664562Sgshapiro * 8764562Sgshapiro * // Name of base outputdir. JIB assumes the actual output dir is formed 8864562Sgshapiro * // by adding the configuration name: <output_basedir>/<config-name> 8964562Sgshapiro * output_basedir: "build", 9064562Sgshapiro * // Configure argument to use to specify configuration name 9164562Sgshapiro * configuration_configure_arg: 9264562Sgshapiro * // Make argument to use to specify configuration name 9364562Sgshapiro * configuration_make_arg: 9464562Sgshapiro * 9564562Sgshapiro * profiles: { 9690792Sgshapiro * <profile-name>: { 9764562Sgshapiro * // Name of os the profile is built to run on 9864562Sgshapiro * target_os; <string> 9964562Sgshapiro * // Name of cpu the profile is built to run on 10064562Sgshapiro * target_cpu; <string> 10164562Sgshapiro * // Combination of target_os and target_cpu for convenience 10264562Sgshapiro * target_platform; <string> 10364562Sgshapiro * // Name of os the profile is built on 10464562Sgshapiro * build_os; <string> 10564562Sgshapiro * // Name of cpu the profile is built on 10664562Sgshapiro * build_cpu; <string> 10764562Sgshapiro * // Combination of build_os and build_cpu for convenience 10864562Sgshapiro * build_platform; <string> 10964562Sgshapiro * 11064562Sgshapiro * // List of dependencies needed to build this profile 11164562Sgshapiro * dependencies: <Array of strings> 11264562Sgshapiro * 11364562Sgshapiro * // List of configure args to use for this profile 11464562Sgshapiro * configure_args: <Array of strings> 11564562Sgshapiro * 11664562Sgshapiro * // List of free form labels describing aspects of this profile 11764562Sgshapiro * labels: <Array of strings> 11864562Sgshapiro * } 11964562Sgshapiro * } 12064562Sgshapiro * 12164562Sgshapiro * // Dependencies use a Maven like deployment structure 12264562Sgshapiro * dependencies: { 12364562Sgshapiro * <dependency-name>: { 12464562Sgshapiro * // Organization part of path defining this dependency 12564562Sgshapiro * organization: <string> 12664562Sgshapiro * // File extension for this dependency 12764562Sgshapiro * ext: <string> 12864562Sgshapiro * // Module part of path for defining this dependency, 12964562Sgshapiro * // defaults to <dependency-name> 13064562Sgshapiro * module: <string> 13164562Sgshapiro * // Revision part of path for defining this dependency 13264562Sgshapiro * revision: <string> 13364562Sgshapiro * 13464562Sgshapiro * // List of configure args to add when using this dependency, 13564562Sgshapiro * // defaults to 13664562Sgshapiro * // "--with-<dependency-name>=input.get("<dependency-name", "install_path")" 13764562Sgshapiro * configure_args: <array of strings> 13864562Sgshapiro * 13964562Sgshapiro * // Name of environment variable to set when using this dependency 14064562Sgshapiro * // when running make 14164562Sgshapiro * environment_name: <string> 14290792Sgshapiro * // Value of environment variable to set when using this dependency 14364562Sgshapiro * // when running make 14464562Sgshapiro * environment_value: <string> 14564562Sgshapiro * 14664562Sgshapiro * // Value to add to the PATH variable when using this dependency, 14764562Sgshapiro * // applies to both make and configure 14864562Sgshapiro * environment_path: <string> 14964562Sgshapiro * } 15064562Sgshapiro * 15164562Sgshapiro * <dependency-name>: { 15290792Sgshapiro * // For certain dependencies where a legacy distribution mechanism is 15364562Sgshapiro * // already in place, the "javare" server layout is also supported 15464562Sgshapiro * // Indicate that an alternate server source and layout should be used 15564562Sgshapiro * server: "javare" 15664562Sgshapiro * 15764562Sgshapiro * // For "javare", a combination of module, revision, 15864562Sgshapiro * // build number (optional), files and checksum file is possible for 15964562Sgshapiro * // artifacts following the standard layout. 16064562Sgshapiro * module: <string> 16164562Sgshapiro * revision: <string> 16264562Sgshapiro * build_number: <string> 16364562Sgshapiro * checksum_file: <string> 16464562Sgshapiro * file: <string> 16564562Sgshapiro * 16664562Sgshapiro * // For other files, use checksum path and path instead 16764562Sgshapiro * checksum_path: <string> 16864562Sgshapiro * path: <string> 16964562Sgshapiro * } 17064562Sgshapiro * } 17164562Sgshapiro * } 17264562Sgshapiro */ 17364562Sgshapiro 17464562Sgshapiro/** 17564562Sgshapiro * Main entry to generate the profile configuration 17664562Sgshapiro * 17764562Sgshapiro * @param input External data to use for generating the configuration 17864562Sgshapiro * @returns {{}} Profile configuration 17964562Sgshapiro */ 18064562Sgshapirovar getJibProfiles = function (input) { 18164562Sgshapiro 18264562Sgshapiro var data = {}; 18364562Sgshapiro 18464562Sgshapiro // Identifies the version of this format to the tool reading it 18564562Sgshapiro data.format_version = "1.0"; 18664562Sgshapiro 18764562Sgshapiro // Organization is used when uploading/publishing build results 18864562Sgshapiro data.organization = "com.oracle.jpg.jdk"; 18964562Sgshapiro 19064562Sgshapiro // The base directory for the build output. JIB will assume that the 19190792Sgshapiro // actual build directory will be <output_basedir>/<configuration> 19264562Sgshapiro data.output_basedir = "build"; 19364562Sgshapiro // The configure argument to use to specify the name of the configuration 19464562Sgshapiro data.configuration_configure_arg = "--with-conf-name="; 19564562Sgshapiro // The make argument to use to specify the name of the configuration 19664562Sgshapiro data.configuration_make_arg = "CONF_NAME="; 19764562Sgshapiro 19864562Sgshapiro // Define some common values 19964562Sgshapiro var common = getJibProfilesCommon(input); 20064562Sgshapiro // Generate the profiles part of the configuration 20164562Sgshapiro data.profiles = getJibProfilesProfiles(input, common); 20264562Sgshapiro // Generate the dependencies part of the configuration 20364562Sgshapiro data.dependencies = getJibProfilesDependencies(input, common); 20464562Sgshapiro 20564562Sgshapiro return data; 20664562Sgshapiro}; 20764562Sgshapiro 20864562Sgshapiro/** 20990792Sgshapiro * Generates some common values 21064562Sgshapiro * 21164562Sgshapiro * @param input External data to use for generating the configuration 21264562Sgshapiro * @returns Common values 21364562Sgshapiro */ 21464562Sgshapirovar getJibProfilesCommon = function (input) { 21564562Sgshapiro var common = { 21664562Sgshapiro dependencies: ["boot_jdk", "gnumake", "jtreg"], 21764562Sgshapiro configure_args: ["--with-default-make-target=all"], 21864562Sgshapiro configure_args_32bit: ["--with-target-bits=32", "--with-jvm-variants=client,server"], 21964562Sgshapiro configure_args_debug: ["--enable-debug"], 22064562Sgshapiro organization: "jpg.infra.builddeps" 22164562Sgshapiro }; 22264562Sgshapiro 22364562Sgshapiro return common; 22464562Sgshapiro}; 22564562Sgshapiro 22664562Sgshapiro/** 22764562Sgshapiro * Generates the profiles part of the configuration. 22864562Sgshapiro * 22964562Sgshapiro * @param input External data to use for generating the configuration 23064562Sgshapiro * @param common The common values 23164562Sgshapiro * @returns {{}} Profiles part of the configuration 23264562Sgshapiro */ 23364562Sgshapirovar getJibProfilesProfiles = function (input, common) { 23464562Sgshapiro var profiles = {}; 23564562Sgshapiro 23664562Sgshapiro // Main SE profiles 23764562Sgshapiro var mainProfiles = { 23864562Sgshapiro 23964562Sgshapiro "linux-x64": { 24064562Sgshapiro target_os: "linux", 24190792Sgshapiro target_cpu: "x64", 24264562Sgshapiro dependencies: concat(common.dependencies, "devkit"), 24390792Sgshapiro configure_args: common.configure_args, 24490792Sgshapiro make_args: common.make_args 24564562Sgshapiro }, 24690792Sgshapiro 24790792Sgshapiro "linux-x86": { 24890792Sgshapiro target_os: "linux", 24990792Sgshapiro target_cpu: "x86", 25064562Sgshapiro build_cpu: "x64", 25164562Sgshapiro dependencies: concat(common.dependencies, "devkit"), 25264562Sgshapiro configure_args: concat(common.configure_args, common.configure_args_32bit), 25364562Sgshapiro make_args: common.make_args 25464562Sgshapiro }, 25564562Sgshapiro 25664562Sgshapiro "macosx-x64": { 25764562Sgshapiro target_os: "macosx", 25864562Sgshapiro target_cpu: "x64", 25964562Sgshapiro dependencies: concat(common.dependencies, "devkit"), 26090792Sgshapiro configure_args: common.configure_args, 26190792Sgshapiro make_args: common.make_args 26264562Sgshapiro }, 26364562Sgshapiro 26464562Sgshapiro "solaris-x64": { 26564562Sgshapiro target_os: "solaris", 26664562Sgshapiro target_cpu: "x64", 26764562Sgshapiro dependencies: concat(common.dependencies, "devkit", "cups"), 26890792Sgshapiro configure_args: common.configure_args, 26990792Sgshapiro make_args: common.make_args 27064562Sgshapiro }, 27164562Sgshapiro 27264562Sgshapiro "solaris-sparcv9": { 27364562Sgshapiro target_os: "solaris", 27464562Sgshapiro target_cpu: "sparcv9", 27564562Sgshapiro dependencies: concat(common.dependencies, "devkit", "cups"), 27690792Sgshapiro configure_args: common.configure_args, 27790792Sgshapiro make_args: common.make_args 27864562Sgshapiro }, 27964562Sgshapiro 28064562Sgshapiro "windows-x64": { 28164562Sgshapiro target_os: "windows", 28264562Sgshapiro target_cpu: "x64", 28364562Sgshapiro dependencies: concat(common.dependencies, "devkit", "freetype"), 28490792Sgshapiro configure_args: common.configure_args, 28590792Sgshapiro make_args: common.make_args 28664562Sgshapiro }, 28764562Sgshapiro 28864562Sgshapiro "windows-x86": { 28964562Sgshapiro target_os: "windows", 29064562Sgshapiro target_cpu: "x86", 29190792Sgshapiro build_cpu: "x64", 29290792Sgshapiro dependencies: concat(common.dependencies, "devkit", "freetype"), 29364562Sgshapiro configure_args: concat(common.configure_args, common.configure_args_32bit), 29464562Sgshapiro make_args: common.make_args 29564562Sgshapiro } 29664562Sgshapiro }; 29764562Sgshapiro profiles = concatObjects(profiles, mainProfiles); 29890792Sgshapiro // Generate debug versions of all the main profiles 29990792Sgshapiro profiles = concatObjects(profiles, generateDebugProfiles(common, mainProfiles)); 30064562Sgshapiro 30164562Sgshapiro // Specific open profiles needed for JPRT testing 30264562Sgshapiro var jprtOpenProfiles = { 30364562Sgshapiro 30464562Sgshapiro "linux-x64-open": { 30564562Sgshapiro target_os: mainProfiles["linux-x64"].target_os, 30664562Sgshapiro target_cpu: mainProfiles["linux-x64"].target_cpu, 307132943Sgshapiro dependencies: mainProfiles["linux-x64"].dependencies, 30890792Sgshapiro configure_args: concat(mainProfiles["linux-x64"].configure_args, 30964562Sgshapiro "--enable-openjdk-only"), 31064562Sgshapiro make_args: mainProfiles["linux-x64"].make_args, 31164562Sgshapiro labels: [ "open" ] 31264562Sgshapiro }, 31364562Sgshapiro 31490792Sgshapiro "linux-x86-open": { 31564562Sgshapiro target_os: mainProfiles["linux-x86"].target_os, 31664562Sgshapiro target_cpu: mainProfiles["linux-x86"].target_cpu, 31764562Sgshapiro dependencies: mainProfiles["linux-x86"].dependencies, 31864562Sgshapiro configure_args: concat(mainProfiles["linux-x86"].configure_args, 31964562Sgshapiro "--enable-openjdk-only"), 32064562Sgshapiro make_args: mainProfiles["linux-x86"].make_args, 32164562Sgshapiro labels: [ "open" ] 32264562Sgshapiro }, 32364562Sgshapiro 32464562Sgshapiro "solaris-x64-open": { 32564562Sgshapiro target_os: mainProfiles["solaris-x64"].target_os, 32664562Sgshapiro target_cpu: mainProfiles["solaris-x64"].target_cpu, 32764562Sgshapiro dependencies: mainProfiles["solaris-x64"].dependencies, 32864562Sgshapiro configure_args: concat(mainProfiles["solaris-x64"].configure_args, 32964562Sgshapiro "--enable-openjdk-only"), 33064562Sgshapiro make_args: mainProfiles["solaris-x64"].make_args, 33164562Sgshapiro labels: [ "open" ] 33264562Sgshapiro }, 33364562Sgshapiro 33464562Sgshapiro "windows-x86-open": { 33564562Sgshapiro target_os: mainProfiles["windows-x86"].target_os, 33664562Sgshapiro target_cpu: mainProfiles["windows-x86"].target_cpu, 33764562Sgshapiro dependencies: mainProfiles["windows-x86"].dependencies, 33864562Sgshapiro configure_args: concat(mainProfiles["windows-x86"].configure_args, 33964562Sgshapiro "--enable-openjdk-only"), 34064562Sgshapiro make_args: mainProfiles["windows-x86"].make_args, 34164562Sgshapiro labels: [ "open" ] 34264562Sgshapiro } 34364562Sgshapiro }; 34464562Sgshapiro profiles = concatObjects(profiles, jprtOpenProfiles); 34564562Sgshapiro // Generate debug profiles for the open jprt profiles 34664562Sgshapiro profiles = concatObjects(profiles, generateDebugProfiles(common, jprtOpenProfiles)); 34764562Sgshapiro 34864562Sgshapiro // Profiles used to run tests. Used in JPRT. 34964562Sgshapiro var testOnlyProfiles = { 35064562Sgshapiro 35164562Sgshapiro "run-test": { 35264562Sgshapiro target_os: input.build_os, 35364562Sgshapiro target_cpu: input.build_cpu, 35490792Sgshapiro dependencies: [ "jtreg", "gnumake" ], 35564562Sgshapiro labels: "test" 35690792Sgshapiro } 35764562Sgshapiro }; 35864562Sgshapiro profiles = concatObjects(profiles, testOnlyProfiles); 35964562Sgshapiro 36064562Sgshapiro // Generate the missing platform attributes 36164562Sgshapiro profiles = generatePlatformAttributes(profiles); 36264562Sgshapiro return profiles; 36390792Sgshapiro}; 36464562Sgshapiro 36564562Sgshapiro/** 36664562Sgshapiro * Generate the dependencies part of the configuration 36790792Sgshapiro * 36864562Sgshapiro * @param input External data to use for generating the configuration 36964562Sgshapiro * @param common The common values 37090792Sgshapiro * @returns {{}} Dependencies part of configuration 37164562Sgshapiro */ 37264562Sgshapirovar getJibProfilesDependencies = function (input, common) { 37364562Sgshapiro 37464562Sgshapiro var boot_jdk_platform = input.build_os + "-" 37564562Sgshapiro + (input.build_cpu == "x86" ? "i586" : input.build_cpu); 37664562Sgshapiro 37764562Sgshapiro var devkit_platform_revisions = { 37864562Sgshapiro linux_x64: "gcc4.9.2-OEL6.4+1.0", 37964562Sgshapiro macosx_x64: "Xcode6.3-MacOSX10.9+1.0", 38064562Sgshapiro solaris_x64: "SS12u4-Solaris11u1+1.0", 38164562Sgshapiro solaris_sparcv9: "SS12u4-Solaris11u1+1.0", 38264562Sgshapiro windows_x64: "VS2013SP4+1.0" 38364562Sgshapiro }; 38464562Sgshapiro 38564562Sgshapiro var devkit_platform = (input.target_cpu == "x86" 38664562Sgshapiro ? input.target_os + "_x64" 38764562Sgshapiro : input.target_platform); 38864562Sgshapiro 38964562Sgshapiro var dependencies = { 39064562Sgshapiro 39164562Sgshapiro boot_jdk: { 39264562Sgshapiro server: "javare", 39364562Sgshapiro module: "jdk", 39464562Sgshapiro revision: "8", 39564562Sgshapiro checksum_file: boot_jdk_platform + "/MD5_VALUES", 39664562Sgshapiro file: boot_jdk_platform + "/jdk-8-" + boot_jdk_platform + ".tar.gz", 39764562Sgshapiro configure_args: (input.build_os == "macosx" 39864562Sgshapiro ? "--with-boot-jdk=" + input.get("boot_jdk", "install_path") + "/jdk1.8.0.jdk/Contents/Home" 39964562Sgshapiro : "--with-boot-jdk=" + input.get("boot_jdk", "install_path") + "/jdk1.8.0") 40064562Sgshapiro }, 40164562Sgshapiro 40264562Sgshapiro devkit: { 40364562Sgshapiro organization: common.organization, 40464562Sgshapiro ext: "tar.gz", 40564562Sgshapiro module: "devkit-" + devkit_platform, 40664562Sgshapiro revision: devkit_platform_revisions[devkit_platform] 40764562Sgshapiro }, 40864562Sgshapiro 40998121Sgshapiro build_devkit: { 41064562Sgshapiro organization: common.organization, 41164562Sgshapiro ext: "tar.gz", 41264562Sgshapiro module: "devkit-" + input.build_platform, 41364562Sgshapiro revision: devkit_platform_revisions[input.build_platform] 41464562Sgshapiro }, 41564562Sgshapiro 41690792Sgshapiro cups: { 41790792Sgshapiro organization: common.organization, 41890792Sgshapiro ext: "tar.gz", 41964562Sgshapiro revision: "1.0118+1.0" 42064562Sgshapiro }, 42164562Sgshapiro 42264562Sgshapiro jtreg: { 42364562Sgshapiro server: "javare", 42490792Sgshapiro revision: "4.2", 42564562Sgshapiro build_number: "b01", 42664562Sgshapiro checksum_file: "MD5_VALUES", 42764562Sgshapiro file: "jtreg_bin-4.2.zip", 42864562Sgshapiro environment_name: "JT_HOME" 42964562Sgshapiro }, 43064562Sgshapiro 43190792Sgshapiro gnumake: { 43264562Sgshapiro organization: common.organization, 43364562Sgshapiro ext: "tar.gz", 43464562Sgshapiro revision: "4.0+1.0", 43564562Sgshapiro 43664562Sgshapiro module: (input.build_os == "windows" 43764562Sgshapiro ? "gnumake-" + input.build_osenv_platform 43864562Sgshapiro : "gnumake-" + input.build_platform), 43964562Sgshapiro 44064562Sgshapiro configure_args: (input.build_os == "windows" 44164562Sgshapiro ? "MAKE=" + input.get("gnumake", "install_path") + "/cygwin/bin/make" 44264562Sgshapiro : "MAKE=" + input.get("gnumake", "install_path") + "/bin/make"), 44364562Sgshapiro 44464562Sgshapiro environment_path: (input.build_os == "windows" 44564562Sgshapiro ? input.get("gnumake", "install_path") + "/cygwin/bin" 44664562Sgshapiro : input.get("gnumake", "install_path") + "/bin") 44764562Sgshapiro }, 44864562Sgshapiro 44964562Sgshapiro freetype: { 45064562Sgshapiro organization: common.organization, 45164562Sgshapiro ext: "tar.gz", 45264562Sgshapiro revision: "2.3.4+1.0", 45364562Sgshapiro module: "freetype-" + input.target_platform 45464562Sgshapiro } 45564562Sgshapiro }; 45664562Sgshapiro 45764562Sgshapiro return dependencies; 45864562Sgshapiro}; 45964562Sgshapiro 46064562Sgshapiro/** 46164562Sgshapiro * Generate the missing platform attributes for profiles 46264562Sgshapiro * 46364562Sgshapiro * @param profiles Profiles map to generate attributes on 46464562Sgshapiro * @returns {{}} New profiles map with platform attributes fully filled in 46564562Sgshapiro */ 46664562Sgshapirovar generatePlatformAttributes = function (profiles) { 46764562Sgshapiro var ret = concatObjects(profiles, {}); 46864562Sgshapiro for (var profile in profiles) { 46964562Sgshapiro if (ret[profile].build_os == null) { 47064562Sgshapiro ret[profile].build_os = ret[profile].target_os; 47164562Sgshapiro } 47290792Sgshapiro if (ret[profile].build_cpu == null) { 47364562Sgshapiro ret[profile].build_cpu = ret[profile].target_cpu; 47464562Sgshapiro } 47564562Sgshapiro ret[profile].target_platform = ret[profile].target_os + "_" + ret[profile].target_cpu; 47664562Sgshapiro ret[profile].build_platform = ret[profile].build_os + "_" + ret[profile].build_cpu; 47764562Sgshapiro } 47864562Sgshapiro return ret; 47964562Sgshapiro}; 48064562Sgshapiro 48164562Sgshapiro/** 48264562Sgshapiro * Generates debug versions of profiles. Clones the given profiles and adds 48364562Sgshapiro * debug metadata. 48464562Sgshapiro * 48564562Sgshapiro * @param common Common values 48664562Sgshapiro * @param profiles Profiles map to generate debug profiles for 48764562Sgshapiro * @returns {{}} New map of profiles containing debug profiles 48864562Sgshapiro */ 48998121Sgshapirovar generateDebugProfiles = function (common, profiles) { 49064562Sgshapiro var newProfiles = {}; 49198121Sgshapiro for (var profile in profiles) { 492141858Sgshapiro var debugProfile = profile + "-debug"; 49364562Sgshapiro newProfiles[debugProfile] = clone(profiles[profile]); 49464562Sgshapiro newProfiles[debugProfile].debug_level = "fastdebug"; 49598121Sgshapiro newProfiles[debugProfile].labels 49698121Sgshapiro = concat(newProfiles[debugProfile].labels || [], "debug"), 49764562Sgshapiro newProfiles[debugProfile].configure_args 49864562Sgshapiro = concat(newProfiles[debugProfile].configure_args, 49964562Sgshapiro common.configure_args_debug); 50064562Sgshapiro } 50198121Sgshapiro return newProfiles; 50298121Sgshapiro}; 50398121Sgshapiro 50498121Sgshapiro/** 50598121Sgshapiro * Deep clones an object tree. 50698121Sgshapiro * 50764562Sgshapiro * @param o Object to clone 50864562Sgshapiro * @returns {{}} Clone of o 50964562Sgshapiro */ 51064562Sgshapirovar clone = function (o) { 51164562Sgshapiro return JSON.parse(JSON.stringify(o)); 51264562Sgshapiro}; 51364562Sgshapiro 51464562Sgshapiro/** 51564562Sgshapiro * Concatenates all arguments into a new array 51664562Sgshapiro * 51764562Sgshapiro * @returns {Array.<T>} New array containing all arguments 51864562Sgshapiro */ 51964562Sgshapirovar concat = function () { 52064562Sgshapiro return Array.prototype.concat.apply([], arguments); 52164562Sgshapiro}; 52264562Sgshapiro 52364562Sgshapiro/** 52464562Sgshapiro * Copies all elements in an array into a new array but replacing all 52564562Sgshapiro * occurrences of original with replacement. 52664562Sgshapiro * 52764562Sgshapiro * @param original Element to look for 52864562Sgshapiro * @param replacement Element to replace with 52964562Sgshapiro * @param a Array to copy 53064562Sgshapiro * @returns {Array} New array with all occurrences of original replaced 53164562Sgshapiro * with replacement 53264562Sgshapiro */ 53364562Sgshapirovar replace = function (original, replacement, a) { 53464562Sgshapiro var newA = []; 53564562Sgshapiro for (var i in a) { 53664562Sgshapiro if (original == a[i]) { 53764562Sgshapiro newA.push(replacement); 53864562Sgshapiro } else { 53964562Sgshapiro newA.push(a[i]); 54064562Sgshapiro } 54164562Sgshapiro } 54264562Sgshapiro return newA; 54364562Sgshapiro}; 54464562Sgshapiro 54564562Sgshapiro/** 54664562Sgshapiro * Deep concatenation of two objects. For each node encountered, merge 54764562Sgshapiro * the contents with the corresponding node in the other object tree, 54864562Sgshapiro * treating all strings as array elements. 54964562Sgshapiro * 55064562Sgshapiro * @param o1 Object to concatenate 55164562Sgshapiro * @param o2 Object to concatenate 55264562Sgshapiro * @returns {{}} New object tree containing the concatenation of o1 and o2 55364562Sgshapiro */ 55490792Sgshapirovar concatObjects = function (o1, o2) { 55590792Sgshapiro var ret = {}; 55690792Sgshapiro for (var a in o1) { 55790792Sgshapiro if (o2[a] == null) { 55890792Sgshapiro ret[a] = o1[a]; 55990792Sgshapiro } 56090792Sgshapiro } 56164562Sgshapiro for (var a in o2) { 56264562Sgshapiro if (o1[a] == null) { 56364562Sgshapiro ret[a] = o2[a]; 56464562Sgshapiro } else { 56564562Sgshapiro if (typeof o1[a] == 'string') { 56664562Sgshapiro ret[a] = [o1[a]].concat(o2[a]); 56764562Sgshapiro } else if (Array.isArray(o1[a])) { 56864562Sgshapiro ret[a] = o1[a].concat(o2[a]); 56990792Sgshapiro } else if (typeof o1[a] == 'object') { 57090792Sgshapiro ret[a] = concatObjects(o1[a], o2[a]); 57190792Sgshapiro } 57264562Sgshapiro } 57364562Sgshapiro } 57464562Sgshapiro return ret; 57564562Sgshapiro}; 57664562Sgshapiro