Skip to content

Commit a546d91

Browse files
committed
Move executable.name destination to .app bundle resources on macOS
1 parent a324c7d commit a546d91

File tree

7 files changed

+76
-17
lines changed

7 files changed

+76
-17
lines changed
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,25 @@ import (
2626
"github.com/TeamDev-IP/Chromium-Branding/pkg/base"
2727
)
2828

29-
// WriteExecutableName creates (or truncates) a file named "executable.name" inside
30-
// the provided binariesDir directory and writes the given executableName string into it.
31-
//
32-
// It returns an error if the file cannot be created or if writing to the file fails.
33-
func WriteExecutableName(executableName string, binariesDir base.Directory) error {
34-
file, err := os.Create(binariesDir.AbsPath().Join(base.RelPathFromEntries("executable.name")).String())
29+
// ExecutableNameFile represents a file that holds the name of the main executable.
30+
// This file is named "executable.name" and is stored in a specific resources directory.
31+
type ExecutableNameFile struct {
32+
// Location is the directory where the executable name file is to be located.
33+
Location base.Directory
34+
// Content is the name of the main executable to be written into the file.
35+
Content string
36+
}
37+
38+
// CreateOrUpdate creates or updates the executable name file in the specified location.
39+
// It writes the Content field to a file named "executable.name" inside the Location directory.
40+
// Returns an error if the file cannot be created or written to.
41+
func (executableName *ExecutableNameFile) CreateOrUpdate() error {
42+
file, err := os.Create(executableName.Location.AbsPath().Join(base.RelPathFromEntries("executable.name")).String())
3543
if err != nil {
3644
return err
3745
}
3846
defer file.Close()
3947

40-
_, err = file.WriteString(executableName)
48+
_, err = file.WriteString(executableName.Content)
4149
return err
4250
}

pkg/core/branding.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,10 @@ type PlatformBranding interface {
9797
// according to the provided BrandingParams.
9898
Apply(params *common.BrandingParams, binariesDir base.Directory) error
9999

100-
// ExecutableName returns the name of the main executable file,
101-
// derived from the BrandingParams.
102-
ExecutableName(params *common.BrandingParams) string
100+
// ExecutableNameFile returns common.ExecutableNameFile for the Chromium binaries from the given
101+
// binariesDir assuming they are branded with the given params.
102+
// Returns an error if the file destination is invalid or cannot be determined.
103+
ExecutableNameFile(params *common.BrandingParams, binariesDir base.Directory) (common.ExecutableNameFile, error)
103104
}
104105

105106
// Branding wraps a set of BrandingParams and a PlatformBranding
@@ -150,9 +151,10 @@ func brandBinariesInDirectory(branding *Branding, params common.BrandingParams,
150151
if err := branding.Apply(outputDir); err != nil {
151152
return err
152153
}
153-
if err := common.WriteExecutableName(branding.platform.ExecutableName(&params), outputDir); err != nil {
154-
return err
154+
executableNameFile, err := branding.platform.ExecutableNameFile(&params, outputDir)
155+
if err != nil {
156+
return fmt.Errorf("the executable.name file destination is invalid: %w", err)
155157
}
156158

157-
return nil
159+
return executableNameFile.CreateOrUpdate()
158160
}

pkg/linux/branding.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ func GetPlatformBranding() (*LinuxBranding, error) {
3737
// LinuxBranding implements branding logic specific to Linux platforms.
3838
type LinuxBranding struct{}
3939

40+
func (branding *LinuxBranding) ExecutableNameFile(params *common.BrandingParams, binariesDir base.Directory) (common.ExecutableNameFile, error) {
41+
return common.ExecutableNameFile{
42+
Location: binariesDir,
43+
Content: branding.ExecutableName(params),
44+
}, nil
45+
}
46+
4047
// ExecutableName returns the Linux process name from BrandingParams if set,
4148
// or defaults to "chromium" otherwise.
4249
func (branding *LinuxBranding) ExecutableName(params *common.BrandingParams) string {

pkg/mac/branding.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,24 @@ func (branding *MacBranding) Apply(params *common.BrandingParams, binariesDir ba
9999
return nil
100100
}
101101

102+
func (branding *MacBranding) ExecutableNameFile(params *common.BrandingParams, binariesDir base.Directory) (common.ExecutableNameFile, error) {
103+
executableName := branding.ExecutableName(params)
104+
mainBundle, err := GetChromiumAppBundle(binariesDir, executableName)
105+
if err != nil {
106+
return common.ExecutableNameFile{}, err
107+
}
108+
109+
resourcesDir, err := mainBundle.ChromiumAppBundle().Path().Join(base.RelPathFromEntries("Contents", "Resources")).AsDirectory()
110+
if err != nil {
111+
return common.ExecutableNameFile{}, err
112+
}
113+
114+
return common.ExecutableNameFile{
115+
Location: resourcesDir,
116+
Content: executableName,
117+
}, nil
118+
}
119+
102120
func (branding *MacBranding) ExecutableName(params *common.BrandingParams) string {
103121
if params.Mac.Bundle.Name != nil {
104122
return *params.Mac.Bundle.Name

pkg/win/branding.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ func GetPlatformBranding() (*WinBranding, error) {
4848
}
4949
}
5050

51+
func (branding *WinBranding) ExecutableNameFile(params *common.BrandingParams, binariesDir base.Directory) (common.ExecutableNameFile, error) {
52+
return common.ExecutableNameFile{
53+
Location: binariesDir,
54+
Content: branding.ExecutableName(params),
55+
}, nil
56+
}
57+
5158
// ExecutableName returns the user-specified Windows executable name
5259
// if set in BrandingParams, or falls back to original chromium executable name.
5360
func (branding *WinBranding) ExecutableName(params *common.BrandingParams) string {

pkg/win/unsigned_binary.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ func (unsignedBinary UnsignedBinary) AbsPath() base.AbsPath {
4343
return unsignedBinary.File().AbsPath()
4444
}
4545

46-
// File returns a pointer to the underlying File in UnsignedBinary.
47-
// The caller can use this file for further operations (e.g., reading,
48-
// copying, or renaming).
46+
// RemoveSignature uses the Windows SDK signtool.exe to remove a digital signature
47+
// from the given binary. It returns an UnsignedBinary if the operation succeeds,
48+
// or an error if it fails.
49+
//
50+
// - binary: The file from which the signature should be removed.
51+
// - returns: An UnsignedBinary containing the same file with the signature removed,
52+
// or an error if removal fails (e.g., if the file isn't signed or can't be accessed).
4953
func RemoveSignature(binary base.File) (UnsignedBinary, error) {
5054
winSdk, err := FindWinSdk()
5155
if err != nil {

pkg/win/win_sdk.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,27 @@ const supportedArch = "x64"
3232

3333
var availableSdk *WinSdk
3434

35+
// WinSdk encapsulates a Windows SDK installation by holding a reference
36+
// to its binaries directory.
3537
type WinSdk struct {
3638
binDir base.Directory
3739
}
3840

41+
// Path returns the absolute path to the Windows SDK bin directory.
3942
func (sdk *WinSdk) Path() base.AbsPath {
4043
return sdk.binDir.AbsPath()
4144
}
4245

46+
// SigntoolPath returns the absolute path to the signtool.exe located within
47+
// the Windows SDK bin directory.
4348
func (sdk *WinSdk) SigntoolPath() base.AbsPath {
4449
return sdk.Path().Join(base.RelPathFromEntries("signtool.exe"))
4550
}
4651

52+
// FindWinSdk attempts to locate a Windows SDK installation by first checking
53+
// the system PATH for signtool.exe and, if not found, falling back to the
54+
// default Windows Kits installation location.
55+
// It returns a WinSdk instance if found, or an error if no suitable SDK can be located.
4756
func FindWinSdk() (*WinSdk, error) {
4857
if availableSdk != nil {
4958
return availableSdk, nil
@@ -63,6 +72,8 @@ func FindWinSdk() (*WinSdk, error) {
6372
return defaultWinSdk, err
6473
}
6574

75+
// WinSdkFromPathEnv tries to locate signtool.exe by invoking the "where" command.
76+
// If found, it converts the result to a base.Directory and returns a WinSdk instance.
6677
func WinSdkFromPathEnv() (*WinSdk, error) {
6778
where, err := base.ExecCommandAndGetOutput("where", []string{"signtool"})
6879
if err != nil {
@@ -75,6 +86,9 @@ func WinSdkFromPathEnv() (*WinSdk, error) {
7586
return &WinSdk{sdkBinDir}, err
7687
}
7788

89+
// DefaultWinSdk searches the default Windows SDK install path for a Windows 10/11 SDK.
90+
// It looks for a directory structure matching "bin/10/<version>/<supportedArch>" and returns
91+
// the latest valid WinSdk found. If none is found, an error with installation instructions is returned.
7892
func DefaultWinSdk() (*WinSdk, error) {
7993
defaultWinSdksInstallDir, err := base.DirectoryFromPathString(defaultWinSdksInstallPath)
8094
if err != nil {
@@ -87,7 +101,6 @@ func DefaultWinSdk() (*WinSdk, error) {
87101
versions := sdkVersionsDir.ChildDirs()
88102
sort.SliceStable(versions, func(i, j int) bool { return versions[i].AbsPath().Base() > versions[j].AbsPath().Base() })
89103
for _, version := range versions {
90-
fmt.Println(version.AbsPath().String())
91104
if sdkBinPath, err := version.AbsPath().Join(base.RelPathFromEntries(supportedArch)).AsDirectory(); err == nil {
92105
return &WinSdk{sdkBinPath}, nil
93106
} else {

0 commit comments

Comments
 (0)