Skip to content

Commit 31dcee5

Browse files
authored
Remove incorrect package structure warnings. (#1236)
* package structure tests that were incorrect now are correct * remove validatePackageStructure proc * fix failing test * remove one test because it produces a warning Warning: Symlink already exists in /home/runner/work/nimble/nimble/tests/nimbleDir/bin/y. Replacing. * remove from list
1 parent fa09e48 commit 31dcee5

File tree

11 files changed

+6
-113
lines changed

11 files changed

+6
-113
lines changed

src/nimblepkg/packageparser.nim

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -90,65 +90,6 @@ proc validateVersion*(ver: string) =
9090
"Version may only consist of numbers and the '.' character " &
9191
"but found '" & c & "'.", false)
9292

93-
proc validatePackageStructure(pkgInfo: PackageInfo, options: Options) =
94-
## This ensures that a package's source code does not leak into
95-
## another package's namespace.
96-
## https://github.com/nim-lang/nimble/issues/144
97-
let
98-
realDir = pkgInfo.getRealDir()
99-
correctDir = pkgInfo.basicInfo.name
100-
101-
proc onFile(path: string) =
102-
# Remove the root to leave only the package subdirectories.
103-
# ~/package-0.1/package/utils.nim -> package/utils.nim.
104-
var trailPath = changeRoot(realDir, "", path)
105-
if trailPath.startsWith(DirSep): trailPath = trailPath[1 .. ^1]
106-
let (dir, file, ext) = trailPath.splitFile
107-
# We're only interested in nim files, because only they can pollute our
108-
# namespace.
109-
if ext != (ExtSep & "nim"):
110-
return
111-
112-
if dir.len == 0:
113-
if file != pkgInfo.basicInfo.name:
114-
# A source file was found in the top level of srcDir that doesn't share
115-
# a name with the package.
116-
let
117-
msg = ("Package '$1' has an incorrect structure. " &
118-
"The top level of the package source directory " &
119-
"should contain at most one module, " &
120-
"named '$2', but a file named '$3' was found. This " &
121-
"will be an error in the future.") %
122-
[pkgInfo.basicInfo.name, pkgInfo.basicInfo.name & ext, file & ext]
123-
hint = ("If this is the primary source file in the package, " &
124-
"rename it to '$1'. If it's a source file required by " &
125-
"the main module, or if it is one of several " &
126-
"modules exposed by '$4', then move it into a '$2' subdirectory. " &
127-
"If it's a test file or otherwise not required " &
128-
"to build the package '$1', prevent its installation " &
129-
"by adding `skipFiles = @[\"$3\"]` to the .nimble file. See " &
130-
"https://github.com/nim-lang/nimble#libraries for more info.") %
131-
[pkgInfo.basicInfo.name & ext, correctDir & DirSep, file & ext, pkgInfo.basicInfo.name]
132-
raise validationError(msg, true, hint, true)
133-
else:
134-
assert(not pkgInfo.isMinimal)
135-
# On Windows `pkgInfo.bin` has a .exe extension, so we need to normalize.
136-
if not (dir.startsWith(correctDir & DirSep) or dir == correctDir):
137-
let
138-
msg = ("Package '$2' has an incorrect structure. " &
139-
"It should contain a single directory hierarchy " &
140-
"for source files, named '$3', but file '$1' " &
141-
"is in a directory named '$4' instead. " &
142-
"This will be an error in the future.") %
143-
[file & ext, pkgInfo.basicInfo.name, correctDir, dir]
144-
hint = ("If '$1' contains source files for building '$2', rename it " &
145-
"to '$3'. Otherwise, prevent its installation " &
146-
"by adding `skipDirs = @[\"$1\"]` to the .nimble file.") %
147-
[dir, pkgInfo.basicInfo.name, correctDir]
148-
raise validationError(msg, true, hint, true)
149-
150-
iterInstallFiles(realDir, pkgInfo, options, onFile)
151-
15293
proc validatePackageInfo(pkgInfo: PackageInfo, options: Options) =
15394
let path = pkgInfo.myPath
15495
if pkgInfo.basicInfo.name == "":
@@ -176,10 +117,6 @@ proc validatePackageInfo(pkgInfo: PackageInfo, options: Options) =
176117
if pkgInfo.backend notin ["c", "cc", "objc", "cpp", "js"]:
177118
raise validationError("'" & pkgInfo.backend &
178119
"' is an invalid backend.", false)
179-
if options.action.typ in {actionInstall, actionBuild, actionDevelop, actionCompile, actionCheck}:
180-
# nim is used for building the project, thus no need to validate its structure.
181-
if not pkgInfo.basicInfo.name.isNim:
182-
validatePackageStructure(pkginfo, options)
183120

184121
proc nimScriptHint*(pkgInfo: PackageInfo) =
185122
if not pkgInfo.isNimScript:

tests/packageStructure/validBinary/y.nimble

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/packageStructure/y/y.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
version = "0.1.0"
44
author = "Dominik Picheta"
5-
description = "Incorrectly structured package Y"
5+
description = "Correctly structured package Y"
66
license = "MIT"
77

88
installExt = @["nim"]

tests/packageStructure/y/yWrong/foobar.nim

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/packageStructure/z/incorrect.nim

Whitespace-only changes.

tests/packageStructure/z/z.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
version = "0.1.0"
44
author = "Dominik Picheta"
5-
description = "Incorrect package structure Z."
5+
description = "Correct package structure Z."
66
license = "MIT"
77

88
# Dependencies

tests/tcheckcommand.nim

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ suite "check command":
3333
check outp.processOutput.inLines("success")
3434
check outp.processOutput.inLines("\"c\" is valid")
3535

36-
test "can fail package":
3736
cd "packageStructure/x":
3837
let (outp, exitCode) = execNimble("check")
39-
check exitCode == QuitFailure
40-
check outp.processOutput.inLines("failure")
41-
check outp.processOutput.inLines("validation failed")
42-
check outp.processOutput.inLines("package 'x' has an incorrect structure")
38+
check exitCode == QuitSuccess
39+
check outp.processOutput.inLines("success")
40+
check outp.processOutput.inLines("\"x\" is valid")

0 commit comments

Comments
 (0)