diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2019-04-20 15:19:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-20 15:19:02 +0200 |
commit | 0121dda9ba903b764cbd234667cc03f79ebadf44 (patch) | |
tree | 6ffcdfa6b68c3f3acc3ed67f9dcc9218b4e2377b /compiler | |
parent | 44ec66bd484e7cf952c20493a30cf1b29d49e3ca (diff) | |
download | Nim-0121dda9ba903b764cbd234667cc03f79ebadf44.tar.gz |
remove the restriction that module names need to be unique per Nimble… (#11064)
* remove the restriction that module names need to be unique per Nimble package * make tests green again * use the 'response' linker file also on Unix in order to fix megatest
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/extccomp.nim | 7 | ||||
-rw-r--r-- | compiler/modules.nim | 34 | ||||
-rw-r--r-- | compiler/packagehandling.nim | 14 |
3 files changed, 36 insertions, 19 deletions
diff --git a/compiler/extccomp.nim b/compiler/extccomp.nim index ab42f4f52..9880ecf4f 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:<filename> flag (there also exists the # /PDBALTPATH:<filename> 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 3d8ced35d..1b8c7b958 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 f94c3d72c..d7c6b25ae 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)) |