Skip to content

Commit

Permalink
feat: automatically set install_name for OSX libs
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Feb 27, 2021
1 parent 7d9b1df commit ecccfe4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
2 changes: 0 additions & 2 deletions v3/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
func init() {
initLogging()
native.Init()
// i := installer.NewInstaller()
// i.CheckInstallation()
}

// QueryStringStyle allows a user to specific the v2 query string serialisation format
Expand Down
43 changes: 42 additions & 1 deletion v3/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"log"
"os"
"os/exec"
"path"
"runtime"
"strings"
Expand Down Expand Up @@ -82,6 +83,11 @@ func (i *Installer) CheckInstallation() error {
return err
}

// Install dependencies
if err := i.installDependencies(); err != nil {
return err
}

if err := i.checkPackageInstall(); err != nil {
return fmt.Errorf("unable to verify downloaded/installed dependencies: %s", err)
}
Expand Down Expand Up @@ -141,8 +147,8 @@ func (i *Installer) downloadDependencies() error {

if err != nil {
return err

}

dst, err := i.getLibDstForPackage(pkg)

if err != nil {
Expand All @@ -159,6 +165,28 @@ func (i *Installer) downloadDependencies() error {
return nil
}

func (i *Installer) installDependencies() error {
if i.os == osx {
for pkg, info := range packages {
log.Println("[INFO] setting install_name on library", info.libName, "for osx")

dst, err := i.getLibDstForPackage(pkg)

if err != nil {
return err
}

err = setOSXInstallName(dst, info.libName)

if err != nil {
return err
}
}
}

return nil
}

// returns src
func (i *Installer) getDownloadURLForPackage(pkg string) (string, error) {
pkgInfo, ok := packages[pkg]
Expand All @@ -178,6 +206,19 @@ func (i *Installer) getLibDstForPackage(pkg string) (string, error) {
return path.Join(i.getLibDir(), pkgInfo.libName) + "." + osToExtension[i.os], nil
}

func setOSXInstallName(file string, lib string) error {
cmd := exec.Command("install_name_tool", "-id", fmt.Sprintf("../../libs/%s.dylib", lib), file)
stdoutStderr, err := cmd.CombinedOutput()

if err != nil {
return fmt.Errorf("error setting install name on pact lib: %s", err)
}

log.Println("[DEBUG] output from command", stdoutStderr)

return err
}

// download template structure: "https://github.com/pact-foundation/pact-reference/releases/download/PACKAGE-vVERSION/LIBNAME-OS-ARCH.EXTENSION.gz"
var downloadTemplate = "https://github.com/pact-foundation/pact-reference/releases/download/%s-v%s/%s-%s-%s.%s.gz"

Expand Down

0 comments on commit ecccfe4

Please sign in to comment.