cake-build / cake

:cake: Cake (C# Make) is a cross platform build automation system.
https://cakebuild.net
MIT License
3.85k stars 724 forks source link

Script caching won't revalidate if script contains multiple files #4131

Open GeertvanHorrik opened 1 year ago

GeertvanHorrik commented 1 year ago

Prerequisites

Cake runner

Cake .NET Tool

Cake version

3.0.0

Operating system

Windows

Operating system architecture

64-Bit

CI Server

No response

What are you seeing?

I would like to enable this feature to see if we can take off a few minutes per build.

For now I would like to add a script cache per project (e.g. %temp%/cake-build/cache/my-project). This value will be set via an environment variable.

However, I checked the code and noticed that only the main script will be used for hash calculation. This means that if I change any of the "included files", the hash will not change.

In our case, we have several scripts that we include with this:

#l "./deployment/cake/tasks.cake"

Unfortunately, this file includes a lot of new includes, so I think there are a few options here:

Pre-process the script by parsing all the includes and use this to generate a hash for the "full script"

Cons: might be a bit slower Pros: reliable script cache hash

Allow configuration of directories to include in the scripts

Cons: more configuration (but we can automate / use environment variable) Pros: less "pre-processing", so "faster"

What is expected?

N/A

Steps to Reproduce

N/A

Output log

No response

tstewart65 commented 1 year ago

At the point in the code you are linking to the script is the complete script with all of the processing done. The ScriptRunner class calls the script analyzer which processes the script.

I currently use the caching on my projects and I use the #load to load a custom recipe we use. We use a nuget package for the recipe so technically if we change the external files the main script will also change for the version change. But for testing I go in and change the files in the cake tools folder where the nuget package exists and the changes are picked and the cached assembly is updated.