Skip to content

Commit

Permalink
Backport generation-compilation ordering fixes from #13282.
Browse files Browse the repository at this point in the history
Correct whitespace difference in opennlp-tools-1.9.4.jar.sha1.
  • Loading branch information
dweiss committed Jun 6, 2024
1 parent a72de3f commit d089cd6
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 49 deletions.
5 changes: 4 additions & 1 deletion gradle/generation/antlr.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ configure(project(":lucene:expressions")) {
}

def generateAntlr = wrapWithPersistentChecksums(
generateAntlrInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
generateAntlrInternal, [
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
mustRunBefore: [ "compileJava" ]
])

regenerate.dependsOn generateAntlr
}
15 changes: 12 additions & 3 deletions gradle/generation/forUtil.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ configure(project(":lucene:core")) {
}
}

regenerate.dependsOn wrapWithPersistentChecksums(generateForUtilInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
regenerate.dependsOn wrapWithPersistentChecksums(generateForUtilInternal, [
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
mustRunBefore: [ "compileJava" ]
])
}

configure(project(":lucene:backward-codecs")) {
Expand All @@ -64,7 +67,10 @@ configure(project(":lucene:backward-codecs")) {
}
}

regenerate.dependsOn wrapWithPersistentChecksums(generateForUtil84Internal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
regenerate.dependsOn wrapWithPersistentChecksums(generateForUtil84Internal, [
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
mustRunBefore: [ "compileJava" ]
])

task generateForUtil90Internal() {
description "Regenerate gen_ForUtil.py"
Expand All @@ -86,6 +92,9 @@ configure(project(":lucene:backward-codecs")) {
}
}

regenerate.dependsOn wrapWithPersistentChecksums(generateForUtil90Internal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
regenerate.dependsOn wrapWithPersistentChecksums(generateForUtil90Internal, [
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
mustRunBefore: [ "compileJava" ]
])
}

14 changes: 11 additions & 3 deletions gradle/generation/icu.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,13 @@ configure(project(":lucene:analysis:icu")) {
}
}

regenerate.dependsOn wrapWithPersistentChecksums(genUtr30DataFilesInternal, [ ignoreWithSource: icuCompileTask ])
regenerate.dependsOn wrapWithPersistentChecksums(genRbbiInternal)
regenerate.dependsOn wrapWithPersistentChecksums(genUtr30DataFilesInternal, [
ignoreWithSource: icuCompileTask,
mustRunBefore: [ "compileJava" ]
])
regenerate.dependsOn wrapWithPersistentChecksums(genRbbiInternal, [
mustRunBefore: [ "compileJava" ]
])

task compileIcuWindows() {
doFirst {
Expand Down Expand Up @@ -281,5 +286,8 @@ configure(project(":lucene:analysis:common")) {
}
}

regenerate.dependsOn wrapWithPersistentChecksums(generateUnicodePropsInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
regenerate.dependsOn wrapWithPersistentChecksums(generateUnicodePropsInternal, [
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
mustRunBefore: [ "compileJava" ]
])
}
11 changes: 8 additions & 3 deletions gradle/generation/javacc.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,14 @@ configure(project(":lucene:queryparser")) {
description "Regenerate query parsers (javacc syntax definitions)."
group "generation"

dependsOn wrapWithPersistentChecksums(javaccParserClassicInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ]),
wrapWithPersistentChecksums(javaccParserSurroundInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ]),
wrapWithPersistentChecksums(javaccParserFlexibleInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
def extraConfig = [
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
mustRunBefore: [ "compileJava" ]
]

dependsOn wrapWithPersistentChecksums(javaccParserClassicInternal, extraConfig),
wrapWithPersistentChecksums(javaccParserSurroundInternal, extraConfig),
wrapWithPersistentChecksums(javaccParserFlexibleInternal, extraConfig)
}

regenerate.dependsOn javacc
Expand Down
26 changes: 19 additions & 7 deletions gradle/generation/jflex.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ configure(project(":lucene:core")) {
}
}

def generateStandardTokenizer = wrapWithPersistentChecksums(generateStandardTokenizerInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
def generateStandardTokenizer = wrapWithPersistentChecksums(generateStandardTokenizerInternal, [
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
mustRunBefore: [ "compileJava" ]
])

regenerate.dependsOn generateStandardTokenizer
}
Expand Down Expand Up @@ -149,7 +152,11 @@ configure(project(":lucene:analysis:common")) {
}
}

def generateUAX29URLEmailTokenizer = wrapWithPersistentChecksums(generateUAX29URLEmailTokenizerInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
def generateUAX29URLEmailTokenizer = wrapWithPersistentChecksums(generateUAX29URLEmailTokenizerInternal, [
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
mustRunBefore: [ "compileJava" ]
])

// UAX29URLEmailTokenizerImpl.jflex includes: ASCIITLD.jflex
// so we make sure it is up to date. Also, make sure the ordering of internal
// tasks is enforced (just scheduling top-level wrappers doesn't mean their subtask graphs cannot be reordered).
Expand Down Expand Up @@ -197,7 +204,12 @@ configure(project(":lucene:analysis:common")) {
skeleton = skeletonDefault
}

def generateHTMLStripCharFilter = wrapWithPersistentChecksums(generateHTMLStripCharFilterInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
def extraConfig = [
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
mustRunBefore: [ "compileJava" ]
]

def generateHTMLStripCharFilter = wrapWithPersistentChecksums(generateHTMLStripCharFilterInternal, extraConfig)
// HTMLStripCharFilter.jflex includes HTMLCharacterEntities.jflex so we make sure it's up to date.
configure(generateHTMLStripCharFilter) {
dependsOn "generateHTMLCharacterEntities"
Expand All @@ -206,12 +218,12 @@ configure(project(":lucene:analysis:common")) {
dependsOn "generateHTMLCharacterEntitiesInternal"
}

regenerate.dependsOn wrapWithPersistentChecksums(generateWikipediaTokenizerInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ]),
wrapWithPersistentChecksums(generateClassicTokenizerInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ]),
regenerate.dependsOn wrapWithPersistentChecksums(generateWikipediaTokenizerInternal, extraConfig),
wrapWithPersistentChecksums(generateClassicTokenizerInternal, extraConfig),
generateUAX29URLEmailTokenizer,
wrapWithPersistentChecksums(generateHTMLCharacterEntitiesInternal),
wrapWithPersistentChecksums(generateHTMLCharacterEntitiesInternal, extraConfig),
generateHTMLStripCharFilter,
wrapWithPersistentChecksums(generateTldsInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
wrapWithPersistentChecksums(generateTldsInternal, extraConfig)
}

class JFlexTask extends DefaultTask {
Expand Down
9 changes: 7 additions & 2 deletions gradle/generation/moman.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,13 @@ configure(project(":lucene:core")) {
description "Regenerate Moman-based sources."
group "generation"

dependsOn wrapWithPersistentChecksums(utilGenPackedInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
dependsOn wrapWithPersistentChecksums(utilGenLevInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
def extraConfig = [
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
mustRunBefore: [ "compileJava" ]
]

dependsOn wrapWithPersistentChecksums(utilGenPackedInternal, extraConfig)
dependsOn wrapWithPersistentChecksums(utilGenLevInternal, extraConfig)
}

regenerate.dependsOn moman
Expand Down
33 changes: 24 additions & 9 deletions gradle/generation/regenerate.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,33 @@ configure([
//
// The idea is that, given source-generating task "sourceTaskInternal" (note the suffix),
// we create a bunch of other tasks that perform checksum generation, validation and
// source task skipping; example (sourceTask has Internal suffix stripped)
// source task skipping. For example, let's say we have a task 'genFooInternal";
// the following tasks would be created
//
// ${sourceTask}ChecksumLoad
// ${sourceTask}ChecksumSave
// ${sourceTask}ChecksumCheck (fails if checksums are inconsistent)
// ${sourceTask} dependsOn [checksum-load, ${sourceTask}Internal, checksum-save]
// genFooChecksumLoad
// genFooChecksumSave
// genFooChecksumCheck (fails if checksums are inconsistent)
//
// and the following set of dependencies would be created (with additional
// constraints to run them in this particular order!).
//
// genFoo.dependsOn [genFooChecksumLoad, genFooInternal, genFooChecksumSave]
//
// Checksums are persisted and computed from sourceTask's inputs/outputs. If the
// persisted checksums are identical to current checksums, source task
// is skipped (via sourceTaskInternal.onlyIf { false }).
// persisted checksums are identical to the now-current checksums, the "internal" task
// is skipped (using onlyIf { false }).
//
// Implementation-wise things get complicated because gradle doesn't have the notion
// of "ordered" task execution with respect to task AND its dependencies (we can add
// constraints to each node in the execution graph but not node-and-dependencies).
//
// sourceTask - the task to wrap
// extraConfig - a map with extra (optional) configuration options.
// andThenTasks: other tasks that should be scheduled to run after source task and
// before checksum calculation.
// andThenTasks: any other tasks that should be scheduled to run after the internal task and
// before checksum calculation/ saving. spotless is a good example of this.
// ignoreWithSource: any other tasks that should be ignored if the internal task is ignored
// (checksums are identical)
// mustRunBefore: any tasks which should be scheduled to run after the internal task.
wrapWithPersistentChecksums = { Task sourceTask, Map<String, Object> extraConfig = [:] ->
if (!sourceTask.name.endsWith("Internal")) {
throw new GradleException("Wrapped task must follow the convention name of *Internal: ${sourceTask.name}")
Expand All @@ -144,6 +152,13 @@ configure([
List<Object> andThenTasks = toList(extraConfig.get("andThenTasks"))
List<Object> ignoreWithSource = toList(extraConfig.get("ignoreWithSource"))

// Schedule must-run-afters
List<Object> mustRunBefore = toList(extraConfig.get("mustRunBefore"))
// TODO: maybe ensure all task refs here are strings?
tasks.matching { it.name in mustRunBefore }.configureEach {
mustRunAfter sourceTask
}

// Create checksum-loader task.
Task checksumLoadTask = tasks.create("${sourceTaskName}ChecksumLoad", {
ext {
Expand Down
6 changes: 5 additions & 1 deletion gradle/generation/snowball.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,9 @@ configure(project(":lucene:analysis:common")) {
}
}

regenerate.dependsOn wrapWithPersistentChecksums(snowballInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"], ignoreWithSource: [downloadSnowballStemmers, downloadSnowballWebsite, downloadSnowballData] ])
regenerate.dependsOn wrapWithPersistentChecksums(snowballInternal, [
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
ignoreWithSource: [downloadSnowballStemmers, downloadSnowballWebsite, downloadSnowballData],
mustRunBefore: [ "compileJava" ]
])
}
11 changes: 8 additions & 3 deletions gradle/generation/unicode-test-classes.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ configure(project(":lucene:test-framework")) {
}
}
}
regenerate.dependsOn wrapWithPersistentChecksums(generateEmojiTokenizationTestInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
regenerate.dependsOn wrapWithPersistentChecksums(generateEmojiTokenizationTestInternal, [
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
mustRunBefore: [ "compileJava" ]
])

task generateJavaUnicodeWordBreakTestInternal() {
def unicodeVersion = "12.1"
Expand Down Expand Up @@ -71,6 +74,8 @@ configure(project(":lucene:test-framework")) {
}
}

regenerate.dependsOn wrapWithPersistentChecksums(generateJavaUnicodeWordBreakTestInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])

regenerate.dependsOn wrapWithPersistentChecksums(generateJavaUnicodeWordBreakTestInternal, [
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
mustRunBefore: [ "compileJava" ]
])
}
16 changes: 0 additions & 16 deletions help/regeneration.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@ In many cases hitting (1) means you'll have to do (2) so let's discuss
these in order.


SPECIAL NOTE
------------

Regeneration tasks currently don't play well with the current gradle version.
To workaround the issue, compile everything first:

gradlew compileJava

Then run the commands as described in this document, excluding compileJava.
For example to run "regenerate":

gradlew regenerate -x compileJava

More information: https://github.com/apache/lucene/issues/13240


Checksum validation errors
--------------------------

Expand Down
2 changes: 1 addition & 1 deletion lucene/licenses/opennlp-tools-1.9.4.jar.sha1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dd5c4a6d82453bcccb78ba4ac90f166366dde12b
dd5c4a6d82453bcccb78ba4ac90f166366dde12b

0 comments on commit d089cd6

Please sign in to comment.