Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated fix for #280 with dependencies #464

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ proc installFromDir(dir: string, requestedVer: VersionRange, options: Options,
result.pkg = pkgInfo
return result

# Run pre-install hook in download directory now that package is downloaded
# and all dependencies have been installed
cd dir:
if not execHook(options, true):
raise newException(NimbleError, "Pre-hook prevented further execution.")

display("Installing", "$1@$2" % [pkginfo.name, pkginfo.specialVersion],
priority = HighPriority)

Expand Down Expand Up @@ -433,6 +439,10 @@ proc installFromDir(dir: string, requestedVer: VersionRange, options: Options,
display("Success:", pkgInfo.name & " installed successfully.",
Success, HighPriority)

# Run post-install hook in installed directory now that package is installed
cd result.pkg.myPath.parentDir():
discard execHook(options, false)

proc getDownloadInfo*(pv: PkgTuple, options: Options,
doPrompt: bool): (DownloadMethod, string,
Table[string, string]) =
Expand Down Expand Up @@ -472,17 +482,7 @@ proc install(packages: seq[PkgTuple],
let (downloadDir, downloadVersion) =
downloadPkg(url, pv.ver, meth, subdir, options)
try:
# Run pre-install hook in download directory now that package is downloaded
cd downloadDir:
if not execHook(options, true):
raise newException(NimbleError, "Pre-hook prevented further execution.")

result = installFromDir(downloadDir, pv.ver, options, url)

# Run post-install hook in installed directory now that package is installed
# Standard hooks run in current directory so it won't detect this new package
cd result.pkg.myPath.parentDir():
discard execHook(options, false)
except BuildFailed:
# The package failed to build.
# Check if we tried building a tagged version of the package.
Expand Down Expand Up @@ -1064,10 +1064,13 @@ proc doAction(options: Options) =
if not existsDir(options.getPkgsDir):
createDir(options.getPkgsDir)

if not execHook(options, true):
display("Warning", "Pre-hook prevented further execution.", Warning,
HighPriority)
return
if options.action.typ != actionInstall:
# Run all pre hooks except for install since that is handled after package
# is downloaded and dependencies installed
if not execHook(options, true):
display("Warning", "Pre-hook prevented further execution.", Warning,
HighPriority)
return
case options.action.typ
of actionRefresh:
refresh(options)
Expand Down Expand Up @@ -1125,7 +1128,8 @@ proc doAction(options: Options) =
# Run the post hook for `test` in case it exists.
discard execHook(options, false)

if options.action.typ != actionCustom:
if not (options.action.typ in [actionCustom, actionInstall]):
# Skip post hooks for custom and install since those are handled elsewhere
discard execHook(options, false)

when isMainModule:
Expand Down