I am trying to figure out how can i take the progress info from a Progress type (in Development.Shake.Progress) to output it before executing a command. The possible desired output would be:
[1/9] Compiling src/Window/Window.cpp
[2/9] Compiling src/Window/GlfwError.cpp
[3/9] Compiling src/Window/GlfwContext.cpp
[4/9] Compiling src/Util/MemTrack.cpp
...
For now i am simulating this using some IORef that keeps the total (initially set to the sum of the source files) and a count that i increase before executing each build command, but this seems like a hackish solution to me.
On top of that this solution seems to work correctly on clean builds, but misbehaves on partial builds as the sum that displayed is still the total of all the source files.
With access to a Progress data type i will be able to calculate this fraction correctly using its countSkipped, countBuild, and countTodo members (see Progress.hs:53), but i am still not sure how i can i achieve this.
Any help is appreciated.
Values of type
Progress
are currently only available as an argument to the function stored inshakeProgress
. You can obtain theProgress
whenever you want with:Here we create an
IORef
to squirrel away the argument passed toshakeProgress
, then retrieve it later when running the rules. Running the above code I see:Running at a higher level of parallelism gives less precise results - initially there are only 3 items in todo (Shake increments
countTodo
as it finds items todo, and spawns items as soon as it knows about any of them), and there are often two rules running at the same index (there is no information about how many are in progress). Given knowledge of your specific rules, you could refine the output, e.g. storing anIORef
you increment to ensure the index was monotonic.The reason this code is somewhat convoluted is that the
Progress
information was intended to be used for asynchronous progress messages, although your approach seems perfectly valid. It may be worth introducing agetProgress :: Action Progress
function for synchronous progress messages.