Skip to content
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

Workaround apple silicon codesigning cache bug #2543

Merged
merged 1 commit into from
Jan 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,16 @@ func Install() {

// Copy porter binaries
mgx.Must(os.MkdirAll(porterHome, pkg.FileModeDirectory))

carolynvs marked this conversation as resolved.
Show resolved Hide resolved
// HACK: Works around a codesigning problem on Apple Silicon where overwriting a binary that has already been executed doesn't cause the corresponding codesign entry in the OS cache to update
// Mac then prevents the updated binary from running because the signature doesn't match
// Removing the file first clears the cache so that we don't run into "zsh: killed porter..."
// See https://stackoverflow.com/questions/67378106/mac-m1-cping-binary-over-another-results-in-crash
// See https://openradar.appspot.com/FB8914231
mgx.Must(os.Remove(filepath.Join(porterHome, "porter"+xplat.FileExt())))
mgx.Must(os.RemoveAll(filepath.Join(porterHome, "runtimes")))

// Okay now it's safe to copy these files over
mgx.Must(shx.Copy(filepath.Join("bin", "porter"+xplat.FileExt()), porterHome))
mgx.Must(shx.Copy(filepath.Join("bin", "runtimes"), porterHome, shx.CopyRecursive))

Expand All @@ -544,6 +554,14 @@ func Install() {
destDir := filepath.Join(porterHome, "mixins", mixin)
mgx.Must(os.MkdirAll(destDir, pkg.FileModeDirectory))

// HACK: Works around a codesigning problem on Apple Silicon where overwriting a binary that has already been executed doesn't cause the corresponding codesign entry in the OS cache to update
// Mac then prevents the updated binary from running because the signature doesn't match
// Removing the file first clears the cache so that we don't run into "zsh: killed MIXIN..."
// See https://stackoverflow.com/questions/67378106/mac-m1-cping-binary-over-another-results-in-crash
// See https://openradar.appspot.com/FB8914231
mgx.Must(os.Remove(filepath.Join(destDir, mixin+xplat.FileExt())))
mgx.Must(os.RemoveAll(filepath.Join(destDir, "runtimes")))

// Copy the mixin client binary
mgx.Must(shx.Copy(filepath.Join(srcDir, mixin+xplat.FileExt()), destDir))

Expand Down