@@ -10,9 +10,10 @@ import cli
10
10
import net.http
11
11
12
12
const installer_version = '0.0 .2 '
13
- const analyzer_sources_path = norm_expand_tilde_to_home('~/.config/ v- analyzer/ sources')
14
- const analyzer_bin_path = norm_expand_tilde_to_home('~/.config/ v- analyzer/ bin')
15
- const analyzer_bin_path_with_name = norm_expand_tilde_to_home('~/.config/ v- analyzer/ bin/ v- analyzer')
13
+ const analyzer_config_dir_path = join_path(home_dir(), '.config', 'v- analyzer')
14
+ const analyzer_sources_dir_path = join_path(analyzer_config_dir_path, 'sources')
15
+ const analyzer_bin_dir_path = join_path(analyzer_config_dir_path, 'bin')
16
+ const analyzer_bin_file_path = join_path(analyzer_bin_dir_path, 'v- analyzer')
16
17
17
18
struct ReleaseAsset {
18
19
tag_name string @[json: '- ']
@@ -138,12 +139,12 @@ fn install_from_binary(asset ReleaseAsset, update bool) ! {
138
139
println('${term.green('✓')} Successfully downloaded ${term.bold('v- analyzer')} archive')
139
140
140
141
println('Extracting ${term.bold('v- analyzer')} archive...')
141
- os.mkdir_all(analyzer_bin_path ) or {
142
- println('Failed to create directory: ${analyzer_bin_path }')
142
+ os.mkdir_all(analyzer_bin_dir_path ) or {
143
+ println('Failed to create directory: ${analyzer_bin_dir_path }')
143
144
return
144
145
}
145
146
146
- szip.extract_zip_to_dir(archive_temp_path, analyzer_bin_path ) or {
147
+ szip.extract_zip_to_dir(archive_temp_path, analyzer_bin_dir_path ) or {
147
148
println('Failed to extract archive: ${err}')
148
149
return
149
150
}
@@ -154,14 +155,14 @@ fn install_from_binary(asset ReleaseAsset, update bool) ! {
154
155
println('${term.green('✓')} ${term.bold('v- analyzer')} successfully updated to ${term.bold(asset.tag_name)}')
155
156
}
156
157
157
- println('Path to the ${term.bold('binary')}: ${analyzer_bin_path_with_name }')
158
+ println('Path to the ${term.bold('binary')}: ${analyzer_bin_file_path }')
158
159
159
160
if ! update {
160
- show_hint_about_path_if_needed(analyzer_bin_path_with_name )
161
+ show_hint_about_path_if_needed(analyzer_bin_file_path )
161
162
}
162
163
163
- os.mkdir_all(analyzer_sources_path ) or {
164
- println('Failed to create directory: ${analyzer_sources_path }')
164
+ os.mkdir_all(analyzer_sources_dir_path ) or {
165
+ println('Failed to create directory: ${analyzer_sources_dir_path }')
165
166
return
166
167
}
167
168
}
@@ -239,7 +240,7 @@ fn update_from_sources(update bool, nightly bool) ! {
239
240
if need_pull {
240
241
println('Updating ${term.bold('v- analyzer')} sources...')
241
242
242
- res : = os.execute('git - C ${analyzer_sources_path } pull')
243
+ res : = os.execute('git - C ${analyzer_sources_dir_path } pull')
243
244
if res.exit_code != 0 {
244
245
errorln('Failed to update sources: ${res.output}')
245
246
return
@@ -265,12 +266,12 @@ fn update_from_sources(update bool, nightly bool) ! {
265
266
println('${term.green('✓')} ${term.bold('v- analyzer')} successfully updated to ${updated_version}')
266
267
}
267
268
268
- println('Path to the ${term.bold('binary')}: ${analyzer_bin_path_with_name }')
269
+ println('Path to the ${term.bold('binary')}: ${analyzer_bin_file_path }')
269
270
return
270
271
}
271
272
272
273
fn get_latest_commit_hash() ! string {
273
- hash_res : = os.execute('git - C ${analyzer_sources_path } log - 1 -- format=%H')
274
+ hash_res : = os.execute('git - C ${analyzer_sources_dir_path } log - 1 -- format=%H')
274
275
if hash_res.exit_code != 0 {
275
276
return error('Failed to get hash of the latest commit: ${hash_res.output}')
276
277
}
@@ -295,15 +296,15 @@ fn install_from_sources(no_interaction bool) ! {
295
296
println('cd v- analyzer')
296
297
println('v build.vsh')
297
298
println(term.gray('# Optionally you can move the binary to the standard location: '))
298
- println('mkdir - p ${analyzer_bin_path }')
299
- println('cp ./bin/ v- analyzer ${analyzer_bin_path }')
299
+ println('mkdir - p ${analyzer_bin_dir_path }')
300
+ println('cp ./bin/ v- analyzer ${analyzer_bin_dir_path }')
300
301
return
301
302
}
302
303
}
303
304
304
305
if already_cloned() {
305
- os.rmdir_all(analyzer_sources_path ) or {
306
- errorln('Failed to remove directory: ${analyzer_sources_path }: ${err}')
306
+ os.rmdir_all(analyzer_sources_dir_path ) or {
307
+ errorln('Failed to remove directory: ${analyzer_sources_dir_path }: ${err}')
307
308
return
308
309
}
309
310
}
@@ -313,15 +314,15 @@ fn install_from_sources(no_interaction bool) ! {
313
314
clone_repository()!
314
315
build_from_sources()!
315
316
316
- println('Path to the ${term.bold('binary')}: ${analyzer_bin_path_with_name }')
317
+ println('Path to the ${term.bold('binary')}: ${analyzer_bin_file_path }')
317
318
318
- show_hint_about_path_if_needed(analyzer_bin_path_with_name )
319
+ show_hint_about_path_if_needed(analyzer_bin_file_path )
319
320
}
320
321
321
322
fn clone_repository() ! {
322
323
println('Cloning ${term.bold('v- analyzer')} repository...')
323
324
324
- exit_code : = run_command('git clone ${git_clone_options} https: // github.com/vlang/v-analyzer.git ${analyzer_sources_path } 2>&1') or {
325
+ exit_code : = run_command('git clone ${git_clone_options} https: // github.com/vlang/v-analyzer.git ${analyzer_sources_dir_path } 2>&1') or {
325
326
errorln('Failed to clone v- analyzer repository: ${err}')
326
327
return
327
328
}
@@ -338,7 +339,7 @@ fn build_from_sources() ! {
338
339
339
340
compiler_flag : = $if windows { '- cc gcc' } $else { '' }
340
341
341
- chdir(analyzer_sources_path )!
342
+ chdir(analyzer_sources_dir_path )!
342
343
install_deps_cmd : = os.execute('v ${compiler_flag} install')
343
344
if install_deps_cmd.exit_code != 0 {
344
345
errorln('Failed to install dependencies for ${term.bold('v- analyzer')}')
@@ -348,7 +349,7 @@ fn build_from_sources() ! {
348
349
349
350
println('${term.green('✓')} Dependencies for ${term.bold('v- analyzer')} installed successfully')
350
351
351
- chdir(analyzer_sources_path )!
352
+ chdir(analyzer_sources_dir_path )!
352
353
exit_code : = run_command('v ${compiler_flag} build.vsh 1 >/dev/ null') or {
353
354
errorln('Failed to build ${term.bold('v- analyzer')}: ${err}')
354
355
return
@@ -360,27 +361,27 @@ fn build_from_sources() ! {
360
361
361
362
println('Moving ${term.bold('v- analyzer')} binary to the standard location...')
362
363
363
- os.mkdir_all(analyzer_bin_path ) or {
364
- println('Failed to create directory: ${analyzer_bin_path }')
364
+ os.mkdir_all(analyzer_bin_dir_path ) or {
365
+ println('Failed to create directory: ${analyzer_bin_dir_path }')
365
366
return
366
367
}
367
368
368
- os.cp_all('${analyzer_sources_path }/ bin/ v- analyzer', analyzer_bin_path , true) or {
369
- println('Failed to copy ${term.bold('v- analyzer')} binary to ${analyzer_bin_path }: ${err}')
369
+ os.cp_all('${analyzer_sources_dir_path }/ bin/ v- analyzer', analyzer_bin_dir_path , true) or {
370
+ println('Failed to copy ${term.bold('v- analyzer')} binary to ${analyzer_bin_dir_path }: ${err}')
370
371
return
371
372
}
372
373
373
- println('${term.green('✓')} Successfully moved ${term.bold('v- analyzer')} binary to ${analyzer_bin_path }')
374
+ println('${term.green('✓')} Successfully moved ${term.bold('v- analyzer')} binary to ${analyzer_bin_dir_path }')
374
375
375
376
println('${term.green('✓')} ${term.bold('v- analyzer')} built successfully')
376
377
}
377
378
378
379
fn already_cloned() bool {
379
- if ! os.exists(analyzer_sources_path ) {
380
+ if ! os.exists(analyzer_sources_dir_path ) {
380
381
return false
381
382
}
382
383
383
- files : = os.ls(analyzer_sources_path ) or { return false }
384
+ files : = os.ls(analyzer_sources_dir_path ) or { return false }
384
385
return files.len > 0
385
386
}
386
387
@@ -459,11 +460,6 @@ fn run_command(cmd string) !int {
459
460
return command.exit_code
460
461
}
461
462
462
- fn norm_expand_tilde_to_home(path string) string {
463
- norm_path : = os.norm_path(path)
464
- return os.expand_tilde_to_home(norm_path)
465
- }
466
-
467
463
pub fn errorln(msg string) {
468
464
eprintln('${term.red('[ERROR]')} ${msg}')
469
465
}
0 commit comments