Skip to content

Commit 2bbcc16

Browse files
committed
Add develop --global option
An option for creating the old-style Nimble link files is added. Those files are created by `nimble develop` when called with the `--global` option. They are placed in a special `links` directory and they are read by Nim in order to have some kind of develop mode functionality when compiling stand-alone files which are not part of a Nimble package. Nimble itself ignores this new directory and files in it. When building with Nimble the new local develop mode should be used instead. Related to #948
1 parent 26c9102 commit 2bbcc16

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

readme.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ packages for which the develop command is executed.
292292
* `--develop-file` - Changes the name of the develop file which to be
293293
manipulated. It is useful for creating a free develop file which is not
294294
associated with any project intended for inclusion in some other develop file.
295+
* `-g, --global` - Creates an old style link file in the special `links`
296+
directory. It is read by Nim to be able to use global develop mode packages but
297+
it is ignored by Nimble.
295298

296299
The options for manipulation of the develop files could be given only when
297300
executing `develop` command from some package's directory unless

src/nimble.nim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,21 @@ proc listTasks(options: Options) =
11381138

11391139
proc developAllDependencies(pkgInfo: PackageInfo, options: var Options)
11401140

1141+
proc saveLinkFile(pkgInfo: PackageInfo, options: Options) =
1142+
let
1143+
pkgName = pkgInfo.basicInfo.name
1144+
pkgLinkDir = options.getPkgsLinksDir / pkgName & "-#head"
1145+
pkgLinkFilePath = pkgLinkDir / pkgName & ".nimble-link"
1146+
pkgLinkFileContent = pkgInfo.myPath & "\n" & pkgInfo.getNimbleFileDir
1147+
1148+
if pkgLinkDir.dirExists and not options.prompt(
1149+
&"The link file for {pkgName} already exists. Overwrite?"):
1150+
return
1151+
1152+
pkgLinkDir.createDir
1153+
writeFile(pkgLinkFilePath, pkgLinkFileContent)
1154+
displaySuccess(&"Package link file saved to \"{pkgLinkFilePath}\".")
1155+
11411156
proc developFromDir(pkgInfo: PackageInfo, options: var Options) =
11421157
assert options.action.typ == actionDevelop,
11431158
"This procedure should be called only when executing develop sub-command."
@@ -1173,6 +1188,9 @@ proc developFromDir(pkgInfo: PackageInfo, options: var Options) =
11731188
# Dependencies need to be processed before the creation of the pkg dir.
11741189
discard processAllDependencies(pkgInfo, options)
11751190

1191+
if options.action.global:
1192+
saveLinkFile(pkgInfo, options)
1193+
11761194
displaySuccess(pkgSetupInDevModeMsg(pkgInfo.basicInfo.name, dir))
11771195

11781196
# Execute the post-develop hook.

src/nimblepkg/common.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type
2424
const
2525
nimbleVersion* = "0.14.0"
2626
nimblePackagesDirName* = "pkgs2"
27+
nimblePackagesLinksDirName* ="links"
2728
nimbleBinariesDirName* = "bin"
2829

2930
proc newNimbleError*[ErrorType](msg: string, hint = "",

src/nimblepkg/options.nim

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ type
7474
## Whether to put in develop mode also the dependencies of the packages
7575
## listed in the develop command.
7676
developFile*: string
77+
global*: bool
7778
of actionSearch:
7879
search*: seq[string] # Search string.
7980
of actionInit, actionDump:
@@ -108,7 +109,7 @@ Commands:
108109
executed in package's directory.
109110
[--with-dependencies] Puts in develop mode also the dependencies
110111
of the packages in the list or of the current
111-
directory package if the list is
112+
directory package if the list is empty.
112113
[--develop-file] Specifies the name of the develop file which
113114
to be manipulated. If not present creates it.
114115
[-p, --path path] Specifies the path whether the packages should
@@ -130,6 +131,10 @@ Commands:
130131
[-e, --exclude file] Excludes a develop file from a specified
131132
develop file or from `nimble.develop` if not
132133
specified and executed in package's directory.
134+
[-g, --global] Creates an old style link file in the special
135+
`links` directory. It is read by Nim to be
136+
able to use global develop mode packages but
137+
it is ignored by Nimble.
133138
check Verifies the validity of a package in the
134139
current working directory.
135140
init [pkgname] Initializes a new Nimble project in the
@@ -311,6 +316,9 @@ proc getNimbleDir*(options: Options): string =
311316
proc getPkgsDir*(options: Options): string =
312317
options.getNimbleDir() / nimblePackagesDirName
313318

319+
proc getPkgsLinksDir*(options: Options): string =
320+
options.getNimbleDir() / nimblePackagesLinksDirName
321+
314322
proc getBinDir*(options: Options): string =
315323
options.getNimbleDir() / nimbleBinariesDirName
316324

@@ -559,6 +567,8 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) =
559567
raise nimbleError(multiplePathOptionsGivenMsg)
560568
of "with-dependencies":
561569
result.action.withDependencies = true
570+
of "global":
571+
result.action.global = true
562572
of "develop-file":
563573
if result.action.developFile.len == 0:
564574
result.action.developFile = val.normalizedPath

0 commit comments

Comments
 (0)