Tracking used files during build

When developing a package I often try to minimize the size of the src to just what’s needed for the build. Simple ways such as src = ./. often include lots of things so I have to filter, but it’s not always clear what is used, or not used, during the build.

I know we can trace what is copied in as src, but is there a way to track what files are used during a build?

My initial thought would be to set up src in a FUSE that tracks accesses and can dump them to another output file, only when debugging package builds perhaps.

I don’t think tracing accesses of a binary works for builds as they can invoke multiple tools.

strace might be a viable option for build scripts with multiple subcommands using the -f option to follow forks.

Check out inotifywait.