From 5702b3581303f89648d49fb489a30c060b26b3e7 Mon Sep 17 00:00:00 2001 From: Andy Davidoff Date: Wed, 27 Nov 2019 16:40:36 -0500 Subject: [PATCH] 0.0.10: doctor adds missing search paths --- nimph.nimble | 2 +- src/nimph/doctor.nim | 10 ++++++++++ src/nimph/project.nim | 38 ++++++++++++++++++++++---------------- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/nimph.nimble b/nimph.nimble index d52f323..28eba2c 100644 --- a/nimph.nimble +++ b/nimph.nimble @@ -1,4 +1,4 @@ -version = "0.0.9" +version = "0.0.10" author = "disruptek" description = "nim package handler from the future" license = "MIT" diff --git a/src/nimph/doctor.nim b/src/nimph/doctor.nim index a70c4ec..82265bf 100644 --- a/src/nimph/doctor.nim +++ b/src/nimph/doctor.nim @@ -168,6 +168,16 @@ proc doctor*(project: var Project; dry = true): bool = notice &"unable to resolve all dependencies for {project}" for requirement, dependency in group.pairs: if dependency.isHappy: + for proj in dependency.projects.values: + for path in project.missingSearchPaths(proj): + if dry: + notice &"missing path `{path}` in `{project.nimcfg}`" + elif project.addSearchPath(path): + info &"added path `{path}` to `{project.nimcfg}`" + # yay, we get to reload again + project.cfg = loadAllCfgs(project.repo) + else: + warn &"couldn't add path `{path}` to `{project.nimcfg}`" continue let name = dependency.names.join("|") if dry: diff --git a/src/nimph/project.nim b/src/nimph/project.nim index 9ade625..cc9a51c 100644 --- a/src/nimph/project.nim +++ b/src/nimph/project.nim @@ -582,7 +582,7 @@ proc addSearchPath*(project: Project; path: string): bool = if exists == path: return if project.cfg == nil: - raise newException(Defect, "nonsensical") + raise newException(Defect, "load a configuration first") result = project.cfg.addSearchPath(project.nimCfg, path) proc determineSearchPath(project: Project): string = @@ -597,23 +597,25 @@ proc determineSearchPath(project: Project): string = break result = project.repo -proc assertSearchPath*(project: Project; target: Project) = - if project.parent != nil: - project.parent.assertSearchPath(target) - else: - let - path = target.determineSearchPath - block found: - for search in project.cfg.packagePaths(exists = false): - if search / "" == path / "": - break found - discard project.addSearchPath(path) - -proc assertSearchPath*(project: Project; target: var Project) = +iterator missingSearchPaths*(project: Project; target: Project): string = + let + path = target.determineSearchPath + block found: + for search in project.cfg.packagePaths(exists = false): + if search / "" == path / "": + break found + yield path + +iterator missingSearchPaths*(project: Project; target: var Project): string = target.fetchDump let readonly = target - project.assertSearchPath(readonly) + var + parent = project + while project.parent != nil: + parent = project.parent + for path in parent.missingSearchPaths(readonly): + yield path proc clone*(project: var Project; url: Uri; name: string): bool = ## clone a package into the project's nimbleDir @@ -662,7 +664,11 @@ proc clone*(project: var Project; url: Uri; name: string): bool = proj.relocateDependency(oid) # reload the project's config to see if we capture a new search path project.cfg = loadAllCfgs(project.repo) - project.assertSearchPath(proj) + for path in project.missingSearchPaths(proj): + if project.addSearchPath(path): + info &"added path `{path}` to `{project.nimcfg}`" + else: + warn &"couldn't add path `{path}` to `{project.nimcfg}`" else: error "couldn't make sense of the project i just cloned"