-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.nims
172 lines (129 loc) · 5.08 KB
/
config.nims
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import strutils
mode = ScriptMode.Verbose
let
binaryName = "luntic"
mainFileName = "main"
version = "1.1.0"
buildFolder = thisDir() & '/' & "build"
buildSourcesMainFolder = buildFolder & "/sources/main"
buildSourcesTestFolder = buildFolder & "/sources/test"
buildCacheFolder = buildFolder & "/cache"
buildTargetFolder = buildFolder & "/target"
buildDockerFolder = buildFolder & "/docker"
buildResourcesMainFolder = buildFolder & "/resources/main"
buildResourcesTestFolder = buildFolder & "/resources/test"
buildBinaryFile = buildTargetFolder & "/" & binaryName
sourcesFolder = thisDir() & '/' & "src"
sourcesMainFolder = sourcesFolder & "/main"
sourcesMainNimFolder = sourcesMainFolder & "/nim"
sourcesMainResourcesFolder = sourcesMainFolder & "/resources"
sourcesTestFolder = sourcesFolder & "/test"
sourcesTestNimFolder = sourcesTestFolder & "/nim"
sourcesTestResourcesFolder = sourcesTestFolder & "/resources"
sourcesMainFile = buildSourcesMainFolder & "/" & mainFileName
template dependsOn (tasks: untyped) =
for taskName in astToStr(tasks).split({',', ' '}):
exec "nim " & taskName
proc build_create () =
for folder in @[buildSourcesMainFolder, buildCacheFolder, buildTargetFolder]:
if not dirExists folder:
mkdir folder
if dirExists sourcesMainResourcesFolder:
mkdir buildResourcesMainFolder
proc build_copy () =
build_create()
if dirExists sourcesMainNimFolder:
exec "cp -r $1/* $2".format(sourcesMainNimFolder, buildSourcesMainFolder)
if dirExists(sourcesMainResourcesFolder) and listFiles(sourcesMainResourcesFolder).len > 0:
exec "cp -r $1/* $2".format(sourcesMainResourcesFolder, buildResourcesMainFolder)
proc test_copy () =
build_copy()
if dirExists(sourcesTestNimFolder) and listFiles(sourcesTestNimFolder).len > 0:
if not dirExists buildSourcesTestFolder:
mkdir buildSourcesTestFolder
exec "cp -r $1/* $2".format(sourcesTestNimFolder, buildSourcesTestFolder)
if dirExists(sourcesTestResourcesFolder) and listFiles(sourcesTestResourcesFolder).len > 0:
if not dirExists buildResourcesTestFolder:
mkdir buildResourcesTestFolder
exec "cp -r $1/* $2".format(sourcesTestResourcesFolder, buildResourcesTestFolder)
proc folders (dir: string): seq[string] =
result = newSeq[string]()
result.add(dir)
for child in listDirs(dir):
result.add(folders(child))
proc findTestFiles (): seq[string] =
result = newSeq[string]()
for folder in folders(buildSourcesTestFolder):
for file in listFiles(folder):
if file.endsWith("_test.nim"):
result.add(file)
proc addAllBuildPaths () =
switch "path", buildSourcesMainFolder
if existsDir buildResourcesMainFolder:
switch "path", buildResourcesMainFolder
for folder in folders(buildSourcesMainFolder):
switch "path", folder
proc collectPaths (folder: string): string =
result = ""
for child in folders(folder):
result &= " --path:" & child
task clean, "cleans the project":
if dirExists buildFolder:
rmdir buildFolder
else:
echo "Nothing to clean"
task test, "tests the project":
dependsOn clean
test_copy()
var command = "nim compile"
command &= collectPaths(buildSourcesMainFolder)
command &= collectPaths(buildResourcesMainFolder)
command &= collectPaths(buildSourcesTestFolder)
command &= collectPaths(buildResourcesTestFolder)
command &= " --nimcache:" & buildCacheFolder
command &= " --out:" & buildTargetFolder & "/test"
command &= " --verbosity:0"
command &= " --run "
for file in findTestFiles():
exec command & file
rmFile buildTargetFolder & "/test"
task build, "builds the project":
if paramCount() == 2 and paramStr(2) == "release":
dependsOn test
switch "define", "release"
else:
dependsOn clean
build_copy()
--verbosity:1
switch "out", buildBinaryFile
switch "nimcache", buildCacheFolder
addAllBuildPaths()
setCommand "compile", sourcesMainFile
task init, "initialize a project":
for folder in @[sourcesMainNimFolder, sourcesMainResourcesFolder, sourcesTestNimFolder, sourcesTestResourcesFolder]:
mkdir folder
exec "echo 'echo \"Hello world\"' > $1/$2.nim".format(sourcesMainNimFolder, mainFileName)
task docker, "builds the project within specific docker container":
dependsOn clean
build_copy()
exec "mkdir -p $1".format(buildDockerFolder)
exec """docker run \
--rm \
-v '$1:/tmp/src' \
-v '$2:/tmp/target' \
xxlabaza/nim:0.17.0 \
compile --define:release \
--symbolFiles:off \
--nimcache:/tmp/src/cache \
--path:/tmp/src/sources/main \
--path:/tmp/src/resources/main \
--out:/tmp/target/$3 \
/tmp/src/sources/main/$4""".format(buildFolder, buildDockerFolder, binaryName, mainFileName)
exec "docker build --force-rm=true --tag xxlabaza/luntic:$1 .".format(version)
task run, "runs the project":
dependsOn build
var command = buildBinaryFile
for parameterIndex in 2..paramCount():
command &= ' ' & paramStr(parameterIndex)
exec command
setCommand "nop"