Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android export] Added validation of the project name when using $genname in the 'Unique Name' field. #71646

Merged
merged 1 commit into from
Jan 20, 2023

Conversation

Vilcrow
Copy link
Contributor

@Vilcrow Vilcrow commented Jan 18, 2023

Fixes #71645.

@Vilcrow Vilcrow requested a review from a team as a code owner January 18, 2023 21:15
Comment on lines 2390 to 2399
//Check package name when used $genname in the "Unique Name" field
String basename = GLOBAL_GET("application/config/name");
String name = get_valid_basename();
if (valid && pn.find("$genname") >= 0 && name != basename) {
String p_name = p_preset->get("package/unique_name");
String fn = get_package_name(p_name); //The final package name
err += vformat(TTR("Invalid package name. Will be replaced with \"%s\" when exporting."), fn);
err += "\n";
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a check above that already validates the package name, can this logic be added to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m4gr3d if I do the check above, then the variable valid may then change to the false. Then this warning will be displayed in red font, which will be wrong. If the export is not possible, then this warning is not necessary.
Here I need to delete line number 2394 and replace p_name with pn.
This is my first pull request and I don't now how to do it yet, because I messed up something with the branches. I will try to figure it out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the warning should be turned into an error, in which case it's fine to merge the added logic with is_package_name_valid.

The reason for being an error is that a warning that doesn't block the user from progressing can easily be overlooked leading to confusion when the package name doesn't match with the unique name.
I'd rather the export dialog to be explicit to the user that the selected name is invalid.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As part of the error, we can suggest the user to manually overwrite the package name with a suitable replacement if they would like to keep the unique name.

@Vilcrow Vilcrow requested a review from m4gr3d January 19, 2023 00:03
@Calinou Calinou added this to the 4.0 milestone Jan 19, 2023
@Vilcrow Vilcrow force-pushed the android-export-genname-check branch from 17071d7 to f56555e Compare January 20, 2023 10:51
@Vilcrow Vilcrow changed the title [Android export] Added warning about the replacement in the package name when using "$genname" and have invalid project name. [Android export] Added validation of the project name when using $genname in the 'Unique Name' field. Jan 20, 2023
@Vilcrow
Copy link
Contributor Author

Vilcrow commented Jan 20, 2023

Fixed the commit history in this branch. It doesn't seem to have broken anything.

Copy link
Contributor

@m4gr3d m4gr3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Added some comments to address before it's ready to merge.

Comment on lines 544 to 552
String basename = GLOBAL_GET("application/config/name");
basename = basename.to_lower();
if (basename != get_valid_basename()) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Can you add a comment describing this logic. Otherwise it could be easy for a contributor to not realize that basename may not be equal to get_valid_basename() and mistakenly remove this method.

return true;
}

bool EditorExportPlatformAndroid::is_project_name_valid(const String &p_package) const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The p_package parameter doesn't seem to be needed.

@@ -525,6 +530,22 @@ bool EditorExportPlatformAndroid::is_package_name_valid(const String &p_package,
return false;
}

if (p_package.find("$genname") >= 0 && !is_project_name_valid(p_package)) {
if (r_error) {
*r_error = TTR("The end result may be unexpected. Try to explicitly specify the project name instead of the '$genname'.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the error message to:
The project name does not meet the requirement for the package name format. Please explicitly specify the package name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@Vilcrow Vilcrow force-pushed the android-export-genname-check branch from f56555e to 9c7c1c5 Compare January 20, 2023 12:06
Copy link
Contributor

@m4gr3d m4gr3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@Vilcrow
Copy link
Contributor Author

Vilcrow commented Jan 20, 2023

@m4gr3d thanks.

Comment on lines 445 to 446
//returns the project name without invalid characters
//or the "noname" string if all characters are invalid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our comment style is full sentences (with capital letter and period), and space after //.

Suggested change
//returns the project name without invalid characters
//or the "noname" string if all characters are invalid
// Returns the project name without invalid characters
// or the "noname" string if all characters are invalid.

Applies to the other comments below.

@Vilcrow Vilcrow force-pushed the android-export-genname-check branch from 9c7c1c5 to b8bc306 Compare January 20, 2023 17:58
@akien-mga akien-mga merged commit 28b2e43 into godotengine:master Jan 20, 2023
@akien-mga
Copy link
Member

Thanks! And congrats for your first merged Godot contribution 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants