From 5d2995c4d56865ccc1f4455485440389934fa347 Mon Sep 17 00:00:00 2001 From: Subhomoy Haldar Date: Tue, 8 Feb 2022 16:53:10 +0530 Subject: [PATCH] tools: support `./v symlink -githubci` (#13403) --- cmd/tools/vsymlink.v | 35 +++++++++++++++++++++++++++++++---- cmd/v/help/symlink.txt | 4 +++- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/cmd/tools/vsymlink.v b/cmd/tools/vsymlink.v index 4ea2c1d894aa0f..a45c120070636f 100644 --- a/cmd/tools/vsymlink.v +++ b/cmd/tools/vsymlink.v @@ -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') { diff --git a/cmd/v/help/symlink.txt b/cmd/v/help/symlink.txt index 105900316adbe4..31b7dddb2c063f 100644 --- a/cmd/v/help/symlink.txt +++ b/cmd/v/help/symlink.txt @@ -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. \ No newline at end of file