aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2021-01-02 13:10:36 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2021-01-02 13:10:36 +0300
commit8759996de452bd3710d1e4f56994bea471bab536 (patch)
tree7cd265db9f0e87fcccfeb9c515a7a413d8d0fa6c
parentrefactoring (diff)
downloadsetup-clang-8759996de452bd3710d1e4f56994bea471bab536.tar.gz
setup-clang-8759996de452bd3710d1e4f56994bea471bab536.zip
setup cc/c++ executables
-rw-r--r--.github/workflows/test.yml9
-rw-r--r--action.yml47
2 files changed, 55 insertions, 1 deletions
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 3373d8d..b367d81 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -86,3 +86,12 @@ jobs:
Unexpected output:
$actual
"@)
+
+ - name: Check cc/c++
+ run: |
+ $cc = & cc --version
+ echo $cc
+ $($cc | Select-String -Pattern "clang version" -SimpleMatch -Quiet) -or $(throw "Unexpected `cc --version` output")
+ $cxx = & c++ --version
+ echo $cxx
+ $($cxx | Select-String -Pattern "clang version" -SimpleMatch -Quiet) -or $(throw "Unexpected `c++ --version` output")
diff --git a/action.yml b/action.yml
index a1c16bf..32aab7e 100644
--- a/action.yml
+++ b/action.yml
@@ -52,6 +52,40 @@ runs:
}
}
+ function Link-Exe {
+ param(
+ [Parameter(Mandatory=$true)]
+ [string] $ExeName,
+ [Parameter(Mandatory=$true)]
+ [string] $LinkName
+ )
+
+ # Full executable path, including the extension:
+ $exe_path = (Get-Command $ExeName).Path
+ $exe_dir = Split-Path $exe_path
+ $exe_name = Split-Path $exe_path -Leaf
+ $exe_ext = [System.IO.Path]::GetExtension($exe_name)
+
+ $link_dir = if ($script:linux_host) { '/usr/local/bin' } else { $exe_dir }
+ $link_name = $LinkName
+ # On Windows, append .exe if required:
+ if (!$script:linux_host -and [System.IO.Path]::GetExtension($link_name) -ne $exe_ext) {
+ $link_name += $exe_ext
+ }
+ $link_path = Join-Path $link_dir $link_name
+
+ echo "Creating link '$link_path', pointing to '$exe_path'"
+ if ($script:linux_host) {
+ sudo rm -f -- $link_path
+ sudo ln -s -- $exe_path $link_path
+ } else {
+ if (Test-Path $link_path) {
+ Remove-Item $link_path -Force
+ }
+ New-Item -ItemType HardLink -Path $link_path -Value $exe_path | Out-Null
+ }
+ }
+
function Convert-CygwinPath {
# Like cygpath -wa, but don't resolve symlinks.
param(
@@ -93,6 +127,9 @@ runs:
$pkgs = 'clang','g++-multilib'
}
Install-Package $pkgs
+
+ Link-Exe -Exe clang -LinkName cc
+ Link-Exe -Exe clang++ -LinkName c++
} elseif ($cygwin_host) {
if (!$x64) {
echo @'
@@ -112,9 +149,17 @@ runs:
# convenient to make proper executables instead so that they can be
# called from Windows' command prompt.
find.exe /usr/bin -iname 'clang*' -type l | %{ Fix-CygwinLink $_ }
+
+ Link-Exe -Exe clang -LinkName cc
+ Link-Exe -Exe clang++ -LinkName c++
} elseif ($windows_host) {
Install-Package llvm
- echo (Join-Path $env:ProgramFiles LLVM bin) >> $env:GITHUB_PATH
+
+ $bin_dir = Join-Path $env:ProgramFiles LLVM bin
+ echo $bin_dir >> $env:GITHUB_PATH
+
+ Link-Exe -Exe (Join-Path $bin_dir clang) -LinkName cc
+ Link-Exe -Exe (Join-Path $bin_dir clang++) -LinkName c++
} else {
throw "Sorry, installing Clang is unsupported on $os"
}