2021-02-14 15:07:39 -05:00
|
|
|
import org.apache.tools.ant.taskdefs.condition.Os
|
|
|
|
import java.nio.file.Files
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership.
|
|
|
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
* (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-04-12 14:16:43 -04:00
|
|
|
def resources = scriptResources(buildscript)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Regenerates ICU-related data files.
|
|
|
|
*
|
|
|
|
* This build file contains regeneration code utilizing both icu4j and icu4c.
|
2021-02-14 15:07:39 -05:00
|
|
|
*
|
|
|
|
* The icu4c version must match exactly the icu4j version in version.props:
|
|
|
|
* The one on your system is probably different. This script will attempt to
|
|
|
|
* download and compile a matching icu4c version automatically.
|
|
|
|
*/
|
2021-04-12 14:16:43 -04:00
|
|
|
|
|
|
|
// Configure different icu4j dependencies.
|
|
|
|
configure(rootProject) {
|
|
|
|
configurations {
|
2021-11-17 12:13:40 -05:00
|
|
|
icu_current
|
2021-04-12 14:16:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
dependencies {
|
2024-06-17 03:49:21 -04:00
|
|
|
icu_current deps.icu4j
|
2021-04-12 14:16:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-17 12:13:40 -05:00
|
|
|
// This retrieves the module name/ version for ICU from the given
|
|
|
|
// configuration (if present).
|
|
|
|
def icuVersionFromConfiguration(Configuration configuration) {
|
|
|
|
return configuration.resolvedConfiguration.getFirstLevelModuleDependencies({ dep -> dep.group.startsWith("com.ibm.icu") }).collect { dep -> dep.module.id }.join(", ")
|
|
|
|
}
|
2021-04-12 14:16:43 -04:00
|
|
|
|
2021-02-14 15:07:39 -05:00
|
|
|
configure(project(":lucene:analysis:icu")) {
|
|
|
|
def utr30DataDir = file("src/data/utr30")
|
|
|
|
|
|
|
|
def icuBuildDir = file("${buildDir}/icu")
|
|
|
|
def icuBinDir
|
|
|
|
def gennorm
|
|
|
|
def icupkg
|
|
|
|
|
|
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
|
|
icuBinDir = file("${icuBuildDir}/bin64")
|
|
|
|
gennorm = file("${icuBinDir}/gennorm2.exe")
|
|
|
|
icupkg = file("${icuBinDir}/icupkg.exe")
|
|
|
|
} else {
|
|
|
|
icuBinDir = file("${icuBuildDir}/icu/source/bin")
|
|
|
|
gennorm = file("${icuBinDir}/gennorm2")
|
|
|
|
icupkg = file("${icuBinDir}/icupkg")
|
|
|
|
}
|
|
|
|
|
2021-04-19 07:37:47 -04:00
|
|
|
// lazy gstring with ICU version.
|
2024-08-15 16:28:49 -04:00
|
|
|
def icu4jVersion = deps.icu4j.get().version
|
2021-04-19 07:37:47 -04:00
|
|
|
|
2021-04-02 05:46:43 -04:00
|
|
|
def icuCompileTask = Os.isFamily(Os.FAMILY_WINDOWS) ? "compileIcuWindows" : "compileIcuLinux"
|
|
|
|
|
2021-04-16 16:35:51 -04:00
|
|
|
task genUtr30DataFilesInternal() {
|
2021-11-17 12:13:40 -05:00
|
|
|
def icuConfig = rootProject.configurations.icu_current
|
|
|
|
|
|
|
|
dependsOn icuConfig
|
2021-04-02 05:46:43 -04:00
|
|
|
dependsOn icuCompileTask
|
2021-02-14 15:07:39 -05:00
|
|
|
|
|
|
|
// May be undefined yet, so use a provider.
|
|
|
|
dependsOn { sourceSets.tools.runtimeClasspath }
|
|
|
|
|
2021-04-02 05:46:43 -04:00
|
|
|
// gennorm generates file order-dependent output, so make it constant here.
|
|
|
|
def inputFiles = fileTree(dir: utr30DataDir, include: "*.txt").asList().toSorted(Comparator.comparing { File f -> f.name })
|
|
|
|
def outputFile = file("src/resources/org/apache/lucene/analysis/icu/utr30.nrm")
|
|
|
|
|
|
|
|
inputs.files inputFiles
|
2021-11-17 12:13:40 -05:00
|
|
|
inputs.property "icuConfig", provider { icuVersionFromConfiguration(icuConfig) }
|
2021-04-02 05:46:43 -04:00
|
|
|
outputs.file outputFile
|
|
|
|
|
2021-02-14 15:07:39 -05:00
|
|
|
doFirst {
|
|
|
|
// all these steps must be done sequentially: it's a pipeline resulting in utr30.nrm
|
|
|
|
project.javaexec {
|
|
|
|
main = "org.apache.lucene.analysis.icu.GenerateUTR30DataFiles"
|
|
|
|
classpath = sourceSets.tools.runtimeClasspath
|
|
|
|
|
|
|
|
ignoreExitValue false
|
|
|
|
workingDir utr30DataDir
|
2021-02-15 14:56:13 -05:00
|
|
|
args = [
|
2021-04-19 07:37:47 -04:00
|
|
|
"release-${icu4jVersion.replace(".", "-")}"
|
2021-02-15 14:56:13 -05:00
|
|
|
]
|
2021-02-14 15:07:39 -05:00
|
|
|
}
|
|
|
|
|
2021-03-30 08:38:13 -04:00
|
|
|
project.quietExec {
|
2021-02-14 15:07:39 -05:00
|
|
|
executable gennorm
|
|
|
|
args = [
|
|
|
|
"-v",
|
|
|
|
"-s",
|
|
|
|
utr30DataDir,
|
|
|
|
"-o",
|
|
|
|
"${buildDir}/utr30.tmp",
|
2021-04-02 05:46:43 -04:00
|
|
|
*(inputFiles.collect { it.name })
|
2021-02-14 15:07:39 -05:00
|
|
|
]
|
|
|
|
}
|
2021-03-30 08:38:13 -04:00
|
|
|
|
|
|
|
project.quietExec {
|
2021-02-14 15:07:39 -05:00
|
|
|
executable icupkg
|
|
|
|
args = [
|
|
|
|
"-tb",
|
|
|
|
"${buildDir}/utr30.tmp",
|
2021-04-02 05:46:43 -04:00
|
|
|
outputFile
|
2021-02-14 15:07:39 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-16 16:35:51 -04:00
|
|
|
task genRbbiInternal() {
|
2021-11-17 12:13:40 -05:00
|
|
|
def icuConfig = rootProject.configurations.icu_current
|
|
|
|
|
|
|
|
dependsOn icuConfig
|
|
|
|
|
2021-02-14 15:07:39 -05:00
|
|
|
// May be undefined yet, so use a provider.
|
|
|
|
dependsOn { sourceSets.tools.runtimeClasspath }
|
|
|
|
|
2021-04-02 05:46:43 -04:00
|
|
|
def sourceDir = file("src/data/uax29")
|
|
|
|
def targetDir = file("src/resources/org/apache/lucene/analysis/icu/segmentation")
|
|
|
|
|
|
|
|
inputs.files fileTree(dir: sourceDir, include: "*.rbbi")
|
2021-11-17 12:13:40 -05:00
|
|
|
inputs.property "icuConfig", provider { icuVersionFromConfiguration(icuConfig) }
|
2021-04-02 05:46:43 -04:00
|
|
|
outputs.files fileTree(dir: targetDir, include: "*.brk")
|
|
|
|
|
2021-02-14 15:07:39 -05:00
|
|
|
doFirst {
|
|
|
|
project.javaexec {
|
|
|
|
main = "org.apache.lucene.analysis.icu.RBBIRuleCompiler"
|
|
|
|
classpath = sourceSets.tools.runtimeClasspath
|
|
|
|
|
|
|
|
ignoreExitValue false
|
|
|
|
enableAssertions true
|
2021-04-02 05:46:43 -04:00
|
|
|
args = [ sourceDir, targetDir ]
|
2021-02-14 15:07:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-09 01:44:07 -04:00
|
|
|
regenerate.dependsOn wrapWithPersistentChecksums(genUtr30DataFilesInternal, [
|
|
|
|
ignoreWithSource: icuCompileTask,
|
|
|
|
mustRunBefore: [ "compileJava" ]
|
|
|
|
])
|
|
|
|
regenerate.dependsOn wrapWithPersistentChecksums(genRbbiInternal, [
|
|
|
|
mustRunBefore: [ "compileJava" ]
|
|
|
|
])
|
2021-02-14 15:07:39 -05:00
|
|
|
|
|
|
|
task compileIcuWindows() {
|
|
|
|
doFirst {
|
2021-04-19 07:37:47 -04:00
|
|
|
def v = icu4jVersion
|
2021-02-14 15:07:39 -05:00
|
|
|
def icuBinZip = file("${icuBuildDir}/icu4c-${v.replace(".", "_")}.zip")
|
|
|
|
if (!icuBinZip.exists()) {
|
|
|
|
icuBuildDir.mkdirs()
|
|
|
|
|
2021-02-20 13:28:47 -05:00
|
|
|
// Download binaries matching icu4j version in version.props
|
2021-02-14 15:07:39 -05:00
|
|
|
def src = URI.create("https://github.com/unicode-org/icu/releases/download/release-${v.replace(".", "-")}/icu4c-${v.replace(".", "_")}-Win64-MSVC2019.zip")
|
|
|
|
|
|
|
|
logger.lifecycle("Trying to download binary ICU version: ${v} from:\n ${src}")
|
|
|
|
Files.write(icuBinZip.toPath(), src.toURL().openStream().bytes)
|
|
|
|
logger.lifecycle("Downloaded ${icuBinZip.size()} bytes.")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unzip.
|
|
|
|
project.copy {
|
|
|
|
into icuBuildDir
|
|
|
|
from zipTree(icuBinZip)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
task compileIcuLinux() {
|
|
|
|
doFirst {
|
|
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
|
|
throw new GradleException("ICU compilation not supported on Windows.")
|
|
|
|
}
|
|
|
|
|
2021-04-19 07:37:47 -04:00
|
|
|
def v = icu4jVersion
|
2021-02-14 15:07:39 -05:00
|
|
|
def icuSrcTgz = file("${icuBuildDir}/icu4c-${v.replace(".", "_")}-src.tgz")
|
|
|
|
|
2021-02-20 13:28:47 -05:00
|
|
|
// Download sources for version matching icu4j version in version.props
|
2021-02-14 15:07:39 -05:00
|
|
|
if (!icuSrcTgz.exists()) {
|
|
|
|
icuBuildDir.mkdirs()
|
|
|
|
def src = URI.create("https://github.com/unicode-org/icu/releases/download/release-${v.replace(".", "-")}/icu4c-${v.replace(".", "_")}-src.tgz")
|
|
|
|
logger.lifecycle("Trying to download and compile ICU version: ${v} from:\n ${src}")
|
|
|
|
Files.write(icuSrcTgz.toPath(), src.toURL().openStream().bytes)
|
|
|
|
logger.lifecycle("Downloaded ${icuSrcTgz.size()} bytes.")
|
|
|
|
}
|
|
|
|
|
|
|
|
def icuSrcDir = file("${icuBuildDir}/icu/source")
|
|
|
|
project.delete icuSrcDir
|
|
|
|
|
2021-02-20 13:28:47 -05:00
|
|
|
// Extract the tgz
|
2021-03-30 08:38:13 -04:00
|
|
|
project.quietExec {
|
2021-02-14 15:07:39 -05:00
|
|
|
executable "tar"
|
|
|
|
workingDir icuBuildDir
|
|
|
|
args = [
|
2021-04-22 07:24:44 -04:00
|
|
|
"-zxf",
|
2021-02-14 15:07:39 -05:00
|
|
|
icuSrcTgz
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2021-02-20 13:28:47 -05:00
|
|
|
// Compile: (cd icu/source && ./configure --prefix=$(pwd) --enable-rpath && make -j4)
|
2021-03-30 08:38:13 -04:00
|
|
|
project.quietExec {
|
2021-02-14 15:07:39 -05:00
|
|
|
executable "sh"
|
|
|
|
|
|
|
|
workingDir icuSrcDir
|
2021-04-22 07:24:44 -04:00
|
|
|
environment("CFLAGS", "-O0")
|
|
|
|
environment("CXXFLAGS", "-O0")
|
2021-02-14 15:07:39 -05:00
|
|
|
args = [
|
|
|
|
"configure",
|
|
|
|
"--prefix=${icuSrcDir}",
|
|
|
|
"--enable-rpath"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2021-03-30 08:38:13 -04:00
|
|
|
project.quietExec {
|
2021-02-14 15:07:39 -05:00
|
|
|
executable "make"
|
|
|
|
workingDir icuSrcDir
|
|
|
|
args = [
|
2021-04-22 07:24:44 -04:00
|
|
|
"-j${propertyOrDefault('tests.jvms', '4')}"
|
2021-02-14 15:07:39 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2021-02-20 13:28:47 -05:00
|
|
|
// Test that the binaries work: derb -V
|
2021-02-14 15:07:39 -05:00
|
|
|
logger.lifecycle("Compiled ICU, checking...")
|
2021-03-30 08:38:13 -04:00
|
|
|
project.quietExec {
|
2021-02-14 15:07:39 -05:00
|
|
|
executable "./derb"
|
|
|
|
workingDir icuBinDir
|
|
|
|
args = [
|
|
|
|
"-V"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-12 14:16:43 -04:00
|
|
|
|
|
|
|
|
|
|
|
// Regenerates UnicodeProps.java
|
|
|
|
configure(project(":lucene:analysis:common")) {
|
2021-04-16 16:35:51 -04:00
|
|
|
task generateUnicodePropsInternal() {
|
2021-11-17 12:13:40 -05:00
|
|
|
def icuConfig = rootProject.configurations.icu_current
|
2021-04-12 14:16:43 -04:00
|
|
|
def outputFile = file("src/java/org/apache/lucene/analysis/util/UnicodeProps.java")
|
|
|
|
|
|
|
|
description "Regenerate ${outputFile} (with ${icuConfig.name})"
|
|
|
|
group "generation"
|
|
|
|
|
|
|
|
dependsOn icuConfig
|
2021-04-19 07:37:47 -04:00
|
|
|
|
2021-11-17 12:13:40 -05:00
|
|
|
inputs.property "icuConfig", provider { icuVersionFromConfiguration(icuConfig) }
|
2021-04-12 14:16:43 -04:00
|
|
|
outputs.file outputFile
|
|
|
|
|
|
|
|
doFirst {
|
|
|
|
project.javaexec {
|
|
|
|
main "groovy.lang.GroovyShell"
|
|
|
|
classpath icuConfig, rootProject.configurations.groovy
|
|
|
|
|
|
|
|
args = [
|
|
|
|
"--encoding", "UTF-8",
|
|
|
|
file("${resources}/GenerateUnicodeProps.groovy"),
|
|
|
|
outputFile
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-09 01:44:07 -04:00
|
|
|
regenerate.dependsOn wrapWithPersistentChecksums(generateUnicodePropsInternal, [
|
|
|
|
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
|
|
|
|
mustRunBefore: [ "compileJava" ]
|
|
|
|
])
|
2021-04-12 14:16:43 -04:00
|
|
|
}
|