mirror of
https://github.com/jimeh/build-emacs-for-macos.git
synced 2026-02-19 10:46:39 +00:00
This finally makes Emacs.app with native-comp fully self-contained, no longer requiring the GCC Homebrew formula to be installed when loading *.eln files that link against /usr/local/lib/gcc/11/libgcc_s.1.dylib. By adding the signing entitlement com.apple.security.cs.allow-dyld-environment-variables, which allows dynamic library loading to be controlled via DYLD_* environment variables. It seems the lack of this was preventing Emacs from loading the bundled libgcc_s.1.dylib file from Contents/Frameworks. Fixes #53
122 lines
3.3 KiB
Go
122 lines
3.3 KiB
Go
package sign
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/jimeh/undent"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var entitlementsTestCases = []struct {
|
|
name string
|
|
entitlements Entitlements
|
|
want string
|
|
}{
|
|
{
|
|
name: "none",
|
|
entitlements: Entitlements{},
|
|
//nolint:lll
|
|
want: undent.String(`
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
<plist version="1.0">
|
|
<dict>
|
|
</dict>
|
|
</plist>`,
|
|
),
|
|
},
|
|
{
|
|
name: "one",
|
|
entitlements: Entitlements{"com.apple.security.cs.allow-jit"},
|
|
//nolint:lll
|
|
want: undent.String(`
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
<plist version="1.0">
|
|
<dict>
|
|
<key>com.apple.security.cs.allow-jit</key>
|
|
<true/>
|
|
</dict>
|
|
</plist>`,
|
|
),
|
|
},
|
|
{
|
|
name: "many",
|
|
entitlements: Entitlements{
|
|
"com.apple.security.cs.allow-jit",
|
|
"com.apple.security.network.client",
|
|
"com.apple.security.cs.disable-library-validation",
|
|
"com.apple.security.cs.allow-dyld-environment-variables",
|
|
"com.apple.security.automation.apple-events",
|
|
},
|
|
//nolint:lll
|
|
want: undent.String(`
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
<plist version="1.0">
|
|
<dict>
|
|
<key>com.apple.security.cs.allow-jit</key>
|
|
<true/>
|
|
<key>com.apple.security.network.client</key>
|
|
<true/>
|
|
<key>com.apple.security.cs.disable-library-validation</key>
|
|
<true/>
|
|
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
|
|
<true/>
|
|
<key>com.apple.security.automation.apple-events</key>
|
|
<true/>
|
|
</dict>
|
|
</plist>`,
|
|
),
|
|
},
|
|
}
|
|
|
|
func TestDefaultEmacsEntitlements(t *testing.T) {
|
|
assert.Equal(t,
|
|
[]string{
|
|
"com.apple.security.cs.allow-jit",
|
|
"com.apple.security.network.client",
|
|
"com.apple.security.cs.disable-library-validation",
|
|
"com.apple.security.cs.allow-dyld-environment-variables",
|
|
"com.apple.security.automation.apple-events",
|
|
},
|
|
DefaultEmacsEntitlements,
|
|
)
|
|
}
|
|
|
|
func TestEntitlements_Write(t *testing.T) {
|
|
for _, tt := range entitlementsTestCases {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
var buf bytes.Buffer
|
|
|
|
err := tt.entitlements.Write(&buf)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, tt.want, strings.TrimSpace(buf.String()))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestEntitlements_TempFile(t *testing.T) {
|
|
for _, tt := range entitlementsTestCases {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
tmpFile, err := tt.entitlements.TempFile()
|
|
require.NoError(t, err)
|
|
defer os.Remove(tmpFile)
|
|
|
|
content, err := os.ReadFile(tmpFile)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, tt.want, strings.TrimSpace(string(content)))
|
|
assert.True(t,
|
|
strings.HasSuffix(tmpFile, ".entitlements.plist"),
|
|
"temp file name does not match \"*.entitlements.plist\"",
|
|
)
|
|
})
|
|
}
|
|
}
|