diff options
| author | Shulhan <ms@kilabit.info> | 2018-06-03 17:08:19 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2018-06-04 00:06:44 +0700 |
| commit | 0fae71f16b5e3194126802905ca0d740c06ee395 (patch) | |
| tree | 488060c0d6422471aa11f60f5e545d496eb115af | |
| parent | b30109159d464ba022608d6f566cfc61bc1c8b26 (diff) | |
| download | beku-0fae71f16b5e3194126802905ca0d740c06ee395.tar.xz | |
Sync(): install missing dependencies
| -rw-r--r-- | README.md | 5 | ||||
| -rw-r--r-- | cmd/beku/main.go | 5 | ||||
| -rw-r--r-- | env.go | 32 | ||||
| -rw-r--r-- | env_test.go | 1 | ||||
| -rw-r--r-- | package.go | 16 | ||||
| -rw-r--r-- | package_test.go | 2 |
6 files changed, 47 insertions, 14 deletions
@@ -110,10 +110,7 @@ branch. A specific version can be set using "@version" suffix. If package already exist, it will reset the HEAD to the version that is set on database file. -Sync operation will not install missing dependencies. - -If no parameter is given, beku will rescan GOPATH, checking for new -packages. +If no parameter is given, beku will do a rescan, checking for new packages. ### Options diff --git a/cmd/beku/main.go b/cmd/beku/main.go index 6226e1b..64fa1d5 100644 --- a/cmd/beku/main.go +++ b/cmd/beku/main.go @@ -101,10 +101,7 @@ // If package already exist, it will reset the HEAD to the version that is set // on database file. // -// Sync operation will not install missing dependencies. -// -// If no parameter is given, beku will rescan GOPATH, checking for new -// packages. +// If no parameter is given, beku will do a rescan, checking for new packages. // // ### Options // @@ -1048,6 +1048,28 @@ func (env *Env) update(curPkg, newPkg *Package) (ok bool, err error) { } // +// installMissing will install all missing packages. +// +func (env *Env) installMissing(pkg *Package) (err error) { + fmt.Printf("[ENV] installMissing: %s\n", pkg.ImportPath) + + for _, misImportPath := range pkg.DepsMissing { + _, misPkg := env.GetPackageFromDB(misImportPath, "") + if misPkg != nil { + continue + } + + err = env.Sync(misImportPath, misImportPath) + if err != nil { + fmt.Fprintf(defStderr, "[ENV] installMissing: %s\n", err) + continue + } + } + + return +} + +// // updateMissing will remove missing package if it's already provided by new // package. If "addAsDep" is true and the new package provide the missing one, // then it will be added as one of package dependencies. @@ -1234,7 +1256,8 @@ func (env *Env) SyncAll() (err error) { // // (1) Update missing packages. // (2) Re-scan package dependencies. -// (3) Run `go install` only if no missing package. +// (3) Install missing dependencies. +// (4) Run `go install` only if no missing package. // func (env *Env) postSync(curPkg, newPkg *Package) (err error) { // (1) @@ -1246,7 +1269,12 @@ func (env *Env) postSync(curPkg, newPkg *Package) (err error) { return } - // (3) + err = env.installMissing(curPkg) + if err != nil { + return + } + + // (4) if len(curPkg.DepsMissing) == 0 { _ = curPkg.GoInstall() } diff --git a/env_test.go b/env_test.go index 456c160..7c603cd 100644 --- a/env_test.go +++ b/env_test.go @@ -484,6 +484,7 @@ func testEnvScan(t *testing.T) { expPkgs: []*Package{{ ImportPath: testGitRepo, FullPath: filepath.Join(testEnv.dirSrc, testGitRepo), + ScanPath: filepath.Join(testEnv.dirSrc, testGitRepo), RemoteName: "origin", RemoteURL: "https://github.com/shuLhan/beku_test", Version: "v0.2.0", @@ -25,6 +25,7 @@ import ( type Package struct { ImportPath string FullPath string + ScanPath string RemoteName string RemoteURL string Version string @@ -62,9 +63,11 @@ func NewPackage(pkgName, importPath string, vcsMode VCSMode) ( pkg = &Package{ ImportPath: repoRoot.Root, - RemoteURL: repoRoot.Repo, FullPath: filepath.Join(build.Default.GOPATH, dirSrc, repoRoot.Root), - vcs: vcsMode, + ScanPath: filepath.Join(build.Default.GOPATH, dirSrc, importPath), + RemoteName: gitDefRemoteName, + RemoteURL: repoRoot.Repo, + vcsMode: repoRoot.VCS.Cmd, state: packageStateNew, } @@ -290,6 +293,10 @@ func (pkg *Package) GetRecursiveImports() ( cmd.Dir = pkg.FullPath cmd.Stderr = defStderr + if len(pkg.ScanPath) > 0 { + cmd.Dir = pkg.ScanPath + } + if Debug >= DebugL1 { fmt.Printf(">>> %s %s\n", cmd.Dir, cmd.Args) } @@ -473,13 +480,14 @@ func (pkg *Package) String() string { VCS = %d RemoteName = %s RemoteURL = %s + ScanPath = %s Version = %s IsTag = %v Deps = %v RequiredBy = %v DepsMissing = %v -`, pkg.ImportPath, pkg.vcs, pkg.RemoteName, pkg.RemoteURL, pkg.Version, - pkg.isTag, pkg.Deps, pkg.RequiredBy, pkg.DepsMissing) +`, pkg.ImportPath, pkg.vcsMode, pkg.RemoteName, pkg.RemoteURL, pkg.ScanPath, + pkg.Version, pkg.isTag, pkg.Deps, pkg.RequiredBy, pkg.DepsMissing) return buf.String() } diff --git a/package_test.go b/package_test.go index 1bbf36f..5b245e4 100644 --- a/package_test.go +++ b/package_test.go @@ -65,6 +65,7 @@ func testPackageInstall(t *testing.T) { pkg: testGitPkgShare, expPkg: &Package{ ImportPath: testGitRepoShare, + ScanPath: testGitPkgShare.FullPath, FullPath: testGitPkgShare.FullPath, RemoteName: gitDefRemoteName, RemoteURL: "https://" + testGitRepoShare, @@ -516,6 +517,7 @@ func testPackageString(t *testing.T) { VCS = 1 RemoteName = origin RemoteURL = https://` + testGitRepo + ` + ScanPath = ` + filepath.Join(testEnv.dirSrc, testGitRepo) + ` Version = v0.2.0 IsTag = true Deps = [] |
