-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[bazel,fusesoc] Add a way to create a hash of all files used by fusesoc #31041
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
base: master
Are you sure you want to change the base?
Changes from all commits
3e135ad
d41d7b0
f365803
e5fa960
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -116,3 +116,51 @@ copy_files = rule( | |||||
| }, | ||||||
| executable = True, | ||||||
| ) | ||||||
|
|
||||||
| def _hash_file_map_fname(file): | ||||||
| return file.path | ||||||
|
|
||||||
| def _hash_files(ctx): | ||||||
| inputs = ctx.files.src | ||||||
| if ctx.attr.output_group: | ||||||
| inputs = getattr(ctx.attr.src[OutputGroupInfo], ctx.attr.output_group).to_list() | ||||||
|
|
||||||
| hash_file = ctx.actions.declare_file(ctx.label.name) | ||||||
|
|
||||||
| args = ctx.actions.args() | ||||||
|
|
||||||
| # This will automatically recursively expand directories which in particular handles | ||||||
| # all the complexity of the various bazel symlinks. | ||||||
| args.add_all( | ||||||
| inputs, | ||||||
| map_each = _hash_file_map_fname, | ||||||
| expand_directories = True, | ||||||
| ) | ||||||
|
|
||||||
| # Hash the content of the files. We sort them by filename to ensure a deterministic order. | ||||||
| # We also hash the file names themselves together with the content. | ||||||
| ctx.actions.run_shell( | ||||||
| inputs = inputs, | ||||||
| outputs = [hash_file], | ||||||
| command = "echo \"$@\" | sort | xargs tail -v -n +1 | sha1sum > \"$HASH_FILE\"", | ||||||
| arguments = [args], | ||||||
| env = {"HASH_FILE": hash_file.path}, | ||||||
|
Comment on lines
+145
to
+147
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've had problems using Would it be sensible to set |
||||||
| ) | ||||||
|
|
||||||
| return [DefaultInfo(files = depset([hash_file]))] | ||||||
|
|
||||||
| hash_files = rule( | ||||||
| implementation = _hash_files, | ||||||
| doc = """Hash the content of the file and produce a file containing that hash. | ||||||
| If the src is a directory, its content will be hashes recursively.""", | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit:
Suggested change
|
||||||
| attrs = { | ||||||
| "src": attr.label( | ||||||
| mandatory = True, | ||||||
| allow_files = True, | ||||||
| doc = "Target producing file outputs", | ||||||
| ), | ||||||
| "output_group": attr.string( | ||||||
| doc = "Output group to use (optional)", | ||||||
| ), | ||||||
| }, | ||||||
| ) | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was running out of time and create a bash command line which at least works but it would be better to use a zero separator I think, I couldn't figure out how to do that nicely.