-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathcontext.nim
More file actions
129 lines (105 loc) · 3.18 KB
/
Copy pathcontext.nim
File metadata and controls
129 lines (105 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#
# Atlas Package Cloner
# (c) Copyright 2023 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
import std / [os, uri, paths, files, tables, sets]
import versions, parse_requires, compiledpatterns, reporters
export reporters
const
UnitTests* = defined(atlasUnitTests)
TestsDir* = "atlas/tests"
const
AtlasProjectConfig = Path"atlas.config"
DefaultPackagesSubDir* = Path"_packages"
DefaultCachesSubDir* = Path"_caches"
DefaultNimbleCachesSubDir* = Path"_nimbles"
type
CfgPath* = distinct string # put into a config `--path:"../x"`
SemVerField* = enum
major, minor, patch
CloneStatus* = enum
Ok, NotFound, OtherError
Flag* = enum
KeepCommits
CfgHere
KeepNimEnv
KeepWorkspace
ShowGraph
AutoEnv
NoExec
UpdateRepos
ListVersions
ListVersionsOff
GlobalWorkspace
ShallowClones
IgnoreGitRemoteUrls
IgnoreErrors
DumpFormular
DumpGraphs
DumbProxy
ForceGitToHttps
IncludeTagsAndNimbleCommits # include nimble commits and tags in the solver
NimbleCommitsMax # takes the newest commit for each version
AtlasContext* = object
projectDir*: Path = Path"."
depsDir*: Path = Path"deps"
flags*: set[Flag] = {}
nameOverrides*: Patterns
urlOverrides*: Patterns
pkgOverrides*: Table[string, Uri]
defaultAlgo*: ResolutionAlgorithm = SemVer
plugins*: PluginInfo
overridesFile*: Path
pluginsFile*: Path
proxy*: Uri
features*: HashSet[string]
extraParams*: seq[string]
parallelCount*: Natural
var atlasContext = AtlasContext()
proc setContext*(ctx: AtlasContext) =
atlasContext = ctx
proc context*(): var AtlasContext =
atlasContext
proc project*(): Path =
atlasContext.projectDir
proc project*(ws: Path) =
atlasContext.projectDir = ws
proc depsDir*(relative = false): Path =
if atlasContext.depsDir == Path"":
result = Path""
elif relative or atlasContext.depsDir.isAbsolute:
result = atlasContext.depsDir
else:
result = atlasContext.projectDir / atlasContext.depsDir
proc packagesDirectory*(): Path =
depsDir() / DefaultPackagesSubDir
proc cachesDirectory*(): Path =
depsDir() / DefaultCachesSubDir
proc nimbleCachesDirectory*(): Path =
depsDir() / DefaultNimbleCachesSubDir
proc depGraphCacheFile*(ctx: AtlasContext): Path =
ctx.projectDir / ctx.depsDir / Path"atlas.cache.json"
proc relativeToWorkspace*(path: Path): string =
result = "$project/" & $path.relativePath(project())
proc getProjectConfig*(dir = project()): Path =
## prefer project atlas.config if found
## otherwise default to one in deps/
## the deps path will be the default for auto-created ones
result = dir / AtlasProjectConfig
if fileExists(result): return
result = depsDir() / AtlasProjectConfig
proc isProject*(dir: Path): bool =
fileExists(getProjectConfig(dir))
proc `==`*(a, b: CfgPath): bool {.borrow.}
proc displayName(c: AtlasContext; p: string): string =
if p == c.projectDir.string:
p.absolutePath
elif $c.depsDir != "" and p.isRelativeTo($c.depsDir):
p.relativePath($c.depsDir)
elif p.isRelativeTo($c.projectDir):
p.relativePath($c.projectDir)
else:
p