-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.vsh
More file actions
203 lines (182 loc) · 5.52 KB
/
Copy pathbuild.vsh
File metadata and controls
203 lines (182 loc) · 5.52 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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/usr/bin/env -S v run
import build
import os
import net.http.file
// Define variables that can be used to change tasks in the build script
const app_name = 'hello'
const program_args = 'World'
const build_dir = 'target'
// Make the build context
mut context := build.context(
// Set the default task to `release` when no arguments are provided
default: 'examples'
)
// Add a few simple tasks
// context.task(name: 'doc', run: |self| system('echo "Nothing to do"'))
// context.task(name: 'run', run: |self| system('v run . ${program_args}'))
// context.task(name: 'build', run: |self| system('v .'))
// context.task(name: 'build.prod', run: |self| system('v -prod -o ${app_name} .'))
// `_` to denote "private" tasks. Nothing stops the user from using it, but
// this tells them that the task is not meant to be used by them.
// context.task(
// name: '_mkdirs'
// // The `help` field is displayed in `--tasks` to give a short summary of what the task does.
// help: 'Makes the directories used by the application'
// run: fn (self build.Task) ! {
// if !exists(build_dir) {
// mkdir_all(build_dir) or { panic(err) }
// }
// }
// )
// This task will only run when the `test.txt` file is outdated
// context.artifact(
// name: 'test.txt'
// help: 'Generate test.txt'
// run: fn (self build.Task) ! {
// write_file('test.txt', time.now().str())!
// }
// )
context.task(
name: 'release'
help: 'Build the app in production mode, generates documentation, and releases the build on Git'
// depends: ['_mkdirs', 'doc', 'test.txt']
run: fn (self build.Task) ! {
// system('v examples/http_server_uv.v')
// system('cd ./thirdparty && git pull origin master')
hash := os.execute('cd ./thirdparty && git rev-parse HEAD').output.trim_space()
println('Latest libuv commit: ${hash}')
// Pretend we are using Git to publish the built file as a release here.
}
)
context.task(
name: 'test'
help: 'Run the tests'
run: fn (self build.Task) ! {
system('v -cc gcc -stats test tests/')
}
)
context.task(
name: 'fmt'
help: 'fmt the source code'
run: fn (self build.Task) ! {
system('v fmt -w .')
}
)
context.task(
name: 'docs'
help: 'build the documentation'
run: fn (self build.Task) ! {
if exists('./docs') {
rmdir_all('./docs') or { panic(err) }
}
system('v doc . -f markdown -o ./docs/markdown')
system('v doc . -f html -o ./docs/html')
rename('./docs/html/vlibuv.html', './docs/html/index.html')!
}
)
context.task(
name: 'docs.view'
help: 'build the documentation'
depends: ['docs']
run: fn (self build.Task) ! {
println('look at the docs on http://localhost:8080')
file.serve(folder: './docs/html', on: ':8080')
}
)
context.task(
name: 'examples'
help: 'build the examples'
run: fn (self build.Task) ! {
examples := os.walk_ext('./examples', '.v')
for ex in examples {
cc_flag := if os.getenv('OS') == 'Windows_NT' { '-cc gcc' } else { '' }
result := execute('v ${cc_flag} ${ex}')
message := if result.exit_code == 0 { 'Success' } else { 'failed' }
println('Building example: ${ex} - ${message}')
}
}
)
context.task(
name: 'symlink'
help: 'Create a symlink to the libuv library'
run: fn (self build.Task) ! {
cwd := os.getwd()
modules_dir := os.vmodules_dir()
symlink_path := '${modules_dir}/vlibuv'
println('Creating symlink: ${symlink_path} -> ${cwd}')
if exists(symlink_path) {
if is_dir(symlink_path) && !is_link(symlink_path) {
rmdir_all(symlink_path)!
} else {
rm(symlink_path)!
}
println('Removed existing path: ${symlink_path}')
}
if os.getenv('OS') == 'Windows_NT' {
// On Windows, use PowerShell to create a symlink (requires admin)
ps_cmd := 'New-Item -ItemType SymbolicLink -Path "${symlink_path}" -Target "${cwd}" -Force'
result := os.execute('powershell -Command "${ps_cmd}"')
if result.exit_code != 0 {
eprintln('Failed to create symlink. You may need to run as Administrator.')
eprintln('Error: ${result.output}')
return error('symlink creation failed')
}
println('Created Windows symlink: ${symlink_path}')
} else {
// On Unix-like systems, create a symlink
symlink(cwd, symlink_path)!
println('Created Unix symlink: ${symlink_path}')
}
}
)
context.task(
name: 'examples.clean'
help: 'Clean all built examples'
run: fn (self build.Task) ! {
walk_fn := fn (path string) {
if !path.ends_with('.v') {
println('removing: ${path}')
rm(path) or { panic(err) }
}
}
walk('./examples', walk_fn)
}
)
context.task(
name: 'update'
help: 'Update libuv'
run: fn (self build.Task) ! {
pull := fn () ! {
branch := 'v1.x'
chdir('./thirdparty')!
output := execute('git pull origin ${branch}').output
if output.contains('Already up to date') {
println('Already up to date')
return
}
}
if exists('./thirdparty/.git') {
pull()!
return
}
if !exists('./thirdparty') {
mkdir('./thirdparty') or { panic(err) }
}
system('cd ./thirdparty && git init')
system('cd ./thirdparty && git remote add origin https://github.com/libuv/libuv.git')
system('cd ./thirdparty && git config core.sparseCheckout true')
// only include the files we need/want
mut checkout := create('./thirdparty/.git/info/sparse-checkout')!
checkout.writeln('include/')!
checkout.writeln('src/')!
checkout.writeln('LICENSE*')!
checkout.writeln('README*')!
checkout.writeln('*.pc*')!
checkout.writeln('!docs/src/')!
checkout.close()
pull()!
}
)
// Run the build context. This will iterate over os.args and each corresponding
// task, skipping any arguments that start with a hyphen (-)
context.run()