big-xylophone-43403
05/13/2021, 5:08 AMProcess
to read tags and populate the version
kwarg. However, I’m not sure what input_digest
and/or working_dir
should be provided to the Git process 🧵big-xylophone-43403
05/13/2021, 5:09 AM.git
dirhundreds-father-404
05/13/2021, 5:20 AMthe process fails since cannot locate the .git dirOh, hm...that will indeed be a problem because Pants ignores
.git
, which is almost always the right thing to do, but not here. PathGlobs
won't be able to see that directory as a result 🤔
--
So, someone has done Git before by sidestepping the Rules API abstractions. Which you can do if you mark things as uncacheable. Use @_uncacheable_rule
instead of @rule
, and then in that function you can do normally unsafe things like subprocess.run(["git", ...)
It must be marked uncacheable because this is not safe to ever cache, e.g. Pants will not monitor the filesystem to know when to invalidate the cache
Does that make sense?enough-analyst-54434
05/13/2021, 3:07 PM@_uncacheable_rule
/ subprocess by leveraging GIT_DIR / GIT_WORK_TREE (c.f.: https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables)
Here's a fully working demo where you can continually run ./pants git --work-tree=/some/other/repo -- describe
and get back new results every time you go over to that repo and git reset
it to some new head: https://github.com/pantsbuild/pants/pull/12071/files#diff-31fcb2cbc80628cb417c19f397c0aac0d5578741d7e3954253ff68065d007726R61hundreds-father-404
05/13/2021, 3:10 PMGIT_DIR
and GIT_WORK_TREE
allows the process to escape the chroot and read from the build root's .git folder, right?enough-analyst-54434
05/13/2021, 3:13 PMenough-analyst-54434
05/13/2021, 3:15 PMbig-xylophone-43403
05/13/2021, 3:37 PMhappy-kitchen-89482
05/13/2021, 3:39 PMhundreds-father-404
05/13/2021, 3:41 PMenough-analyst-54434
05/13/2021, 3:41 PMenough-analyst-54434
05/13/2021, 3:42 PM