bitwes / Gut

Godot Unit Test. Unit testing tool for Godot Game Engine.
1.71k stars 96 forks source link

CLI script that creates/updates .godot/global_script_class_cache.cfg #629

Open bitwes opened 1 week ago

bitwes commented 1 week ago

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.

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
---------------------------------------------------------
bitwes commented 1 week ago

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

589

491

m21-cerutti commented 1 week ago

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: https://github.com/godotengine/godot/issues/69511 https://github.com/godotengine/godot/issues/72360 https://github.com/godotengine/godot/issues/77478 https://github.com/godotengine/godot/issues/81615 https://github.com/godotengine/godot/issues/82392 https://github.com/godotengine/godot/issues/85467 https://github.com/godotengine/godot/issues/87323 https://github.com/godotengine/godot/issues/92833

Seems also ther is an --import now that could do the job ? https://github.com/godotengine/godot/pull/90431 Or even better a fix ? https://github.com/godotengine/godot/pull/92303

Ajver commented 1 week ago

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.

bitwes commented 1 week ago

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.

Dracks commented 1 week ago

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)