Skip to content
Closed

WIP #18499

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 0 additions & 111 deletions .github/workflows/ci_docs.yml

This file was deleted.

63 changes: 0 additions & 63 deletions .github/workflows/ci_packages.yml

This file was deleted.

48 changes: 24 additions & 24 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,35 @@ jobs:

strategy:
matrix:
Linux_amd64:
vmImage: 'ubuntu-18.04'
CPU: amd64
# regularly breaks, refs bug #17325
Linux_i386:
# on 'ubuntu-16.04' (not supported anymore anyways) it errored with:
# g++-multilib : Depends: gcc-multilib (>= 4:5.3.1-1ubuntu1) but it is not going to be installed
vmImage: 'ubuntu-18.04'
CPU: i386
OSX_amd64:
vmImage: 'macOS-10.15'
CPU: amd64
OSX_amd64_cpp:
vmImage: 'macOS-10.15'
CPU: amd64
NIM_COMPILE_TO_CPP: true
# Linux_amd64:
# vmImage: 'ubuntu-18.04'
# CPU: amd64
# # regularly breaks, refs bug #17325
# Linux_i386:
# # on 'ubuntu-16.04' (not supported anymore anyways) it errored with:
# # g++-multilib : Depends: gcc-multilib (>= 4:5.3.1-1ubuntu1) but it is not going to be installed
# vmImage: 'ubuntu-18.04'
# CPU: i386
# OSX_amd64:
# vmImage: 'macOS-10.15'
# CPU: amd64
# OSX_amd64_cpp:
# vmImage: 'macOS-10.15'
# CPU: amd64
# NIM_COMPILE_TO_CPP: true
Windows_amd64_batch0_3:
vmImage: 'windows-2019'
CPU: amd64
# see also: `NIM_TEST_PACKAGES`
NIM_TESTAMENT_BATCH: "0_3"
Windows_amd64_batch1_3:
vmImage: 'windows-2019'
CPU: amd64
NIM_TESTAMENT_BATCH: "1_3"
Windows_amd64_batch2_3:
vmImage: 'windows-2019'
CPU: amd64
NIM_TESTAMENT_BATCH: "2_3"
# Windows_amd64_batch1_3:
# vmImage: 'windows-2019'
# CPU: amd64
# NIM_TESTAMENT_BATCH: "1_3"
# Windows_amd64_batch2_3:
# vmImage: 'windows-2019'
# CPU: amd64
# NIM_TESTAMENT_BATCH: "2_3"

pool:
vmImage: $(vmImage)
Expand Down
18 changes: 18 additions & 0 deletions compiler/commands.nim
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,24 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
else: conf.spellSuggestMax = parseInt(arg)
of "declaredlocs":
processOnOffSwitchG(conf, {optDeclaredLocs}, arg, pass, info)
of "moduleoverride":
# --moduleoverride:std/sequtils:pkg/foo/sequtils2:prefix1,prefix2/sub
proc validate(path: string): string =
if path.isAbsolute or path.isCanonicalPath: result = path
else: localError(conf, info, "module path must be canonical or absolute, got: $1" % path)
let args = arg.split(":")
if args.len notin {2, 3}:
localError(conf, info, "invalid arg: $1" % arg)
else:
let lhs = args[0].validate
let rhs = args[1].validate
if args.len == 2:
conf.localOverrides.add LocalOverride(lhs: lhs, rhs: rhs, prefix: "/")
elif args.len == 3:
let prefixes = args[2].split(",")
for a in prefixes:
let prefix = a.validate
conf.localOverrides.add LocalOverride(lhs: lhs, rhs: rhs, prefix: prefix)
of "dynliboverride":
dynlibOverride(conf, switch, arg, pass, info)
of "dynliboverrideall":
Expand Down
2 changes: 2 additions & 0 deletions compiler/debugutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ proc isCompilerDebug*(): bool =
{.undef(nimCompilerDebug).}
echo 'x'
conf0.isDefined("nimCompilerDebug")

include timn/exp/nim_compiler_debugutils
49 changes: 48 additions & 1 deletion compiler/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,12 @@ type
foLegacyRelProj # legacy, shortest of (foAbs, foRelProject)
foName # lastPathPart, e.g.: foo.nim
foStacktrace # if optExcessiveStackTrace: foAbs else: foName
LocalOverrideAtom* = object

LocalOverride* = object
lhs*: string
rhs*: string
prefix*: string
ConfigRef* {.acyclic.} = ref object ## every global configuration
## fields marked with '*' are subject to
## the incremental compilation mechanisms
Expand Down Expand Up @@ -344,6 +349,7 @@ type
jsonBuildFile*: AbsoluteFile
prefixDir*, libpath*, nimcacheDir*: AbsoluteDir
dllOverrides, moduleOverrides*, cfileSpecificOptions*: StringTableRef
localOverrides*: seq[LocalOverride]
projectName*: string # holds a name like 'nim'
projectPath*: AbsoluteDir # holds a path like /home/alice/projects/nim/compiler/
projectFull*: AbsoluteFile # projectPath/projectName
Expand Down Expand Up @@ -823,6 +829,12 @@ const stdlibDirs = [
const
pkgPrefix = "pkg/"
stdPrefix = "std/"
systemPrefix = "system/"

proc isCanonicalPath*(path: string): bool =
# in future work we can support also `this/` for current package.
let path = path & '/'
result = path.startsWith(stdPrefix) or path.startsWith(systemPrefix) or path.startsWith(pkgPrefix)

proc getRelativePathFromConfigPath*(conf: ConfigRef; f: AbsoluteFile, isTitle = false): RelativeFile =
let f = $f
Expand Down Expand Up @@ -852,7 +864,24 @@ proc findFile*(conf: ConfigRef; f: string; suppressStdlib = false): AbsoluteFile
result = rawFindFile2(conf, RelativeFile f.toLowerAscii)
patchModule(conf)

proc findModule*(conf: ConfigRef; modulename, currentModule: string): AbsoluteFile =
proc canonicalImport*(conf: ConfigRef, file: AbsoluteFile): string

proc canonicalImportPkg*(conf: ConfigRef, file: AbsoluteFile): string =
result = canonicalImport(conf, file)
let tmp = result & '/'
if not (tmp.startsWith(stdPrefix) or tmp.startsWith(systemPrefix)):
result = pkgPrefix & result

proc pathMatchesPrefix(conf: ConfigRef, path: string, prefix: string): bool =
# see also `prefixmatches.prefixMatch`
if prefix == "/": result = true
elif prefix.isAbsolute:
result = path.isRelativeTo(prefix)
else: # canonical, eg std/foo or pkg/fusion/bar
let canon = canonicalImportPkg(conf, AbsoluteFile(path)) & '/'
result = canon.startsWith(prefix & '/')

proc findModule*(conf: ConfigRef; modulename, currentModule: string, depth = 0): AbsoluteFile =
# returns path to module
var m = addFileExt(modulename, NimExt)
if m.startsWith(pkgPrefix):
Expand All @@ -870,6 +899,19 @@ proc findModule*(conf: ConfigRef; modulename, currentModule: string): AbsoluteFi
result = AbsoluteFile currentPath / m
if not fileExists(result):
result = findFile(conf, m)
if not result.isEmpty:
let canon = canonicalImportPkg(conf, result)
for ai in conf.localOverrides:
if ai.lhs == canon:
if pathMatchesPrefix(conf, currentModule, ai.prefix):
if depth > 10:
# can happen with: `--moduleoverride:std/foo2:std/foo2` or `--moduleoverride:std/foo2:/pathto/std/foo2`
# or more complex cases with cycles. Future work could improve things but this is a rare edge case.
# `localError` not defined in scope, alternative is some simple refactoring.
stderr.write "module resolution too deep, possible cyclic overrides detected\n"
return AbsoluteFile""
result = findModule(conf, ai.rhs, currentModule, depth + 1)
break
patchModule(conf)

proc findProjectNimFile*(conf: ConfigRef; pkg: string): string =
Expand Down Expand Up @@ -918,17 +960,22 @@ proc canonicalImportAux*(conf: ConfigRef, file: AbsoluteFile): string =
system, std/tables, fusion/pointers, system/assertions, std/private/asciitables
]##
var ret = getRelativePathFromConfigPath(conf, file, isTitle = true)
echo "D20210715T122459"
let dir = getNimbleFile(conf, $file).parentDir.AbsoluteDir
echo file, " ", ret, " ", getNimbleFile(conf, $file), " ", dir
if not dir.isEmpty:
let relPath = relativeTo(file, dir)
echo "relPath: ", relPath
if not relPath.isEmpty and (ret.isEmpty or relPath.string.len < ret.string.len):
ret = relPath
if ret.isEmpty:
ret = relativeTo(file, conf.projectPath)
echo "ret: ", ret
result = ret.string

proc canonicalImport*(conf: ConfigRef, file: AbsoluteFile): string =
let ret = canonicalImportAux(conf, file)
echo "canonicalImport: ret: ", ret, " file: ", file
result = ret.nativeToUnixPath.changeFileExt("")

proc canonDynlibName(s: string): string =
Expand Down
Loading