-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please add a repository_ctx method for reading files by Label #3766
Comments
This sounds related to (though definitely not a duplicate of) #3438 |
Has there been any progress on this, or prioritization? It's worse than the issue description when you consider windows compatibility, as "cat" isn't an external executable on that platform (it being a powershell alias to Get-Content, which is also not an external executable file. So for windows, one has to implement platform-specific toolchains to supply a call to powershell with that command, all to read text file contents with a repository_ctx. |
PR: #7309 |
What is the motivation for reading the file into Starlark rule? |
Getting metadata in that you can use to generate the repository more effectively. In my case, for example, getting teh appropriate maven metadata (pom files) to ensure that we generate dependencies properly in the generated bazel targets. Right now I'm using "cat" which doesn't work on windows. I don't want to have to set up a per-platform toolchain just to read a file. |
I've been reading files in repository rules for two reasons:
|
+1, would be nice to have an OS-independent |
This came up in a discussion with @dkelmer earlier on again. Currently, to do cross-platform def _cat_file(repository_ctx, filepath):
# For Windows, use cat from msys.
cat = "C:\\msys64\\usr\\bin\\cat" if (_is_windows(repository_ctx)) else repository_ctx.which("cat")
exec_result = repository_ctx.execute([cat, repository_ctx.path(filepath)])
if (exec_result.return_code != 0):
fail("Error while trying to read %s: %s" % (filepath, exec_result.stderr))
return exec_result.stdout It'll be nice to shorten this to |
I mean, it's that or add toolchains. :) |
A
repository_ctx
can have Label attributes that point to files in other repositories (useful for tool plumbing), but such attributes are awkward to work with because there's no direct way to read their content.The best workaround I've found is to use symlinks and run
cat
as a subprocess, which certainly deserves an entry in the Useless Use of Cat Award.That whole mess could, ideally, be simplified down to this:
The text was updated successfully, but these errors were encountered: