diff --git a/internal/mk/mk.go b/internal/mk/mk.go index b9681dd..6321e56 100644 --- a/internal/mk/mk.go +++ b/internal/mk/mk.go @@ -16,21 +16,8 @@ import ( "github.com/spf13/viper" ) -var pkgEnv = func(pkg *Package) map[string]string { - return map[string]string{ - "PACKAGE_ORIGIN": pkg.Origin, - "PACKAGE_VERSION": pkg.Version, - "PACKAGE_LATEST": pkg.Latest, - "PACKAGE_MAINTAINER": pkg.Maintainer, - "PACKAGE_TYPE": pkg.Type, - "PACKAGE_DIR": CleanPath(viper.GetString("base")) + pkg.Origin, - } -} - func run(pkg *Package, makefile string) { - for k, v := range pkgEnv(pkg) { - os.Setenv(k, v) - } + SetPkgEnv(pkg) scriptDir := CleanPath(viper.GetString("scriptdir")) args := strings.Fields("make -f" + scriptDir + makefile) cmd := exec.Command(args[0], args[1:]...) diff --git a/internal/util/util.go b/internal/util/util.go index bfef637..13d506e 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -4,6 +4,9 @@ import ( "os" "path/filepath" "strings" + + . "github.com/lcook/portsync/internal/_package" + "github.com/spf13/viper" ) func CleanPath(path string) string { @@ -17,3 +20,22 @@ func CleanPath(path string) string { } return tmp } + +var ( + PkgEnv = func(pkg *Package) map[string]string { + return map[string]string{ + "PACKAGE_ORIGIN": pkg.Origin, + "PACKAGE_VERSION": pkg.Version, + "PACKAGE_LATEST": pkg.Latest, + "PACKAGE_MAINTAINER": pkg.Maintainer, + "PACKAGE_TYPE": pkg.Type, + "PACKAGE_DIR": CleanPath(viper.GetString("base")) + pkg.Origin, + "PACKAGE_ROOT": CleanPath(viper.GetString("base")), + } + } + SetPkgEnv = func(pkg *Package) { + for k, v := range PkgEnv(pkg) { + os.Setenv(k, v) + } + } +)