-
-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
redress 1.2.0 (new formula) #155724
redress 1.2.0 (new formula) #155724
Conversation
15341de
to
7a4aa21
Compare
224267c
to
b6d8d65
Compare
@chenrui333 Looks like this is finally ready to go 🎉 |
Formula/r/redress.rb
Outdated
# https://github.com/goretk/redress/blob/develop/Makefile#L11-L14 | ||
redress_version = version | ||
gore_version = File.read(buildpath/"go.mod").scan(%r{goretk/gore v(\S+)}).flatten.first | ||
go_version = Formula["go"].version | ||
|
||
ldflags = %W[ | ||
-s -w | ||
-X main.redressVersion=#{redress_version} | ||
-X main.goreVersion=#{gore_version} | ||
-X main.compilerVersion=#{go_version} | ||
] |
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.
Can't it figure out the go version from the compiler?
And what is the gore version for?
# https://github.com/goretk/redress/blob/develop/Makefile#L11-L14 | |
redress_version = version | |
gore_version = File.read(buildpath/"go.mod").scan(%r{goretk/gore v(\S+)}).flatten.first | |
go_version = Formula["go"].version | |
ldflags = %W[ | |
-s -w | |
-X main.redressVersion=#{redress_version} | |
-X main.goreVersion=#{gore_version} | |
-X main.compilerVersion=#{go_version} | |
] | |
# https://github.com/goretk/redress/blob/develop/Makefile#L11-L14 | |
gore_version = File.read(buildpath/"go.mod").scan(%r{goretk/gore v(\S+)}).flatten.first | |
ldflags = %W[ | |
-s -w | |
-X main.redressVersion=#{version} | |
-X main.goreVersion=#{gore_version} | |
-X main.compilerVersion=#{Formula["go"].version} | |
] |
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.
These are flags taken directly out of the Makefile for the project; and match the implementation there.
I haven't deeply evaluated the source code to see if/how/where they make use of them.
Gore is a library it depends on.
Presumably it uses these for the version command or similar.
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.
Can we check what happens if we don't pass them?
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.
Anything is possible. Though I would ask why and whether it's important to spend time doing so.
Wouldn't it make the most sense to keep the way homebrew builds the program as close to the way it's officially built?
That way it prevents introducing issues in the homebrew version through diverging from the official build.
Makefile defining the variables as I implemented them here:
Variables set in code by those ldflags:
Which are used later on in that same file:
Not setting them would not be in line with users expectations of how the CLI reports it's versions.
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.
But if we wanted to do that, why not run the makefile? We're now adding a second implementation of the same logic that is up to the Homebrew community to keep in sync and maintain.
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.
If you don't want to use the upstream version because you think it's too much code and don't want to try and reduce your ruby copy of it here I'm afraid we're at an impasse, because I don't want this merged before we at least attempt to minimise the code in this formula.
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'm afraid we're at an impasse, because I don't want this merged before we at least attempt to minimise the code in this formula.
I'm confused.. I don't believe I said anything about not being open to reducing code here?
All I've done is answer your questions and provide relevant context?
Aside from a high level 'attempt to minimise the code', do you have more concrete suggestions of areas that are currently 'unacceptable'; that I haven't already spoken to above/elsewhere?
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.
Now that I'm at a computer, I've accepted the suggested changes above in 2548aa0
Though since the enforced standard is that I need to manually squash commits (which is why I didn't accept them straight away, as that workflow doesn't work with squashed commits), that reference will no longer be valid after I force push.
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.
@SMillerDev Does the above satisfy your desires for landing this PR? Or do you still consider it unmergeable in it's current state?
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.
See this comment for latest updates, which sort of sidesteps the core testing issue being discussed here:
Formula/r/redress.rb
Outdated
assert_match "Version: #{version}", shell_output("#{bin}/redress version") | ||
|
||
if Hardware::CPU.arm? | ||
# redress can't currently process ARM binaries, so we cross-compile this test binary |
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.
Can it check test_fixtures("elf/hello")
?
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.
Not unless that test fixture is a golang binary.
Edit: Now that i'm on a computer, I tried this, and it technically runs, but IMO it's probably not really any better than a test that checks the version number of a CLI; it's not really demonstrating that the core functionality works well, and given this tool is only meant to be run against Golang binaries, there's a high likelihood that the test would break at some future point for no good reason.
Formula diff patch (doesn't currently pass the test):
diff --git a/Formula/r/redress.rb b/Formula/r/redress.rb
index c5ecfbcdc9e..333d7214be0 100644
--- a/Formula/r/redress.rb
+++ b/Formula/r/redress.rb
@@ -52,10 +52,12 @@ class Redress < Formula
else
# on supported architectures, redress can just check it's own binary
test_module_root = "github.com/goretk/redress"
- test_bin_path = bin/"redress"
+ # test_bin_path = bin/"redress"
+ test_bin_path = test_fixtures("elf/hello")
end
output = shell_output("#{bin}/redress info '#{test_bin_path}'")
+ print output
assert_match(/Main root\s+#{Regexp.escape(test_module_root)}/, output)
end
end
Output from CLI:
..snip..
==> Testing redress
==> /usr/local/Cellar/redress/1.1.1/bin/redress version
==> /usr/local/Cellar/redress/1.1.1/bin/redress info '/usr/local/Homebrew/Library/Homebrew/test/support/fixtures/elf/hello'
OS EM_X86_64
Arch amd64
# main 0
# std 0
# vendor 0
..snip..
There is no "Main root" in the output when run against a non-Golang binary, which is what we were using to demonstrate that the CLI is working as intended.
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.
Is there some hello-world binary we can download somewhere?
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.
Somewhere unrelated on the internet; maybe. Though I'm not sure how it would be a better option to download an arbitrary binary just to run in the test?
This is in line with how tests are implemented for other Golang formula like this; which is what I based it off. (Ref)
Everything I've done here was already discussed earlier on this PR (including alternative options) and the approach taken was based on that discussion, eg.:
- Alternative options were considered in this comment
- References to other formula that depend on Golang for their tests (and that use the same pattern of 'compile a small test binary') were listed and used as references in this comment
- Confirming that the additional test logic worked around the initial problem when building on Apple Silicon in this comment
- Which was all confirmed as a good direction to go in by a maintainer in this comment
- etc
If you think this pattern is common enough among current formula to warrant extracting some helpers/similar into homebrew so that the boilerplate in each individual formula is abstracted; that could ultimately also be a good solution; but:
- a) from my brief review, I don't think there are enough formula currently implementing this that it would be worthwhile
- b) even if it was something to be done, feels like something that doesn't need to block this PR, and could be carried out as an improvement to homebrew separately after the fact
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.
it does not have to be that arbitrary (as it can be trusted domain hosted on github.com or something alike) and we also use checksum to guard the integrity of the binary.
Let me see what I can help with.
(Sorry about the hassle, we are trying to get it right from the beginning :) )
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.
it does not have to be that arbitrary (as it can be trusted domain hosted on github.com or something alike) and we also use checksum to guard the integrity of the binary.
@chenrui333 I guess by 'arbitrary', I was less concerned about file integrity (because checksum/etc), and more that it just seems like a worse solution to download a random binary from somewhere that's unrelated to the project/homebrew, just to avoid using an existing pattern of compiling a small binary to be used in the tests.
Let me see what I can help with.
@chenrui333 I'd appreciate that.
(Sorry about the hassle, we are trying to get it right from the beginning :) )
@chenrui333 nods even though it's frustrating from a "trying to contribute" perspective, I do understand the 'why' of it, at least at a high level (even if I don't personally agree with the specifics of it in this instance)
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.
See this comment for latest updates, which sort of sidesteps the core testing issue being discussed here:
2548aa0
to
2331ade
Compare
c71be0e
to
2106caf
Compare
2106caf
to
f52bc81
Compare
@chenrui333 @SMillerDev Bumped from
Since that worked, I simplified the test code back to the original 'redress processes it's own binary as a test' method that I had before working around the ARM failures (which is also the same test process I used in #155716) |
Co-Authored-By: Sean Molenaar <[email protected]>
2339678
to
26b0338
Compare
test_module_root = "github.com/goretk/redress" | ||
test_bin_path = bin/"redress" | ||
|
||
output = shell_output("#{bin}/redress info '#{test_bin_path}'") |
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.
can the '
be removed?
output = shell_output("#{bin}/redress info '#{test_bin_path}'") | |
output = shell_output("#{bin}/redress info #{test_bin_path}") |
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.
@chenrui333 It could.. but why? If I did that, then if test_bin_path
is updated in future to contain spaces, it will break. It was explicitly written this way to defensibly avoid creating future problems for maintainers.
It could also have been fully inlined like this, but I chose not to do that to improve the readability of it:
test_module_root = "github.com/goretk/redress"
- test_bin_path = bin/"redress"
-
- output = shell_output("#{bin}/redress info '#{test_bin_path}'")
+ output = shell_output("#{bin}/redress info #{bin/"redress"}")
My previous PR that followed this same pattern had the '
and it wasn't an issue there?
test do
json_output = JSON.parse(shell_output("#{bin}/goresym '#{bin}/goresym'"))
assert_equal json_output["BuildInfo"]["Main"]["Path"], "github.com/mandiant/GoReSym"
end
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.
yeah, it is fine, just some code style thing. sounds good then.
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.
lgtm, just one nit comment
HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source <formula>
, where<formula>
is the name of the formula you're submitting?brew test <formula>
, where<formula>
is the name of the formula you're submitting?brew audit --strict <formula>
(after doingHOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source <formula>
)? If this is a new formula, does it passbrew audit --new <formula>
?Add new formula for
redress
CLI: