Is it possible to get information about source in a rule?

14 views
Skip to first unread message

from...@gmail.com

unread,
Jul 25, 2020, 12:11:07 PM7/25/20
to Shake build system
I want to build a dynamic list of rules and execute them. The problem is that a target name doesn't uniquely identify the source. So I make the list before running shake:

main = do
mdPages <- getDirectoryFilesIO "pages" ["//*.md"]
rstPages <- getDirectoryFilesIO "pages" ["//*.rst"]
let
pageRules =
[ ("pages" </> page, "_site" </> page -<.> "html")
| page <- mdPages ++ rstPages
]
shakeArgs shakeOptions $ do
want $ map snd pageRules
for_ pageRules \(source, html) -> do
html %> \_ -> do something with source

I want to use an Action for this, but I can emit only target names from the Action. Is it possible? Or do I wnat something bad?

Neil Mitchell

unread,
Jul 27, 2020, 6:35:26 AM7/27/20
to from...@gmail.com, Shake build system
Hi,

Doing things before running Shake has the disadvantage they run in every iteration. But if you're OK with that, it should be fine. Most directory traversal rules need to run in every iteration anyway though, so its probably not a big deal.

What's the restriction to "emit only target names from the Action" ? What you've written above looks totally feasible.

And as a small simplification/optimisation, getDirectoryFilesIO "pages" ["//*.md","//*.rst"] will only do one directory traversal, and you append the two lists anyway, so might be easier.

Thanks, Neil

--
You received this message because you are subscribed to the Google Groups "Shake build system" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shake-build-sys...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/shake-build-system/dc0e30d2-8b77-4e1b-ad3f-7d096292dc38o%40googlegroups.com.

Yuriy Syrovetskiy

unread,
Jul 27, 2020, 7:28:36 AM7/27/20
to Neil Mitchell, Shake build system
> What's the restriction to "emit only target names from the Action" ?

I want to run `getDirectoryFiles "pages" ["//*.md","//*.rst"]` inside
Action, but for each `x.md` or `x.rst` found I can't make a rule, I
can only `need x.html`, but when `x.html` is built, it doesn't have
information about its source -- `x.md` or `x.rst`.

It's possible to inverse `source_name -> artifact_name` function, but
it may be more difficult.
--
Сыр Российский (Cheese Russian), http://cblp.su, email/jabber: cb...@cblp.su

Neil Mitchell

unread,
Jul 27, 2020, 12:23:15 PM7/27/20
to Yuriy Syrovetskiy, Shake build system
Hi Yuriy,

The way you've written it is perfectly reasonable. The alternatives would be:

* You could make a map from output file to source file, e.g. x.html -> x.rst, and then have a single rule, which looks up the source in a HashMap or similar. As a variation, you can make that Map itself an output of an oracle or cache.

* You could make the rule do doesFileExist on the ".rst", and then switch based on that. The advantage is that the inputs are fully tracked, and you can make it clear whether .md or .rst is the "first preference".

However, if what you've got works, I'd probably leave it as it is.

Thanks, Neil

Reply all
Reply to author
Forward
0 new messages