Merge pull request #84674 from m4gr3d/add_flag_to_run_scons_from_gradle

Add parameter to allow generation of the Godot native shared libraries from gradle
This commit is contained in:
Rémi Verschelde 2024-01-29 23:24:05 +01:00 committed by GitHub
commit 51991e2014
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 49 additions and 33 deletions

View File

@ -160,10 +160,21 @@ task zipGradleBuild(type: Zip) {
destinationDirectory = file(binDir) destinationDirectory = file(binDir)
} }
/**
* Returns true if the scons build tasks responsible for generating the Godot native shared
* libraries should be excluded.
*/
def excludeSconsBuildTasks() {
return !isAndroidStudio() && !project.hasProperty("generateNativeLibs")
}
/**
* Generates the list of build tasks that should be excluded from the build process.\
*/
def templateExcludedBuildTask() { def templateExcludedBuildTask() {
// We exclude these gradle tasks so we can run the scons command manually. // We exclude these gradle tasks so we can run the scons command manually.
def excludedTasks = [] def excludedTasks = []
if (!isAndroidStudio()) { if (excludeSconsBuildTasks()) {
logger.lifecycle("Excluding Android studio build tasks") logger.lifecycle("Excluding Android studio build tasks")
for (String flavor : supportedFlavors) { for (String flavor : supportedFlavors) {
String[] supportedBuildTypes = supportedFlavorsBuildTypes[flavor] String[] supportedBuildTypes = supportedFlavorsBuildTypes[flavor]
@ -177,23 +188,42 @@ def templateExcludedBuildTask() {
return excludedTasks return excludedTasks
} }
def templateBuildTasks() { /**
* Generates the build tasks for the given flavor
* @param flavor Must be one of the supported flavors ('template' / 'editor')
*/
def generateBuildTasks(String flavor = "template") {
if (!supportedFlavors.contains(flavor)) {
throw new GradleException("Invalid build flavor: $flavor")
}
def tasks = [] def tasks = []
// Only build the apks and aar files for which we have native shared libraries. // Only build the apks and aar files for which we have native shared libraries unless we intend
for (String target : supportedFlavorsBuildTypes["template"]) { // to run the scons build tasks.
File targetLibs = new File("lib/libs/" + target) boolean excludeSconsBuildTasks = excludeSconsBuildTasks()
if (targetLibs != null boolean isTemplate = flavor == "template"
String libsDir = isTemplate ? "lib/libs/" : "lib/libs/tools/"
for (String target : supportedFlavorsBuildTypes[flavor]) {
File targetLibs = new File(libsDir + target)
if (!excludeSconsBuildTasks || (targetLibs != null
&& targetLibs.isDirectory() && targetLibs.isDirectory()
&& targetLibs.listFiles() != null && targetLibs.listFiles() != null
&& targetLibs.listFiles().length > 0) { && targetLibs.listFiles().length > 0)) {
String capitalizedTarget = target.capitalize() String capitalizedTarget = target.capitalize()
// Copy the generated aar library files to the build directory. if (isTemplate) {
tasks += "copy" + capitalizedTarget + "AARToAppModule" // Copy the generated aar library files to the build directory.
// Copy the generated aar library files to the bin directory. tasks += "copy${capitalizedTarget}AARToAppModule"
tasks += "copy" + capitalizedTarget + "AARToBin" // Copy the generated aar library files to the bin directory.
// Copy the prebuilt binary templates to the bin directory. tasks += "copy${capitalizedTarget}AARToBin"
tasks += "copy" + capitalizedTarget + "BinaryToBin" // Copy the prebuilt binary templates to the bin directory.
tasks += "copy${capitalizedTarget}BinaryToBin"
} else {
// Copy the generated editor apk to the bin directory.
tasks += "copyEditor${capitalizedTarget}ApkToBin"
// Copy the generated editor aab to the bin directory.
tasks += "copyEditor${capitalizedTarget}AabToBin"
}
} else { } else {
logger.lifecycle("No native shared libs for target $target. Skipping build.") logger.lifecycle("No native shared libs for target $target. Skipping build.")
} }
@ -252,27 +282,13 @@ task copyEditorDevAabToBin(type: Copy) {
/** /**
* Generate the Godot Editor Android apk. * Generate the Godot Editor Android apk.
* *
* Note: The Godot 'tools' shared libraries must have been generated (via scons) prior to running * Note: Unless the 'generateNativeLibs` argument is specified, the Godot 'tools' shared libraries
* this gradle task. The task will only build the apk(s) for which the shared libraries is * must have been generated (via scons) prior to running this gradle task.
* available. * The task will only build the apk(s) for which the shared libraries is available.
*/ */
task generateGodotEditor { task generateGodotEditor {
gradle.startParameter.excludedTaskNames += templateExcludedBuildTask() gradle.startParameter.excludedTaskNames += templateExcludedBuildTask()
dependsOn = generateBuildTasks("editor")
def tasks = []
for (String target : supportedFlavorsBuildTypes["editor"]) {
File targetLibs = new File("lib/libs/tools/" + target)
if (targetLibs != null
&& targetLibs.isDirectory()
&& targetLibs.listFiles() != null
&& targetLibs.listFiles().length > 0) {
tasks += "copyEditor${target.capitalize()}ApkToBin"
tasks += "copyEditor${target.capitalize()}AabToBin"
}
}
dependsOn = tasks
} }
/** /**
@ -280,7 +296,7 @@ task generateGodotEditor {
*/ */
task generateGodotTemplates { task generateGodotTemplates {
gradle.startParameter.excludedTaskNames += templateExcludedBuildTask() gradle.startParameter.excludedTaskNames += templateExcludedBuildTask()
dependsOn = templateBuildTasks() dependsOn = generateBuildTasks("template")
finalizedBy 'zipGradleBuild' finalizedBy 'zipGradleBuild'
} }
@ -293,7 +309,7 @@ task generateDevTemplate {
gradle.startParameter.projectProperties += [doNotStrip: "true"] gradle.startParameter.projectProperties += [doNotStrip: "true"]
gradle.startParameter.excludedTaskNames += templateExcludedBuildTask() gradle.startParameter.excludedTaskNames += templateExcludedBuildTask()
dependsOn = templateBuildTasks() dependsOn = generateBuildTasks("template")
finalizedBy 'zipGradleBuild' finalizedBy 'zipGradleBuild'
} }