jib-profiles.js revision 2084:7de7decfd096
1213237Sgonzo/* 2213237Sgonzo * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3213237Sgonzo * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4213237Sgonzo * 5213237Sgonzo * This code is free software; you can redistribute it and/or modify it 6213237Sgonzo * under the terms of the GNU General Public License version 2 only, as 7213237Sgonzo * published by the Free Software Foundation. Oracle designates this 8213237Sgonzo * particular file as subject to the "Classpath" exception as provided 9213237Sgonzo * by Oracle in the LICENSE file that accompanied this code. 10213237Sgonzo * 11213237Sgonzo * This code is distributed in the hope that it will be useful, but WITHOUT 12213237Sgonzo * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13213237Sgonzo * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14213277Sgonzo * version 2 for more details (a copy is included in the LICENSE file that 15213277Sgonzo * accompanied this code). 16213277Sgonzo * 17213277Sgonzo * You should have received a copy of the GNU General Public License version 18213277Sgonzo * 2 along with this work; if not, write to the Free Software Foundation, 19213277Sgonzo * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20213277Sgonzo * 21213277Sgonzo * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22213277Sgonzo * or visit www.oracle.com if you need additional information or have any 23213277Sgonzo * questions. 24213277Sgonzo */ 25213237Sgonzo 26213237Sgonzo/* 27213237Sgonzo * This file defines build profiles for the JIB tool and others. 28213237Sgonzo * 29213237Sgonzo * A build profile defines a set of configuration options and external 30213237Sgonzo * dependencies that we for some reason or other care about specifically. 31265289Sloos * Typically, build profiles are defined for the build configurations we 32265191Sloos * build regularly. 33274670Sloos * 34298738Smmel * Contract against this file from the tools that use it, is to provide 35265191Sloos * a function on the form: 36213237Sgonzo * 37213237Sgonzo * getJibProfiles(input) 38213237Sgonzo * 39265191Sloos * which returns an object graph describing the profiles and their 40213237Sgonzo * dependencies. The name of the function is based on the name of this 41213237Sgonzo * file, minus the extension and the '-', camel cased and prefixed with 42213237Sgonzo * 'get'. 43274638Sloos * 44274638Sloos * 45274638Sloos * The parameter 'input' is an object that optionally contains some data. 46274638Sloos * Optionally because a tool may read the configuration for different purposes. 47274638Sloos * To initially get a list of available profiles, the active profile may not 48274638Sloos * yet be known for instance. 49274638Sloos * 50274643Sloos * Data that may be set on the input object: 51213237Sgonzo * 52213237Sgonzo * input.profile = <name of active profile> 53213237Sgonzo * 54213237Sgonzo * If the active profile is set, the following data from it must also 55213237Sgonzo * be provided: 56213237Sgonzo * 57279620Sloos * input.profile 58213237Sgonzo * input.target_os 59213237Sgonzo * input.target_cpu 60213237Sgonzo * input.build_os 61213237Sgonzo * input.build_cpu 62213237Sgonzo * input.target_platform 63213237Sgonzo * input.build_platform 64213237Sgonzo * // The build_osenv_* variables describe the unix layer on Windows systems, 65213237Sgonzo * // i.e. Cygwin, which may also be 32 or 64 bit. 66213237Sgonzo * input.build_osenv 67273917Sloos * input.build_osenv_cpu 68213237Sgonzo * input.build_osenv_platform 69213237Sgonzo * 70213237Sgonzo * For more complex nested attributes, there is a method "get": 71213237Sgonzo * 72213237Sgonzo * input.get("<dependency>", "<attribute>") 73213237Sgonzo * 74213237Sgonzo * Valid attributes are: 75213237Sgonzo * install_path 76298738Smmel * download_path 77298738Smmel * download_dir 78298738Smmel * 79298738Smmel * 80298738Smmel * The output data generated by this configuration file has the following 81298738Smmel * format: 82301539Smmel * 83301539Smmel * data: { 84301539Smmel * // Identifies the version of this format to the tool reading it 85301539Smmel * format_version: "1.0", 86301539Smmel * 87301539Smmel * // Name of base outputdir. JIB assumes the actual output dir is formed 88301539Smmel * // by adding the configuration name: <output_basedir>/<config-name> 89301539Smmel * output_basedir: "build", 90301539Smmel * // Configure argument to use to specify configuration name 91301539Smmel * configuration_configure_arg: 92298738Smmel * // Make argument to use to specify configuration name 93298738Smmel * configuration_make_arg: 94298738Smmel * 95298738Smmel * profiles: { 96301539Smmel * <profile-name>: { 97301539Smmel * // Name of os the profile is built to run on 98301539Smmel * target_os; <string> 99301539Smmel * // Name of cpu the profile is built to run on 100298738Smmel * target_cpu; <string> 101301539Smmel * // Combination of target_os and target_cpu for convenience 102301539Smmel * target_platform; <string> 103301539Smmel * // Name of os the profile is built on 104301539Smmel * build_os; <string> 105301539Smmel * // Name of cpu the profile is built on 106301539Smmel * build_cpu; <string> 107301539Smmel * // Combination of build_os and build_cpu for convenience 108301539Smmel * build_platform; <string> 109301539Smmel * 110301539Smmel * // List of dependencies needed to build this profile 111301539Smmel * dependencies: <Array of strings> 112298738Smmel * 113301539Smmel * // List of configure args to use for this profile 114298738Smmel * configure_args: <Array of strings> 115301539Smmel * 116301539Smmel * // List of free form labels describing aspects of this profile 117301539Smmel * labels: <Array of strings> 118301539Smmel * } 119301539Smmel * } 120301539Smmel * 121301539Smmel * // Dependencies use a Maven like deployment structure 122301539Smmel * dependencies: { 123298738Smmel * <dependency-name>: { 124300871Sian * // Organization part of path defining this dependency 125300871Sian * organization: <string> 126300871Sian * // File extension for this dependency 127300871Sian * ext: <string> 128300871Sian * // Module part of path for defining this dependency, 129300871Sian * // defaults to <dependency-name> 130300871Sian * module: <string> 131300871Sian * // Revision part of path for defining this dependency 132298738Smmel * revision: <string> 133298738Smmel * 134274670Sloos * // List of configure args to add when using this dependency, 135274670Sloos * // defaults to 136274670Sloos * // "--with-<dependency-name>=input.get("<dependency-name", "install_path")" 137274670Sloos * configure_args: <array of strings> 138274670Sloos * 139274670Sloos * // Name of environment variable to set when using this dependency 140274670Sloos * // when running make 141274670Sloos * environment_name: <string> 142274670Sloos * // Value of environment variable to set when using this dependency 143274670Sloos * // when running make 144274670Sloos * environment_value: <string> 145274670Sloos * 146274670Sloos * // Value to add to the PATH variable when using this dependency, 147274670Sloos * // applies to both make and configure 148274670Sloos * environment_path: <string> 149274670Sloos * } 150274670Sloos * 151274643Sloos * <dependency-name>: { 152274643Sloos * // For certain dependencies where a legacy distribution mechanism is 153213237Sgonzo * // already in place, the "javare" server layout is also supported 154274643Sloos * // Indicate that an alternate server source and layout should be used 155274643Sloos * server: "javare" 156213237Sgonzo * 157213237Sgonzo * // For "javare", a combination of module, revision, 158213237Sgonzo * // build number (optional), files and checksum file is possible for 159213237Sgonzo * // artifacts following the standard layout. 160213237Sgonzo * module: <string> 161213237Sgonzo * revision: <string> 162213237Sgonzo * build_number: <string> 163213237Sgonzo * checksum_file: <string> 164213237Sgonzo * file: <string> 165274643Sloos * 166274643Sloos * // For other files, use checksum path and path instead 167213237Sgonzo * checksum_path: <string> 168274643Sloos * path: <string> 169274643Sloos * } 170213237Sgonzo * } 171274643Sloos * } 172274643Sloos */ 173274643Sloos 174213237Sgonzo/** 175213237Sgonzo * Main entry to generate the profile configuration 176213237Sgonzo * 177213237Sgonzo * @param input External data to use for generating the configuration 178213237Sgonzo * @returns {{}} Profile configuration 179213237Sgonzo */ 180213237Sgonzovar getJibProfiles = function (input) { 181213237Sgonzo 182213237Sgonzo var data = {}; 183274643Sloos 184274643Sloos // Identifies the version of this format to the tool reading it 185213237Sgonzo data.format_version = "1.0"; 186274643Sloos 187274643Sloos // Organization is used when uploading/publishing build results 188213237Sgonzo data.organization = "com.oracle.jpg.jdk"; 189274643Sloos 190274643Sloos // The base directory for the build output. JIB will assume that the 191274643Sloos // actual build directory will be <output_basedir>/<configuration> 192213237Sgonzo data.output_basedir = "build"; 193213237Sgonzo // The configure argument to use to specify the name of the configuration 194277996Sloos data.configuration_configure_arg = "--with-conf-name="; 195277996Sloos // The make argument to use to specify the name of the configuration 196277996Sloos data.configuration_make_arg = "CONF_NAME="; 197277996Sloos 198277996Sloos // Define some common values 199277996Sloos var common = getJibProfilesCommon(input); 200277996Sloos // Generate the profiles part of the configuration 201277996Sloos data.profiles = getJibProfilesProfiles(input, common); 202277996Sloos // Generate the dependencies part of the configuration 203277996Sloos data.dependencies = getJibProfilesDependencies(input, common); 204277996Sloos 205277996Sloos return data; 206278108Sloos}; 207278108Sloos 208278108Sloos/** 209277996Sloos * Generates some common values 210277996Sloos * 211277996Sloos * @param input External data to use for generating the configuration 212277996Sloos * @returns Common values 213277996Sloos */ 214273569Sloosvar getJibProfilesCommon = function (input) { 215277996Sloos var common = {}; 216277996Sloos 217286845Sloos common.dependencies = ["boot_jdk", "gnumake", "jtreg"], 218277996Sloos common.default_make_targets = ["product-bundles", "test-bundles"], 219278108Sloos common.default_make_targets_debug = common.default_make_targets; 220278108Sloos common.default_make_targets_slowdebug = common.default_make_targets; 221278108Sloos common.configure_args = ["--enable-jtreg-failure-handler"], 222286845Sloos common.configure_args_32bit = ["--with-target-bits=32"], 223286845Sloos common.configure_args_debug = ["--enable-debug"], 224286845Sloos common.configure_args_slowdebug = ["--with-debug-level=slowdebug"], 225278108Sloos common.organization = "jpg.infra.builddeps" 226286845Sloos 227277996Sloos return common; 228277996Sloos}; 229277996Sloos 230273569Sloos/** 231273569Sloos * Generates the profiles part of the configuration. 232273569Sloos * 233273569Sloos * @param input External data to use for generating the configuration 234273569Sloos * @param common The common values 235273569Sloos * @returns {{}} Profiles part of the configuration 236273569Sloos */ 237274638Sloosvar getJibProfilesProfiles = function (input, common) { 238274638Sloos var profiles = {}; 239274638Sloos 240274638Sloos // Main SE profiles 241274638Sloos var mainProfiles = { 242273569Sloos 243273569Sloos "linux-x64": { 244273569Sloos target_os: "linux", 245273569Sloos target_cpu: "x64", 246293872Sadrian dependencies: concat(common.dependencies, "devkit"), 247273569Sloos configure_args: concat(common.configure_args, "--with-zlib=system"), 248273569Sloos default_make_targets: concat(common.default_make_targets, "docs-bundles") 249273569Sloos }, 250273569Sloos 251279761Sloos "linux-x86": { 252273569Sloos target_os: "linux", 253279761Sloos target_cpu: "x86", 254273569Sloos build_cpu: "x64", 255273569Sloos dependencies: concat(common.dependencies, "devkit"), 256273569Sloos configure_args: concat(common.configure_args, common.configure_args_32bit, 257273569Sloos "--with-jvm-variants=minimal,client,server", "--with-zlib=system"), 258273569Sloos default_make_targets: common.default_make_targets 259273569Sloos }, 260273569Sloos 261273569Sloos "macosx-x64": { 262279402Sloos target_os: "macosx", 263279402Sloos target_cpu: "x64", 264279402Sloos dependencies: concat(common.dependencies, "devkit"), 265279402Sloos configure_args: concat(common.configure_args, "--with-zlib=system"), 266279402Sloos default_make_targets: common.default_make_targets 267279402Sloos }, 268279402Sloos 269279402Sloos "solaris-x64": { 270279402Sloos target_os: "solaris", 271279402Sloos target_cpu: "x64", 272279402Sloos dependencies: concat(common.dependencies, "devkit", "cups"), 273279402Sloos configure_args: concat(common.configure_args, "--with-zlib=system"), 274279402Sloos default_make_targets: common.default_make_targets 275279402Sloos }, 276279402Sloos 277279402Sloos "solaris-sparcv9": { 278279402Sloos target_os: "solaris", 279279402Sloos target_cpu: "sparcv9", 280279402Sloos dependencies: concat(common.dependencies, "devkit", "cups"), 281279402Sloos configure_args: concat(common.configure_args, "--with-zlib=system"), 282279402Sloos default_make_targets: common.default_make_targets 283279402Sloos }, 284279402Sloos 285279402Sloos "windows-x64": { 286279402Sloos target_os: "windows", 287279402Sloos target_cpu: "x64", 288279402Sloos dependencies: concat(common.dependencies, "devkit", "freetype"), 289279402Sloos configure_args: concat(common.configure_args), 290279402Sloos default_make_targets: common.default_make_targets 291279402Sloos }, 292279402Sloos 293279402Sloos "windows-x86": { 294279402Sloos target_os: "windows", 295279553Sloos target_cpu: "x86", 296300750Sian build_cpu: "x64", 297279553Sloos dependencies: concat(common.dependencies, "devkit", "freetype"), 298279553Sloos configure_args: concat(common.configure_args, 299279553Sloos "--with-jvm-variants=client,server", common.configure_args_32bit), 300279553Sloos default_make_targets: common.default_make_targets 301279553Sloos } 302279553Sloos }; 303279622Sloos profiles = concatObjects(profiles, mainProfiles); 304279553Sloos // Generate debug versions of all the main profiles 305279553Sloos profiles = concatObjects(profiles, generateDebugProfiles(common, mainProfiles)); 306279553Sloos // Generate slowdebug versions of all the main profiles 307279553Sloos profiles = concatObjects(profiles, generateSlowdebugProfiles(common, mainProfiles)); 308279761Sloos 309279622Sloos // Generate open only profiles for all the main profiles for JPRT and reference 310279553Sloos // implementation builds. 311279553Sloos var openOnlyProfiles = generateOpenOnlyProfiles(common, mainProfiles); 312279761Sloos // The open only profiles on linux are used for reference builds and should 313279553Sloos // produce the compact profile images by default. This adds "profiles" as an 314279553Sloos // extra default target. 315279553Sloos var openOnlyProfilesExtra = { 316279553Sloos "linux-x64-open": { 317299563Sgonzo default_make_targets: "profiles" 318299563Sgonzo }, 319299563Sgonzo 320299563Sgonzo "linux-x86-open": { 321299563Sgonzo default_make_targets: "profiles" 322299563Sgonzo } 323299563Sgonzo }; 324299563Sgonzo var openOnlyProfiles = concatObjects(openOnlyProfiles, openOnlyProfilesExtra); 325299563Sgonzo 326299563Sgonzo profiles = concatObjects(profiles, openOnlyProfiles); 327300750Sian // Generate debug profiles for the open jprt profiles 328299563Sgonzo profiles = concatObjects(profiles, generateDebugProfiles(common, openOnlyProfiles)); 329299563Sgonzo 330299563Sgonzo // Profiles used to run tests. Used in JPRT. 331299563Sgonzo var testOnlyProfiles = { 332299563Sgonzo 333300750Sian "run-test": { 334299563Sgonzo target_os: input.build_os, 335299563Sgonzo target_cpu: input.build_cpu, 336299563Sgonzo dependencies: [ "jtreg", "gnumake" ], 337299563Sgonzo labels: "test" 338299563Sgonzo } 339299563Sgonzo }; 340299563Sgonzo profiles = concatObjects(profiles, testOnlyProfiles); 341213237Sgonzo 342213237Sgonzo // Generate the missing platform attributes 343213237Sgonzo profiles = generatePlatformAttributes(profiles); 344213237Sgonzo profiles = generateDefaultMakeTargetsConfigureArg(common, profiles); 345213237Sgonzo return profiles; 346213237Sgonzo}; 347213237Sgonzo 348213237Sgonzo/** 349213237Sgonzo * Generate the dependencies part of the configuration 350213237Sgonzo * 351213237Sgonzo * @param input External data to use for generating the configuration 352213237Sgonzo * @param common The common values 353255254Ssbruno * @returns {{}} Dependencies part of configuration 354213237Sgonzo */ 355213237Sgonzovar getJibProfilesDependencies = function (input, common) { 356213237Sgonzo 357279402Sloos var boot_jdk_platform = input.build_os + "-" 358279402Sloos + (input.build_cpu == "x86" ? "i586" : input.build_cpu); 359279402Sloos 360279402Sloos var devkit_platform_revisions = { 361213237Sgonzo linux_x64: "gcc4.9.2-OEL6.4+1.0", 362213237Sgonzo macosx_x64: "Xcode6.3-MacOSX10.9+1.0", 363213237Sgonzo solaris_x64: "SS12u4-Solaris11u1+1.0", 364213237Sgonzo solaris_sparcv9: "SS12u4-Solaris11u1+1.0", 365279553Sloos windows_x64: "VS2013SP4+1.0" 366300750Sian }; 367279402Sloos 368213237Sgonzo var devkit_platform = (input.target_cpu == "x86" 369213237Sgonzo ? input.target_os + "_x64" 370213237Sgonzo : input.target_platform); 371279761Sloos 372279761Sloos var dependencies = { 373279761Sloos 374213237Sgonzo boot_jdk: { 375213237Sgonzo server: "javare", 376213237Sgonzo module: "jdk", 377213237Sgonzo revision: "8", 378213237Sgonzo checksum_file: boot_jdk_platform + "/MD5_VALUES", 379213237Sgonzo file: boot_jdk_platform + "/jdk-8-" + boot_jdk_platform + ".tar.gz", 380213237Sgonzo configure_args: (input.build_os == "macosx" 381213237Sgonzo ? "--with-boot-jdk=" + input.get("boot_jdk", "install_path") + "/jdk1.8.0.jdk/Contents/Home" 382213237Sgonzo : "--with-boot-jdk=" + input.get("boot_jdk", "install_path") + "/jdk1.8.0") 383258050Sloos }, 384258050Sloos 385213237Sgonzo devkit: { 386213237Sgonzo organization: common.organization, 387213237Sgonzo ext: "tar.gz", 388213237Sgonzo module: "devkit-" + devkit_platform, 389213237Sgonzo revision: devkit_platform_revisions[devkit_platform] 390273569Sloos }, 391213237Sgonzo 392273569Sloos build_devkit: { 393273569Sloos organization: common.organization, 394273569Sloos ext: "tar.gz", 395213237Sgonzo module: "devkit-" + input.build_platform, 396213237Sgonzo revision: devkit_platform_revisions[input.build_platform] 397213237Sgonzo }, 398213237Sgonzo 399258050Sloos cups: { 400213237Sgonzo organization: common.organization, 401258050Sloos ext: "tar.gz", 402213237Sgonzo revision: "1.0118+1.0" 403213237Sgonzo }, 404213237Sgonzo 405213237Sgonzo jtreg: { 406213237Sgonzo server: "javare", 407213237Sgonzo revision: "4.2", 408213237Sgonzo build_number: "b02", 409213237Sgonzo checksum_file: "MD5_VALUES", 410213237Sgonzo file: "jtreg_bin-4.2.zip", 411213237Sgonzo environment_name: "JT_HOME" 412254988Sloos }, 413254988Sloos 414254988Sloos gnumake: { 415254988Sloos organization: common.organization, 416213237Sgonzo ext: "tar.gz", 417254988Sloos revision: "4.0+1.0", 418213237Sgonzo 419213237Sgonzo module: (input.build_os == "windows" 420213237Sgonzo ? "gnumake-" + input.build_osenv_platform 421213237Sgonzo : "gnumake-" + input.build_platform), 422213237Sgonzo 423213237Sgonzo configure_args: (input.build_os == "windows" 424213237Sgonzo ? "MAKE=" + input.get("gnumake", "install_path") + "/cygwin/bin/make" 425254988Sloos : "MAKE=" + input.get("gnumake", "install_path") + "/bin/make"), 426254988Sloos 427254988Sloos environment_path: (input.build_os == "windows" 428254988Sloos ? input.get("gnumake", "install_path") + "/cygwin/bin" 429279402Sloos : input.get("gnumake", "install_path") + "/bin") 430286845Sloos }, 431286845Sloos 432286845Sloos freetype: { 433254988Sloos organization: common.organization, 434254988Sloos ext: "tar.gz", 435286845Sloos revision: "2.3.4+1.0", 436279761Sloos module: "freetype-" + input.target_platform 437279761Sloos } 438279761Sloos }; 439279761Sloos 440279761Sloos return dependencies; 441279761Sloos}; 442279761Sloos 443279761Sloos/** 444213237Sgonzo * Generate the missing platform attributes for profiles 445213237Sgonzo * 446213237Sgonzo * @param profiles Profiles map to generate attributes on 447213237Sgonzo * @returns {{}} New profiles map with platform attributes fully filled in 448213237Sgonzo */ 449213237Sgonzovar generatePlatformAttributes = function (profiles) { 450213237Sgonzo var ret = concatObjects(profiles, {}); 451213237Sgonzo for (var profile in profiles) { 452213237Sgonzo if (ret[profile].build_os == null) { 453213237Sgonzo ret[profile].build_os = ret[profile].target_os; 454213237Sgonzo } 455213237Sgonzo if (ret[profile].build_cpu == null) { 456213237Sgonzo ret[profile].build_cpu = ret[profile].target_cpu; 457213237Sgonzo } 458213237Sgonzo ret[profile].target_platform = ret[profile].target_os + "_" + ret[profile].target_cpu; 459213237Sgonzo ret[profile].build_platform = ret[profile].build_os + "_" + ret[profile].build_cpu; 460213237Sgonzo } 461213237Sgonzo return ret; 462213237Sgonzo}; 463279620Sloos 464279620Sloos/** 465279620Sloos * Generates debug versions of profiles. Clones the given profiles and adds 466279620Sloos * debug metadata. 467279620Sloos * 468279620Sloos * @param common Common values 469279620Sloos * @param profiles Profiles map to generate debug profiles for 470279620Sloos * @returns {{}} New map of profiles containing debug profiles 471279620Sloos */ 472286909Sloosvar generateDebugProfiles = function (common, profiles) { 473286909Sloos var newProfiles = {}; 474286909Sloos for (var profile in profiles) { 475286909Sloos var debugProfile = profile + "-debug"; 476297199Sjhibbits newProfiles[debugProfile] = clone(profiles[profile]); 477279620Sloos newProfiles[debugProfile].debug_level = "fastdebug"; 478279620Sloos newProfiles[debugProfile].default_make_targets 479279620Sloos = common.default_make_targets_debug; 480213237Sgonzo newProfiles[debugProfile].labels 481213237Sgonzo = concat(newProfiles[debugProfile].labels || [], "debug"), 482213237Sgonzo newProfiles[debugProfile].configure_args 483274643Sloos = concat(newProfiles[debugProfile].configure_args, 484213237Sgonzo common.configure_args_debug); 485274643Sloos } 486213237Sgonzo return newProfiles; 487274643Sloos}; 488274643Sloos 489213237Sgonzo/** 490285784Sloos * Generates slowdebug versions of profiles. Clones the given profiles and adds 491285784Sloos * debug metadata. 492285784Sloos * 493285784Sloos * @param common Common values 494285784Sloos * @param profiles Profiles map to generate debug profiles for 495285784Sloos * @returns {{}} New map of profiles containing debug profiles 496285784Sloos */ 497285784Sloosvar generateSlowdebugProfiles = function (common, profiles) { 498297199Sjhibbits var newProfiles = {}; 499213237Sgonzo for (var profile in profiles) { 500213237Sgonzo var debugProfile = profile + "-slowdebug"; 501213237Sgonzo newProfiles[debugProfile] = clone(profiles[profile]); 502213237Sgonzo newProfiles[debugProfile].debug_level = "slowdebug"; 503213237Sgonzo newProfiles[debugProfile].default_make_targets 504213237Sgonzo = common.default_make_targets_slowdebug; 505213237Sgonzo newProfiles[debugProfile].labels 506213237Sgonzo = concat(newProfiles[debugProfile].labels || [], "slowdebug"), 507213237Sgonzo newProfiles[debugProfile].configure_args 508274643Sloos = concat(newProfiles[debugProfile].configure_args, 509213237Sgonzo common.configure_args_slowdebug); 510274643Sloos } 511286909Sloos return newProfiles; 512286909Sloos}; 513286909Sloos 514286909Sloos/** 515274643Sloos * Generates open only versions of profiles. Clones the given profiles and adds 516274643Sloos * open metadata. 517213237Sgonzo * 518213237Sgonzo * @param common Common values 519213237Sgonzo * @param profiles Profiles map to generate open only profiles for 520213237Sgonzo * @returns {{}} New map of profiles containing open only profiles 521213237Sgonzo */ 522213237Sgonzovar generateOpenOnlyProfiles = function (common, profiles) { 523213237Sgonzo var newProfiles = {}; 524213237Sgonzo for (var profile in profiles) { 525213237Sgonzo var openProfile = profile + "-open"; 526213237Sgonzo newProfiles[openProfile] = clone(profiles[profile]); 527213237Sgonzo newProfiles[openProfile].labels 528213237Sgonzo = concat(newProfiles[openProfile].labels || [], "open"), 529213237Sgonzo newProfiles[openProfile].configure_args 530213237Sgonzo = concat(newProfiles[openProfile].configure_args, 531213237Sgonzo "--enable-openjdk-only"); 532213237Sgonzo } 533213237Sgonzo return newProfiles; 534213237Sgonzo}; 535213237Sgonzo 536213237Sgonzo/** 537213237Sgonzo * The default_make_targets attribute on a profile is not a real Jib attribute. 538213237Sgonzo * This function rewrites that attribute into the corresponding configure arg. 539213237Sgonzo * Calling this function multiple times on the same profiles object is safe. 540213237Sgonzo * 541286845Sloos * @param common Common values 542213237Sgonzo * @param profiles Profiles map to rewrite profiles for 543274638Sloos * @returns {{}} New map of profiles with the make targets converted 544213237Sgonzo */ 545274638Sloosvar generateDefaultMakeTargetsConfigureArg = function (common, profiles) { 546213237Sgonzo var ret = concatObjects(profiles, {}); 547213237Sgonzo for (var profile in ret) { 548213237Sgonzo if (ret[profile]["default_make_targets"] != null) { 549213237Sgonzo var targetsString = concat(ret[profile].default_make_targets).join(" "); 550213237Sgonzo // Iterate over all configure args and see if --with-default-make-target 551213237Sgonzo // is already there and change it, otherwise add it. 552213237Sgonzo var found = false; 553213237Sgonzo for (var arg in ret[profile].configure_args) { 554213237Sgonzo if (arg.startsWith("--with-default-make-target")) { 555274638Sloos found = true; 556213237Sgonzo arg.replace(/=.*/, "=" + targetsString); 557213237Sgonzo } 558213237Sgonzo } 559213237Sgonzo if (!found) { 560286845Sloos ret[profile].configure_args = concat( 561286845Sloos ret[profile].configure_args, 562286845Sloos "--with-default-make-target=" + targetsString); 563213237Sgonzo } 564286845Sloos } 565274638Sloos } 566274638Sloos return ret; 567274638Sloos} 568274638Sloos 569274638Sloos/** 570213237Sgonzo * Deep clones an object tree. 571213237Sgonzo * 572273917Sloos * @param o Object to clone 573274638Sloos * @returns {{}} Clone of o 574294883Sjhibbits */ 575274638Sloosvar clone = function (o) { 576274638Sloos return JSON.parse(JSON.stringify(o)); 577274638Sloos}; 578274638Sloos 579274638Sloos/** 580274638Sloos * Concatenates all arguments into a new array 581274638Sloos * 582274638Sloos * @returns {Array.<T>} New array containing all arguments 583274638Sloos */ 584274638Sloosvar concat = function () { 585274638Sloos return Array.prototype.concat.apply([], arguments); 586274638Sloos}; 587274638Sloos 588274638Sloos/** 589274638Sloos * Copies all elements in an array into a new array but replacing all 590274638Sloos * occurrences of original with replacement. 591274638Sloos * 592294883Sjhibbits * @param original Element to look for 593274638Sloos * @param replacement Element to replace with 594274638Sloos * @param a Array to copy 595274638Sloos * @returns {Array} New array with all occurrences of original replaced 596274638Sloos * with replacement 597274638Sloos */ 598274638Sloosvar replace = function (original, replacement, a) { 599274638Sloos var newA = []; 600274638Sloos for (var i in a) { 601274638Sloos if (original == a[i]) { 602295832Sjhibbits newA.push(replacement); 603274638Sloos } else { 604274638Sloos newA.push(a[i]); 605274638Sloos } 606274638Sloos } 607274638Sloos return newA; 608274638Sloos}; 609274638Sloos 610274638Sloos/** 611274638Sloos * Deep concatenation of two objects. For each node encountered, merge 612274638Sloos * the contents with the corresponding node in the other object tree, 613274638Sloos * treating all strings as array elements. 614274638Sloos * 615274638Sloos * @param o1 Object to concatenate 616274638Sloos * @param o2 Object to concatenate 617274638Sloos * @returns {{}} New object tree containing the concatenation of o1 and o2 618274638Sloos */ 619274638Sloosvar concatObjects = function (o1, o2) { 620274638Sloos var ret = {}; 621274638Sloos for (var a in o1) { 622274638Sloos if (o2[a] == null) { 623274638Sloos ret[a] = o1[a]; 624274638Sloos } 625274638Sloos } 626274638Sloos for (var a in o2) { 627274638Sloos if (o1[a] == null) { 628274638Sloos ret[a] = o2[a]; 629274638Sloos } else { 630274638Sloos if (typeof o1[a] == 'string') { 631274638Sloos ret[a] = [o1[a]].concat(o2[a]); 632274638Sloos } else if (Array.isArray(o1[a])) { 633274638Sloos ret[a] = o1[a].concat(o2[a]); 634274638Sloos } else if (typeof o1[a] == 'object') { 635274638Sloos ret[a] = concatObjects(o1[a], o2[a]); 636274638Sloos } 637274638Sloos } 638274638Sloos } 639274638Sloos return ret; 640274638Sloos}; 641274638Sloos