Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,6 @@ proc dump(options: var Options, nimBin: var Option[string]) =
fn "srcDir", p.srcDir
fn "backend", p.backend
fn "paths", p.paths
fn "nimDir", getNimDir(options, nimBin)
fn "entryPoints", p.getEntryPoints(options)
fn "testEntryPoint", p.testEntryPoint
if json:
Expand Down Expand Up @@ -2290,6 +2289,9 @@ proc doAction(options: var Options, nimBinParam: Option[string]) {.instrument.}
of actionDump:
needNim()
dump(options, nimBin)
of actionGetNimDir:
needNim()
echo getNimDir(options, nimBin)
of actionTasks:
needNim()
listTasks(options, nimBin)
Expand Down Expand Up @@ -2370,7 +2372,7 @@ when isMainModule:
opt.action.withDependencies = true

# Actions that don't go through the main resolving pipeline (no SAT solve / install).
const nonResolvingActions = {actionNil, actionRefresh, actionInit, actionDump,
const nonResolvingActions = {actionNil, actionRefresh, actionInit, actionDump, actionGetNimDir,
actionPublish, actionSearch, actionList, actionPath, actionUninstall,
actionCheck, actionTasks, actionClean, actionManual}
var shouldRun = opt.action.typ notin nonResolvingActions
Expand Down
14 changes: 11 additions & 3 deletions src/nimblepkg/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type
lenient*: bool # When true, conflicting special versions produce warnings. When false, they error. For now it cant be disabled.

ActionType* = enum
actionNil, actionRefresh, actionInit, actionDump, actionPublish, actionUpgrade
actionNil, actionRefresh, actionInit, actionDump, actionGetNimDir, actionPublish, actionUpgrade
actionInstall, actionSearch, actionList, actionBuild, actionPath,
actionUninstall, actionCompile, actionDoc, actionCustom, actionTasks,
actionDevelop, actionCheck, actionLock, actionRun, actionSync, actionSetup,
Expand Down Expand Up @@ -119,7 +119,7 @@ type
onlyNimBinaries*: bool
onlyInstalled*: bool
showListVersions*: bool
of actionInit, actionDump:
of actionInit, actionDump, actionGetNimDir:
projName*: string
vcsOption*: string
collect*: bool
Expand Down Expand Up @@ -235,6 +235,12 @@ Commands:
[--ini, --json] Selects the output format (the default is --ini). Only applicable to package information.
[--collect] Collects all the packages in the dependency tree of the given package and shows the result in the console.
[--solve] Solves the dependency tree of the given package and shows the result in the console.
getnimdir [pkgname] Outputs the Nim compiler directory for a
package. The argument can be a .nimble file,
a project directory or the name of an
installed package. This may trigger a SAT
solver run to determine the correct Nim
version.
lock Generates or updates a package lock file.
upgrade [pkgname, ...] Upgrades a list of packages in the lock file.
deps Outputs dependencies for current package.
Expand Down Expand Up @@ -378,6 +384,8 @@ proc parseActionType*(action: string): ActionType =
result = actionInit
of "dump":
result = actionDump
of "getnimdir":
result = actionGetNimDir
of "update", "refresh":
result = actionRefresh
of "search":
Expand Down Expand Up @@ -681,7 +689,7 @@ proc parseArgument*(key: string, result: var Options) =
result.action.optionalURL = key
of actionSearch:
result.action.search.add(key)
of actionInit, actionDump:
of actionInit, actionDump, actionGetNimDir:
if result.action.projName != "":
raise nimbleError(
"Can only perform this action on one package at a time.")
Expand Down
12 changes: 8 additions & 4 deletions tests/tnimbledump.nim
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ suite "nimble dump":
check: outp.processOutput.inLines("desc: \"Test package for dump command\"")

test "can dump when explicitly asking for INI format":
let nimDir = parentDir findExe "nim"
let nimblePath = "testdump" / "testdump.nimble"

let outpExpected = &"""
Expand All @@ -66,7 +65,6 @@ binDir: ""
srcDir: ""
backend: "c"
paths: "path"
nimDir: {nimDir.escape}
entryPoints: "testdump.nim, entrypoint.nim"
testEntryPoint: "tests/tall.nim"
"""
Expand All @@ -75,7 +73,6 @@ testEntryPoint: "tests/tall.nim"
check: outp == outpExpected

test "can dump in JSON format":
let nimDir = parentDir findExe "nim"
let nimblePath = "testdump" / "testdump.nimble"

let outpExpected = &"""
Expand All @@ -100,7 +97,6 @@ testEntryPoint: "tests/tall.nim"
"paths": [
"path"
],
"nimDir": {nimDir.escape},
"entryPoints": [
"testdump.nim",
"entrypoint.nim"
Expand All @@ -111,3 +107,11 @@ testEntryPoint: "tests/tall.nim"
let (outp, exitCode) = execNimble("dump", "--json", "testdump")
check: exitCode == 0
check: outp == outpExpected

test "can get nimdir for current project":
cd "testdump":
let (outp, exitCode) = execNimble("getnimdir")
check: exitCode == 0
check: outp.strip.len > 0
check: dirExists(outp.strip)
check: fileExists(outp.strip / "nim".addFileExt(ExeExt))
Loading