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

SCons: Generate all scripts natively, implement wrapper function #91624

Merged
merged 1 commit into from
May 10, 2024

Conversation

Repiteo
Copy link
Contributor

@Repiteo Repiteo commented May 6, 2024

Retires methods.write_file_if_needed, as every single script is now generated through SCons methods directly! This means that these scripts will now show up on the Progressor & are automatically cleaned/rebuilt as needed. Any converted function that's tailored to a specific directory is now in the appropriate SCSub, to properly link up with their expected libraries.

In the process of converting these functions to SCons natively, I implemented methods.generated_wrapper to make the generated files much prettier. This wrapper is a contextlib.contextmanager, meaning it utilizes the with keyword to handle most boilerplate logic (automatically writes to provided path & adds documentation header + header guards) while only needing to be passed the SCons target. I'm very likely to continue porting over generated functions to this new wrapper (especially considering the high probability of other non-SCons generated scripts that didn't use methods.write_file_if_needed); however, I wanted to specifically focus on the methods.write_file_if_needed functions as that made for a healthy initial sample size.


Examples:

version_generated.gen.h | Before
/* THIS FILE IS GENERATED DO NOT EDIT */
#ifndef VERSION_GENERATED_GEN_H
#define VERSION_GENERATED_GEN_H
#define VERSION_SHORT_NAME "{short_name}"
#define VERSION_NAME "{name}"
#define VERSION_MAJOR {major}
#define VERSION_MINOR {minor}
#define VERSION_PATCH {patch}
#define VERSION_STATUS "{status}"
#define VERSION_BUILD "{build}"
#define VERSION_MODULE_CONFIG "{module_config}"
#define VERSION_WEBSITE "{website}"
#define VERSION_DOCS_BRANCH "{docs_branch}"
#define VERSION_DOCS_URL "https://docs.godotengine.org/en/" VERSION_DOCS_BRANCH
#endif // VERSION_GENERATED_GEN_H
version_generated.gen.h | After
/**************************************************************************/
/*  version_generated.gen.h                                               */
/**************************************************************************/
/*                         This file is part of:                          */
/*                             GODOT ENGINE                               */
/*                        https://godotengine.org                         */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                  */
/*                                                                        */
/* Permission is hereby granted, free of charge, to any person obtaining  */
/* a copy of this software and associated documentation files (the        */
/* "Software"), to deal in the Software without restriction, including    */
/* without limitation the rights to use, copy, modify, merge, publish,    */
/* distribute, sublicense, and/or sell copies of the Software, and to     */
/* permit persons to whom the Software is furnished to do so, subject to  */
/* the following conditions:                                              */
/*                                                                        */
/* The above copyright notice and this permission notice shall be         */
/* included in all copies or substantial portions of the Software.        */
/*                                                                        */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */
/**************************************************************************/

/* THIS FILE IS GENERATED. EDITS WILL BE LOST. */

#ifndef VERSION_GENERATED_GEN_H
#define VERSION_GENERATED_GEN_H

#define VERSION_SHORT_NAME "godot"
#define VERSION_NAME "Godot Engine"
#define VERSION_MAJOR 4
#define VERSION_MINOR 3
#define VERSION_PATCH 0
#define VERSION_STATUS "dev"
#define VERSION_BUILD "custom_build"
#define VERSION_MODULE_CONFIG ""
#define VERSION_WEBSITE "https://godotengine.org"
#define VERSION_DOCS_BRANCH "latest"
#define VERSION_DOCS_URL "https://docs.godotengine.org/en/" VERSION_DOCS_BRANCH

#endif // VERSION_GENERATED_GEN_H
windows/export/logo_svg.gen.h | Before
 /* AUTOGENERATED FILE, DO NOT EDIT */ 
 static const char *_windows_logo_svg = "\x3c\x73\x76\x67\x20\x68\x65\x69\x67\x68\x74\x3d\x22\x33\x32\x22\x20\x77\x69\x64\x74\x68\x3d\x22\x33\x32\x22\x20\x78\x6d\x6c\x6e\x73\x3d\x22\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x77\x33\x2e\x6f\x72\x67\x2f\x32\x30\x30\x30\x2f\x73\x76\x67\x22\x3e\x3c\x70\x61\x74\x68\x20\x64\x3d\x22\x6d\x31\x20\x35\x2e\x31\x33\x32\x20\x31\x32\x2e\x32\x39\x35\x2d\x31\x2e\x36\x39\x34\x76\x31\x31\x2e\x38\x37\x39\x48\x31\x7a\x6d\x30\x20\x32\x31\x2e\x37\x33\x36\x20\x31\x32\x2e\x32\x39\x35\x20\x31\x2e\x36\x39\x35\x56\x31\x36\x2e\x38\x33\x48\x31\x7a\x6d\x31\x33\x2e\x36\x34\x37\x20\x31\x2e\x38\x37\x35\x4c\x33\x31\x20\x33\x31\x56\x31\x36\x2e\x38\x33\x48\x31\x34\x2e\x36\x34\x37\x7a\x6d\x30\x2d\x32\x35\x2e\x34\x38\x36\x76\x31\x32\x2e\x30\x36\x48\x33\x31\x56\x31\x7a\x22\x20\x66\x69\x6c\x6c\x3d\x22\x23\x30\x30\x61\x62\x65\x64\x22\x2f\x3e\x3c\x2f\x73\x76\x67\x3e\xa";
windows/export/logo_svg.gen.h | After
/**************************************************************************/
/*  logo_svg.gen.h                                                        */
/**************************************************************************/
/*                         This file is part of:                          */
/*                             GODOT ENGINE                               */
/*                        https://godotengine.org                         */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                  */
/*                                                                        */
/* Permission is hereby granted, free of charge, to any person obtaining  */
/* a copy of this software and associated documentation files (the        */
/* "Software"), to deal in the Software without restriction, including    */
/* without limitation the rights to use, copy, modify, merge, publish,    */
/* distribute, sublicense, and/or sell copies of the Software, and to     */
/* permit persons to whom the Software is furnished to do so, subject to  */
/* the following conditions:                                              */
/*                                                                        */
/* The above copyright notice and this permission notice shall be         */
/* included in all copies or substantial portions of the Software.        */
/*                                                                        */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */
/**************************************************************************/

/* THIS FILE IS GENERATED. EDITS WILL BE LOST. */

#ifndef WINDOWS_LOGO_SVG_GEN_H
#define WINDOWS_LOGO_SVG_GEN_H

static const char *_windows_logo_svg = "\x3c\x73\x76\x67\x20\x68\x65\x69\x67\x68\x74\x3d\x22\x33\x32\x22\x20\x77\x69\x64\x74\x68\x3d\x22\x33\x32\x22\x20\x78\x6d\x6c\x6e\x73\x3d\x22\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x77\x33\x2e\x6f\x72\x67\x2f\x32\x30\x30\x30\x2f\x73\x76\x67\x22\x3e\x3c\x70\x61\x74\x68\x20\x64\x3d\x22\x6d\x31\x20\x35\x2e\x31\x33\x32\x20\x31\x32\x2e\x32\x39\x35\x2d\x31\x2e\x36\x39\x34\x76\x31\x31\x2e\x38\x37\x39\x48\x31\x7a\x6d\x30\x20\x32\x31\x2e\x37\x33\x36\x20\x31\x32\x2e\x32\x39\x35\x20\x31\x2e\x36\x39\x35\x56\x31\x36\x2e\x38\x33\x48\x31\x7a\x6d\x31\x33\x2e\x36\x34\x37\x20\x31\x2e\x38\x37\x35\x4c\x33\x31\x20\x33\x31\x56\x31\x36\x2e\x38\x33\x48\x31\x34\x2e\x36\x34\x37\x7a\x6d\x30\x2d\x32\x35\x2e\x34\x38\x36\x76\x31\x32\x2e\x30\x36\x48\x33\x31\x56\x31\x7a\x22\x20\x66\x69\x6c\x6c\x3d\x22\x23\x30\x30\x61\x62\x65\x64\x22\x2f\x3e\x3c\x2f\x73\x76\x67\x3e\xa";

#endif // WINDOWS_LOGO_SVG_GEN_H

@Repiteo Repiteo requested review from a team as code owners May 6, 2024 16:36
@AThousandShips AThousandShips added this to the 4.x milestone May 6, 2024
@Repiteo Repiteo force-pushed the scons/native-generation branch 6 times, most recently from 3bd86ae to 87c0b13 Compare May 6, 2024 20:58
@Repiteo
Copy link
Contributor Author

Repiteo commented May 6, 2024

I have no clue why the Windows test fails; it's passing without issue for me locally

@Repiteo Repiteo force-pushed the scons/native-generation branch 2 times, most recently from 53453e1 to 75c4bd6 Compare May 7, 2024 15:26
@Riteo
Copy link
Contributor

Riteo commented May 7, 2024

@Repiteo I never touched the test suite before, but I'd take a look at modules/modules_tests.gen.h, since it's the only thing that really changed in that regard AFAICT.

From what I can tell, it looks like the gdscript test suite is responsible for loading the project settings and it, being a module, perhaps now gets loaded differently.

To remove any doubt I'd copy the current file, blast it out, let it regenerate and make a diff. That's probably why it works for you.

@Repiteo
Copy link
Contributor Author

Repiteo commented May 7, 2024

Finally got it to fail on my end, and it was through replicating the exact build flags used by GHA. Now I have a starting point to start looking back at where the disparity could've happened, though it'll still take quite a bit of digging.

@Repiteo Repiteo force-pushed the scons/native-generation branch from 75c4bd6 to 34fb3f7 Compare May 7, 2024 20:30
Copy link
Member

@akien-mga akien-mga 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 to me!

@akien-mga akien-mga modified the milestones: 4.x, 4.3 May 9, 2024
@akien-mga akien-mga merged commit 6fcdd24 into godotengine:master May 10, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@Repiteo Repiteo deleted the scons/native-generation branch May 11, 2024 16:50
akien-mga pushed a commit to scgm0/godot that referenced this pull request May 13, 2024
akien-mga added a commit that referenced this pull request May 13, 2024
SCons: Fix generation of `disabled_classes.gen.h` after #91624
dimitry- pushed a commit to AndroidWasm/godot that referenced this pull request May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants