From 2113853bafe637a55a531498f63158dacf11320a Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 2 Jan 2021 07:55:53 +0300 Subject: set up cc/c++ executables --- .github/workflows/test.yml | 10 ++++++++++ action.yml | 41 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ffffe70..2dcc535 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -85,3 +85,13 @@ jobs: Unexpected output: $actual "@) + + # Is this really the most stable piece of `gcc --version` output? + - name: Check cc/c++ + run: | + $cc = & cc --version + echo $cc + $($cc | Select-String -Pattern "This is free software; see the source for copying conditions." -SimpleMatch -Quiet) -or $(throw "Unexpected `cc --version` output") + $cxx = & c++ --version + echo $cxx + $($cxx | Select-String -Pattern "This is free software; see the source for copying conditions." -SimpleMatch -Quiet) -or $(throw "Unexpected `c++ --version` output") diff --git a/action.yml b/action.yml index b05f777..8b2a038 100644 --- a/action.yml +++ b/action.yml @@ -14,8 +14,7 @@ inputs: runs: using: composite steps: - - id: setup - run: | + - run: | New-Variable os -Value '${{ runner.os }}' -Option Constant New-Variable linux_host -Value ($os -eq 'Linux') -Option Constant @@ -33,6 +32,38 @@ runs: } } + function Make-Link { + param( + [Parameter(Mandatory=$true)] + [string] $ExeName, + [Parameter(Mandatory=$true)] + [string] $LinkName + ) + + $exe_path = (Get-Command $ExeName).Path + $exe_dir = Split-Path $exe_path + $exe_name = Split-Path $exe_path -Leaf + if (!$exe_name.StartsWith($ExeName)) { + throw "'$exe_name' must start with '$ExeName'" + } + $ext = $exe_name.Substring($ExeName.Length) + + $link_dir = if ($script:linux_host) { '/usr/local/bin' } else { $exe_dir } + $link_name = $LinkName + $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 + } + } + if ($linux_host) { sudo apt update if ($x64) { @@ -40,6 +71,9 @@ runs: } else { sudo apt install -y g++-multilib } + + Make-Link -Exe gcc -LinkName cc + Make-Link -Exe g++ -LinkName c++ } elseif ($cygwin_host) { if (!$x64) { echo @' @@ -51,6 +85,9 @@ runs: } $choco = Locate-Choco & $choco install -y --no-progress --source=cygwin gcc-g++ + + Make-Link -Exe gcc -LinkName cc + Make-Link -Exe g++ -LinkName c++ } elseif ($windows_host) { # TODO: use setup-mingw when calling composite actions within # composite actions is implemented. -- cgit v1.2.3