-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[TODO] Nim now allows modules with same name in a package #8614
Changes from all commits
17e485d
7fc7f78
d2969a9
720a4bd
821c72f
b67bc2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,38 +12,53 @@ iterator myParentDirs(p: string): string = | |
var current = p | ||
while true: | ||
current = current.parentDir | ||
if current.len == 0: break | ||
# IMPROVE:parentDir is buggy, "foo.nim".parentDir should be ".", not "" | ||
if current.len == 0: | ||
current = "." | ||
yield current | ||
break | ||
yield current | ||
|
||
proc resetPackageCache*(conf: ConfigRef) = | ||
conf.packageCache = newPackageCache() | ||
const packageSep = "." | ||
|
||
proc getPackageName*(conf: ConfigRef; path: string): string = | ||
var parents = 0 | ||
var dirs:seq[string] = @[] | ||
var pkg = "" | ||
var path_root = "" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The compiler and all of Nim's stdlib use |
||
block packageSearch: | ||
for d in myParentDirs(path): | ||
path_root = d | ||
if conf.packageCache.hasKey(d): | ||
#echo "from cache ", d, " |", packageCache[d], "|", path.splitFile.name | ||
return conf.packageCache[d] | ||
inc parents | ||
pkg = conf.packageCache[d] | ||
break packageSearch | ||
for file in walkFiles(d / "*.nimble"): | ||
result = file.splitFile.name | ||
pkg = file.splitFile.name | ||
break packageSearch | ||
for file in walkFiles(d / "*.babel"): | ||
result = file.splitFile.name | ||
pkg = file.splitFile.name | ||
break packageSearch | ||
# we also store if we didn't find anything: | ||
if result.isNil: result = "" | ||
for d in myParentDirs(path): | ||
#echo "set cache ", d, " |", result, "|", parents | ||
conf.packageCache[d] = result | ||
dec parents | ||
if parents <= 0: break | ||
dirs.add d.splitPath.tail | ||
|
||
# at this point, path_root maps to pkg | ||
for index in 0 .. dirs.len: | ||
if index > 0: | ||
let dir = dirs[^index] | ||
path_root = path_root & DirSep & dir | ||
pkg = pkg & packageSep & dir | ||
if conf.packageCache.hasKey(path_root): | ||
doAssert conf.packageCache[path_root] == pkg | ||
else: | ||
conf.packageCache[path_root] = pkg | ||
result = pkg | ||
|
||
proc fullyQualifiedName*(conf: ConfigRef; path: string): string = | ||
let pkg = getPackageName(conf, path) | ||
doAssert pkg.len > 0 | ||
let (p, file, ext) = path.splitFile | ||
result = pkg & packageSep & file | ||
|
||
proc withPackageName*(conf: ConfigRef; path: string): string = | ||
let x = getPackageName(conf, path) | ||
if x.len == 0: | ||
result = path | ||
else: | ||
let (p, file, ext) = path.splitFile | ||
result = (p / (x & '_' & file)) & ext | ||
let fqname = fullyQualifiedName(conf, path) | ||
let (p, file, ext) = path.splitFile | ||
# TODO: is `p/` part needed? | ||
result = p / (fqname & ext) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,19 +16,19 @@ from math import sqrt, ln, log10, log2, exp, round, arccos, arcsin, | |
from os import getEnv, existsEnv, dirExists, fileExists, putEnv, walkDir | ||
|
||
template mathop(op) {.dirty.} = | ||
registerCallback(c, "stdlib.math." & astToStr(op), `op Wrapper`) | ||
registerCallback(c, "stdlib.pure.math." & astToStr(op), `op Wrapper`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should all not be changed, other tools also rely on |
||
|
||
template osop(op) {.dirty.} = | ||
registerCallback(c, "stdlib.os." & astToStr(op), `op Wrapper`) | ||
registerCallback(c, "stdlib.pure.os." & astToStr(op), `op Wrapper`) | ||
|
||
template ospathsop(op) {.dirty.} = | ||
registerCallback(c, "stdlib.ospaths." & astToStr(op), `op Wrapper`) | ||
registerCallback(c, "stdlib.pure.ospaths." & astToStr(op), `op Wrapper`) | ||
|
||
template systemop(op) {.dirty.} = | ||
registerCallback(c, "stdlib.system." & astToStr(op), `op Wrapper`) | ||
|
||
template macrosop(op) {.dirty.} = | ||
registerCallback(c, "stdlib.macros." & astToStr(op), `op Wrapper`) | ||
registerCallback(c, "stdlib.core.macros." & astToStr(op), `op Wrapper`) | ||
|
||
template wrap1f_math(op) {.dirty.} = | ||
proc `op Wrapper`(a: VmArgs) {.nimcall.} = | ||
|
@@ -116,6 +116,7 @@ proc registerAdditionalOps*(c: PCtx) = | |
wrap2svoid(writeFile, systemop) | ||
wrap1s(readFile, systemop) | ||
systemop getCurrentExceptionMsg | ||
#TODO: should that be: stdlib.pure.*.staticWalkDir ? | ||
registerCallback c, "stdlib.*.staticWalkDir", proc (a: VmArgs) {.nimcall.} = | ||
setResult(a, staticWalkDirImpl(getString(a, 0), getBool(a, 1))) | ||
systemop gorgeEx | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,7 +92,7 @@ proc patchFile*(package, filename, replacement: string) = | |
## | ||
## .. code-block:: nim | ||
## | ||
## patchFile("stdlib", "asyncdispatch", "patches/replacement") | ||
## patchFile("stdlib.pure", "asyncdispatch", "patches/replacement") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
discard | ||
|
||
proc getCommand*(): string = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
discard """ | ||
output: "ok" | ||
""" | ||
import strutils as strutils1 | ||
import strutils as strutils2 | ||
import std/strutils as strutils3 | ||
import std/strutils | ||
|
||
import std/sha1 | ||
import std/sha1 as sha1_2 | ||
# TODO: Error: cannot open file: stdlib/std/sha1; inconsistent with the fact we | ||
# generate `stdlib.std.sha1` | ||
# import stdlib/std/sha1 as sha1_3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would |
||
|
||
import ./mnotuniquename | ||
import ./tnotuniquename/mnotuniquename as mnotuniquename1 | ||
|
||
import pure/ospaths as ospaths1 | ||
import std/ospaths as ospaths2 | ||
import ospaths as ospaths3 | ||
|
||
# Error: cannot open file: std/pure/ospaths | ||
# import std/pure/ospaths as ospaths4 | ||
|
||
echo "ok" |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
discard """ | ||
output: "ok" | ||
""" | ||
|
||
# module names need not be unique (but must be renamed to avoid clashes) | ||
import mnotuniquename | ||
import tnotuniquename/mnotuniquename as mnotuniquename1 | ||
echo "ok" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
discard """ | ||
file: "tnotuniquename/mnotuniquename.nim" | ||
errormsg: "module names need to be unique per Nimble package" | ||
errormsg: "redefinition of 'mnotuniquename'" | ||
""" | ||
|
||
# avoid name clashes | ||
import mnotuniquename | ||
import tnotuniquename/mnotuniquename |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ import ospaths | |
warning("uninit", off) | ||
hint("processing", off) | ||
#--verbosity:2 | ||
patchFile("stdlib", "math", "mymath") | ||
patchFile("stdlib.pure", "math", "mymath") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get of this |
||
|
||
task listDirs, "lists every subdirectory": | ||
for x in listDirs("."): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,12 +229,20 @@ proc cmpMsgs(r: var TResults, expected, given: TSpec, test: TTest, target: TTarg | |
r.addResult(test, target, expected.msg, given.msg, reSuccess) | ||
inc(r.passed) | ||
|
||
import compiler/options | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh come on, the tester does not import the compiler. |
||
var conf = newConfigRef() | ||
|
||
proc generatedFile(test: TTest, target: TTarget): string = | ||
let (_, name, _) = test.name.splitFile | ||
let ext = targetToExt[target] | ||
result = nimcacheDir(test.name, test.options, target) / | ||
(if target == targetJS: "" else: "compiler_") & | ||
name.changeFileExt(ext) | ||
|
||
let fqname = fullyQualifiedName(conf, test.name) | ||
# echo ("generatedFile", test.name, fqname, ext) | ||
result = nimcacheDir(test.name, test.options, target) | ||
if target == targetJS: #TODO:why? | ||
result = result / name.changeFileExt(ext) | ||
else: | ||
result = result / fqname & "." & ext | ||
|
||
proc needsCodegenCheck(spec: TSpec): bool = | ||
result = spec.maxCodeSize > 0 or spec.ccodeCheck.len > 0 | ||
|
@@ -262,6 +270,7 @@ proc codegenCheck(test: TTest, target: TTarget, spec: TSpec, expectedMsg: var st | |
echo getCurrentExceptionMsg() | ||
except IOError: | ||
given.err = reCodeNotFound | ||
echo getCurrentExceptionMsg() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is nothing to report here, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is introduced in this dependent PR #8631 and discussed there |
||
|
||
proc nimoutCheck(test: TTest; expectedNimout: string; given: var TSpec) = | ||
let exp = expectedNimout.strip.replace("\C\L", "\L") | ||
|
@@ -509,7 +518,8 @@ proc main() = | |
backend.close() | ||
var failed = r.total - r.passed - r.skipped | ||
if failed != 0: | ||
echo "FAILURE! total: ", r.total, " passed: ", r.passed, " skipped: ", r.skipped | ||
echo "FAILURE! total: ", r.total, " passed: ", r.passed, " skipped: ", | ||
r.skipped, " failed: ", failed | ||
quit(QuitFailure) | ||
|
||
if paramCount() == 0: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What? It should be
.
? No.