Skip to content

Conversation

@mikeland73
Copy link
Contributor

Summary

Some repos (e.g. https://github.com/mvdan/gofumpt) release files as binaries instead of archives. This expands runx to treat unknown files (that still match the platform and architecture name structure) as binaries. It only does so if it finds a compatible artifact but the type is unknown.

We could additionally test the mime type of the file, but it doesn't seem like binaries use consistent mime types.

How was it tested?

./dist/runx +mvdan/gofumpt gofumpt --help

@mikeland73 mikeland73 requested review from gcurtis, loreto and savil October 9, 2023 19:11
}

func createSymbolicLink(src, dest, repoName string) error {
if err := fileutil.EnsureDir(dest); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could just be os.MkdirAll.

Comment on lines 73 to 75
if errors.Is(err, os.ErrExist) {
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to check that the symlink is pointing to the right binary if it already exists in case the user ever installs a different version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The symlink is already in a versioned directory: (Both the symlink and the source)

ls -al ~/Library/Caches/jetpack.io/pkgs/mvdan/gofumpt/v0.5.0/darwin/arm64/       
gofumpt -> /Users/mike/Library/Caches/jetpack.io/pkgs/mvdan/gofumpt/v0.5.0/gofumpt_v0.5.0_darwin_arm64

So nice to have in case we ever change the download logic but not urgent. Will add TODO

if isKnownArchive(filepath.Base(artifactPath)) {
err = Extract(ctx, artifactPath, installPath.String())
} else {
// If we can't extract, treat as binary
Copy link
Contributor

@gcurtis gcurtis Oct 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking the first 4 bytes would be a pretty good heuristic for determining if it's meant to be executable:

  • #! = shell script
  • 0x7f454c46 = ELF (Linux)
  • 0xfeedface = macho 32 bit binary (macOS)
  • 0xfeedfacf = macho 64 bit binary (macOS)
  • 0xcafebabe = macho universal binary (macOS)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like I also need to add little endian for mac binaries

@mikeland73 mikeland73 merged commit 090d910 into main Oct 10, 2023
@mikeland73 mikeland73 deleted the landau/allow-non-archived-binaries branch October 10, 2023 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants