-
Notifications
You must be signed in to change notification settings - Fork 59
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
Implement target distance metrics #230
Merged
tinder-maxwellelliott
merged 18 commits into
Tinder:master
from
alex-torok:add-direct-hash-to-rule-hasher
Oct 15, 2024
Merged
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
30c0f19
refactor: Update hashing logic to use TargetHash and TargetDigest
alex-torok 39bb6fc
Update RuleHasher to track separate digests
alex-torok edfe0c8
Add ability to compute target distance metrics
alex-torok aba2f87
Add ability to dump dependency edges to json file.
alex-torok 117e64e
Update get-impacted-targets
alex-torok 56a955e
Update documentation
alex-torok 27b0b68
Move target type filtering to happen after impacted targets are computed
alex-torok 02efb3e
Address review feedback
alex-torok 8766a1f
Merge branch 'refs/heads/master' into add-direct-hash-to-rule-hasher
alex-torok 8a59899
Fix typo in variable name
alex-torok aaa9771
Add test workspace and e2e test
alex-torok 6ebe6cd
Merge branch 'master' into add-direct-hash-to-rule-hasher
alex-torok a60e006
remove printlns
alex-torok 68bef93
Missing bazelignore
alex-torok 69b2f0e
Merge branch 'refs/heads/master' into add-direct-hash-to-rule-hasher
alex-torok 16be749
Remove e2e test that is duplicated by other one
alex-torok dce92e4
Merge branch 'master' into add-direct-hash-to-rule-hasher
alex-torok 50b1609
Update BUILD
alex-torok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.bazel_diff.hash | ||
// import com.google.common.hash.Hasher | ||
import com.google.common.hash.Hashing | ||
|
||
data class TargetDigest( | ||
val overallDigest: ByteArray, | ||
val directDigest: ByteArray, | ||
val deps: List<String>? = null, | ||
) { | ||
fun clone(newDeps: List<String>? = null): TargetDigest { | ||
var toUse = newDeps | ||
if (newDeps == null) { | ||
toUse = deps | ||
} | ||
return TargetDigest(overallDigest.clone(), directDigest.clone(), toUse) | ||
} | ||
} | ||
|
||
fun targetSha256(trackDepLabels: Boolean, block: TargetDigestBuilder.() -> Unit): TargetDigest { | ||
val hasher = TargetDigestBuilder(trackDepLabels) | ||
hasher.apply(block) | ||
return hasher.finish() | ||
} | ||
|
||
class TargetDigestBuilder(trackDepLabels: Boolean) { | ||
|
||
private val overallHasher = Hashing.sha256().newHasher() | ||
private val directHasher = Hashing.sha256().newHasher() | ||
private val deps: MutableList<String>? = if (trackDepLabels) mutableListOf() else null | ||
|
||
fun putDirectBytes(block: ByteArray?) { | ||
block?.let { directHasher.putBytes(it) } | ||
} | ||
|
||
fun putBytes(block: ByteArray?) { | ||
block?.let { overallHasher.putBytes(it) } | ||
} | ||
|
||
fun putTransitiveBytes(dep: String, block: ByteArray?) { | ||
block?.let { overallHasher.putBytes(it) } | ||
if (deps != null) { | ||
deps.add(dep) | ||
} | ||
} | ||
|
||
fun finish(): TargetDigest { | ||
val directHash = directHasher.hash().asBytes().clone() | ||
overallHasher.putBytes(directHash) | ||
|
||
return TargetDigest( | ||
overallHasher.hash().asBytes().clone(), | ||
directHash, | ||
deps, | ||
) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
❤️