Skip to content

Commit

Permalink
FIXUP: testing
Browse files Browse the repository at this point in the history
  • Loading branch information
utzig committed Aug 21, 2023
1 parent affb566 commit 0209655
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
4 changes: 2 additions & 2 deletions newt/cli/project_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ func makeRepoPredicate(repoNames []string) func(r *repo.Repo) bool {
}

func upgradeRunCmd(cmd *cobra.Command, args []string) {
proj := TryGetOrDownloadProject(args)
proj := TryGetOrDownloadProject(newtutil.NewtNoDeps, args)
interfaces.SetProject(proj)

proj.GetPkgRepos(args)
proj.GetPkgRepos(newtutil.NewtNoDeps, args)

pred := makeRepoPredicate(args)
if err := proj.UpgradeIf(
Expand Down
4 changes: 2 additions & 2 deletions newt/cli/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ func TryGetProject() *project.Project {
return p
}

func TryGetOrDownloadProject(okRepos []string) *project.Project {
func TryGetOrDownloadProject(noDeps bool, okRepos []string) *project.Project {
var p *project.Project
var err error

if p, err = project.TryGetOrDownloadProject(okRepos); err != nil {
if p, err = project.TryGetOrDownloadProject(noDeps, okRepos); err != nil {
NewtUsage(nil, err)
}

Expand Down
2 changes: 1 addition & 1 deletion newt/deprepo/deprepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func BuildDepGraph(repos RepoMap, rootReqs RequirementMap, noDeps bool) (DepGrap
// Add inter-repo dependencies to the graph.
for _, r := range repos.Sorted() {
nvers, err := r.NormalizedVersions()
if err != nil && noDeps && isInReqs(r.Name(), rootReqs) {
if err != nil && !noDeps && isInReqs(r.Name(), rootReqs) {
return nil, err
}
for _, v := range nvers {
Expand Down
47 changes: 24 additions & 23 deletions newt/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ type Project struct {
yc ycfg.YCfg
}

func initProject(dir string, download bool, okRepos []string) error {
func initProject(dir string, download bool, noDeps bool, okRepos []string) error {
var err error

globalProject, err = loadProject(dir, download, okRepos)
globalProject, err = loadProject(dir, download, noDeps, okRepos)
if err != nil {
return err
}
Expand All @@ -99,29 +99,29 @@ func initProject(dir string, download bool, okRepos []string) error {
return nil
}

func initialize(download bool, okRepos []string) error {
func initialize(download bool, noDeps bool, okRepos []string) error {
if globalProject == nil {
wd, err := os.Getwd()
wd = filepath.ToSlash(wd)
if err != nil {
return util.NewNewtError(err.Error())
}
if err := initProject(wd, download, okRepos); err != nil {
if err := initProject(wd, download, noDeps, okRepos); err != nil {
return err
}
}
return nil
}

func TryGetProject() (*Project, error) {
if err := initialize(false, nil); err != nil {
if err := initialize(false, false, nil); err != nil {
return nil, err
}
return globalProject, nil
}

func TryGetOrDownloadProject(okRepos []string) (*Project, error) {
if err := initialize(true, okRepos); err != nil {
func TryGetOrDownloadProject(noDeps bool, okRepos []string) (*Project, error) {
if err := initialize(true, noDeps, okRepos); err != nil {
return nil, err
}
return globalProject, nil
Expand Down Expand Up @@ -153,10 +153,10 @@ func ResetDeps(newList interfaces.PackageList) interfaces.PackageList {
return oldList
}

func newProject(dir string, download bool, okRepos []string) (*Project, error) {
func newProject(dir string, download bool, noDeps bool, okRepos []string) (*Project, error) {
proj := &Project{}

if err := proj.Init(dir, download, okRepos); err != nil {
if err := proj.Init(dir, download, noDeps, okRepos); err != nil {
return nil, err
}

Expand All @@ -175,14 +175,14 @@ func isOkRepo(repo string, okRepos []string) bool {
return false
}

func (proj *Project) GetPkgRepos(okRepos []string) error {
func (proj *Project) GetPkgRepos(noDeps bool, okRepos []string) error {

for _, pkgList := range proj.packages {
for _, pkg := range *pkgList {
if pkg.PkgConfig().HasKey("repository") {
for k, _ := range pkg.PkgConfig().AllSettings() {
repoName := strings.TrimPrefix(k, "repository.")
if repoName != k && isOkRepo(repoName, okRepos) {
if repoName != k && (!noDeps || isOkRepo(repoName, okRepos)) {
fields, err := pkg.PkgConfig().GetValStringMapString(k, nil)
util.OneTimeWarningError(err)

Expand Down Expand Up @@ -318,7 +318,7 @@ func (proj *Project) UpgradeIf(
predicate func(r *repo.Repo) bool) error {

// Make sure we have an up to date copy of all `repository.yml` files.
if err := proj.downloadRepositoryYmlFiles(okRepos); err != nil {
if err := proj.downloadRepositoryYmlFiles(noDeps, okRepos); err != nil {
return err
}

Expand All @@ -341,7 +341,7 @@ func (proj *Project) InfoIf(predicate func(r *repo.Repo) bool,

if remote {
// Make sure we have an up to date copy of all `repository.yml` files.
if err := proj.downloadRepositoryYmlFiles(nil); err != nil {
if err := proj.downloadRepositoryYmlFiles(false, nil); err != nil {
return err
}
}
Expand Down Expand Up @@ -438,7 +438,7 @@ func (proj *Project) checkNewtVer() error {
}

// Loads the `repository.yml` file for each depended-on repo. This
func (proj *Project) loadRepoDeps(download bool, okRepos []string) error {
func (proj *Project) loadRepoDeps(download bool, noDeps bool, okRepos []string) error {
seen := map[string]struct{}{}

loadDeps := func(r *repo.Repo) ([]*repo.Repo, error) {
Expand All @@ -447,7 +447,7 @@ func (proj *Project) loadRepoDeps(download bool, okRepos []string) error {
depMap := r.CommitDepMap()
for _, depSlice := range depMap {
for _, dep := range depSlice {
if !isOkRepo(dep.Name, okRepos) {
if !isOkRepo(dep.Name, okRepos) && noDeps {
log.Debugf("Skipping repo %s", dep.Name)
continue
}
Expand Down Expand Up @@ -503,7 +503,8 @@ func (proj *Project) loadRepoDeps(download bool, okRepos []string) error {
return nil
}

func (proj *Project) downloadRepositoryYmlFiles(okRepos []string) error {
func (proj *Project) downloadRepositoryYmlFiles(noDeps bool,
okRepos []string) error {
// Download the `repository.yml` file for each root-level repo (those
// specified in the `project.yml` file).
for _, r := range proj.repos.Sorted() {
Expand All @@ -518,7 +519,7 @@ func (proj *Project) downloadRepositoryYmlFiles(okRepos []string) error {
}

// Download the `repository.yml` file for each depended-on repo.
if err := proj.loadRepoDeps(true, okRepos); err != nil {
if err := proj.loadRepoDeps(true, noDeps, okRepos); err != nil {
return err
}

Expand Down Expand Up @@ -584,7 +585,7 @@ func (proj *Project) addRepo(r *repo.Repo, download bool, isDep bool) error {
return nil
}

func (proj *Project) loadConfig(download bool, okRepos []string) error {
func (proj *Project) loadConfig(download bool, noDeps bool, okRepos []string) error {
yc, err := config.ReadFile(proj.BasePath + "/" + PROJECT_FILE_NAME)
if err != nil {
return util.NewNewtError(err.Error())
Expand Down Expand Up @@ -643,7 +644,7 @@ func (proj *Project) loadConfig(download bool, okRepos []string) error {
// Read `repository.yml` files belonging to dependee repos from disk.
// These repos might not be specified in the `project.yml` file, but they
// are still part of the project.
if err := proj.loadRepoDeps(download, okRepos); err != nil {
if err := proj.loadRepoDeps(download, noDeps, okRepos); err != nil {
return err
}

Expand Down Expand Up @@ -680,7 +681,7 @@ func (proj *Project) loadConfig(download bool, okRepos []string) error {
return nil
}

func (proj *Project) Init(dir string, download bool, okRepos []string) error {
func (proj *Project) Init(dir string, download bool, noDeps bool, okRepos []string) error {
proj.BasePath = filepath.ToSlash(filepath.Clean(dir))

// Only one project per system, when created, set it as the global project
Expand All @@ -690,7 +691,7 @@ func (proj *Project) Init(dir string, download bool, okRepos []string) error {
proj.rootRepoReqs = map[string]newtutil.RepoVersion{}

// Load Project configuration
if err := proj.loadConfig(download, okRepos); err != nil {
if err := proj.loadConfig(download, noDeps, okRepos); err != nil {
return err
}

Expand Down Expand Up @@ -831,13 +832,13 @@ func (proj *Project) PackagesOfType(pkgType interfaces.PackageType) []interfaces
return matches
}

func loadProject(dir string, download bool, okRepos []string) (*Project, error) {
func loadProject(dir string, download bool, noDeps bool, okRepos []string) (*Project, error) {
projDir, err := findProjectDir(dir)
if err != nil {
return nil, err
}

proj, err := newProject(projDir, download, okRepos)
proj, err := newProject(projDir, download, noDeps, okRepos)

return proj, err
}

0 comments on commit 0209655

Please sign in to comment.