CLI script that creates/updates .godot/global_script_class_cache.cfg
bitwes opened this issue · comments
I'm looking for feedback on a standalone script I created to generate/update the global script class cache config file that seems to be a point of contention when running tests through a CI/CD pipeline. Any and all feedback is appreciated. I'm not even sure if this is needed, but it felt like it was.
This script is meant to replace having to load the project once godot --headless --import
or having to have .godot/global_script_class_cache.cfg
under source control.
The script takes a list of scripts to create class_name entries for. It will parse all the info to create the entries from the script itself. You just have to tell it which scripts have class_name
in them. It will then create/update .godot/global_script_class_cache.cfg
without having to load the project.
The script knows about all the GUT scripts that need to be added/updated. You only have to add any of your own scripts or the scripts of other plugins.
Maybe later it can just scan the whole project instead of having to be told.
The related code can be found in the (global_class_cache_updater)[https://github.com/bitwes/Gut/tree/global_class_cache_updater] branch.
- (optparse.gd)[https://github.com/bitwes/Gut/blob/global_class_cache_updater/addons/gut/cli/optparse.gd] Used by
global_script_class_cache_updater.gd
to parse options. This has been updated frommain
. - global_script_class_cache_updater.gd The script that does all the magic.
Script help:
---------------------------------------------------------
This will create/update a global_script_class_cache.cfg file for the provided
scripts. It will parse out the class_name from the scripts and add entries to
the config file.
Entries are created for any script that is missing in the global class cache file.
Entries in the global class cache are updated (if they need to be) if they
already exist. Any entries for scripts not provided are not altered.
The global class cache file will be created, as well as any parent directories,
if they do not exist.
Usage
--------
<path to godot> --headless -s addons/gut/cli/update_script_class_cache.gd [opts] script_path1 script_path2 ...
Options
-----------
-class-cache-file The relative or absolute path to class cache config file. Default res://.godot/global_script_class_cache.cfg
-class-list-file An optional file containing a list of scripts to add to the global class cache, one per line.
-dry-run Print results instead of updating file
-help Show this help
---------------------------------------------------------
This is probably bad form but I couldn't think of better way of getting some good eyes on this. Sorry in advance. If I tagged you then you either had issues with .godot/global_script_class_cache.cfg
, CI/CD questions, or maintain a public pipeline that I found.
@Ajver @Theylok @asciifaceman @Dracks @m21-cerutti @98teg @ngburke @char32 @croconut @ceceppa
Seems interesting but could be more convenient maybe with a folder instead of a list of script paths (I think when you said it could scan the whole projet that's the idea).
Also seems to me more a bug about how works Godot in the first place, if the path of global_script_class_cache.cfg change or the format, even the solution of how Godot remember class_name change inside Godot, this script seems to be really easy to turn deprecate.
Here the list of relevant issues in Godot side for the sake of tracking:
godotengine/godot#69511
godotengine/godot#72360
godotengine/godot#77478
godotengine/godot#81615
godotengine/godot#82392
godotengine/godot#85467
godotengine/godot#87323
godotengine/godot#92833
Seems also ther is an --import
now that could do the job ?
godotengine/godot#90431
Or even better a fix ?
godotengine/godot#92303
I agree with @m21-cerutti that it will be mutch better to be able to specify the directory to scan, rather than individual files, one by one. For bigger projects there may be a huge amount of scripts with class_name
, that would need to be cached, and it just doesn't scale well. Having a text file with listed directories to the scripts kind of simplifies running the command, but still requires manual update everytime one creates new script with class_name in it.
I also feel like this script is actually a hacky approach to solve godot-typical behavior. We shouldn't consider this as Gut issue (I know that my original issue #589 might have sound like it's gut problem, but turned out to be Godot specific thing).
For now I'm happily using godot --headless --import
in my automated CI build, and I think it's solid way of doing it. It is an extra step, but so is running the updater script.
But I can see one reason to use the standalone updater script: When I run the godot --import
command, it takes quite a while to scan the project (I tested it on fresh clone of Gut repo, without .godot folder) - it took almost a minute to complete on my laptop! Where the updater script takes less than a second to fill the cache file.
This is good feedback. I wasn't sure how well/reliable the godot --headless --import
was working. This is definitely a workaround for Godot behavior and not an issue with GUT. The issue got stuck in my head, so I threw this together.
I'm going to abandon further development for now. I'll leave the branch out there for a bit, just in case something changes. If development continues, I think the addition of scanning directories would be good.
Thanks everyone.
Maybe you can put the script into assets or as an snipped by itself? if it helps to generate this file generating it faster, maybe makes sense to keep it. (only an idea)