Skip to content

Commit

Permalink
Merge pull request #2543 from carolynvs/fix-apple-codesign-bug
Browse files Browse the repository at this point in the history
Workaround apple silicon codesigning cache bug
  • Loading branch information
carolynvs authored Jan 31, 2023
2 parents 81a070a + 980bf68 commit b165007
Showing 1 changed file with 18 additions and 0 deletions.
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))

// 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

0 comments on commit b165007

Please sign in to comment.