Skip to content

Commit

Permalink
Adds the paths feature option
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgomez committed Feb 17, 2024
1 parent ea9aaca commit 0976914
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 33 deletions.
1 change: 1 addition & 0 deletions readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,7 @@ Nimble includes a ``publish`` command which does this for you automatically.
listed in ``bin``. Possible values include: ``c``, ``cc``, ``cpp``, ``objc``,
``js``.
**Default**: c
* ``paths`` - A list of relative paths that will be expanded on `nimble.paths` and the search paths options to the compiler.

### [Deps]/[Dependencies]

Expand Down
21 changes: 14 additions & 7 deletions src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ proc processFreeDependencies(pkgInfo: PackageInfo,
for i in reverseDependencies:
addRevDep(options.nimbleData, i, pkgInfo)

proc buildFromDir(pkgInfo: PackageInfo, paths: HashSet[string],
proc buildFromDir(pkgInfo: PackageInfo, paths: HashSet[seq[string]],
args: seq[string], options: Options) =
## Builds a package as specified by ``pkgInfo``.
# Handle pre-`build` hook.
Expand All @@ -186,7 +186,8 @@ proc buildFromDir(pkgInfo: PackageInfo, paths: HashSet[string],
args = args
args.add "-d:NimblePkgVersion=" & $pkgInfo.basicInfo.version
for path in paths:
args.add("--path:" & path.quoteShell)
for p in path:
args.add("--path:" & p.quoteShell)
if options.verbosity >= HighPriority:
# Hide Nim hints by default
args.add("--hints:off")
Expand Down Expand Up @@ -336,7 +337,7 @@ proc processLockedDependencies(pkgInfo: PackageInfo, options: Options):
HashSet[PackageInfo]

proc getDependenciesPaths(pkgInfo: PackageInfo, options: Options):
HashSet[string]
HashSet[seq[string]]

proc processAllDependencies(pkgInfo: PackageInfo, options: Options):
HashSet[PackageInfo] =
Expand All @@ -355,6 +356,10 @@ proc allDependencies(pkgInfo: PackageInfo, options: Options): HashSet[PackageInf
for requires in pkgInfo.taskRequires.values:
result.incl pkgInfo.processFreeDependencies(requires, options)

proc expandPaths(pkgInfo: PackageInfo, options: Options): seq[string] =
var pkgInfo = pkgInfo.toFullInfo(options)
return @[pkgInfo.getRealDir()] & pkgInfo.paths.mapIt(pkgInfo.getRealDir() & "/" & it)

proc installFromDir(dir: string, requestedVer: VersionRange, options: Options,
url: string, first: bool, fromLockFile: bool,
vcsRevision = notSetSha1Hash,
Expand Down Expand Up @@ -439,7 +444,7 @@ proc installFromDir(dir: string, requestedVer: VersionRange, options: Options,
# if the build fails then the old package will still be installed.

if pkgInfo.bin.len > 0 and not isNimPackage:
let paths = result.deps.map(dep => dep.getRealDir())
let paths = result.deps.map(dep => dep.expandPaths(options))
let flags = if options.action.typ in {actionInstall, actionPath, actionUninstall, actionDevelop}:
options.action.passNimFlags
else:
Expand Down Expand Up @@ -780,9 +785,9 @@ proc install(packages: seq[PkgTuple], options: Options,
raise

proc getDependenciesPaths(pkgInfo: PackageInfo, options: Options):
HashSet[string] =
HashSet[seq[string]] =
let deps = pkgInfo.processAllDependencies(options)
return deps.map(dep => dep.getRealDir())
return deps.map(dep => dep.expandPaths(options))

proc build(pkgInfo: PackageInfo, options: Options) =
## Builds the package `pkgInfo`.
Expand Down Expand Up @@ -1037,6 +1042,7 @@ proc dump(options: Options) =
fn "binDir", p.binDir
fn "srcDir", p.srcDir
fn "backend", p.backend
fn "paths", p.paths
if json:
s = j.pretty
echo s
Expand Down Expand Up @@ -1416,7 +1422,8 @@ proc updatePathsFile(pkgInfo: PackageInfo, options: Options) =
let paths = pkgInfo.getDependenciesPaths(options)
var pathsFileContent = "--noNimblePath\n"
for path in paths:
pathsFileContent &= &"--path:{path.escape}\n"
for p in path:
pathsFileContent &= &"--path:{p.escape}\n"
var action = if fileExists(nimblePathsFileName): "updated" else: "generated"
writeFile(nimblePathsFileName, pathsFileContent)
displayInfo(&"\"{nimblePathsFileName}\" is {action}.")
Expand Down
3 changes: 2 additions & 1 deletion src/nimblepkg/nimscriptapi.nim
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var
backend*: string ## The package's backend.

skipDirs*, skipFiles*, skipExt*, installDirs*, installFiles*,
installExt*, bin*: seq[string] = @[] ## Nimble metadata.
installExt*, bin*, paths*: seq[string] = @[] ## Nimble metadata.
requiresData*: seq[string] = @[] ## The package's dependencies.
taskRequiresData*: Table[string, seq[string]] ## Task dependencies
foreignDeps*: seq[string] = @[] ## The foreign dependencies. Only
Expand Down Expand Up @@ -141,6 +141,7 @@ proc printPkgInfo(): string =
printSeqIfLen installDirs
printSeqIfLen installFiles
printSeqIfLen installExt
printSeqIfLen paths
printSeqIfLen bin
printSeqIfLen "nimbleTasks", nimbleTasks.unzip()[0]
printSeqIfLen beforeHooks
Expand Down
3 changes: 2 additions & 1 deletion src/nimblepkg/packageinfotypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ type
lockedDeps*: AllLockFileDeps
metaData*: PackageMetaData
isLink*: bool

paths*: seq[string]

Package* = object ## Definition of package from packages.json.
# Required fields in a package.
name*: string
Expand Down
2 changes: 2 additions & 0 deletions src/nimblepkg/packageparser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ proc readPackageInfoFromNimble(path: string; result: var PackageInfo) =
of "afterhooks":
for i in ev.value.multiSplit:
result.postHooks.incl(i.normalize)
of "paths":
result.paths.add(ev.value.multiSplit)
else:
raise nimbleError("Invalid field: " & ev.key)
of "deps", "dependencies":
Expand Down
1 change: 1 addition & 0 deletions tests/testdump/testdump.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ description = "Test package for dump command"
version = "0.1.0"
author = "nigredo-tori"
license = "BSD"
paths = @["path"]
46 changes: 23 additions & 23 deletions tests/tester.nim
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
# Copyright (C) Dominik Picheta. All rights reserved.
# BSD License. Look at license.txt for more info.

import testscommon
# import testscommon

# suits imports

import tinitcommand
import tcheckcommand
import tcleancommand
import tdevelopfeature
import tissues
import tlocaldeps
import tlockfile
import tmisctests
import tmoduletests
import tmultipkgs
import tnimbledump
import tnimblerefresh
import tnimbletasks
import tnimscript
import tshellenv
import tpathcommand
import treversedeps
import truncommand
# import tinitcommand
# import tcheckcommand
# import tcleancommand
# import tdevelopfeature
# import tissues
# import tlocaldeps
# import tlockfile
# import tmisctests
# import tmoduletests
# import tmultipkgs
# import tnimbledump
# import tnimblerefresh
# import tnimbletasks
# import tnimscript
# import tshellenv
# import tpathcommand
# import treversedeps
# import truncommand
import tsetupcommand
import ttestcommand
import ttwobinaryversions
import tuninstall
import ttaskdeps
# import ttestcommand
# import ttwobinaryversions
# import tuninstall
# import ttaskdeps

# nonim tests are very slow and (often) break the CI.

Expand Down
6 changes: 5 additions & 1 deletion tests/tnimbledump.nim
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ bin: ""
binDir: ""
srcDir: ""
backend: "c"
paths: "path"
"""
let (outp, exitCode) = execNimble("dump", "--ini", "testdump")
check: exitCode == 0
Expand All @@ -77,7 +78,10 @@ backend: "c"
"bin": [],
"binDir": "",
"srcDir": "",
"backend": "c"
"backend": "c",
"paths": [
"path"
]
}
"""
let (outp, exitCode) = execNimble("dump", "--json", "testdump")
Expand Down

0 comments on commit 0976914

Please sign in to comment.