Skip to content

Commit

Permalink
Only set arch on bin dir when we are building for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany committed Sep 6, 2024
1 parent 7041121 commit 16b30e2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
10 changes: 6 additions & 4 deletions pkg/packaging/detectLauncherVersion.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ func (p *PackageOptions) detectLauncherVersion(ctx context.Context) error {
logger := log.With(ctxlog.FromContext(ctx), "library", "detectLauncherVersion")
level.Debug(logger).Log("msg", "Attempting launcher autodetection")

launcherPath := p.launcherLocation(filepath.Join(p.packageRoot, p.binDir, string(p.target.Arch)))
launcherPath := p.launcherLocation(filepath.Join(p.packageRoot, p.binDir))
if p.target.Platform == Windows {
launcherPath = p.launcherLocation(filepath.Join(p.packageRoot, p.binDir, string(p.target.Arch)))
}

stdout, err := p.execOut(ctx, launcherPath, "-version")
if err != nil {
Expand Down Expand Up @@ -51,9 +54,8 @@ func (p *PackageOptions) detectLauncherVersion(ctx context.Context) error {
// fall back to the common location if it doesn't.
func (p *PackageOptions) launcherLocation(binDir string) string {
if p.target.Platform == Darwin {
// We want /usr/local/Kolide.app, not /usr/local/bin/universal/Kolide.app, so we use Dir to strip out `bin`
// and universal
appBundleBinaryPath := filepath.Join(filepath.Dir(filepath.Dir(binDir)), "Kolide.app", "Contents", "MacOS", "launcher")
// We want /usr/local/Kolide.app, not /usr/local/bin/Kolide.app, so we use Dir to strip out `bin`
appBundleBinaryPath := filepath.Join(filepath.Dir(binDir), "Kolide.app", "Contents", "MacOS", "launcher")
if info, err := os.Stat(appBundleBinaryPath); err == nil && !info.IsDir() {
return appBundleBinaryPath
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/packaging/detectLauncherVersion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestLauncherLocation(t *testing.T) {

// Create a temp directory with an app bundle in it
tmpDir := t.TempDir()
binDir := filepath.Join(tmpDir, "bin", "universal")
binDir := filepath.Join(tmpDir, "bin")
require.NoError(t, os.MkdirAll(binDir, 0755))
baseDir := filepath.Join(tmpDir, "Kolide.app", "Contents", "MacOS")
require.NoError(t, os.MkdirAll(baseDir, 0755))
Expand Down
10 changes: 8 additions & 2 deletions pkg/packaging/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func FetchBinary(ctx context.Context, localCacheDir, name, binaryName, channelOr

// put binaries in arch specific directory to avoid naming collisions in wix msi building
// where a single destination will have multiple, mutally exclusive sources
localCacheDir = filepath.Join(localCacheDir, string(target.Arch))
if target.Platform == Windows {
localCacheDir = filepath.Join(localCacheDir, string(target.Arch))
}

if err := os.MkdirAll(localCacheDir, fsutil.DirMode); err != nil {
return "", fmt.Errorf("could not create cache directory: %w", err)
Expand Down Expand Up @@ -140,7 +142,11 @@ func dlTarPath(name, channelOrVersion, platform, arch string) (string, error) {
}

func dlTarPathFromVersion(name, version, platform, arch string) string {
return path.Join("kolide", name, platform, arch, fmt.Sprintf("%s-%s.tar.gz", name, version))
// Include arch for Windows
if platform == string(Windows) {
return path.Join("kolide", name, platform, arch, fmt.Sprintf("%s-%s.tar.gz", name, version))
}
return path.Join("kolide", name, platform, fmt.Sprintf("%s-%s.tar.gz", name, version))
}

//go:embed assets/tuf/root.json
Expand Down
5 changes: 4 additions & 1 deletion pkg/packaging/packaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,10 @@ func (p *PackageOptions) getBinary(ctx context.Context, symbolicName, binaryName
return nil
}

binPath := filepath.Join(p.packageRoot, p.binDir, string(p.target.Arch), binaryName)
binPath := filepath.Join(p.packageRoot, p.binDir, binaryName)
if p.target.Platform == Windows {
binPath = filepath.Join(p.packageRoot, p.binDir, string(p.target.Arch), binaryName)
}
if err := os.MkdirAll(filepath.Dir(binPath), fsutil.DirMode); err != nil {
return fmt.Errorf("could not create directory for binary %s: %w", binaryName, err)
}
Expand Down

0 comments on commit 16b30e2

Please sign in to comment.