Skip to content

Commit

Permalink
Import library files in separate task from SetupVanilla
Browse files Browse the repository at this point in the history
This means SetupVanilla only needs to rerun when ATs or imports change, not whenever a patch changes
  • Loading branch information
jpenilla committed Dec 16, 2024
1 parent 66a73c9 commit 4934411
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import io.papermc.paperweight.tasks.softspoon.ApplyFeaturePatches
import io.papermc.paperweight.tasks.softspoon.ApplyFilePatches
import io.papermc.paperweight.tasks.softspoon.ApplyFilePatchesFuzzy
import io.papermc.paperweight.tasks.softspoon.FixupFilePatches
import io.papermc.paperweight.tasks.softspoon.ImportLibraryFiles
import io.papermc.paperweight.tasks.softspoon.RebuildFilePatches
import io.papermc.paperweight.tasks.softspoon.SetupPaperScript
import io.papermc.paperweight.util.*
Expand Down Expand Up @@ -116,27 +117,29 @@ open class SoftSpoonTasks(
secondFile.set(collectAccessTransform.flatMap { it.outputFile })
}

val importLibraryFiles = tasks.register<ImportLibraryFiles>("importLibraryFiles") {
paperPatches.from(project.ext.paper.sourcePatchDir, project.ext.paper.featurePatchDir)
devImports.set(project.ext.paper.devImports.fileExists(project))
libraries.from(
allTasks.downloadPaperLibrariesSources.flatMap { it.outputDir },
allTasks.downloadMcLibrariesSources.flatMap { it.outputDir }
)
}

private fun SetupVanilla.configureSetupMacheSources() {
group = "mache"

mache.from(project.configurations.named(MACHE_CONFIG))
macheOld.set(project.ext.macheOldPath)
minecraftClasspath.from(macheMinecraftLibraries)

paperPatches.from(project.ext.paper.sourcePatchDir, project.ext.paper.featurePatchDir)
devImports.set(project.ext.paper.devImports.fileExists(project))

inputFile.set(macheDecompileJar.flatMap { it.outputJar })
predicate.set { Files.isRegularFile(it) && it.toString().endsWith(".java") }
}

val setupMacheSources by tasks.registering(SetupVanilla::class) {
description = "Setup vanilla source dir (applying mache patches and paper ATs)."
configureSetupMacheSources()
libraries.from(
allTasks.downloadPaperLibrariesSources.flatMap { it.outputDir },
allTasks.downloadMcLibrariesSources.flatMap { it.outputDir }
)
libraryImports.set(importLibraryFiles.flatMap { it.outputDir })
ats.set(mergeCollectedAts.flatMap { it.outputFile })
outputDir.set(layout.cache.resolve(BASE_PROJECT).resolve("sources"))
restamp.from(restampConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,8 @@ abstract class SetupVanilla : JavaLauncherTask() {
abstract val ats: RegularFileProperty

@get:Optional
@get:InputFiles
abstract val libraries: ConfigurableFileCollection

@get:Optional
@get:InputFiles
abstract val paperPatches: ConfigurableFileCollection

@get:Optional
@get:InputFile
abstract val devImports: RegularFileProperty
@get:InputDirectory
abstract val libraryImports: DirectoryProperty

@get:Optional
@get:CompileClasspath
Expand Down Expand Up @@ -197,9 +189,8 @@ abstract class SetupVanilla : JavaLauncherTask() {
commitAndTag(git, "ATs")
}

if (!libraries.isEmpty && !paperPatches.isEmpty) {
val patches = paperPatches.files.flatMap { it.toPath().walk().filter { path -> path.toString().endsWith(".patch") }.toList() }
McDev.importMcDev(patches, null, devImports.pathOrNull, outputPath, null, libraries.files.map { it.toPath() }, true, "")
if (libraryImports.isPresent) {
libraryImports.path.copyRecursivelyTo(outputPath)

commitAndTag(git, "Imports")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* paperweight is a Gradle plugin for the PaperMC project.
*
* Copyright (c) 2023 Kyle Wood (DenWav)
* Contributors
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 only, no later versions.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/

package io.papermc.paperweight.tasks.softspoon

import io.papermc.paperweight.tasks.*
import io.papermc.paperweight.util.*
import io.papermc.paperweight.util.constants.*
import kotlin.io.path.*
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction

abstract class ImportLibraryFiles : BaseTask() {

@get:Optional
@get:InputFiles
abstract val libraries: ConfigurableFileCollection

@get:Optional
@get:InputFiles
abstract val paperPatches: ConfigurableFileCollection

@get:Optional
@get:InputFile
abstract val devImports: RegularFileProperty

@get:OutputDirectory
abstract val outputDir: DirectoryProperty

override fun init() {
super.init()
outputDir.set(layout.cache.resolve(paperTaskOutput()))
}

@TaskAction
fun run() {
outputDir.path.deleteRecursive()
outputDir.path.createDirectories()
if (!libraries.isEmpty && !paperPatches.isEmpty) {
val patches = paperPatches.files.flatMap { it.toPath().walk().filter { path -> path.toString().endsWith(".patch") }.toList() }
McDev.importMcDev(
patches,
null,
devImports.pathOrNull,
outputDir.path,
null,
libraries.files.map { it.toPath() },
true,
""
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,5 @@ private const val MACHE_PATH = "$PAPER_PATH/mache"
const val BASE_PROJECT = "$MACHE_PATH/base"

fun paperSetupOutput(name: String, ext: String) = "$SETUP_CACHE/$name.$ext"
fun Task.paperTaskOutput(ext: String) = paperTaskOutput(name, ext)
fun paperTaskOutput(name: String, ext: String) = "$TASK_CACHE/$name.$ext"
fun Task.paperTaskOutput(ext: String? = null) = paperTaskOutput(name, ext)
fun paperTaskOutput(name: String, ext: String? = null) = "$TASK_CACHE/$name" + (ext?.let { ".$it" } ?: "")

0 comments on commit 4934411

Please sign in to comment.