Skip to content

Commit

Permalink
Add libs_version and modules_version
Browse files Browse the repository at this point in the history
PUBLISHED_FROM=2caa08204c98293bf2839e31e911ffe6f6e10867
  • Loading branch information
dimonomid authored and cesantabot committed Jun 19, 2017
1 parent ef5c5bc commit 7b09323
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
18 changes: 13 additions & 5 deletions mos/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func buildLocal(ctx context.Context, bParams *buildParams) (err error) {
reportf("The flag --module is not given for the module %q, going to use the repository", name)

var err error
targetDir, err = m.PrepareLocalDir(modulesDir, logFile, true)
targetDir, err = m.PrepareLocalDir(modulesDir, logFile, true, manifest.ModulesVersion)
if err != nil {
return errors.Trace(err)
}
Expand Down Expand Up @@ -335,7 +335,7 @@ func buildLocal(ctx context.Context, bParams *buildParams) (err error) {
}

var err error
mosDirEffective, err = m.PrepareLocalDir(modulesDir, logFile, true)
mosDirEffective, err = m.PrepareLocalDir(modulesDir, logFile, true, "")
if err != nil {
return errors.Trace(err)
}
Expand Down Expand Up @@ -1235,7 +1235,7 @@ func readManifestWithLibs(
deps.AddNode(depsApp)

manifest, mtime, err := readManifestWithLibs2(
dir, bParams, logFile, userLibsDir, skipClean, depsApp, deps, libsHandled,
dir, bParams, logFile, userLibsDir, skipClean, depsApp, deps, libsHandled, nil,
)
if err != nil {
return nil, time.Time{}, errors.Trace(err)
Expand Down Expand Up @@ -1274,13 +1274,20 @@ func readManifestWithLibs2(
dir string, bParams *buildParams,
logFile io.Writer, userLibsDir string, skipClean bool,
nodeName string, deps *Deps, libsHandled map[string]build.FWAppManifestLibHandled,
appManifest *build.FWAppManifest,
) (*build.FWAppManifest, time.Time, error) {

manifest, mtime, err := readManifest(dir, bParams)
if err != nil {
return nil, time.Time{}, errors.Trace(err)
}

// If the given appManifest is nil, it means that we've just read one, so
// remember it as such
if appManifest == nil {
appManifest = manifest
}

curDir, err := getCodeDir()
if err != nil {
return nil, time.Time{}, errors.Trace(err)
Expand Down Expand Up @@ -1330,7 +1337,7 @@ libs:
needPull := true

if *noLibsUpdate {
localDir, err := m.GetLocalDir(libsDir)
localDir, err := m.GetLocalDir(libsDir, appManifest.LibsVersion)
if err != nil {
return nil, time.Time{}, errors.Trace(err)
}
Expand All @@ -1357,7 +1364,7 @@ libs:

// Note: we always call PrepareLocalDir for libsDir, but then,
// if userLibsDir is different, will need to copy it to the new location
libDirAbs, err = m.PrepareLocalDir(libsDir, os.Stdout, true)
libDirAbs, err = m.PrepareLocalDir(libsDir, os.Stdout, true, appManifest.LibsVersion)
if err != nil {
return nil, time.Time{}, errors.Trace(err)
}
Expand Down Expand Up @@ -1401,6 +1408,7 @@ libs:

libManifest, libMtime, err := readManifestWithLibs2(
libDirAbs, &bParams2, logFile, userLibsDir, skipClean, name, deps, libsHandled,
appManifest,
)
if err != nil {
return nil, time.Time{}, errors.Trace(err)
Expand Down
3 changes: 3 additions & 0 deletions mos/build/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ type FWAppManifest struct {
CDefs map[string]string `yaml:"cdefs" json:"cdefs,omitempty"`
Tags []string `yaml:"tags" json:"tags,omitempty"`

LibsVersion string `yaml:"libs_version" json:"libs_version,omitempty"`
ModulesVersion string `yaml:"modules_version" json:"modules_version,omitempty"`

Conds []ManifestCond `yaml:"conds" json:"conds,omitempty"`

ManifestVersion string `yaml:"manifest_version" json:"manifest_version,omitempty"`
Expand Down
26 changes: 20 additions & 6 deletions mos/build/swmodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,23 @@ func (m *SWModule) IsClean(libsDir string) (bool, error) {
}

// PrepareLocalDir prepares local directory, if that preparation is needed
// in the first place, and returns the path to it
// in the first place, and returns the path to it. If defaultVersion is an
// empty string, then the default will depend on the kind of lib (e.g. for
// git it's "master")
func (m *SWModule) PrepareLocalDir(
libsDir string, logFile io.Writer, deleteIfFailed bool,
libsDir string, logFile io.Writer, deleteIfFailed bool, defaultVersion string,
) (string, error) {
if m.localPath == "" {

lp, err := m.GetLocalDir(libsDir)
lp, err := m.GetLocalDir(libsDir, defaultVersion)
if err != nil {
return "", errors.Trace(err)
}

switch m.GetType() {
case SWModuleTypeGit:
if err := prepareLocalCopyGit(m.Origin, m.Version, lp, logFile, deleteIfFailed); err != nil {
version := m.getVersionGit(defaultVersion)
if err := prepareLocalCopyGit(m.Origin, version, lp, logFile, deleteIfFailed); err != nil {
return "", errors.Trace(err)
}

Expand All @@ -102,15 +105,26 @@ func (m *SWModule) PrepareLocalDir(
return m.localPath, nil
}

func (m *SWModule) GetLocalDir(libsDir string) (string, error) {
func (m *SWModule) getVersionGit(defaultVersion string) string {
version := m.Version
if version == "" {
version = defaultVersion
}
if version == "" {
version = "master"
}
return version
}

func (m *SWModule) GetLocalDir(libsDir, defaultVersion string) (string, error) {
switch m.GetType() {
case SWModuleTypeGit:
name, err := m.GetName()
if err != nil {
return "", errors.Trace(err)
}

return filepath.Join(libsDir, getGitDirName(name, m.Version)), nil
return filepath.Join(libsDir, getGitDirName(name, m.getVersionGit(defaultVersion))), nil

case SWModuleTypeLocal:
if m.Origin != "" {
Expand Down
2 changes: 1 addition & 1 deletion mos/ui_proj_mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func initProjectManagementEndpoints() {
swmod.Name = target_name
}

_, err = swmod.PrepareLocalDir(dirPath, os.Stdout, true)
_, err = swmod.PrepareLocalDir(dirPath, os.Stdout, true, "")
if err != nil {
httpReply(w, "", err)
return
Expand Down

0 comments on commit 7b09323

Please sign in to comment.