Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gcc, gfortran and clang on Windows and Ubuntu images #369

Merged
merged 7 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
68 changes: 49 additions & 19 deletions images/linux/scripts/installers/clang.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,61 @@
#!/bin/bash
################################################################################
## File: example.sh
## Desc: This is an example script that can be copied to add a new software
## installer to the image
## File: clang.sh
## Desc: Installs Clang compiler (versions: 6, 8 and 9)
################################################################################

# Source the helpers for use with the script
source $HELPER_SCRIPTS/document.sh
source $HELPER_SCRIPTS/apt.sh

function InstallClang {
version=$1

echo "Installing clang-$version..."
# Clang 6.0 is not supported by automatic installation script (`llvm.sh`)
# Thus we have to install it explicitly
if [[ $version == 6* ]]; then
apt-get install -y "clang-$version" "lldb-$version" "lld-$version"
else
./llvm.sh $version
fi

# Run tests to determine that the software installed as expected
echo "Testing to make sure that script performed as expected, and basic scenarios work"
for cmd in clang-$version clang++-$version; do
if ! command -v $cmd; then
echo "$cmd was not installed"
exit 1
fi
done

# Document what was added to the image
echo "Documenting clang-$version..."
DocumentInstalledItem "Clang $version ($(clang-$version --version | head -n 1 | cut -d ' ' -f 3 | cut -d '-' -f 1))"
}

# Install Clang compiler
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
apt-add-repository "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-6.0 main"
apt-get update
apt-get install -y clang-6.0 lldb-6.0 lld-6.0

update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-6.0 100
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-6.0 100

# Run tests to determine that the software installed as expected
echo "Testing to make sure that script performed as expected, and basic scenarios work"
for cmd in clang clang++ clang-6.0 clang++-6.0; do
if ! command -v $cmd; then
echo "$cmd was not installed"
exit 1
fi
apt-get update -y

# Download script for automatic installation
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh

versions=(
"6.0"
"8"
"9"
)

for version in ${versions[*]}
do
InstallClang $version
done

# Document what was added to the image
echo "Lastly, documenting what we added to the metadata file"
DocumentInstalledItem "Clang 6.0 ($(clang-6.0 --version | head -n 1 | sed 's/~/\\~/g'))"
rm llvm.sh

# Make Clang 9 default
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-9 100
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-9 100
38 changes: 27 additions & 11 deletions images/linux/scripts/installers/gcc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,35 @@
# Source the helpers for use with the script
source $HELPER_SCRIPTS/document.sh

function InstallGcc {
version=$1

echo "Installing $version..."
apt-get install $version -y

# Run tests to determine that the software installed as expected
echo "Testing to make sure that script performed as expected, and basic scenarios work"
if ! command -v $version; then
echo "$version was not installed"
exit 1
fi

# Document what was added to the image
echo "Documenting $version..."
DocumentInstalledItem "GNU C++ $($version --version | head -n 1 | cut -d ' ' -f 4)"
}

# Install GNU C++ compiler
add-apt-repository ppa:ubuntu-toolchain-r/test -y
apt-get update -y
apt-get install g++-7 -y


# Run tests to determine that the software installed as expected
echo "Testing to make sure that script performed as expected, and basic scenarios work"
if ! command -v g++-7; then
echo "GNU C++ was not installed"
exit 1
fi
versions=(
"g++-7"
"g++-8"
"g++-9"
)

# Document what was added to the image
echo "Lastly, documenting what we added to the metadata file"
DocumentInstalledItem "GNU C++ $(g++-7 --version | head -n 1 | cut -d ' ' -f 4)"
for version in ${versions[*]}
do
InstallGcc $version
done
40 changes: 40 additions & 0 deletions images/linux/scripts/installers/gfortran.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
################################################################################
## File: gfortran.sh
## Desc: Installs GNU Fortran
################################################################################

# Source the helpers for use with the script
source $HELPER_SCRIPTS/document.sh

function InstallFortran {
version=$1

echo "Installing $version..."
apt-get install $version -y

# Run tests to determine that the software installed as expected
echo "Testing to make sure that script performed as expected, and basic scenarios work"
if ! command -v $version; then
echo "$version was not installed"
exit 1
fi

# Document what was added to the image
echo "Documenting $version..."
DocumentInstalledItem "GNU Fortran $($version --version | head -n 1 | cut -d ' ' -f 5)"
}

# Install GNU Fortran compiler
add-apt-repository ppa:ubuntu-toolchain-r/test -y
apt-get update -y

versions=(
"gfortran-8"
"gfortran-9"
)

for version in ${versions[*]}
do
InstallFortran $version
done
1 change: 1 addition & 0 deletions images/linux/ubuntu1604.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
"{{template_dir}}/scripts/installers/erlang.sh",
"{{template_dir}}/scripts/installers/firefox.sh",
"{{template_dir}}/scripts/installers/gcc.sh",
"{{template_dir}}/scripts/installers/gfortran.sh",
"{{template_dir}}/scripts/installers/git.sh",
"{{template_dir}}/scripts/installers/1604/go.sh",
"{{template_dir}}/scripts/installers/google-chrome.sh",
Expand Down
1 change: 1 addition & 0 deletions images/linux/ubuntu1804.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
"{{template_dir}}/scripts/installers/erlang.sh",
"{{template_dir}}/scripts/installers/firefox.sh",
"{{template_dir}}/scripts/installers/gcc.sh",
"{{template_dir}}/scripts/installers/gfortran.sh",
"{{template_dir}}/scripts/installers/git.sh",
"{{template_dir}}/scripts/installers/1804/go.sh",
"{{template_dir}}/scripts/installers/google-chrome.sh",
Expand Down
12 changes: 12 additions & 0 deletions images/win/Windows2016-Azure.json
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,12 @@
"{{ template_dir }}/scripts/Installers/Install-MinGW.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Install-Clang.ps1"
]
},
{
"type": "powershell",
"scripts":[
Expand Down Expand Up @@ -727,6 +733,12 @@
"{{ template_dir }}/scripts/Installers/Validate-MinGW.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-Clang.ps1"
]
},
{
"type": "powershell",
"scripts":[
Expand Down
12 changes: 12 additions & 0 deletions images/win/Windows2019-Azure.json
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,12 @@
"{{ template_dir }}/scripts/Installers/Install-MinGW.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Install-Clang.ps1"
]
},
{
"type": "powershell",
"scripts":[
Expand Down Expand Up @@ -702,6 +708,12 @@
"{{ template_dir }}/scripts/Installers/Validate-MinGW.ps1"
]
},
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-Clang.ps1"
]
},
{
"type": "powershell",
"scripts":[
Expand Down
6 changes: 6 additions & 0 deletions images/win/scripts/Installers/Install-Clang.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
################################################################################
## File: Install-Clang.ps1
## Desc: Install Clang compiler as a part of LLVM framework for Windows
################################################################################

choco install -y llvm
46 changes: 46 additions & 0 deletions images/win/scripts/Installers/Validate-Clang.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
################################################################################
## File: Validate-Clang.ps1
## Desc: Validate Clang installation
################################################################################

if (Get-Command -Name 'clang')
{
Write-Host "clang is successfully installed:"
clang --version | Write-Host
}
else
{
Write-Host "clang is not on PATH"
exit 1
}

if (Get-Command -Name 'clang++')
{
Write-Host "clang++ is successfully installed:"
clang++ --version | Write-Host
}
else
{
Write-Host "clang++ is not on PATH"
exit 1
}

# Adding description of the software to Markdown

# `clang --version` gives output like:
# clang version 9.0.0 (tags/RELEASE_900/final)
# Target: x86_64-pc-windows-msvc
# Thread model: posix
# InstalledDir: C:\Program Files\LLVM\bin

$SoftwareName = "Clang"
$(clang --version).Split([System.Environment]::NewLine)[0] -match "\d+\.\d+\.\d+"
$Version = $matches[0]

$Description = @"
_Version:_ $Version<br/>
_Environment:_
* PATH: contains location of the LLVM 'bin' directory
"@

Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description