diff --git a/compiler/extccomp.nim b/compiler/extccomp.nim index ab42f4f52b..9880ecf4f8 100644 --- a/compiler/extccomp.nim +++ b/compiler/extccomp.nim @@ -376,7 +376,7 @@ proc nameToCC*(name: string): TSystemCC = result = ccNone proc isVSCompatible*(conf: ConfigRef): bool = - return conf.cCompiler == ccVcc or + return conf.cCompiler == ccVcc or conf.cCompiler == ccClangCl or (conf.cCompiler == ccIcl and conf.target.hostOS in osDos..osWindows) @@ -738,7 +738,7 @@ proc getLinkCmd(conf: ConfigRef; output: AbsoluteFile, # way of being able to debug and rebuild the program at the same time. This # is accomplished using the /PDB: flag (there also exists the # /PDBALTPATH: flag). The only downside is that the .pdb files are - # atleast 300kb big (when linking statically to the runtime - or else 5mb+) + # atleast 300kb big (when linking statically to the runtime - or else 5mb+) # and will quickly accumulate. There is a hacky solution: we could try to # delete all .pdb files with a pattern and swallow exceptions. # @@ -910,7 +910,8 @@ proc callCCompiler*(conf: ConfigRef) = else: AbsoluteFile(conf.projectName) linkCmd = getLinkCmd(conf, mainOutput, objfiles) if optCompileOnly notin conf.globalOptions: - if defined(windows) and linkCmd.len > 8_000: + const MaxCmdLen = when defined(windows): 8_000 else: 32_000 + if linkCmd.len > MaxCmdLen: # Windows's command line limit is about 8K (don't laugh...) so C compilers on # Windows support a feature where the command line can be passed via ``@linkcmd`` # to them. diff --git a/compiler/modules.nim b/compiler/modules.nim index 3d8ced35d9..1b8c7b9581 100644 --- a/compiler/modules.nim +++ b/compiler/modules.nim @@ -17,9 +17,9 @@ import proc resetSystemArtifacts*(g: ModuleGraph) = magicsys.resetSysTypes(g) -proc partialInitModule(result: PSym; graph: ModuleGraph; fileIdx: FileIndex; filename: string) = +proc partialInitModule(result: PSym; graph: ModuleGraph; fileIdx: FileIndex; filename: AbsoluteFile) = let - pck = getPackageName(graph.config, filename) + pck = getPackageName(graph.config, filename.string) pck2 = if pck.len > 0: pck else: "unknown" pack = getIdent(graph.cache, pck2) var packSym = graph.packageSyms.strTableGet(pack) @@ -27,6 +27,22 @@ proc partialInitModule(result: PSym; graph: ModuleGraph; fileIdx: FileIndex; fil packSym = newSym(skPackage, getIdent(graph.cache, pck2), nil, result.info) initStrTable(packSym.tab) graph.packageSyms.strTableAdd(packSym) + else: + let existing = strTableGet(packSym.tab, result.name) + if existing != nil and existing.info.fileIndex != result.info.fileIndex: + when false: + # we used to produce an error: + localError(graph.config, result.info, + "module names need to be unique per Nimble package; module clashes with " & + toFullPath(graph.config, existing.info.fileIndex)) + else: + # but starting with version 0.20 we now produce a fake Nimble package instead + # to resolve the conflicts: + let pck3 = fakePackageName(graph.config, filename) + packSym = newSym(skPackage, getIdent(graph.cache, pck3), nil, result.info) + initStrTable(packSym.tab) + graph.packageSyms.strTableAdd(packSym) + result.owner = packSym result.position = int fileIdx @@ -37,13 +53,7 @@ proc partialInitModule(result: PSym; graph: ModuleGraph; fileIdx: FileIndex; fil incl(result.flags, sfUsed) initStrTable(result.tab) strTableAdd(result.tab, result) # a module knows itself - let existing = strTableGet(packSym.tab, result.name) - if existing != nil and existing.info.fileIndex != result.info.fileIndex: - localError(graph.config, result.info, - "module names need to be unique per Nimble package; module clashes with " & - toFullPath(graph.config, existing.info.fileIndex)) - # strTableIncl() for error corrections: - discard strTableIncl(packSym.tab, result) + strTableAdd(packSym.tab, result) proc newModule(graph: ModuleGraph; fileIdx: FileIndex): PSym = # We cannot call ``newSym`` here, because we have to circumvent the ID @@ -51,7 +61,7 @@ proc newModule(graph: ModuleGraph; fileIdx: FileIndex): PSym = new(result) result.id = -1 # for better error checking result.kind = skModule - let filename = toFullPath(graph.config, fileIdx) + let filename = AbsoluteFile toFullPath(graph.config, fileIdx) result.name = getIdent(graph.cache, splitFile(filename).name) if not isNimIdentifier(result.name.s): rawMessage(graph.config, errGenerated, "invalid module name: " & result.name.s) @@ -61,8 +71,8 @@ proc newModule(graph: ModuleGraph; fileIdx: FileIndex): PSym = proc compileModule*(graph: ModuleGraph; fileIdx: FileIndex; flags: TSymFlags): PSym = result = graph.getModule(fileIdx) if result == nil: - let filename = toFullPath(graph.config, fileIdx) - let (r, id) = loadModuleSym(graph, fileIdx, AbsoluteFile filename) + let filename = AbsoluteFile toFullPath(graph.config, fileIdx) + let (r, id) = loadModuleSym(graph, fileIdx, filename) result = r if result == nil: result = newModule(graph, fileIdx) diff --git a/compiler/packagehandling.nim b/compiler/packagehandling.nim index f94c3d72c6..d7c6b25aec 100644 --- a/compiler/packagehandling.nim +++ b/compiler/packagehandling.nim @@ -29,9 +29,6 @@ proc getPackageName*(conf: ConfigRef; path: string): string = for file in walkFiles(d / "*.nimble"): result = file.splitFile.name break packageSearch - for file in walkFiles(d / "*.babel"): - result = file.splitFile.name - break packageSearch # we also store if we didn't find anything: when not defined(nimNoNilSeqs): if result.isNil: result = "" @@ -41,10 +38,19 @@ proc getPackageName*(conf: ConfigRef; path: string): string = dec parents if parents <= 0: break +proc fakePackageName*(conf: ConfigRef; path: AbsoluteFile): string = + # foo/../bar becomes foo7_7bar + result = relativeTo(path, conf.projectPath, '/').string.multiReplace( + {"/": "7", "..": "_", "7": "77", "_": "__"}) + proc withPackageName*(conf: ConfigRef; path: AbsoluteFile): AbsoluteFile = let x = getPackageName(conf, path.string) if x.len == 0: result = path else: let (p, file, ext) = path.splitFile - result = p / RelativeFile((x & '_' & file) & ext) + if x == "stdlib": + # Hot code reloading now relies on 'stdlib_system' names etc. + result = p / RelativeFile((x & '_' & file) & ext) + else: + result = p / RelativeFile(fakePackageName(conf, path)) diff --git a/testament/tester.nim b/testament/tester.nim index 1df08aa34f..5b1d327c8f 100644 --- a/testament/tester.nim +++ b/testament/tester.nim @@ -320,7 +320,7 @@ proc generatedFile(test: TTest, target: TTarget): string = let (_, name, _) = test.name.splitFile let ext = targetToExt[target] result = nimcacheDir(test.name, test.options, target) / - ("compiler_" & name.changeFileExt(ext)) + name.replace("_", "__").changeFileExt(ext) proc needsCodegenCheck(spec: TSpec): bool = result = spec.maxCodeSize > 0 or spec.ccodeCheck.len > 0 diff --git a/tests/modules/mnotuniquename.nim b/tests/modules/mnotuniquename.nim index e69de29bb2..54d5883cd3 100644 --- a/tests/modules/mnotuniquename.nim +++ b/tests/modules/mnotuniquename.nim @@ -0,0 +1 @@ +proc flat*() = echo "flat" diff --git a/tests/modules/tnotuniquename.nim b/tests/modules/tnotuniquename.nim index 403c8a47e6..bc401e6621 100644 --- a/tests/modules/tnotuniquename.nim +++ b/tests/modules/tnotuniquename.nim @@ -1,7 +1,10 @@ discard """ - errormsg: "module names need to be unique per Nimble package" - file: "tnotuniquename/mnotuniquename.nim" + output: '''nested +flat''' """ import mnotuniquename -import tnotuniquename/mnotuniquename as nun +import tnotuniquename_dir/mnotuniquename as nun + +nested() +flat() diff --git a/tests/modules/tnotuniquename/mnotuniquename.nim b/tests/modules/tnotuniquename/mnotuniquename.nim deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/modules/tnotuniquename2.nim b/tests/modules/tnotuniquename2.nim index 7aa4de515d..e4501bc243 100644 --- a/tests/modules/tnotuniquename2.nim +++ b/tests/modules/tnotuniquename2.nim @@ -1,6 +1,7 @@ discard """ errormsg: "module names need to be unique per Nimble package" file: "tnotuniquename/mnotuniquename.nim" + disabled: "true" """ import mnotuniquename diff --git a/tests/modules/tnotuniquename_dir/mnotuniquename.nim b/tests/modules/tnotuniquename_dir/mnotuniquename.nim new file mode 100644 index 0000000000..11e52d9d0b --- /dev/null +++ b/tests/modules/tnotuniquename_dir/mnotuniquename.nim @@ -0,0 +1,2 @@ + +proc nested*() = echo "nested"