Skip to content

Commit 3b32899

Browse files
Keep symlinks in legal subdirectories in linux/macos packages. Remove root legal files that already exist in legal/java.base (corretto#141)
1 parent 8481693 commit 3b32899

7 files changed

Lines changed: 115 additions & 58 deletions

File tree

build.gradle

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ allprojects {
109109

110110
// If this is a certified release build, exclude the README.JAVASE file
111111
excludeReadmeJavaSE = Boolean.parseBoolean(project.findProperty("corretto.excludeReadmeJavaSE"))
112-
rootFiles = ['ADDITIONAL_LICENSE_INFO', 'ASSEMBLY_EXCEPTION', 'LICENSE', 'README.md', 'commitId.txt', 'version.txt']
112+
rootFiles = ['README.md', 'commitId.txt', 'version.txt']
113113
if (!excludeReadmeJavaSE) {
114114
rootFiles += 'README.JAVASE'
115115
}
@@ -138,6 +138,8 @@ allprojects {
138138
asyncProfilerBinariesPath = project.findProperty("asyncProfilerBinariesPath") ?: ""
139139
asyncProfilerLegal = "${rootDir}/installers/legal/async-profiler.md"
140140

141+
keepSymlinks = Boolean.parseBoolean(project.findProperty("corretto.keepSymlinks"))
142+
141143
// Valid value: null, release, debug, fastdebug, slowdebug
142144
correttoDebugLevel = "release" // Default: release
143145
switch(project.findProperty("corretto.debug_level")) {
@@ -342,3 +344,20 @@ project(':openjdksrc') {
342344
archives sourceDistributionTarball
343345
}
344346
}
347+
348+
def runCmdAndLog(Project project, List<String> args) {
349+
def output = new ByteArrayOutputStream()
350+
def result = project.exec {
351+
commandLine args
352+
standardOutput = output
353+
errorOutput = output
354+
ignoreExitValue = true
355+
}
356+
357+
if (result.exitValue != 0) {
358+
project.logger.error("ERROR: command failed with exit code ${result.exitValue}:\n${args.join(" ")}\nOUTPUT:\n${output}")
359+
throw new GradleException("Command '${args.join("' '")}' failed with exit code=${result.exitValue}")
360+
} else {
361+
project.logger.info("Command output:\n${output}")
362+
}
363+
}

installers/linux/al2/spec/java-amazon-corretto.spec.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ BuildRequires: make
127127
BuildRequires: alsa-lib-devel
128128
BuildRequires: binutils
129129
BuildRequires: which
130+
BuildRequires: bsdtar
130131
BuildRequires: cups-devel
131132
BuildRequires: fontconfig-devel
132133
BuildRequires: freetype-devel

installers/linux/alpine/tar/build.gradle

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -153,36 +153,49 @@ task packageDebugSymbols(type: Tar) {
153153
}
154154
}
155155

156-
task packageBuildResults(type: Tar) {
156+
task packageBuildResults {
157157
description 'Compresses the JDK image and puts the results in build/distributions.'
158158
dependsOn packageDebugSymbols
159159
dependsOn executeBuild
160160
dependsOn bundleThirdPartyBinaries
161-
archiveName "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-
}
176161

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
162+
def jdkArchiveName = "amazon-corretto-${project.version.full}-alpine-linux-${arch_alias}"
163+
def outputTarFile = "${distributionDir}/${jdkArchiveName}.tar"
164+
def prefix = jdkArchiveName
165+
166+
// Omit legal files in the root of the package
167+
def javaBaseLegalFiles = file("$jdkResultingImage/legal/java.base").listFiles().findAll { it.isFile() }.collect { it.name };
168+
def rootFilesNoLegal = project.rootFiles.findAll { !(it in javaBaseLegalFiles) }
169+
170+
inputs.files(rootFilesNoLegal)
171+
inputs.dir(jdkResultingImage)
172+
outputs.file("${outputTarFile}.gz")
173+
174+
doLast {
175+
def tarSymlinkOption = project.keepSymlinks ? '' : '-L'
176+
177+
// -s option adds prefix to each file name, but not to symlink targets (S modifier)
178+
def script = """
179+
set -ex
180+
181+
output=`realpath "$outputTarFile"`
182+
rm -f "\$output.gz"
183+
pushd "$buildRoot"
184+
bsdtar -cvf "\$output" -s '|^|$prefix/|S' $tarSymlinkOption --uid 0 --uname '' --gid 0 --gname '' "${rootFilesNoLegal.join('" "')}"
185+
popd
186+
pushd "$jdkResultingImage"
187+
bsdtar -rvf "\$output" -s '|^|$prefix/|S' --exclude '*.diz' $tarSymlinkOption --uid 0 --uname '' --gid 0 --gname '' bin conf include jmods lib man/man1 release
188+
find legal -type f | xargs -n100 chmod 444
189+
find legal -type d | xargs -n100 chmod 755
190+
bsdtar -rvf "\$output" -s '|^|$prefix/|S' $tarSymlinkOption --uid 0 --uname '' --gid 0 --gname '' legal
191+
popd
192+
gzip -9 "\$output"
193+
"""
194+
195+
runCmdAndLog(project, ['bash', '-c', script])
182196
}
183-
into "amazon-corretto-${project.version.full}-alpine-linux-${arch_alias}"
184197
}
185198

186199
artifacts {
187-
archives packageBuildResults
200+
archives file: packageBuildResults.outputs.files.singleFile, builtBy: packageBuildResults
188201
}

installers/linux/universal/deb/build.gradle

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,16 @@ ospackage {
7777

7878
/**
7979
* Uncompress and copy the universal Corretto artifact
80-
* tar for DEB packaging.
80+
* tar for DEB packaging via external tar to correctly handle symlinks.
8181
*/
82-
task extractUniversalTar(type: Copy) {
82+
task extractUniversalTar(type: Exec) {
8383
dependsOn project.configurations.compile
84-
from tarTree(project.configurations.compile.singleFile)
85-
into buildRoot
84+
85+
inputs.file project.configurations.compile.singleFile
86+
outputs.dir jdkBinaryDir
87+
88+
workingDir buildRoot
89+
commandLine 'tar', 'xvf', project.configurations.compile.singleFile
8690
}
8791

8892
/**

installers/linux/universal/rpm/build.gradle

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,16 @@ ospackage {
6969

7070
/**
7171
* Uncompress and copy the universal Corretto artifact
72-
* tar for RPM packaging.
72+
* tar for RPM packaging. Use native tar to correctly handle symlinks.
7373
*/
74-
task extractUniversalTar(type: Copy) {
74+
task extractUniversalTar(type: Exec) {
7575
dependsOn project.configurations.compile
76-
from tarTree(project.configurations.compile.singleFile)
77-
into buildRoot
76+
77+
inputs.file project.configurations.compile.singleFile
78+
outputs.dir jdkBinaryDir
79+
80+
workingDir buildRoot
81+
commandLine 'tar', 'xvf', project.configurations.compile.singleFile
7882
}
7983

8084
/**

installers/linux/universal/tar/build.gradle

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -143,37 +143,47 @@ task packageDebugSymbols(type: Tar) {
143143
}
144144
}
145145

146-
task packageBuildResults(type: Tar) {
146+
task packageBuildResults {
147147
description 'Compresses the JDK image and puts the results in build/distributions.'
148148
dependsOn packageDebugSymbols
149149
dependsOn bundleThirdPartyBinaries
150-
archiveName "${project.correttoJdkArchiveName}.tar.gz"
151-
compression Compression.GZIP
152-
from(buildRoot) {
153-
include project.rootFiles
154-
into project.correttoJdkArchiveName
155-
}
156-
from(jdkResultingImage) {
157-
include 'bin/**'
158-
include 'conf/**'
159-
include 'include/**'
160-
include 'jmods/**'
161-
include 'lib/**'
162-
include 'man/man1/**'
163-
include 'release'
164-
exclude '**/*.diz'
165-
into project.correttoJdkArchiveName
166-
}
167150

168-
// Copy legal directory specifically to set permission correctly.
169-
// See https://github.com/corretto/corretto-11/issues/129
170-
from("${jdkResultingImage}/legal") {
171-
include '**'
172-
fileMode 0444
173-
into "${project.correttoJdkArchiveName}/legal"
151+
def outputTarFile = "${distributionDir}/${project.correttoJdkArchiveName}.tar"
152+
def prefix = project.correttoJdkArchiveName
153+
154+
// Omit legal files in the root of the package
155+
def javaBaseLegalFiles = file("$jdkResultingImage/legal/java.base").listFiles().findAll { it.isFile() }.collect { it.name };
156+
def rootFilesNoLegal = project.rootFiles.findAll { !(it in javaBaseLegalFiles) }
157+
158+
inputs.files(rootFilesNoLegal)
159+
inputs.dir(jdkResultingImage)
160+
outputs.file("${outputTarFile}.gz")
161+
162+
doLast {
163+
def tarSymlinkOption = project.keepSymlinks ? '' : '-L'
164+
165+
// -s option adds prefix to each file name, but not to symlink targets (S modifier)
166+
def script = """
167+
set -ex
168+
169+
output=`realpath "$outputTarFile"`
170+
rm -f "\$output.gz"
171+
pushd "$buildRoot"
172+
bsdtar -cvf "\$output" -s '|^|$prefix/|S' $tarSymlinkOption --uid 0 --uname '' --gid 0 --gname '' "${rootFilesNoLegal.join('" "')}"
173+
popd
174+
pushd "$jdkResultingImage"
175+
bsdtar -rvf "\$output" -s '|^|$prefix/|S' --exclude '*.diz' $tarSymlinkOption --uid 0 --uname '' --gid 0 --gname '' bin conf include jmods lib man/man1
176+
find legal -type f | xargs -n100 chmod 444
177+
find legal -type d | xargs -n100 chmod 755
178+
bsdtar -rvf "\$output" -s '|^|$prefix/|S' $tarSymlinkOption --uid 0 --uname '' --gid 0 --gname '' legal
179+
popd
180+
gzip -9 "\$output"
181+
"""
182+
183+
runCmdAndLog(project, ['bash', '-c', script])
174184
}
175185
}
176186

177187
artifacts {
178-
archives packageBuildResults
188+
archives file: packageBuildResults.outputs.files.singleFile, builtBy: packageBuildResults
179189
}

installers/mac/tar/build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ task prepareArtifacts {
144144
include "Contents/Home/conf/**"
145145
include "Contents/Home/include/**"
146146
include "Contents/Home/jmods/**"
147-
include "Contents/Home/legal/**"
148147
include "Contents/Home/lib/**"
149148
include "Contents/Home/man/man1/**"
150149
include "Contents/Home/release"
@@ -158,6 +157,13 @@ task prepareArtifacts {
158157
}
159158
into "${buildDir}/${correttoMacDir}"
160159
}
160+
161+
// cp preserves symlinks
162+
def cpOptions = project.keepSymlinks ? '-R' : '-RL'
163+
exec {
164+
commandLine 'cp', cpOptions, "${jdkResultingImage}/${correttoMacDir}/Contents/Home/legal", "${buildDir}/${correttoMacDir}/Contents/Home/"
165+
}
166+
161167
// Set the directory as bundle
162168
exec {
163169
commandLine "SetFile", "-a", "B", "${buildDir}/${correttoMacDir}"

0 commit comments

Comments
 (0)