Skip to content

Commit

Permalink
Merge pull request #2 from PumasAI/mh/crlf
Browse files Browse the repository at this point in the history
Windows-specific `tree_hash` issue
  • Loading branch information
MichaelHatherly authored Feb 8, 2024
2 parents dbe42ca + 9f9ae4a commit 832168f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
17 changes: 16 additions & 1 deletion src/code_stripping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function _generate_stripped_bundle(;
run(`$gitcmd init`)
run(`$gitcmd config user.name "PackageBundler"`)
run(`$gitcmd config user.email ""`)
run(`$gitcmd config core.autocrlf false`)
end

# Ensure that the versions are sorted first before committing,
Expand All @@ -69,7 +70,21 @@ function _generate_stripped_bundle(;
run(Cmd([gitcmd, "commit", "-m", msg]))
run(Cmd([gitcmd, "tag", "-a", "v$version", "-m", msg]))

pkg_info["git-tree-sha1"] = bytes2hex(Pkg.GitTools.tree_hash(temp_dir))
# Interestingly, using `tree_hash` failed on Windows with a
# `git object <commit> could not be found` error when attempting to
# clone the stripped packages. It would appear that the tree hash
# doesn't match what it should be on that platform, whereas it works
# correctly on macOS and Linux, both locally and on GitHub runners.
#
# ```
# sha = bytes2hex(Pkg.GitTools.tree_hash(temp_dir))
# ```
#
# To get around this we use the `rev-parse` and `^{tree}` to get the
# "real" tree hash.
rev = readchomp(`$gitcmd rev-parse HEAD`)
sha = readchomp(Cmd([gitcmd, "rev-parse", "$rev^{tree}"]))
pkg_info["git-tree-sha1"] = sha
end
run(`$gitcmd log`)
end
Expand Down
6 changes: 3 additions & 3 deletions src/openssl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function keypair(dir::AbstractString = pwd())

@info "Generating key pair for signing stripped packages." dir
dir = abspath(dir)
openssl = OpenSSL_jll.openssl
openssl = OpenSSL_jll.openssl()
cmd = Cmd(["genrsa", "-out", private, "4096"])
run(`$openssl $cmd`)
cmd = Cmd(["rsa", "-in", private, "-pubout"])
Expand All @@ -27,7 +27,7 @@ function keypair(dir::AbstractString = pwd())
end

function _sign_file(file, private_key)
openssl = OpenSSL_jll.openssl
openssl = OpenSSL_jll.openssl()
cmd = Cmd([
"dgst",
"-sign",
Expand All @@ -44,7 +44,7 @@ function _sign_file(file, private_key)
end

function _verify_file(file, public_key)
openssl = OpenSSL_jll.openssl
openssl = OpenSSL_jll.openssl()
cmd = Cmd([
"dgst",
"-verify",
Expand Down

0 comments on commit 832168f

Please sign in to comment.