From 0f4b96df94cac45f1cfd89787208a244f2dab6be Mon Sep 17 00:00:00 2001 From: Alexey-Ayupov <116575425+Alexey-Ayupov@users.noreply.github.com> Date: Tue, 4 Mar 2025 15:57:10 +0100 Subject: [PATCH] [Ubuntu] Add Ninja (#11706) --- images/ubuntu/scripts/build/install-ninja.sh | 17 ++++++++++++++ .../docs-gen/Generate-SoftwareReport.ps1 | 1 + .../docs-gen/SoftwareReport.Tools.psm1 | 4 ++++ images/ubuntu/scripts/tests/Tools.Tests.ps1 | 22 +++++++++++++++++++ images/ubuntu/templates/ubuntu-20.04.pkr.hcl | 3 ++- images/ubuntu/templates/ubuntu-22.04.pkr.hcl | 3 ++- images/ubuntu/templates/ubuntu-24.04.pkr.hcl | 3 ++- 7 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 images/ubuntu/scripts/build/install-ninja.sh diff --git a/images/ubuntu/scripts/build/install-ninja.sh b/images/ubuntu/scripts/build/install-ninja.sh new file mode 100644 index 000000000..3943505d8 --- /dev/null +++ b/images/ubuntu/scripts/build/install-ninja.sh @@ -0,0 +1,17 @@ +#!/bin/bash -e +################################################################################ +## File: install-ninja.sh +## Desc: Install ninja-build +################################################################################ + +# Source the helpers for use with the script +source $HELPER_SCRIPTS/install.sh + +# Install ninja +download_url=$(resolve_github_release_asset_url "ninja-build/ninja" "endswith(\"ninja-linux.zip\")" "latest") +ninja_binary_path=$(download_with_retry "${download_url}") + +# Unzip the ninja binary +unzip -qq "$ninja_binary_path" -d /usr/local/bin + +invoke_tests "Tools" "Ninja" diff --git a/images/ubuntu/scripts/docs-gen/Generate-SoftwareReport.ps1 b/images/ubuntu/scripts/docs-gen/Generate-SoftwareReport.ps1 index 962262335..9cbd19541 100644 --- a/images/ubuntu/scripts/docs-gen/Generate-SoftwareReport.ps1 +++ b/images/ubuntu/scripts/docs-gen/Generate-SoftwareReport.ps1 @@ -156,6 +156,7 @@ if ((Test-IsUbuntu20) -or (Test-IsUbuntu22)) { $tools.AddToolVersion("yamllint", $(Get-YamllintVersion)) $tools.AddToolVersion("yq", $(Get-YqVersion)) $tools.AddToolVersion("zstd", $(Get-ZstdVersion)) +$tools.AddToolVersion("Ninja", $(Get-NinjaVersion)) # CLI Tools $cliTools = $installedSoftware.AddHeader("CLI Tools") diff --git a/images/ubuntu/scripts/docs-gen/SoftwareReport.Tools.psm1 b/images/ubuntu/scripts/docs-gen/SoftwareReport.Tools.psm1 index b4656b779..33f4306aa 100644 --- a/images/ubuntu/scripts/docs-gen/SoftwareReport.Tools.psm1 +++ b/images/ubuntu/scripts/docs-gen/SoftwareReport.Tools.psm1 @@ -275,6 +275,10 @@ function Get-ZstdVersion { return "$zstdVersion" } +function Get-NinjaVersion { + return $(ninja --version) +} + function Get-YqVersion { $yqVersion = $(yq -V) | Get-StringPart -Part 3 return $yqVersion.TrimStart("v").Trim() diff --git a/images/ubuntu/scripts/tests/Tools.Tests.ps1 b/images/ubuntu/scripts/tests/Tools.Tests.ps1 index 54f02e72d..7b3da1346 100644 --- a/images/ubuntu/scripts/tests/Tools.Tests.ps1 +++ b/images/ubuntu/scripts/tests/Tools.Tests.ps1 @@ -411,3 +411,25 @@ Describe "Kotlin" { "kotlinc-js -version" | Should -ReturnZeroExitCode } } + +Describe "Ninja" { + New-item -Path "/tmp/ninjaproject" -ItemType Directory -Force + Set-Location '/tmp/ninjaproject' +@' +cmake_minimum_required(VERSION 3.10) +project(NinjaTest NONE) +'@ | Out-File -FilePath "./CMakeLists.txt" + + It "Make a simple ninja project" { + "cmake -GNinja /tmp/ninjaproject" | Should -ReturnZeroExitCode + } + + It "build.ninja file should exist" { + $buildFilePath = Join-Path "/tmp/ninjaproject" "build.ninja" + $buildFilePath | Should -Exist + } + + It "Ninja" { + "ninja --version" | Should -ReturnZeroExitCode + } +} diff --git a/images/ubuntu/templates/ubuntu-20.04.pkr.hcl b/images/ubuntu/templates/ubuntu-20.04.pkr.hcl index 8839e11c0..2025c727c 100644 --- a/images/ubuntu/templates/ubuntu-20.04.pkr.hcl +++ b/images/ubuntu/templates/ubuntu-20.04.pkr.hcl @@ -328,7 +328,8 @@ build { "${path.root}/../scripts/build/install-android-sdk.sh", "${path.root}/../scripts/build/install-pypy.sh", "${path.root}/../scripts/build/install-python.sh", - "${path.root}/../scripts/build/install-zstd.sh" + "${path.root}/../scripts/build/install-zstd.sh", + "${path.root}/../scripts/build/install-ninja.sh" ] } diff --git a/images/ubuntu/templates/ubuntu-22.04.pkr.hcl b/images/ubuntu/templates/ubuntu-22.04.pkr.hcl index 0af16d284..eb96bd314 100644 --- a/images/ubuntu/templates/ubuntu-22.04.pkr.hcl +++ b/images/ubuntu/templates/ubuntu-22.04.pkr.hcl @@ -324,7 +324,8 @@ build { "${path.root}/../scripts/build/install-android-sdk.sh", "${path.root}/../scripts/build/install-pypy.sh", "${path.root}/../scripts/build/install-python.sh", - "${path.root}/../scripts/build/install-zstd.sh" + "${path.root}/../scripts/build/install-zstd.sh", + "${path.root}/../scripts/build/install-ninja.sh" ] } diff --git a/images/ubuntu/templates/ubuntu-24.04.pkr.hcl b/images/ubuntu/templates/ubuntu-24.04.pkr.hcl index 9e2ba3810..f67b7f33d 100644 --- a/images/ubuntu/templates/ubuntu-24.04.pkr.hcl +++ b/images/ubuntu/templates/ubuntu-24.04.pkr.hcl @@ -313,7 +313,8 @@ provisioner "shell" { "${path.root}/../scripts/build/install-android-sdk.sh", "${path.root}/../scripts/build/install-pypy.sh", "${path.root}/../scripts/build/install-python.sh", - "${path.root}/../scripts/build/install-zstd.sh" + "${path.root}/../scripts/build/install-zstd.sh", + "${path.root}/../scripts/build/install-ninja.sh" ] }