aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2021-01-06 04:56:17 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2021-01-06 07:06:13 +0300
commita404df762f7859cd62eb88e90e38fe3442fe67d5 (patch)
treee4ef4b6001f363b2bb5b50c3d6244e031e324194
parentrefactoring (diff)
downloadsetup-clang-a404df762f7859cd62eb88e90e38fe3442fe67d5.tar.gz
setup-clang-a404df762f7859cd62eb88e90e38fe3442fe67d5.zip
setting up cc/converting symlinks is optional now
Diffstat (limited to '')
-rw-r--r--.github/workflows/test.yml4
-rw-r--r--action.yml107
2 files changed, 63 insertions, 48 deletions
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 7348cbe..5b0444d 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -56,6 +56,8 @@ jobs:
with:
platform: '${{ matrix.platform }}'
cygwin: '${{ matrix.cygwin }}'
+ cc: 1
+ hardlinks: 1
- name: Build foo.exe
run: |
@@ -87,9 +89,11 @@ jobs:
- name: Check cc/c++
run: |
+ echo (Get-Command cc).Path
$cc = & cc --version
echo $cc
$($cc | Select-String -Pattern "clang version" -SimpleMatch -Quiet) -or $(throw "Unexpected `cc --version` output")
+ echo (Get-Command c++).Path
$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 cec9ed1..c543523 100644
--- a/action.yml
+++ b/action.yml
@@ -10,6 +10,14 @@ inputs:
description: Install inside Cygwin
required: false
default: 0
+ cc:
+ description: Set up cc/c++ executables
+ required: false
+ default: 1
+ hardlinks:
+ description: On Cygwin, replace executable symlinks with hardlinks
+ required: false
+ default: 0
runs:
using: composite
@@ -19,7 +27,7 @@ runs:
New-Variable linux_host -Value ($os -eq 'Linux') -Option Constant
New-Variable cygwin_host -Value ('${{ inputs.cygwin }}' -eq '1') -Option Constant
- New-Variable windows_host -Value ($os -eq 'Windows' -and !$cygwin) -Option Constant
+ New-Variable windows_host -Value ($os -eq 'Windows' -and !$cygwin_host) -Option Constant
New-Variable x64 -Value ('${{ inputs.platform }}' -eq 'x64') -Option Constant
@@ -52,40 +60,6 @@ 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 -> $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
- }
- }
-
if ($linux_host) {
if ($x64) {
$pkgs = 'clang','g++','llvm'
@@ -116,8 +90,50 @@ runs:
} else {
throw "Sorry, installing Clang is unsupported on $os"
}
+ shell: pwsh
+
+ - run: |
+ New-Variable os -Value '${{ runner.os }}' -Option Constant
+
+ New-Variable linux_host -Value ($os -eq 'Linux') -Option Constant
+ New-Variable cygwin_host -Value ('${{ inputs.cygwin }}' -eq '1') -Option Constant
+ New-Variable windows_host -Value ($os -eq 'Windows' -and !$cygwin_host) -Option Constant
+
+ New-Variable cc -Value ('${{ inputs.cc }}' -eq '1') -Option Constant
- if ($cygwin_host) {
+ function Link-Exe {
+ param(
+ [Parameter(Mandatory=$true)]
+ [string] $Exe,
+ [Parameter(Mandatory=$true)]
+ [string] $LinkName
+ )
+
+ $exe_path = (Get-Command $Exe).Path
+ $link_dir = if ($script:windows_host) { Split-Path $exe_path } else { '/usr/local/bin' }
+ $link_name = if ($script:windows_host) { "$LinkName.exe" } else { $LinkName }
+ $link_path = if ($script:cygwin_host) { "$link_dir/$link_name" } else { Join-Path $link_dir $link_name }
+ echo "Creating link $link_path -> $exe_path"
+ if ($script:linux_host) {
+ sudo ln -f -s $exe_path $link_path
+ } elseif ($script:cygwin_host) {
+ ln.exe -f -s $exe_path $link_path
+ } elseif ($script:windows_host) {
+ New-Item -ItemType HardLink -Path $link_path -Value $exe_path -Force | Out-Null
+ }
+ }
+
+ if ($cc) {
+ Link-Exe clang cc
+ Link-Exe clang++ c++
+ }
+ shell: pwsh
+
+ - run: |
+ New-Variable cygwin_host -Value ('${{ inputs.cygwin }}' -eq '1') -Option Constant
+ New-Variable hardlinks -Value ('${{ inputs.hardlinks }}' -eq '1') -Option Constant
+
+ if ($cygwin_host -and $hardlinks) {
# clang/clang++ are Cygwin symlinks, pointing to clang-X.exe. It's
# convenient to make proper executables instead so that they can be
# called from Windows' command prompt.
@@ -132,20 +148,15 @@ runs:
[ "$link_ext" != "$dest_ext" ] && echo "${PATHEXT//\;/
}" | grep -q --ignore-case --line-regexp -F -- "$dest_ext" && link_path="$link_path$dest_ext"
echo "Creating hardlink $link_path -> $dest_path" && ln -- "$dest_path" "$link_path"
- done < <( find /usr/bin -type l -a '-(' -iname 'clang*' -o -iname 'llvm*' '-)' -print0 )
+ done < <( find /usr/local/bin /usr/bin \
+ -type l '-(' \
+ -path '/usr/bin/clang*' -o \
+ -path '/usr/bin/llvm*' -o \
+ -path /usr/local/bin/cc -o \
+ -path /usr/local/bin/c++ \
+ '-)' -print0 )
'@ | & bash.exe --login -o errexit -o nounset -o pipefail -o igncr
}
-
- if ($linux_host) {
- Link-Exe -Exe clang -LinkName cc
- Link-Exe -Exe clang++ -LinkName c++
- } elseif ($cygwin_host) {
- Link-Exe -Exe clang -LinkName cc
- Link-Exe -Exe clang++ -LinkName c++
- } elseif ($windows_host) {
- Link-Exe -Exe (Join-Path $bin_dir clang) -LinkName cc
- Link-Exe -Exe (Join-Path $bin_dir clang++) -LinkName c++
- }
shell: pwsh
branding: