зеркало из https://github.com/golang/dep.git
Convert SourceManager to use on ProjectIdentifier
I pulled this out a while back, but going back to it's been a long time coming. Not all the SourceManager methods strictly need the information in a ProjectIdentifier, but it's much easier to be consistent and just always require it. This does not actually convert function/method bodies - just signatures. In no way does this come even close to compiling.
This commit is contained in:
Родитель
7f527406f1
Коммит
23396e8341
|
@ -1202,7 +1202,7 @@ func newdepspecSM(ds []depspec, ignore []string) *depspecSourceManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *depspecSourceManager) GetManifestAndLock(n ProjectRoot, v Version) (Manifest, Lock, error) {
|
func (sm *depspecSourceManager) GetManifestAndLock(id ProjectIdentifier, v Version) (Manifest, Lock, error) {
|
||||||
for _, ds := range sm.specs {
|
for _, ds := range sm.specs {
|
||||||
if n == ds.n && v.Matches(ds.v) {
|
if n == ds.n && v.Matches(ds.v) {
|
||||||
return ds, dummyLock{}, nil
|
return ds, dummyLock{}, nil
|
||||||
|
@ -1217,7 +1217,7 @@ func (sm *depspecSourceManager) AnalyzerInfo() (string, *semver.Version) {
|
||||||
return "depspec-sm-builtin", sv("v1.0.0")
|
return "depspec-sm-builtin", sv("v1.0.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *depspecSourceManager) ExternalReach(n ProjectRoot, v Version) (map[string][]string, error) {
|
func (sm *depspecSourceManager) ExternalReach(id ProjectIdentifier, v Version) (map[string][]string, error) {
|
||||||
id := pident{n: n, v: v}
|
id := pident{n: n, v: v}
|
||||||
if m, exists := sm.rm[id]; exists {
|
if m, exists := sm.rm[id]; exists {
|
||||||
return m, nil
|
return m, nil
|
||||||
|
@ -1225,7 +1225,7 @@ func (sm *depspecSourceManager) ExternalReach(n ProjectRoot, v Version) (map[str
|
||||||
return nil, fmt.Errorf("No reach data for %s at version %s", n, v)
|
return nil, fmt.Errorf("No reach data for %s at version %s", n, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *depspecSourceManager) ListExternal(n ProjectRoot, v Version) ([]string, error) {
|
func (sm *depspecSourceManager) ListExternal(id ProjectIdentifier, v Version) ([]string, error) {
|
||||||
// This should only be called for the root
|
// This should only be called for the root
|
||||||
id := pident{n: n, v: v}
|
id := pident{n: n, v: v}
|
||||||
if r, exists := sm.rm[id]; exists {
|
if r, exists := sm.rm[id]; exists {
|
||||||
|
@ -1234,7 +1234,7 @@ func (sm *depspecSourceManager) ListExternal(n ProjectRoot, v Version) ([]string
|
||||||
return nil, fmt.Errorf("No reach data for %s at version %s", n, v)
|
return nil, fmt.Errorf("No reach data for %s at version %s", n, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *depspecSourceManager) ListPackages(n ProjectRoot, v Version) (PackageTree, error) {
|
func (sm *depspecSourceManager) ListPackages(id ProjectIdentifier, v Version) (PackageTree, error) {
|
||||||
id := pident{n: n, v: v}
|
id := pident{n: n, v: v}
|
||||||
if r, exists := sm.rm[id]; exists {
|
if r, exists := sm.rm[id]; exists {
|
||||||
ptree := PackageTree{
|
ptree := PackageTree{
|
||||||
|
@ -1297,7 +1297,7 @@ func (sm *depspecSourceManager) VendorCodeExists(name ProjectRoot) (bool, error)
|
||||||
|
|
||||||
func (sm *depspecSourceManager) Release() {}
|
func (sm *depspecSourceManager) Release() {}
|
||||||
|
|
||||||
func (sm *depspecSourceManager) ExportProject(n ProjectRoot, v Version, to string) error {
|
func (sm *depspecSourceManager) ExportProject(id ProjectIdentifier, v Version, to string) error {
|
||||||
return fmt.Errorf("dummy sm doesn't support exporting")
|
return fmt.Errorf("dummy sm doesn't support exporting")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -649,7 +649,7 @@ func newbmSM(bmf bimodalFixture) *bmSourceManager {
|
||||||
return sm
|
return sm
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *bmSourceManager) ListPackages(n ProjectRoot, v Version) (PackageTree, error) {
|
func (sm *bmSourceManager) ListPackages(id ProjectIdentifier, v Version) (PackageTree, error) {
|
||||||
for k, ds := range sm.specs {
|
for k, ds := range sm.specs {
|
||||||
// Cheat for root, otherwise we blow up b/c version is empty
|
// Cheat for root, otherwise we blow up b/c version is empty
|
||||||
if n == ds.n && (k == 0 || ds.v.Matches(v)) {
|
if n == ds.n && (k == 0 || ds.v.Matches(v)) {
|
||||||
|
@ -674,7 +674,7 @@ func (sm *bmSourceManager) ListPackages(n ProjectRoot, v Version) (PackageTree,
|
||||||
return PackageTree{}, fmt.Errorf("Project %s at version %s could not be found", n, v)
|
return PackageTree{}, fmt.Errorf("Project %s at version %s could not be found", n, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *bmSourceManager) GetManifestAndLock(n ProjectRoot, v Version) (Manifest, Lock, error) {
|
func (sm *bmSourceManager) GetManifestAndLock(id ProjectIdentifier, v Version) (Manifest, Lock, error) {
|
||||||
for _, ds := range sm.specs {
|
for _, ds := range sm.specs {
|
||||||
if n == ds.n && v.Matches(ds.v) {
|
if n == ds.n && v.Matches(ds.v) {
|
||||||
if l, exists := sm.lm[string(n)+" "+v.String()]; exists {
|
if l, exists := sm.lm[string(n)+" "+v.String()]; exists {
|
||||||
|
|
|
@ -15,42 +15,42 @@ import (
|
||||||
// source repositories. Its primary purpose is to serve the needs of a Solver,
|
// source repositories. Its primary purpose is to serve the needs of a Solver,
|
||||||
// but it is handy for other purposes, as well.
|
// but it is handy for other purposes, as well.
|
||||||
//
|
//
|
||||||
// gps's built-in SourceManager, accessible via NewSourceManager(), is
|
// gps's built-in SourceManager, SourceMgr, is intended to be generic and
|
||||||
// intended to be generic and sufficient for any purpose. It provides some
|
// sufficient for any purpose. It provides some additional semantics around the
|
||||||
// additional semantics around the methods defined here.
|
// methods defined here.
|
||||||
type SourceManager interface {
|
type SourceManager interface {
|
||||||
// RepoExists checks if a repository exists, either upstream or in the
|
// RepoExists checks if a repository exists, either upstream or in the
|
||||||
// SourceManager's central repository cache.
|
// SourceManager's central repository cache.
|
||||||
RepoExists(ProjectRoot) (bool, error)
|
RepoExists(ProjectIdentifier) (bool, error)
|
||||||
|
|
||||||
// ListVersions retrieves a list of the available versions for a given
|
// ListVersions retrieves a list of the available versions for a given
|
||||||
// repository name.
|
// repository name.
|
||||||
ListVersions(ProjectRoot) ([]Version, error)
|
ListVersions(ProjectIdentifier) ([]Version, error)
|
||||||
|
|
||||||
// RevisionPresentIn indicates whether the provided Version is present in
|
// RevisionPresentIn indicates whether the provided Version is present in
|
||||||
// the given repository.
|
// the given repository.
|
||||||
RevisionPresentIn(ProjectRoot, Revision) (bool, error)
|
RevisionPresentIn(ProjectIdentifier, Revision) (bool, error)
|
||||||
|
|
||||||
// ListPackages retrieves a tree of the Go packages at or below the provided
|
// ListPackages parses the tree of the Go packages at or below root of the
|
||||||
// import path, at the provided version.
|
// provided ProjectIdentifier, at the provided version.
|
||||||
ListPackages(ProjectRoot, Version) (PackageTree, error)
|
ListPackages(ProjectIdentifier, Version) (PackageTree, error)
|
||||||
|
|
||||||
// GetManifestAndLock returns manifest and lock information for the provided
|
// GetManifestAndLock returns manifest and lock information for the provided
|
||||||
// root import path.
|
// root import path.
|
||||||
//
|
//
|
||||||
// gps currently requires that projects be rooted at their
|
// gps currently requires that projects be rooted at their repository root,
|
||||||
// repository root, necessitating that this ProjectRoot must also be a
|
// necessitating that the ProjectIdentifier's ProjectRoot must also be a
|
||||||
// repository root.
|
// repository root.
|
||||||
GetManifestAndLock(ProjectRoot, Version) (Manifest, Lock, error)
|
GetManifestAndLock(ProjectIdentifier, Version) (Manifest, Lock, error)
|
||||||
|
|
||||||
|
// ExportProject writes out the tree of the provided import path, at the
|
||||||
|
// provided version, to the provided directory.
|
||||||
|
ExportProject(ProjectIdentifier, Version, string) error
|
||||||
|
|
||||||
// AnalyzerInfo reports the name and version of the logic used to service
|
// AnalyzerInfo reports the name and version of the logic used to service
|
||||||
// GetManifestAndLock().
|
// GetManifestAndLock().
|
||||||
AnalyzerInfo() (name string, version *semver.Version)
|
AnalyzerInfo() (name string, version *semver.Version)
|
||||||
|
|
||||||
// ExportProject writes out the tree of the provided import path, at the
|
|
||||||
// provided version, to the provided directory.
|
|
||||||
ExportProject(ProjectRoot, Version, string) error
|
|
||||||
|
|
||||||
// Release lets go of any locks held by the SourceManager.
|
// Release lets go of any locks held by the SourceManager.
|
||||||
Release()
|
Release()
|
||||||
}
|
}
|
||||||
|
@ -72,10 +72,9 @@ type ProjectAnalyzer interface {
|
||||||
// tools; control via dependency injection is intended to be sufficient.
|
// tools; control via dependency injection is intended to be sufficient.
|
||||||
type SourceMgr struct {
|
type SourceMgr struct {
|
||||||
cachedir string
|
cachedir string
|
||||||
pms map[ProjectRoot]*pmState
|
pms map[ProjectIdentifier]*pmState
|
||||||
an ProjectAnalyzer
|
an ProjectAnalyzer
|
||||||
ctx build.Context
|
ctx build.Context
|
||||||
//pme map[ProjectRoot]error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SourceManager = &SourceMgr{}
|
var _ SourceManager = &SourceMgr{}
|
||||||
|
@ -148,13 +147,14 @@ func (sm *SourceMgr) AnalyzerInfo() (name string, version *semver.Version) {
|
||||||
return sm.an.Info()
|
return sm.an.Info()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetManifestAndLock returns manifest and lock information for the provided import
|
// GetManifestAndLock returns manifest and lock information for the provided
|
||||||
// path. gps currently requires that projects be rooted at their repository
|
// import path. gps currently requires that projects be rooted at their
|
||||||
// root, which means that this ProjectRoot must also be a repository root.
|
// repository root, necessitating that the ProjectIdentifier's ProjectRoot must
|
||||||
|
// also be a repository root.
|
||||||
//
|
//
|
||||||
// The work of producing the manifest and lock is delegated to the injected
|
// The work of producing the manifest and lock is delegated to the injected
|
||||||
// ProjectAnalyzer's DeriveManifestAndLock() method.
|
// ProjectAnalyzer's DeriveManifestAndLock() method.
|
||||||
func (sm *SourceMgr) GetManifestAndLock(n ProjectRoot, v Version) (Manifest, Lock, error) {
|
func (sm *SourceMgr) GetManifestAndLock(id ProjectIdentifier, v Version) (Manifest, Lock, error) {
|
||||||
pmc, err := sm.getProjectManager(n)
|
pmc, err := sm.getProjectManager(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
@ -163,9 +163,9 @@ func (sm *SourceMgr) GetManifestAndLock(n ProjectRoot, v Version) (Manifest, Loc
|
||||||
return pmc.pm.GetInfoAt(v)
|
return pmc.pm.GetInfoAt(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListPackages retrieves a tree of the Go packages at or below the provided
|
// ListPackages parses the tree of the Go packages at and below the ProjectRoot
|
||||||
// import path, at the provided version.
|
// of the given ProjectIdentifier, at the given version.
|
||||||
func (sm *SourceMgr) ListPackages(n ProjectRoot, v Version) (PackageTree, error) {
|
func (sm *SourceMgr) ListPackages(id ProjectIdentifier, v Version) (PackageTree, error) {
|
||||||
pmc, err := sm.getProjectManager(n)
|
pmc, err := sm.getProjectManager(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return PackageTree{}, err
|
return PackageTree{}, err
|
||||||
|
@ -182,10 +182,11 @@ func (sm *SourceMgr) ListPackages(n ProjectRoot, v Version) (PackageTree, error)
|
||||||
// expected that the caller either not care about order, or sort the result
|
// expected that the caller either not care about order, or sort the result
|
||||||
// themselves.
|
// themselves.
|
||||||
//
|
//
|
||||||
// This list is always retrieved from upstream; if upstream is not accessible
|
// This list is always retrieved from upstream on the first call. Subsequent
|
||||||
// (network outage, access issues, or the resource actually went away), an error
|
// calls will return a cached version of the first call's results. if upstream
|
||||||
// will be returned.
|
// is not accessible (network outage, access issues, or the resource actually
|
||||||
func (sm *SourceMgr) ListVersions(n ProjectRoot) ([]Version, error) {
|
// went away), an error will be returned.
|
||||||
|
func (sm *SourceMgr) ListVersions(id ProjectIdentifier) ([]Version, error) {
|
||||||
pmc, err := sm.getProjectManager(n)
|
pmc, err := sm.getProjectManager(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO(sdboyer) More-er proper-er errors
|
// TODO(sdboyer) More-er proper-er errors
|
||||||
|
@ -197,7 +198,7 @@ func (sm *SourceMgr) ListVersions(n ProjectRoot) ([]Version, error) {
|
||||||
|
|
||||||
// RevisionPresentIn indicates whether the provided Revision is present in the given
|
// RevisionPresentIn indicates whether the provided Revision is present in the given
|
||||||
// repository.
|
// repository.
|
||||||
func (sm *SourceMgr) RevisionPresentIn(n ProjectRoot, r Revision) (bool, error) {
|
func (sm *SourceMgr) RevisionPresentIn(id ProjectIdentifier, r Revision) (bool, error) {
|
||||||
pmc, err := sm.getProjectManager(n)
|
pmc, err := sm.getProjectManager(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO(sdboyer) More-er proper-er errors
|
// TODO(sdboyer) More-er proper-er errors
|
||||||
|
@ -208,8 +209,8 @@ func (sm *SourceMgr) RevisionPresentIn(n ProjectRoot, r Revision) (bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RepoExists checks if a repository exists, either upstream or in the cache,
|
// RepoExists checks if a repository exists, either upstream or in the cache,
|
||||||
// for the provided ProjectRoot.
|
// for the provided ProjectIdentifier.
|
||||||
func (sm *SourceMgr) RepoExists(n ProjectRoot) (bool, error) {
|
func (sm *SourceMgr) RepoExists(id ProjectIdentifier) (bool, error) {
|
||||||
pms, err := sm.getProjectManager(n)
|
pms, err := sm.getProjectManager(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -218,9 +219,9 @@ func (sm *SourceMgr) RepoExists(n ProjectRoot) (bool, error) {
|
||||||
return pms.pm.CheckExistence(existsInCache) || pms.pm.CheckExistence(existsUpstream), nil
|
return pms.pm.CheckExistence(existsInCache) || pms.pm.CheckExistence(existsUpstream), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExportProject writes out the tree of the provided import path, at the
|
// ExportProject writes out the tree of the provided ProjectIdentifier's
|
||||||
// provided version, to the provided directory.
|
// ProjectRoot, at the provided version, to the provided directory.
|
||||||
func (sm *SourceMgr) ExportProject(n ProjectRoot, v Version, to string) error {
|
func (sm *SourceMgr) ExportProject(id ProjectIdentifier, v Version, to string) error {
|
||||||
pms, err := sm.getProjectManager(n)
|
pms, err := sm.getProjectManager(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -229,10 +230,10 @@ func (sm *SourceMgr) ExportProject(n ProjectRoot, v Version, to string) error {
|
||||||
return pms.pm.ExportVersionTo(v, to)
|
return pms.pm.ExportVersionTo(v, to)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getProjectManager gets the project manager for the given ProjectRoot.
|
// getProjectManager gets the project manager for the given ProjectIdentifier.
|
||||||
//
|
//
|
||||||
// If no such manager yet exists, it attempts to create one.
|
// If no such manager yet exists, it attempts to create one.
|
||||||
func (sm *SourceMgr) getProjectManager(n ProjectRoot) (*pmState, error) {
|
func (sm *SourceMgr) getProjectManager(id ProjectIdentifier) (*pmState, error) {
|
||||||
// Check pm cache and errcache first
|
// Check pm cache and errcache first
|
||||||
if pm, exists := sm.pms[n]; exists {
|
if pm, exists := sm.pms[n]; exists {
|
||||||
return pm, nil
|
return pm, nil
|
||||||
|
|
Загрузка…
Ссылка в новой задаче