summaryrefslogtreecommitdiffstats
path: root/editor/export/export_template_manager.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-02-17 00:23:32 +0100
committerRémi Verschelde <rverschelde@gmail.com>2024-02-17 00:23:32 +0100
commit66b33c15e42005bfd4c60c4c50805a0aaf5a2c80 (patch)
tree800a638ac75e389dfac0aa3ca873eaab48ce7673 /editor/export/export_template_manager.cpp
parentc28493ad048f65bdcd62f6be7558fa7b442ea801 (diff)
parenta37ad265dc818d2aeaec97e1559ecae42e5487e2 (diff)
downloadredot-engine-66b33c15e42005bfd4c60c4c50805a0aaf5a2c80.tar.gz
Merge pull request #88297 from dsnopek/android-configure-gradle-path
Android: Allow using alternative Gradle build directory
Diffstat (limited to 'editor/export/export_template_manager.cpp')
-rw-r--r--editor/export/export_template_manager.cpp72
1 files changed, 56 insertions, 16 deletions
diff --git a/editor/export/export_template_manager.cpp b/editor/export/export_template_manager.cpp
index b3951d2c28..c3e48820b2 100644
--- a/editor/export/export_template_manager.cpp
+++ b/editor/export/export_template_manager.cpp
@@ -38,6 +38,7 @@
#include "editor/editor_paths.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
+#include "editor/export/editor_export.h"
#include "editor/progress_dialog.h"
#include "editor/themes/editor_scale.h"
#include "scene/gui/file_dialog.h"
@@ -655,39 +656,78 @@ void ExportTemplateManager::_hide_dialog() {
hide();
}
-bool ExportTemplateManager::can_install_android_template() {
+String ExportTemplateManager::get_android_build_directory(const Ref<EditorExportPreset> &p_preset) {
+ if (p_preset.is_valid()) {
+ String gradle_build_dir = p_preset->get("gradle_build/gradle_build_directory");
+ if (!gradle_build_dir.is_empty()) {
+ return gradle_build_dir.path_join("build");
+ }
+ }
+ return "res://android/build";
+}
+
+String ExportTemplateManager::get_android_source_zip(const Ref<EditorExportPreset> &p_preset) {
+ if (p_preset.is_valid()) {
+ String android_source_zip = p_preset->get("gradle_build/android_source_template");
+ if (!android_source_zip.is_empty()) {
+ return android_source_zip;
+ }
+ }
+
const String templates_dir = EditorPaths::get_singleton()->get_export_templates_dir().path_join(VERSION_FULL_CONFIG);
- return FileAccess::exists(templates_dir.path_join("android_source.zip"));
+ return templates_dir.path_join("android_source.zip");
}
-Error ExportTemplateManager::install_android_template() {
- const String &templates_path = EditorPaths::get_singleton()->get_export_templates_dir().path_join(VERSION_FULL_CONFIG);
- const String &source_zip = templates_path.path_join("android_source.zip");
+String ExportTemplateManager::get_android_template_identifier(const Ref<EditorExportPreset> &p_preset) {
+ // The template identifier is the Godot version for the default template, and the full path plus md5 hash for custom templates.
+ if (p_preset.is_valid()) {
+ String android_source_zip = p_preset->get("gradle_build/android_source_template");
+ if (!android_source_zip.is_empty()) {
+ return android_source_zip + String(" [") + FileAccess::get_md5(android_source_zip) + String("]");
+ }
+ }
+ return VERSION_FULL_CONFIG;
+}
+
+bool ExportTemplateManager::is_android_template_installed(const Ref<EditorExportPreset> &p_preset) {
+ return DirAccess::exists(get_android_build_directory(p_preset));
+}
+
+bool ExportTemplateManager::can_install_android_template(const Ref<EditorExportPreset> &p_preset) {
+ return FileAccess::exists(get_android_source_zip(p_preset));
+}
+
+Error ExportTemplateManager::install_android_template(const Ref<EditorExportPreset> &p_preset) {
+ const String source_zip = get_android_source_zip(p_preset);
ERR_FAIL_COND_V(!FileAccess::exists(source_zip), ERR_CANT_OPEN);
- return install_android_template_from_file(source_zip);
+ return install_android_template_from_file(source_zip, p_preset);
}
-Error ExportTemplateManager::install_android_template_from_file(const String &p_file) {
+
+Error ExportTemplateManager::install_android_template_from_file(const String &p_file, const Ref<EditorExportPreset> &p_preset) {
// To support custom Android builds, we install the Java source code and buildsystem
// from android_source.zip to the project's res://android folder.
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
ERR_FAIL_COND_V(da.is_null(), ERR_CANT_CREATE);
- // Make res://android dir (if it does not exist).
- da->make_dir("android");
+ String build_dir = get_android_build_directory(p_preset);
+ String parent_dir = build_dir.get_base_dir();
+
+ // Make parent of the build dir (if it does not exist).
+ da->make_dir_recursive(parent_dir);
{
- // Add version, to ensure building won't work if template and Godot version don't match.
- Ref<FileAccess> f = FileAccess::open("res://android/.build_version", FileAccess::WRITE);
+ // Add identifier, to ensure building won't work if the current template doesn't match.
+ Ref<FileAccess> f = FileAccess::open(parent_dir.path_join(".build_version"), FileAccess::WRITE);
ERR_FAIL_COND_V(f.is_null(), ERR_CANT_CREATE);
- f->store_line(VERSION_FULL_CONFIG);
+ f->store_line(get_android_template_identifier(p_preset));
}
// Create the android build directory.
- Error err = da->make_dir_recursive("android/build");
+ Error err = da->make_dir_recursive(build_dir);
ERR_FAIL_COND_V(err != OK, err);
{
// Add an empty .gdignore file to avoid scan.
- Ref<FileAccess> f = FileAccess::open("res://android/build/.gdignore", FileAccess::WRITE);
+ Ref<FileAccess> f = FileAccess::open(build_dir.path_join(".gdignore"), FileAccess::WRITE);
ERR_FAIL_COND_V(f.is_null(), ERR_CANT_CREATE);
f->store_line("");
}
@@ -735,11 +775,11 @@ Error ExportTemplateManager::install_android_template_from_file(const String &p_
unzCloseCurrentFile(pkg);
if (!dirs_tested.has(base_dir)) {
- da->make_dir_recursive(String("android/build").path_join(base_dir));
+ da->make_dir_recursive(build_dir.path_join(base_dir));
dirs_tested.insert(base_dir);
}
- String to_write = String("res://android/build").path_join(path);
+ String to_write = build_dir.path_join(path);
Ref<FileAccess> f = FileAccess::open(to_write, FileAccess::WRITE);
if (f.is_valid()) {
f->store_buffer(uncomp_data.ptr(), uncomp_data.size());