Macro hygiene problem with macros from external workspace

66 views
Skip to first unread message

iain.m...@gmail.com

unread,
Nov 4, 2016, 2:48:57 PM11/4/16
to bazel-discuss
Hi all,

I've run into what seems like a slightly awkward macro hygiene problem.

What I want to do is:
- Workspace A defines a tool, and a macro for calling that tool (i.e. wrapping a genrule)
- Workspace B imports and uses that macro

But the macro is evaluated in the context of workspace B, so I don't see how it can unambiguously refer to the tool which lives in workspace A. It needs to use e.g. "@A//tools/macro.bzl", but how do I know my workspace is going to be imported as @A? Workspace B might want to import it under a different name, to resolve a namespace conflict.

Here's my specific example: https://github.com/iainmerrick/ink/commit/153b75808933883cd601494c2db64d79e8a999d9

Iain

László Csomor

unread,
Nov 7, 2016, 3:56:58 AM11/7/16
to Iain Merrick, bazel-discuss, Laurent Le Brun, Kristina Chodorow
cc'ing smart people



--
László Csomor | Software Engineer | laszlo...@google.com

Google Germany GmbH | Erika-Mann-Str. 33 | 80636 München | Germany
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Matthew Scott Sucherman, Paul Terence Manicle


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/99bc27ee-b886-4c99-90ea-0c0936d12f16%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kristina Chodorow

unread,
Nov 7, 2016, 10:07:44 AM11/7/16
to László Csomor, Iain Merrick, bazel-discuss, Laurent Le Brun
It's not required, but every WORKSPACE file should start with a line:

workspace(name = "A")

(or "B", or whatever you want the global name of that workspace to be).  We're encouraging people to use Java package-like names (e.g., Bazel's workspace name is io_bazel).  Bazel gives you an annoying warning if you try to import a repository using the wrong name (e.g., if you wrote http_archive(name = "com_bazel", ...) for importing io_bazel).  


Iain Merrick

unread,
Nov 7, 2016, 11:41:58 AM11/7/16
to Kristina Chodorow, László Csomor, bazel-discuss, Laurent Le Brun
Aha, that'll do it, thanks!

The docs are fantastic overall, but they're a little bit light on explaining the best practices for publishing a repository for other people to use. The info is there but you have to hop around a lot. (This isn't unique to Bazel, other build systems tend have the same documentation gap.)

Iain Merrick

unread,
Nov 7, 2016, 12:00:54 PM11/7/16
to Kristina Chodorow, László Csomor, bazel-discuss, Laurent Le Brun
Just figured out a specific problem -- the workspace() function isn't mentioned on the "Workspace Rules" page: https://www.bazel.io/versions/master/docs/be/workspace.html
Reply all
Reply to author
Forward
0 new messages