Skip to content

Commit

Permalink
build: migrate subprojects.settings.gradle to kotlin (#5203)
Browse files Browse the repository at this point in the history
  • Loading branch information
soloturn authored Jan 8, 2024
1 parent f3140ef commit 8f37f92
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
3 changes: 2 additions & 1 deletion docs/Using-Locally-Developed-Libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ Subprojects and included builds are similar in many respects, but the root proje

## Implementation Details

Our [`libs/subprojects.settings.gradle`](https://github.com/MovingBlocks/Terasology/blob/develop/libs/subprojects.settings.gradle) checks each subdirectory to see if it contains files that look like a Gradle root project, and if it finds them it [adds that directory as an included build](https://docs.gradle.org/current/dsl/org.gradle.api.initialization.Settings.html#org.gradle.api.initialization.Settings:includeBuild(java.lang.Object)).
Our [`libs/subprojects.settings.gradle.kts`](https://github.com/MovingBlocks/Terasology/blob/develop/libs/subprojects.settings.gradle.kts) checks each subdirectory
to see if it contains files that look like a Gradle root project, and if it finds them it [adds that directory as an included build](https://docs.gradle.org/current/dsl/org.gradle.api.initialization.Settings.html#org.gradle.api.initialization.Settings:includeBuild(java.lang.Object)).
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// This magically allows subdirs in this subproject to themselves become sub-subprojects in a proper tree structure
new File(rootDir, 'facades').eachDir { possibleSubprojectDir ->
File(rootDir, "facades").listFiles()?.filter { it.isDirectory }?.forEach { possibleSubprojectDir ->
if (!possibleSubprojectDir.name.startsWith(".")) {
def subprojectName = 'facades:' + possibleSubprojectDir.name
val subprojectName = "facades:" + possibleSubprojectDir.name
println("Processing facade $subprojectName, including it as a sub-project")
include subprojectName
def subprojectPath = ":" + subprojectName
def subproject = project(subprojectPath)
include(subprojectName)
val subprojectPath = ":" + subprojectName
val subproject = project(subprojectPath)
subproject.projectDir = possibleSubprojectDir
} else {
println("Ignoring entry $possibleSubprojectDir as it starts with .")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

// This magically allows subdirs in this subproject to themselves become sub-subprojects in a proper tree structure
// This magically allows subdirs to become included builds
// so getting a library and build it should work, e.g.:
// ./groovyw lib get TeraNUI
// ./gradlew :TeraNUI:build
new File(rootDir, 'libs').eachDir { possibleSubprojectDir ->
def subprojectName = ':libs:' + possibleSubprojectDir.name
File buildFile = new File(possibleSubprojectDir, "build.gradle")
File settingsFile = new File(possibleSubprojectDir, "settings.gradle")
File(rootDir, "libs").listFiles()?.filter { it.isDirectory }?.forEach { possibleSubprojectDir ->
val subprojectName = ":libs:" + possibleSubprojectDir.name
val buildFile = File(possibleSubprojectDir, "build.gradle")
val settingsFile = File(possibleSubprojectDir, "settings.gradle")
if (!buildFile.exists()) {
logger.warn("***** WARNING: Found a lib without a build.gradle, corrupt dir? NOT including {} *****", subprojectName)
return
return@forEach
}
if (!settingsFile.exists()) {
logger.warn("lib {} has build.gradle, but no settings.gradle? NOT including it." subprojectName)
return
logger.warn("lib {} has build.gradle, but no settings.gradle? NOT including it.", subprojectName)
return@forEach
}
logger.info("lib {} has a build file so counting it complete and including it.", subprojectName)
includeBuild(possibleSubprojectDir)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// This magically allows subdirs in this subproject to themselves become sub-subprojects in a proper tree structure
new File(rootDir, "metas").eachDir { possibleSubprojectDir ->
File(rootDir, "metas").listFiles()?.filter { it.isDirectory }?.forEach { possibleSubprojectDir ->
if (!possibleSubprojectDir.name.startsWith(".")) {
def subprojectName = "metas:" + possibleSubprojectDir.name
val subprojectName = "metas:" + possibleSubprojectDir.name
println("Processing meta module $subprojectName, including it as a sub-project")
include(subprojectName)
def subprojectPath = ":" + subprojectName
def subproject = project(subprojectPath)
val subprojectPath = ":" + subprojectName
val subproject = project(subprojectPath)
subproject.projectDir = possibleSubprojectDir
} else {
println("Ignoring entry $possibleSubprojectDir as it starts with .")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
// SPDX-License-Identifier: Apache-2.0

// This magically allows subdirs in this subproject to themselves become sub-subprojects in a proper tree structure
new File(rootDir, "modules").eachDir { possibleSubprojectDir ->
def subprojectName = ":modules:" + possibleSubprojectDir.name
File buildFile = new File(possibleSubprojectDir, "build.gradle")
File moduleTxt = new File(possibleSubprojectDir, "module.txt")
File(rootDir, "modules").listFiles()?.filter { it.isDirectory }?.forEach { possibleSubprojectDir ->
val subprojectName = ":modules:" + possibleSubprojectDir.name
val buildFile = File(possibleSubprojectDir, "build.gradle")
val moduleTxt = File(possibleSubprojectDir, "module.txt")
if (!buildFile.exists()) {
logger.warn("***** WARNING: Found a module without a build.gradle, corrupt dir? NOT including {} *****", subprojectName)
return
return@forEach
}
if (!moduleTxt.exists()) {
logger.warn("Module {} has build.gradle, but no module.txt? NOT including it.", subprojectName)
return
return@forEach
}
logger.info("Module {} has a build file so counting it complete and including it.", subprojectName)
include(subprojectName)
}

2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include("engine", "engine-tests", "facades", "metas", "libs", "modules")
rootDir.listFiles()?.forEach { possibleSubprojectDir ->
if (possibleSubprojectDir.isDirectory && possibleSubprojectDir.name != ".gradle") {
possibleSubprojectDir.walkTopDown().forEach { it.listFiles { file ->
file.isFile && file.name == "subprojects.settings.gradle" }?.forEach { subprojectsSpecificationScript ->
file.isFile && file.name == "subprojects.settings.gradle.kts" }?.forEach { subprojectsSpecificationScript ->
//println("Magic is happening, applying from $subprojectsSpecificationScript")
apply {
from(subprojectsSpecificationScript)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// SPDX-License-Identifier: Apache-2.0

// This magically allows subdirs in this subproject to themselves become sub-subprojects in a proper tree structure
new File(rootDir, "subsystems").eachDir { possibleSubprojectDir ->
File(rootDir, "subsystems").listFiles()?.filter { it.isDirectory }?.forEach { possibleSubprojectDir ->
if (!possibleSubprojectDir.name.startsWith(".")) {
def subprojectName = "subsystems:" + possibleSubprojectDir.name
val subprojectName = "subsystems:" + possibleSubprojectDir.name
logger.info("Including '{}' as a sub-project.", subprojectName)
include(subprojectName)
def subprojectPath = ":" + subprojectName
def subproject = project(subprojectPath)
val subprojectPath = ":" + subprojectName
val subproject = project(subprojectPath)
subproject.projectDir = possibleSubprojectDir
} else {
logger.info("Ignoring hidden folder '{}'.", possibleSubprojectDir)
}
}
}

0 comments on commit 8f37f92

Please sign in to comment.