Skip to content

Commit

Permalink
Make it possible to specify --libs-dir multiple times
Browse files Browse the repository at this point in the history
When looking for libraries, directories will be searched in the order they appear on the command line.

CL: mos: Make it possible to specify --libs-dir multiple times

PUBLISHED_FROM=edf703eb2f76edefb5fa1f6c8c0ab9151bfd3058
  • Loading branch information
Deomid Ryabkov authored and cesantabot committed Apr 3, 2019
1 parent 67eed18 commit addc012
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
18 changes: 12 additions & 6 deletions mos/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"context"
"encoding/json"
"io"
"io/ioutil"
Expand All @@ -12,8 +13,6 @@ import (
"time"
"unicode"

"context"

"cesanta.com/common/go/fwbundle"
"cesanta.com/common/go/ourutil"
"cesanta.com/mos/build"
Expand All @@ -27,6 +26,7 @@ import (
"cesanta.com/mos/update"
"cesanta.com/mos/version"
"github.com/cesanta/errors"
"github.com/golang/glog"
flag "github.com/spf13/pflag"
yaml "gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -434,11 +434,17 @@ func (lpr *compProviderReal) GetLibLocalPath(
}

// If --libs-dir is set, this is where all the libs are.
if paths.LibsDirFlag != "" {
if len(paths.LibsDirFlag) > 0 {
name2, _ := m.GetName2()
libDirAbs := filepath.Join(paths.LibsDirFlag, name2)
ourutil.Freportf(lpr.logWriter, "%s: Using %q (--libs-dir) %s", name, libDirAbs, name2)
return libDirAbs, nil
for _, libsDir := range paths.LibsDirFlag {
libDir := filepath.Join(libsDir, name2)
glog.V(2).Infof("%s (%s): Trying %s...", name, name2, libDir)
if fi, err := os.Stat(libDir); err == nil && fi.IsDir() {
ourutil.Freportf(lpr.logWriter, "%s: Using %q (--libs-dir)", name, libDir)
return libDir, nil
}
}
return "", errors.Errorf("%s not found in --libs-dir", name2)
}

// Try to fetch
Expand Down
14 changes: 8 additions & 6 deletions mos/common/paths/paths.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package paths

import (
"flag"
"fmt"
"os"
"path/filepath"
Expand All @@ -11,6 +10,7 @@ import (
"cesanta.com/mos/version"

"github.com/cesanta/errors"
flag "github.com/spf13/pflag"
)

var (
Expand All @@ -20,7 +20,7 @@ var (

TmpDir = ""
depsDirFlag = ""
LibsDirFlag = ""
LibsDirFlag = []string{}
AppsDir = ""
modulesDirFlag = ""

Expand All @@ -31,7 +31,7 @@ var (
func init() {
flag.StringVar(&TmpDir, "temp-dir", "~/.mos/tmp", "Directory to store temporary files")
flag.StringVar(&depsDirFlag, "deps-dir", "", "Directory to fetch libs, modules into")
flag.StringVar(&LibsDirFlag, "libs-dir", "", "Directory to find libs in")
flag.StringSliceVar(&LibsDirFlag, "libs-dir", []string{}, "Directory to find libs in. Can be used multiple times.")
flag.StringVar(&AppsDir, "apps-dir", AppsDirTpl, "Directory to store apps into")
flag.StringVar(&modulesDirFlag, "modules-dir", "", "Directory to store modules into")

Expand All @@ -52,9 +52,11 @@ func Init() error {
return errors.Trace(err)
}

LibsDirFlag, err = NormalizePath(LibsDirFlag, version.GetMosVersion())
if err != nil {
return errors.Trace(err)
for i, s := range LibsDirFlag {
LibsDirFlag[i], err = NormalizePath(s, version.GetMosVersion())
if err != nil {
return errors.Trace(err)
}
}

AppsDir, err = NormalizePath(AppsDir, version.GetMosVersion())
Expand Down

0 comments on commit addc012

Please sign in to comment.