Our Bazel build has a `genrule` which generates a ...
# general
Our Bazel build has a
which generates a file which dumps some git info to be included in packaged things. Trying to use
to do the same thing, I unfortunately noticed the command runs in the sandbox and not in repo root. Alternatively I could use
but then I can't capture outputs 😞
@happy-kitchen-89482 landed https://github.com/pantsbuild/pants/pull/15374 yesterday to do a flavor of this… but yea, scripted direct access to git isn’t currently possible. a rule could do it in a similar fashion to what he did here
Ahh bummer. I'll just make a dirty in-repo plugin which dumps the file. It's the only place we do this kinda thing
Or I could just...
Copy code
def build_file_aliases():
    def repo_root_path(parse_context):
        return lambda: PurePath(parse_context.build_root)
    return BuildFileAliases(context_aware_object_factories={"repo_root_path": repo_root_path})
sounds like it would be useful for Pants to surface that in BUILD files? That doesn't seem dirty to me
oh well I guess, actually, you need the absolute path?
It is the absolute path 😂 Otherwise I tried
which is
I can make a PR later
how was the
invalidated in bazel? i’m guessing it wasn’t, and you needed to restart the server?
I know little of Bazel's behavior. i suspect one of these is responsible:
Copy code
local = True,
    stamp = 1,
    tags = ["no-cache"],
👍 1
Apparently this is still cached in Bazel. Also my hack doesn't invalidate the cache 😞
mm, yea. my expectation of
would be to skip writing it to the persistent cache, rather than to necessarily not memoize it in memory. would be the same here probably… interaction with
needs the pants equivalent of
i have a vague feeling that there might be some cases where exposing PER_SESSION to
could be useful… but i’m not sure what the API would look like, since when you set it, you’d still also need to escape the sandbox like you did with the absolute path.
💯 1
cc @curved-television-6568, in case you have thoughts
Yeah. I admit what I'm doing is dirty. Really I need a hack for this to work today (ideally in a way that doesn't shut me out from using the equivalent Bazel thing while I'm straddleing). And then also whatever the right way of doing this is, which I can upgrade to when off bazel 🙂
@bitter-ability-32190: doing a much lighter form of what Benjy did (codegen rule attached to a target) would do it. depending on the
gives you PER_SESSION behavior.
Yeah that's what I started with. The reason I short-circuited to the caof is I'd like to still use the same sh script we're using in Bazel. And easily 😛
Aww RIP 2.11.x doesn't use
as an
Awww darn:
Exception: Error lifting Process: Absolute paths are not allowed: "/home/joshuacannon/work/techlabs"
Copy code
result = await Get(
            ["git", "rev-parse", "HEAD"],
            description="Getting Git SHA.",
Was trying to whip up a way to have the rule fire per-state change and this was my current path
Ahh ignore me. I just found it this file is deeply rooted in our deps, so trying to make it work right would invalidate most of our graph lol
👍 1
When workingwith git you dont need pwd set, you can pass the —git-root (IIRC the option name, or as env var) for your .git dir to it. https://git-scm.com/docs/git#Documentation/git.txt---git-dirltpathgt
👍 1
So, for the curious, here's how I'm solving it: • Expose the file just like we do in bazel. Bazel has the cache bug (as I found out) so keeping that in theme with Pants • Make another plugin which exposes a dummy file codegen which only gets cached per git SHA, and a target for it • Make another
which generates the file but depends on the address of the target which depends on git state ◦ This means the file correctly gets re-generated every time SHA changes • Use the latter dependency when building docker images
Once everything is migrated to Pants, I can untangle the first generated file, since it will no longer be needed.
Make another plugin which exposes a dummy file codegen which only gets cached per git SHA
I feel so evil, yet so good
😈 1