Skip to content

Commit

Permalink
Merge pull request #88611 from Alex2782/force_device_cpu_architecture
Browse files Browse the repository at this point in the history
Display a warning if device CPU architecture is not active in the export preset.
  • Loading branch information
akien-mga committed Feb 26, 2024
2 parents 63bde2f + 293c34a commit e7bf883
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
27 changes: 26 additions & 1 deletion editor/editor_run_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,21 @@ void EditorRunNative::_notification(int p_what) {
}
}

void EditorRunNative::_confirm_run_native() {
run_confirmed = true;
resume_run_native();
}

Error EditorRunNative::start_run_native(int p_id) {
if (p_id < 0) {
return OK;
}

int platform = p_id / 10000;
int idx = p_id % 10000;
resume_id = p_id;

if (!EditorNode::get_singleton()->ensure_main_scene(true)) {
resume_id = p_id;
return OK;
}

Expand All @@ -110,6 +115,22 @@ Error EditorRunNative::start_run_native(int p_id) {
return ERR_UNAVAILABLE;
}

String architecture = eep->get_device_architecture(idx);
if (!run_confirmed && !architecture.is_empty()) {
String preset_arch = "architectures/" + architecture;
bool is_arch_enabled = preset->get(preset_arch);

if (!is_arch_enabled) {
String warning_message = vformat(TTR("Warning: The CPU architecture '%s' is not active in your export preset.\n\n"), Variant(architecture));
warning_message += TTR("Run 'Remote Debug' anyway?");

run_native_confirm->set_text(warning_message);
run_native_confirm->popup_centered();
return OK;
}
}
run_confirmed = false;

emit_signal(SNAME("native_run"), preset);

int flags = 0;
Expand Down Expand Up @@ -174,5 +195,9 @@ EditorRunNative::EditorRunNative() {
add_child(result_dialog);
result_dialog->hide();

run_native_confirm = memnew(ConfirmationDialog);
add_child(run_native_confirm);
run_native_confirm->connect("confirmed", callable_mp(this, &EditorRunNative::_confirm_run_native));

set_process(true);
}
4 changes: 4 additions & 0 deletions editor/editor_run_native.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ class EditorRunNative : public HBoxContainer {

RichTextLabel *result_dialog_log = nullptr;
AcceptDialog *result_dialog = nullptr;
ConfirmationDialog *run_native_confirm = nullptr;
bool run_confirmed = false;

MenuButton *remote_debug = nullptr;
bool first = true;

int resume_id = -1;

void _confirm_run_native();

protected:
static void _bind_methods();
void _notification(int p_what);
Expand Down
1 change: 1 addition & 0 deletions editor/export/editor_export_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ class EditorExportPlatform : public RefCounted {
virtual Ref<ImageTexture> get_option_icon(int p_index) const;
virtual String get_option_label(int p_device) const { return ""; }
virtual String get_option_tooltip(int p_device) const { return ""; }
virtual String get_device_architecture(int p_device) const { return ""; }

enum DebugFlags {
DEBUG_FLAG_DUMB_CLIENT = 1,
Expand Down
9 changes: 8 additions & 1 deletion platform/android/export/export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ void EditorExportPlatformAndroid::_check_for_changes_poll_thread(void *ud) {
} else if (p.begins_with("ro.build.version.sdk=")) {
d.api_level = p.get_slice("=", 1).to_int();
} else if (p.begins_with("ro.product.cpu.abi=")) {
d.description += "CPU: " + p.get_slice("=", 1).strip_edges() + "\n";
d.architecture = p.get_slice("=", 1).strip_edges();
d.description += "CPU: " + d.architecture + "\n";
} else if (p.begins_with("ro.product.manufacturer=")) {
d.description += "Manufacturer: " + p.get_slice("=", 1).strip_edges() + "\n";
} else if (p.begins_with("ro.board.platform=")) {
Expand Down Expand Up @@ -1992,6 +1993,12 @@ String EditorExportPlatformAndroid::get_option_tooltip(int p_index) const {
return s;
}

String EditorExportPlatformAndroid::get_device_architecture(int p_index) const {
ERR_FAIL_INDEX_V(p_index, devices.size(), "");
MutexLock lock(device_lock);
return devices[p_index].architecture;
}

Error EditorExportPlatformAndroid::run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) {
ERR_FAIL_INDEX_V(p_device, devices.size(), ERR_INVALID_PARAMETER);

Expand Down
3 changes: 3 additions & 0 deletions platform/android/export/export_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
String name;
String description;
int api_level = 0;
String architecture;
};

struct APKExportData {
Expand Down Expand Up @@ -221,6 +222,8 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {

virtual String get_option_tooltip(int p_index) const override;

virtual String get_device_architecture(int p_index) const override;

virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) override;

virtual Ref<Texture2D> get_run_icon() const override;
Expand Down

0 comments on commit e7bf883

Please sign in to comment.