From cb49f6a8e05b4aeedc55ce25741c38e0bec2ff98 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 7 Jan 2021 12:59:33 +0300 Subject: setting up cc is optional now The better version of Link-Exe routine have been copied from setup-clang. --- action.yml | 81 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 41 insertions(+), 40 deletions(-) (limited to 'action.yml') diff --git a/action.yml b/action.yml index 0b220e0..ec7170c 100644 --- a/action.yml +++ b/action.yml @@ -10,6 +10,10 @@ inputs: description: Install inside Cygwin required: false default: 0 + cc: + description: Set up cc/c++ executables + required: false + default: 1 runs: using: composite @@ -52,46 +56,9 @@ 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 - } - } - if ($linux_host) { $pkg = if ($x64) { 'g++' } else { 'g++-multilib' } Install-Package $pkg - - Link-Exe -Exe gcc -LinkName cc - Link-Exe -Exe g++ -LinkName c++ } elseif ($cygwin_host) { if (!$x64) { echo @' @@ -103,9 +70,6 @@ runs: } Install-Package gcc-g++ - - Link-Exe -Exe gcc -LinkName cc - Link-Exe -Exe g++ -LinkName c++ } elseif ($windows_host) { # TODO: use setup-mingw when calling composite actions within # composite actions is implemented. @@ -119,6 +83,43 @@ runs: } 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 + + 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 gcc cc + Link-Exe g++ c++ + } + shell: pwsh + branding: icon: star color: green -- cgit v1.2.3