Skip to content

Commit

Permalink
0.0.10: doctor adds missing search paths
Browse files Browse the repository at this point in the history
  • Loading branch information
disruptek committed Nov 27, 2019
1 parent 9247ac5 commit 5702b35
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion nimph.nimble
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "0.0.9"
version = "0.0.10"
author = "disruptek"
description = "nim package handler from the future"
license = "MIT"
Expand Down
10 changes: 10 additions & 0 deletions src/nimph/doctor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
38 changes: 22 additions & 16 deletions src/nimph/project.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
Expand Down Expand Up @@ -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"

Expand Down

0 comments on commit 5702b35

Please sign in to comment.