Skip to content

Commit 8e58c76

Browse files
committed
Enable remapping for deprecated projects
1 parent 3928e12 commit 8e58c76

File tree

2 files changed

+46
-38
lines changed

2 files changed

+46
-38
lines changed

build.gradle.kts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,20 @@ repositories {
5858
}
5959

6060
val ignoredProjects = listOf("fabric-api-bom", "fabric-api-catalog")
61-
val projectNames = file("fabric-api-upstream").list()?.filter { it.startsWith("fabric-") }?.let { it - ignoredProjects } ?: emptyList()
61+
val upstreamProjectNames = file("fabric-api-upstream").listFiles()?.toList() ?: emptyList()
62+
val deprecatedProjectFiles = file("fabric-api-upstream/deprecated").listFiles()?.toList() ?: emptyList()
63+
val allProjectRoots = (upstreamProjectNames + deprecatedProjectFiles).filter { it.name.startsWith("fabric-") && !ignoredProjects.contains(it.name) }
6264

6365
// TODO Move to setup script
6466
val generateMergedAccessWidener by tasks.registering(GenerateMergedAccessWidenerTask::class) {
6567
group = "sinytra"
6668

67-
inputFiles.from(projectNames
69+
inputFiles.from(allProjectRoots
6870
.flatMap {
6971
listOf(
70-
file("fabric-api-upstream/$it/src/client/resources"),
71-
file("fabric-api-upstream/$it/src/main/resources"),
72-
file("fabric-api-upstream/$it/src/testmod/resources")
72+
it.resolve("src/client/resources"),
73+
it.resolve("src/main/resources"),
74+
it.resolve("src/testmod/resources")
7375
)
7476
}
7577
.flatMap { it.listFiles { f -> f.name.endsWith(".accesswidener") }?.toList() ?: emptyList() })
@@ -165,26 +167,26 @@ val remapUpstreamSources by tasks.registering {
165167
group = "sinytra"
166168
}
167169

168-
val projectRoots = projectNames.map { file("fabric-api-upstream/$it") }
169-
170-
projectNames.forEach { projectName ->
170+
allProjectRoots.forEach { projectRootFile ->
171+
val isDeprecated = projectRootFile in deprecatedProjectFiles
172+
val projectName = if (isDeprecated) "deprecated-${projectRootFile.name}" else projectRootFile.name
171173
val taskName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, projectName)
172174

173175
val remapTask = tasks.register("remap${taskName}UpstreamSources", RemapSourceDirectory::class) {
174176
group = "sinytra"
175177

176-
projectRoot.set(file("fabric-api-upstream/$projectName"))
178+
projectRoot.set(projectRootFile)
177179
classpath.from(
178180
configurations["compileClasspath"],
179181
configurations["mercuryClasspath"],
180182
configurations["modCompileClasspathMapped"]
181183
)
182-
sourcepath.from(projectRoots)
184+
sourcepath.from(allProjectRoots)
183185
mappingFile.set(createMappings.flatMap { it.outputFile })
184186

185187
sourceNamespace.set(MappingsNamespace.NAMED.toString())
186188
targetNamespace.set(MappingsNamespace.MOJANG.toString())
187-
outputDir.set(file("fabric-api-mojmap"))
189+
outputDir.set(file("fabric-api-mojmap").let { if (isDeprecated) it.resolve("deprecated") else it })
188190
}
189191

190192
remapUpstreamSources.configure {

scripts/setup.main.kts

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -464,36 +464,40 @@ fun setupTask() {
464464
architecturyCommonJson.writeText(serialized)
465465
}
466466

467+
fun ensureMappedBranchExists(git: Git, sGit: Git) {
468+
// Ensure we're up to date
469+
git.fetch().setRemote(upstreamRemote).call()
470+
sGit.fetch().setRemote(upstreamRemote).call()
471+
472+
if (!sGit.branchExists(tempMappedBranch)) {
473+
if (git.branchExists(originMappedBranch, true)) {
474+
if (!git.branchExists(mappedBranch)) {
475+
logger.info("Pulling remote mapped branch from $originRemote")
476+
git.branchCreate()
477+
.setName(mappedBranch)
478+
.setStartPoint(originMappedBranch)
479+
.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM)
480+
.call()
481+
}
482+
483+
logger.info("Creating branch $tempMappedBranch")
484+
sGit.checkout()
485+
.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM)
486+
.setCreateBranch(true)
487+
.setForceRefUpdate(true)
488+
.setName(tempMappedBranch)
489+
.setStartPoint(localMappedBranch)
490+
.call()
491+
} else {
492+
setupMappedBranch(sGit)
493+
}
494+
}
495+
}
496+
467497
fun syncUpstreamTask() {
468498
Git.open(rootDir).use { git ->
469499
initSubmodule(git).use { sGit ->
470-
// Ensure we're up to date
471-
git.fetch().setRemote(upstreamRemote).call()
472-
sGit.fetch().setRemote(upstreamRemote).call()
473-
474-
if (!sGit.branchExists(tempMappedBranch)) {
475-
if (git.branchExists(originMappedBranch, true)) {
476-
if (!git.branchExists(mappedBranch)) {
477-
logger.info("Pulling remote mapped branch from $originRemote")
478-
git.branchCreate()
479-
.setName(mappedBranch)
480-
.setStartPoint(originMappedBranch)
481-
.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM)
482-
.call()
483-
}
484-
485-
logger.info("Creating branch $tempMappedBranch")
486-
sGit.checkout()
487-
.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM)
488-
.setCreateBranch(true)
489-
.setForceRefUpdate(true)
490-
.setName(tempMappedBranch)
491-
.setStartPoint(localMappedBranch)
492-
.call()
493-
} else {
494-
setupMappedBranch(sGit)
495-
}
496-
}
500+
ensureMappedBranchExists(git, sGit)
497501

498502
sGit.checkout()
499503
.setName(tempLocalBranch)
@@ -507,6 +511,8 @@ fun syncUpstreamTask() {
507511
fun updateMappingsTask() {
508512
Git.open(rootDir).use { git ->
509513
initSubmodule(git).use { sGit ->
514+
ensureMappedBranchExists(git, sGit)
515+
510516
updateMappings(sGit)
511517
}
512518
}

0 commit comments

Comments
 (0)