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 ext { 28 // all linux distros and macos support 'uname -m' 29 arch = ['uname', '-m'].execute().text.trim() 30 31 switch (arch) { 32 case 'aarch64': 33 arch_alias = arch 34 break; 35 case 'x86_64': 36 arch_alias = 'x64' 37 break; 38 default: 39 throw new GradleException("${arch} is not suported") 40 } 41 } 42 def jdkResultingImage = "$buildRoot/build/linux-${arch}-server-${correttoDebugLevel}/images/jdk" 43 def testResultingImage = "$buildRoot/build/linux-${arch}-server-${correttoDebugLevel}/images/test" 44 45 // deps 46 def depsMap = [:] 47 project.configurations.compile.getFiles().each { depsMap[it.getName()] = it } 48 /** 49 * Create a local copy of the source tree in our 50 * build root -- this is required since OpenJDK's 51 * build wants to occur inside the source tree, 52 * and we don't want to tamper with someone 53 * else's tree. 54 */ 55 task copySource(type: Exec) { 56 if (!file(buildRoot).exists()) { 57 file(buildRoot).mkdirs() 58 } 59 workingDir '/usr/bin' 60 commandLine 'rsync', '-am', 61 '--exclude=pre-build', 62 '--exclude=installers', 63 '--exclude=corretto-build', 64 "${project.rootDir}/", buildRoot 65 } 66 67 /** 68 * Scan the patches folder for any .patch that needs 69 * to be applied before start building. 70 */ 71 task applyPatches() { 72 dependsOn copySource 73 doLast { 74 fileTree('patches').matching { 75 include '*.patch' 76 }.each { f -> 77 ant.patch(patchfile: f, dir: "$buildRoot", strip: 0) 78 } 79 } 80 } 81 82 task configureBuild(type: Exec) { 83 84 dependsOn project.configurations.compile 85 dependsOn applyPatches 86 workingDir "$buildRoot" 87 88 // Platform specific flags 89 def command = ['bash', 'configure'] 90 // Common flags 91 command += project.correttoCommonFlags 92 command += ["--with-cacerts-file=${depsMap[caCerts]}", 93 "--with-zlib=system" 94 ] 95 commandLine command.flatten() 96 } 97 98 task executeBuild(type: Exec) { 99 dependsOn configureBuild 100 workingDir "$buildRoot" 101 commandLine 'make', 'images' 102 outputs.dir jdkResultingImage 103 } 104 105 task createTestImage(type: Exec) { 106 dependsOn executeBuild 107 workingDir "$buildRoot" 108 commandLine 'make','test-image' 109 } 110 111 task bundleThirdPartyBinaries { 112 dependsOn executeBuild 113 doLast { 114 // If property set, copy async profiler binaries to bundle 115 if (project.asyncProfilerBinariesPath != "") { 116 if (!file(project.asyncProfilerBinariesPath).isDirectory()) { 117 throw new GradleException("asyncProfilerBinariesPath is not a valid directory: ${project.asyncProfilerBinariesPath}") 118 } 119 copy { 120 from project.asyncProfilerBinariesPath 121 include 'bin/**', 'lib/**' 122 into jdkResultingImage 123 } 124 copy { 125 from project.asyncProfilerLegal 126 into "${jdkResultingImage}/legal" 127 } 128 } 129 } 130 } 131 132 task packageTestImage(type: Tar) { 133 dependsOn createTestImage 134 description = 'Package test results' 135 archiveFileName = "amazon-corretto-testimage-${project.version.full}-alpine-linux-${arch_alias}.tar.gz" 136 compression = Compression.GZIP 137 from(testResultingImage) { 138 include '**' 139 } 140 into "amazon-corretto-testimage-${project.version.full}-alpine-linux-${arch_alias}" 141 } 142 143 task packageDebugSymbols(type: Tar) { 144 dependsOn packageTestImage 145 description = 'Package debug symbols' 146 archiveFileName = "amazon-corretto-debugsymbols-${project.version.full}-alpine-linux-${arch_alias}.tar.gz" 147 compression = Compression.GZIP 148 from(jdkResultingImage) { 149 include 'bin/*.diz' 150 include 'lib/*.diz' 151 include 'lib/server/*.diz' 152 into "amazon-corretto-debugsymbols-${project.version.full}-alpine-linux-${arch_alias}" 153 } 154 } 155 156 task packageBuildResults(type: Tar) { 157 description = 'Compresses the JDK image and puts the results in build/distributions.' 158 dependsOn packageDebugSymbols 159 dependsOn executeBuild 160 dependsOn bundleThirdPartyBinaries 161 archiveFileName = "amazon-corretto-${project.version.full}-alpine-linux-${arch_alias}.tar.gz" 162 compression = Compression.GZIP 163 from(buildRoot) { 164 include project.rootFiles 165 } 166 from(jdkResultingImage) { 167 include 'bin/**' 168 include 'conf/**' 169 include 'include/**' 170 include 'jmods/**' 171 include 'lib/**' 172 include 'man/man1/**' 173 include 'release' 174 exclude '**/*.diz' 175 } 176 177 // Copy legal directory specifically to set permission correctly. 178 // See https://github.com/corretto/corretto-11/issues/129 179 from(jdkResultingImage) { 180 include 'legal/**' 181 fileMode = 0444 182 } 183 into "amazon-corretto-${project.version.full}-alpine-linux-${arch_alias}" 184 } 185 186 artifacts { 187 archives packageBuildResults 188 }