tools: support `./v symlink -githubci` (#13403)

pull/13405/head
Subhomoy Haldar 2022-02-08 16:53:10 +05:30 committed by GitHub
parent 1dbde05267
commit 5d2995c4d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 5 deletions

View File

@ -8,13 +8,26 @@ $if windows {
#flag -luser32
}
}
fn main() {
C.atexit(cleanup_vtmp_folder)
if os.args.len > 3 {
print('usage: v symlink [OPTIONS]')
exit(1)
}
ci_mode := '-githubci' in os.args
vexe := os.real_path(pref.vexe_path())
$if windows {
setup_symlink_windows(vexe)
} $else {
setup_symlink_unix(vexe)
if ci_mode {
setup_symlink_github()
} else {
$if windows {
setup_symlink_windows(vexe)
} $else {
setup_symlink_unix(vexe)
}
}
}
@ -22,6 +35,20 @@ fn cleanup_vtmp_folder() {
os.rmdir_all(util.get_vtmp_folder()) or {}
}
fn setup_symlink_github() {
// We append V's install location (which should
// be the current directory) to the PATH environment variable.
// Resources:
// 1. https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files
// 2. https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
mut content := os.read_file(os.getenv('GITHUB_PATH')) or {
panic('Failed to read GITHUB_PATH.')
}
content += '\n$os.getwd()\n'
os.write_file(os.getenv('GITHUB_PATH'), content) or { panic('Failed to write to GITHUB_PATH.') }
}
fn setup_symlink_unix(vexe string) {
mut link_path := '/data/data/com.termux/files/usr/bin/v'
if !os.is_dir('/data/data/com.termux/files') {

View File

@ -1,5 +1,7 @@
Usage: v symlink
Usage: v symlink [OPTIONS]
This command adds a symlink for the V compiler executable.
Note that on Unix systems this command requires write permissions to /usr/local/bin to work.
For GitHub Actions, the option -githubci needs to be specified.