Skip to content

Commit

Permalink
Time setup and file copy separately
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Dec 27, 2024
1 parent 452a7f0 commit b0cfc77
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ interface SetupHandler {

fun populateRuntimeConfiguration(context: ConfigurationContext, dependencySet: DependencySet)

fun generateCombinedOrClassesJar(context: ExecutionContext, output: Path, legacyOutput: Path?)
data class ArtifactsResult(
val mainOutput: Path,
val legacyOutput: Path?,
)

fun generateArtifacts(context: ExecutionContext): ArtifactsResult

fun extractReobfMappings(output: Path)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,12 @@ class SetupHandlerImpl(
}

@Volatile
private var completedOutput: Path? = null
private var completedOutput: SetupHandler.ArtifactsResult? = null

@Synchronized
override fun generateCombinedOrClassesJar(context: SetupHandler.ExecutionContext, output: Path, legacyOutput: Path?) {
override fun generateArtifacts(context: SetupHandler.ExecutionContext): SetupHandler.ArtifactsResult {
if (completedOutput != null) {
requireNotNull(completedOutput).copyTo(output, true)
return
return requireNotNull(completedOutput)
}

// If the config cache is reused then the mache config may not be populated
Expand All @@ -185,8 +184,8 @@ class SetupHandlerImpl(
progressLogger.progress(it)
}
}
request.get().copyTo(output, true)
completedOutput = request.get()
return SetupHandler.ArtifactsResult(request.get(), null)
.also { completedOutput = it }
}

override fun extractReobfMappings(output: Path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ abstract class UserdevSetup : BuildService<UserdevSetup.Parameters>, SetupHandle
setup.populateRuntimeConfiguration(context, dependencySet)
}

override fun generateCombinedOrClassesJar(context: SetupHandler.ExecutionContext, output: Path, legacyOutput: Path?) {
setup.generateCombinedOrClassesJar(context, output, legacyOutput)
override fun generateArtifacts(context: SetupHandler.ExecutionContext): SetupHandler.ArtifactsResult {
return setup.generateArtifacts(context)
}

override fun extractReobfMappings(output: Path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import io.papermc.paperweight.userdev.internal.util.formatNs
import io.papermc.paperweight.util.*
import io.papermc.paperweight.util.constants.*
import javax.inject.Inject
import kotlin.io.path.*
import kotlin.system.measureNanoTime
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.RegularFileProperty
Expand Down Expand Up @@ -120,14 +121,17 @@ abstract class UserdevSetupTask : JavaLauncherTask() {
macheCodebookConfig,
)

val took = measureNanoTime {
setupService.get().generateCombinedOrClassesJar(
context,
mappedServerJar.path.createParentDirectories(),
legacyPaperclipResult.pathOrNull?.createParentDirectories(),
)
val result: SetupHandler.ArtifactsResult
val generatedIn = measureNanoTime {
result = setupService.get().generateArtifacts(context)
}
logger.lifecycle("Completed setup in ${formatNs(generatedIn)}")

val copiedTime = measureNanoTime {
result.mainOutput.copyTo(mappedServerJar.path.createParentDirectories(), overwrite = true)
result.legacyOutput?.copyTo(legacyPaperclipResult.path.createParentDirectories(), overwrite = true)
setupService.get().extractReobfMappings(reobfMappings.path.createParentDirectories())
}
logger.lifecycle("Completed setup in ${formatNs(took)}")
logger.lifecycle("Copied artifacts to project cache in ${formatNs(copiedTime)}")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,12 @@ class SetupHandlerImplV2(
}

@Volatile
private var completedOutput: Pair<Path, Path>? = null
private var completedOutput: SetupHandler.ArtifactsResult? = null

@Synchronized
override fun generateCombinedOrClassesJar(context: SetupHandler.ExecutionContext, output: Path, legacyOutput: Path?) {
override fun generateArtifacts(context: SetupHandler.ExecutionContext): SetupHandler.ArtifactsResult {
if (completedOutput != null) {
val (main, legacy) = requireNotNull(completedOutput)
main.copyTo(output, true)
legacy.copyTo(requireNotNull(legacyOutput), true)
return
return requireNotNull(completedOutput)
}

val dispatcher = createDispatcher(context)
Expand All @@ -251,9 +248,8 @@ class SetupHandlerImplV2(
progressLogger.progress(it)
}
}
filter.get().copyTo(output, true)
paperclip.get().copyTo(requireNotNull(legacyOutput), true)
completedOutput = filter.get() to paperclip.get()
return SetupHandler.ArtifactsResult(filter.get(), paperclip.get())
.also { completedOutput = it }
}

override fun extractReobfMappings(output: Path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,12 @@ class SetupHandlerImplV5(
}

@Volatile
private var completedOutput: Path? = null
private var completedOutput: SetupHandler.ArtifactsResult? = null

@Synchronized
override fun generateCombinedOrClassesJar(context: SetupHandler.ExecutionContext, output: Path, legacyOutput: Path?) {
override fun generateArtifacts(context: SetupHandler.ExecutionContext): SetupHandler.ArtifactsResult {
if (completedOutput != null) {
requireNotNull(completedOutput).copyTo(output, true)
return
return requireNotNull(completedOutput)
}

val dispatcher = createDispatcher(context)
Expand All @@ -233,8 +232,8 @@ class SetupHandlerImplV5(
progressLogger.progress(it)
}
}
request.get().copyTo(output, true)
completedOutput = request.get()
return SetupHandler.ArtifactsResult(request.get(), null)
.also { completedOutput = it }
}

override fun extractReobfMappings(output: Path) {
Expand Down

0 comments on commit b0cfc77

Please sign in to comment.