1 /* 2 * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Amazon designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 */ 21 22 dependencies { 23 compile project(path: ':openjdksrc', configuration: 'archives') 24 compile project(path: ':prebuild', configuration: 'cacerts') 25 } 26 27 // Two configurations for tgz & Jtreg native library respectively. 28 // Separate artifacts to simplify the artifacts fetching in :mac:pkg. 29 configurations { 30 buildTar 31 testLib 32 } 33 // consts 34 def imageDir= "$buildRoot/build/${project.jdkImageName}/images" 35 def jdkResultingImage = "${imageDir}/jdk-bundle" 36 def testResultingImage = "${imageDir}/test" 37 def correttoMacDir = "amazon-corretto-${project.version.major}.jdk" 38 39 // deps 40 def depsMap = [:] 41 project.configurations.compile.getFiles().each { depsMap[it.getName()] = it } 42 43 /** 44 * Create a local copy of the source tree in our 45 * build root -- this is required since OpenJDK's 46 * build wants to occur inside the source tree, 47 * and we don't want to tamper with someone 48 * else's tree. 49 */ 50 task copySource(type: Exec) { 51 if (!file(buildRoot).exists()) { 52 file(buildRoot).mkdirs() 53 } 54 workingDir '/usr/bin' 55 commandLine 'rsync', '-am', 56 '--exclude=pre-build', 57 '--exclude=installers', 58 '--exclude=corretto-build', 59 "${project.rootDir}/", buildRoot 60 } 61 62 task configureBuild(type: Exec) { 63 dependsOn project.configurations.compile 64 dependsOn copySource 65 workingDir "$buildRoot" 66 67 // Platform specific flags 68 def command = ['bash', 'configure', 69 "--with-cacerts-file=${depsMap[caCerts]}" 70 ] 71 if (project.correttoArch == "aarch64") { 72 command += "--with-zlib=bundled" 73 } 74 // Common flags 75 command += project.correttoCommonFlags 76 commandLine command.flatten() 77 } 78 79 task executeBuild(type: Exec) { 80 dependsOn configureBuild 81 workingDir "$buildRoot" 82 commandLine 'make', 'images' 83 } 84 85 task executeTestBuild(type: Exec) { 86 dependsOn executeBuild 87 workingDir "$buildRoot" 88 commandLine 'make','test-image' 89 } 90 91 task prepareArtifacts { 92 dependsOn executeBuild 93 doLast { 94 if(file("${jdkResultingImage}/${correttoMacDir}").exists()) { 95 delete "${jdkResultingImage}/${correttoMacDir}" 96 } 97 // Rename bundle 98 exec { 99 workingDir jdkResultingImage 100 commandLine 'bash', '-c', "\"\"mv jdk-${version.major}*.jdk ${correttoMacDir}\"\"" 101 } 102 103 // Replace Info.plist 104 def plistTokens = new Properties() 105 plistTokens["INFO"] = "Amazon Corretto ${project.version.full}-${versionOpt}".toString() 106 plistTokens["ID"] = "com.amazon.corretto.${project.version.major}".toString() 107 plistTokens["NAME"] = "Amazon Corretto ${project.version.major}".toString() 108 plistTokens["VERSION"] = "${project.version.major}.${project.version.minor}.${project.version.security}".toString() 109 plistTokens["BUILD_VERSION"] = "${project.version.full}".toString() 110 plistTokens["MACOSX_VERSION_MIN"] = (correttoArch == "x64" ? "10.12" : "11.0") 111 plistTokens["VENDOR"] = "Amazon.com Inc." 112 113 copy { 114 from("${rootDir}/make/data/bundle/JDK-Info.plist.template") { 115 rename { file -> 'Info.plist' } 116 filter(org.apache.tools.ant.filters.ReplaceTokens, beginToken: "@@", endToken: "@@", tokens: plistTokens) 117 } 118 into "${jdkResultingImage}/${correttoMacDir}/Contents" 119 } 120 121 // If property set, copy async profiler binaries to bundle 122 if (project.asyncProfilerBinariesPath != "") { 123 if (!file(project.asyncProfilerBinariesPath).isDirectory()) { 124 throw new GradleException("asyncProfilerBinariesPath is not a valid directory: ${project.asyncProfilerBinariesPath}") 125 } 126 copy { 127 from project.asyncProfilerBinariesPath 128 include 'bin/**', 'lib/**' 129 into "${jdkResultingImage}/${correttoMacDir}/Contents/Home" 130 } 131 copy { 132 from project.asyncProfilerLegal 133 into "${jdkResultingImage}/${correttoMacDir}/Contents/Home/legal" 134 } 135 } 136 137 // Filter files 138 if(file("${buildDir}/${correttoMacDir}").exists()) { 139 delete "${buildDir}/${correttoMacDir}" 140 } 141 copy { 142 from("${jdkResultingImage}/${correttoMacDir}") { 143 include "Contents/Home/bin/**" 144 include "Contents/Home/conf/**" 145 include "Contents/Home/include/**" 146 include "Contents/Home/jmods/**" 147 include "Contents/Home/legal/**" 148 include "Contents/Home/lib/**" 149 include "Contents/Home/man/man1/**" 150 include "Contents/Home/release" 151 include "Contents/Info.plist" 152 include "Contents/MacOS/**" 153 exclude "Contents/Home/**/*.diz" 154 } 155 from(buildRoot) { 156 include project.rootFiles 157 into "Contents/Home" 158 } 159 into "${buildDir}/${correttoMacDir}" 160 } 161 // Set the directory as bundle 162 exec { 163 commandLine "SetFile", "-a", "B", "${buildDir}/${correttoMacDir}" 164 } 165 } 166 } 167 168 task packaging(type: Exec) { 169 dependsOn prepareArtifacts 170 String tarDir = "${distributionDir}/${project.correttoJdkArchiveName}.tar.gz" 171 workingDir buildDir 172 commandLine "tar", "czf", tarDir, correttoMacDir 173 outputs.file tarDir 174 } 175 176 task packageDebugSymbols(type: Tar) { 177 dependsOn prepareArtifacts 178 description 'Package debug symbols' 179 archiveFileName = "${project.correttoDebugSymbolsArchiveName}.tar.gz" 180 compression Compression.GZIP 181 from("${jdkResultingImage}/${correttoMacDir}") { 182 include "Contents/Home/bin/*.diz" 183 include "Contents/Home/lib/*.diz" 184 include "Contents/Home/lib/server/*.diz" 185 } 186 into "${buildDir}/${correttoMacDir}" 187 into project.correttoDebugSymbolsArchiveName 188 } 189 190 task packageTestResults(type: Tar) { 191 dependsOn executeTestBuild 192 description 'Package test results' 193 archiveFileName = "${project.correttoTestImageArchiveName}.tar.gz" 194 compression Compression.GZIP 195 from(testResultingImage) { 196 include '**' 197 } 198 into project.correttoTestImageArchiveName 199 } 200 201 build.dependsOn packaging 202 build.dependsOn packageDebugSymbols 203 build.dependsOn packageTestResults 204 205 artifacts { 206 buildTar file: packaging.outputs.getFiles().getSingleFile(), builtBy: packaging 207 testLib packageTestResults 208 }