Skip to content

Commit

Permalink
add better required subtool enforcing
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed Nov 15, 2016
1 parent fb29e20 commit f9e894f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
14 changes: 11 additions & 3 deletions gxutil/pm.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,12 @@ func (pm *PM) InitPkg(dir, name, lang string, setup func(*Package)) error {
}

func CheckForHelperTools(lang string) {
_, err := exec.LookPath("gx-" + lang)
if err == nil {
p, err := getSubtoolPath(lang)
if err == nil && p != "" {
return
}

if strings.Contains(err.Error(), "file not found") {
if p == "" || strings.Contains(err.Error(), "file not found") {
Log("notice: no helper tool found for", lang)
return
}
Expand Down Expand Up @@ -615,6 +615,14 @@ func resolveDepName(pkg *Package, out interface{}, dir, name string, checked map

return ErrUnrecognizedName
}
func IsSubtoolInstalled(env string) (bool, error) {
p, err := getSubtoolPath(env)
if err != nil {
return false, err
}

return p != "", nil
}

func getSubtoolPath(env string) (string, error) {
if env == "" {
Expand Down
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ func LoadPackageFile(path string) (*gx.Package, error) {
pkg.GxVersion = gx.GxVersion
}

if pkg.SubtoolRequired {
found, err := gx.IsSubtoolInstalled(pkg.Language)
if err != nil {
return nil, err
}
if !found {
return nil, fmt.Errorf("package requires a subtool (gx-%s) and none was found.", pkg.Language)
}
}

return &pkg, nil
}

Expand Down

0 comments on commit f9e894f

Please sign in to comment.