tools/ci: Added CI system on Windows Native

This PR adds support for the CI system for native Windows as well. It allows you to build NuttX on GitHub and test it locally for Windows users.

With these CI tools with PowerShell scripts, it is possible to build NuttX for Windows Native using (for now only) Cmake + Ninja with the same logic as the CI system with Bash scripts.

This allows the msvc job to be used not only with the simulator (currently only with Visual Studio 17 2022), but also with other architectures using the same Windows runner to get more coverage and avoid future breakage.
As with the other jobs, we use artifacts to save the compilation result at the end of the workflow execution (previously for the simulator it was not done).

The proposed solution is based on the following additions and modified:

Modified Files
buildyml -> only CI Jobs MSVC

New Files in tools/
ci/cibuild.ps1 -> Added Powershell script for Run the CI Builds
ci/platforms/windows.ps1 -> Added Powershell script for installing toolchains and tools.
testlist/windows.dat -> Target (Add sim (msvc), risc-v arm)
tools/testbuild.ps1

We tested the NuttX build on GitHub and locally.

How we build on GitHub and test locally.

Locally
cd .\nuttx\tools\ci\

.\cibuild.ps1 -n -i -A -C -N .\testlist\windows.dat

Signed-off-by: simbit18 <simbit18@gmail.com>
This commit is contained in:
simbit18 2025-03-13 16:15:22 +01:00 committed by Lup Yuen Lee
parent f0f54be9f9
commit 34c4b15b4d
5 changed files with 1005 additions and 6 deletions

View File

@ -375,15 +375,16 @@ jobs:
7z x sources.tar.gz -y
7z x sources.tar -y
# Build the project using the given CMake commands
- name: Configure and build with CMake
- name: Run Builds
run: |
cd sources/nuttx
cmake -B vs2022 -DBOARD_CONFIG=sim/windows -G"Visual Studio 17 2022" -A Win32
cmake --build vs2022
"ARTIFACTDIR=${{github.workspace}}\sources\buildartifacts" >> $env:GITHUB_ENV
git config --global --add safe.directory ${{github.workspace}}\sources\nuttx
git config --global --add safe.directory ${{github.workspace}}\sources\apps
cd sources\nuttx\tools\ci
.\cibuild.ps1 -n -i -A -C -N testlist\windows.dat
- uses: actions/upload-artifact@v4
with:
name: msvc-builds
path: buildartifacts/
path: ./sources/buildartifacts/
continue-on-error: true

165
tools/ci/cibuild.ps1 Normal file
View File

@ -0,0 +1,165 @@
#!/usr/bin/env pswd
############################################################################
# tools/ci/cibuild.ps1
# PowerShell script for CI on Windows Native
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
# Set-PSDebug -Trace 0
Write-Host "===================================================================================="
$timestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss")
Write-Host "Start CI build: $timestamp" -ForegroundColor Yellow
Write-Host "------------------------------------------------------------------------------------"
$myname = $($MyInvocation.MyCommand.Name)
$CID = Get-Location
$CIWORKSPACE = Resolve-Path("$CID\..\..\..")
$CIPLAT = "$CIWORKSPACE\nuttx\tools\ci\platforms"
$nuttx = "$CIWORKSPACE\nuttx"
$apps = "$CIWORKSPACE\apps"
if ($IsWindows -or ($Env:OS -match '^($|(Windows )?Win)')) {
Write-Host "$ENV:OS"
}
else {
Write-Host "Not Windows"
}
function install_tools {
$NUTTXTOOLS = "$CIWORKSPACE\tools"
$env:NUTTXTOOLS = "$NUTTXTOOLS"
if (-not (Test-Path -Path $NUTTXTOOLS)) {
New-Item -ItemType Directory -Path $NUTTXTOOLS -Force > $null
}
$Pathps1 = "$CIPLAT\windows.ps1"
# Check if the file exists
if (Test-Path $Pathps1) {
try {
# Run the script
& $Pathps1
}
catch {
# Handle errors
Write-Host "An error occurred while executing the script: $_" -ForegroundColor Red
}
}
else {
Write-Host "The specified script does not exist: $Pathps1" -ForegroundColor Red
exit 1
}
}
# Function to display the help
function usage {
Write-Host ""
Write-Host "USAGE: $myname [-h] [-i] [-s] [-c] [-*] <testlist>"
Write-Host ""
Write-Host "Where:"
Write-Host " -i install tools"
Write-Host " -s setup repos"
Write-Host " -c enable ccache"
Write-Host " -* support all options in testbuild.ps1"
Write-Host " -h will show this help text and terminate"
Write-Host " <testlist> select testlist file"
Write-Host ""
exit 1
}
function enable_ccache {
# Currently for windows not needed
Write-Host "enable_ccache: to-do"
}
function setup_repos {
$oldpath = Get-Location
if (Test-Path $nuttx) {
Set-Location "$nuttx"
git pull
}
else {
git clone https://github.com/apache/nuttx.git "$nuttx"
Set-Location "$nuttx"
}
git log -1
if (Test-Path $apps) {
Set-Location "$apps"
git pull
}
else {
git clone https://github.com/apache/nuttx-apps.git "$apps"
Set-Location "$apps"
}
git log -1
Set-Location "$oldpath"
}
function run_builds {
if ($null -eq $builds) {
Write-Host "ERROR: Missing test list file" -ForegroundColor Yellow
usage
}
foreach ( $build in $builds ) {
& $nuttx\tools\testbuild.ps1 $options $build
}
}
$builds = @()
if (!$args[0]) {
usage
}
for ( $i = 0; $i -lt $args.count; $i++ ) {
switch -regex -casesensitive ($($args[$i])) {
'-h' {
usage
}
'-i' {
install_tools
continue
}
'-c' {
enable_ccache
continue
}
'-s' {
setup_repos
continue
}
{ $_ -like '-*' } {
$options += "$($args[$i]) "
continue
}
default {
$builds += $($args[$i])
}
}
}
# Main script execution
run_builds

View File

@ -0,0 +1,307 @@
#!/usr/bin/env pswd
############################################################################
# tools/ci/platforms/windows.ps1
# PowerShell script for CI on Windows Native
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
# Windows native
# Set-PSDebug -Trace 0
function add_path() {
param (
[string]$Path
)
if (!$Path) {
Write-Host "Error: add_path path file not found" -ForegroundColor Red
return
}
$envPaths = $env:Path -split ';'
if ($envPaths -notcontains $Path) {
Add-Content -Path "$NUTTXTOOLS\env.ps1" -Value "add_path $Path"
$env:PATH = "$Path;" + $env:PATH
}
}
function add_envpath {
param(
[string] $envfile
)
$head = @"
#!/usr/bin/env pswd
############################################################################
# env.ps1
# PowerShell script for CI on Windows Native
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
function add_path() {
param (
[string]`$Path
)
if (!`$Path) {
Write-Host "Error: add_path path file not found" -ForegroundColor Red
return
}
`$envPaths = `$env:Path -split ';'
if (`$envPaths -notcontains `$Path) {
`$env:PATH = "`$Path;" + `$env:PATH
}
}
"@
Add-Content -Path "$envfile" -Value "$head"
}
function arm_clang_toolchain {
Write-Host "Check ARM clang toolchain ..." -ForegroundColor Green
try {
if (run_command("clang") -ne 0) {
add_path "$NUTTXTOOLS\clang-arm-none-eabi\bin"
if (-not (Test-Path -Path "$NUTTXTOOLS\clang-arm-none-eabi\bin\clang.exe")) {
# Download the file
Write-Host "Download: ARM clang toolchain" -ForegroundColor Green
$basefile = "LLVMEmbeddedToolchainForArm-17.0.1-Windows-x86_64"
Set-Location "$NUTTXTOOLS"
# Download the latest ARM clang toolchain prebuilt by ARM
Invoke-WebRequest -Uri "https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/releases/download/release-17.0.1/$basefile.zip" -OutFile "$NUTTXTOOLS\$basefile.zip" -ErrorAction Stop
Expand-Archive "$NUTTXTOOLS\$basefile.zip"
Move-Item -Path "$basefile\$basefile" -Destination "clang-arm-none-eabi"
Remove-Item "$basefile*" -Force
}
}
clang --version
Write-Host ""
}
catch {
Write-Error "Failed to download the file: $_"
}
}
function arm_gcc_toolchain() {
Write-Host "Check ARM GCC toolchain toolchain ..." -ForegroundColor Green
try {
if (run_command("arm-none-eabi-gcc") -ne 0) {
add_path "$NUTTXTOOLS\gcc-arm-none-eabi\bin"
if (-not (Test-Path -Path "$NUTTXTOOLS\gcc-arm-none-eabi\bin\arm-none-eabi-gcc.exe")) {
# Download the file
Write-Host "Download: ARM GCC toolchain" -ForegroundColor Green
$basefile = "arm-gnu-toolchain-13.2.Rel1-mingw-w64-i686-arm-none-eabi"
Set-Location "$NUTTXTOOLS"
# Download the latest ARM GCC toolchain prebuilt by ARM
Invoke-WebRequest -Uri "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/$basefile.zip" -OutFile "$NUTTXTOOLS\$basefile.zip" -ErrorAction Stop
Expand-Archive "$NUTTXTOOLS\$basefile.zip"
Move-Item -Path "$basefile\$basefile" -Destination "gcc-arm-none-eabi"
Remove-Item "$basefile*" -Force
}
}
arm-none-eabi-gcc --version
}
catch {
Write-Error "Failed to download the file: $_"
}
}
function arm64_gcc_toolchain() {
Write-Host "Check ARM64 GCC toolchain toolchain ..." -ForegroundColor Green
try {
if (run_command("aarch64-none-elf-gcc") -ne 0) {
add_path "$NUTTXTOOLS\gcc-aarch64-none-elf\bin"
if (-not (Test-Path -Path "$NUTTXTOOLS\gcc-aarch64-none-elf\bin\aarch64-none-elf-gcc.exe")) {
# Download the file
Write-Host "Download: ARM64 GCC toolchain" -ForegroundColor Green
$basefile = "arm-gnu-toolchain-13.2.rel1-mingw-w64-i686-aarch64-none-elf"
Set-Location "$NUTTXTOOLS"
# Download the latest ARM64 GCC toolchain prebuilt by ARM
Invoke-WebRequest -Uri "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.Rel1/binrel/$basefile.zip" -OutFile "$NUTTXTOOLS\$basefile.zip" -ErrorAction Stop
Expand-Archive "$NUTTXTOOLS\$basefile.zip"
Move-Item -Path "$basefile\$basefile" -Destination "gcc-aarch64-none-elf"
Remove-Item "$basefile*" -Force
}
}
aarch64-none-elf-gcc --version
}
catch {
Write-Error "Failed to download the file: $_"
}
}
function cmake_tool {
Write-Host "Check Cmake ..." -ForegroundColor Green
if (run_command("cmake") -ne 0) {
add_path "$NUTTXTOOLS\cmake\bin"
if ($null -eq (Get-Command cmake -ErrorAction SilentlyContinue)) {
Write-Host "Download: Ninja package" -ForegroundColor Green
# Download the file
$basefile = "cmake-3.31.6-windows-x86_64"
Set-Location "$NUTTXTOOLS"
# Download tool cmake
Invoke-WebRequest -Uri "https://github.com/Kitware/CMake/releases/download/v3.31.6/$basefile.zip" -OutFile "$NUTTXTOOLS\$basefile.zip" -ErrorAction Stop
Expand-Archive "$NUTTXTOOLS\$basefile.zip"
Move-Item -Path "$basefile" -Destination "cmake"
Remove-Item "$basefile*" -Force
}
}
cmake --version
}
function kconfig_frontends() {
Write-Host "Check kconfig-frontends ..." -ForegroundColor Green
add_path "$NUTTXTOOLS\kconfig-frontends\bin"
try {
if (-not (Test-Path -Path "$NUTTXTOOLS\kconfig-frontends\bin\kconfig-conf.exe")) {
# Download the file
Write-Host "Download: kconfig-frontends package" -ForegroundColor Green
$basefile = "kconfig-frontends-windows-mingw64"
Set-Location "$NUTTXTOOLS"
# Download the kconfig-frontends prebuilt
Invoke-WebRequest -Uri "https://github.com/simbit18/kconfig-frontends-windows-mingw64/releases/download/kconfig-frontends-4.11.0/$basefile.zip" -OutFile "$NUTTXTOOLS\$basefile.zip" -ErrorAction Stop
Expand-Archive "$NUTTXTOOLS\$basefile.zip"
Move-Item -Path "$basefile\$basefile" -Destination "kconfig-frontends"
Remove-Item "$basefile*" -Force
Write-Host "File downloaded successfully to kconfig-frontends"
}
}
catch {
Write-Error "Failed to download the file: $_"
}
}
function ninja_tool {
Write-Host "Check Ninja ..." -ForegroundColor Green
if (run_command("ninja") -ne 0) {
add_path "$NUTTXTOOLS\ninja"
if ($null -eq (Get-Command ninja -ErrorAction SilentlyContinue)) {
Write-Host "Download: Ninja package" -ForegroundColor Green
# Download the file
$basefile = "ninja-win"
Set-Location "$NUTTXTOOLS"
# Download tool ninja
Invoke-WebRequest -Uri "https://github.com/ninja-build/ninja/releases/download/v1.12.1/$basefile.zip" -OutFile "$NUTTXTOOLS\$basefile.zip" -ErrorAction Stop
Expand-Archive "$NUTTXTOOLS\$basefile.zip" # -DestinationPath "$basefile"
Move-Item -Path "$basefile" -Destination "ninja"
Remove-Item "$basefile*" -Force
}
}
ninja --version
Write-Host ""
}
function riscv_gcc_toolchain() {
Write-Host "Check RISCV GCC toolchain ..." -ForegroundColor Green
add_path "$NUTTXTOOLS\riscv-none-elf-gcc\bin"
try {
if (run_command("riscv-none-elf-gcc") -ne 0) {
add_path "$NUTTXTOOLS\riscv-none-elf-gcc\bin"
if (-not (Test-Path -Path "$NUTTXTOOLS\riscv-none-elf-gcc\bin\riscv-none-elf-gcc.exe")) {
Write-Host "Download: RISCV GCC toolchain" -ForegroundColor Green
$basefile = "xpack-riscv-none-elf-gcc-13.2.0-2-win32-x64"
Set-Location "$NUTTXTOOLS"
# Download the latest RISCV GCC toolchain prebuilt by xPack
Invoke-WebRequest -Uri "https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v13.2.0-2/$basefile.zip" -OutFile "$NUTTXTOOLS\$basefile.zip" -ErrorAction Stop
Expand-Archive "$NUTTXTOOLS\$basefile.zip"
Move-Item -Path "$basefile\xpack-riscv-none-elf-gcc-13.2.0-2" -Destination "riscv-none-elf-gcc"
Remove-Item "$basefile*" -Force
}
}
riscv-none-elf-gcc --version
}
catch {
Write-Error "Failed to download the file: $_"
}
}
# GitHub Actions runners already have rustup installed
function rust() {
Write-Host "Check Rust ..."
if (run_command("rustc") -ne 0) {
add_path "$NUTTXTOOLS\rust\cargo\bin"
# Configuring the PATH environment variable
$env:CARGO_HOME = "$NUTTXTOOLS\rust\cargo"
$env:RUSTUP_HOME = "$NUTTXTOOLS\rust\rustup"
Add-Content -Path "$NUTTXTOOLS\env.ps1" -Value "CARGO_HOME=$NUTTXTOOLS\rust\cargo"
Add-Content -Path "$NUTTXTOOLS\env.ps1" -Value "RUSTUP_HOME=$NUTTXTOOLS\rust\rustup"
if ($null -eq (Get-Command rustc -ErrorAction SilentlyContinue)) {
Write-Host "Download: Rust package" -ForegroundColor Green
# Download the file
$basefile = "x86_64-pc-windows-gnu"
New-Item -ItemType Directory -Path "$NUTTXTOOLS\rust" -Force
Set-Location "$NUTTXTOOLS"
# Download tool rustup-init.exe
Invoke-WebRequest -Uri https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-gnu/rustup-init.exe -OutFile "rustup-init.exe" -ErrorAction Stop
# Install Rust target x86_64-pc-windows-gnu
cmd /c start /wait rustup-init.exe -y --default-host $basefile --no-modify-path
# Install targets supported from NuttX
cmd /c start /wait rustup.exe target add thumbv6m-none-eabi
cmd /c start /wait rustup.exe target add thumbv7m-none-eabi
cmd /c start /wait rustup.exe target add riscv64gc-unknown-none-elf
Remove-Item rustup-init.exe -Force
}
}
rustc --version
}
function run_command ($command) {
if ($null -eq (Get-Command "$command" -ErrorAction SilentlyContinue)) {
return 1
}
else {
return 0
}
}
function install_build_tools {
if (-not (Test-Path -Path "$NUTTXTOOLS\env.ps1")) {
add_envpath "$NUTTXTOOLS\env.ps1"
}
$install = "arm_clang_toolchain arm_gcc_toolchain arm64_gcc_toolchain riscv_gcc_toolchain cmake_tool kconfig_frontends ninja_tool"
$splitArray = $install.Split(" ")
$oldpath = Get-Location
foreach ( $node in $splitArray ) {
& $node
}
Set-Location "$oldpath"
}
install_build_tools

View File

@ -0,0 +1,26 @@
# Choose a subset of board/configs due to Windows native builds
# ARM
/arm/stm32/nucleo-l152re/configs/nsh,CONFIG_ARM_TOOLCHAIN_GNU_EABI
/arm/stm32/nucleo-f411re/configs/nsh,CONFIG_ARM_TOOLCHAIN_CLANG
# ARM64
# /arm64/qemu/qemu-armv8a/configs/nsh_smp
# RISC-V
/risc-v/qemu-rv/rv-virt/configs/nsh
# The simulator currently builds only with Visual Studio 2022
/sim/sim/sim/configs/windows
# Boards build by CMake
CMake,nucleo-l152re:nsh
CMake,nucleo-f411re:nsh
CMake,rv-virt:nsh
CMake,sim:windows

500
tools/testbuild.ps1 Normal file
View File

@ -0,0 +1,500 @@
#!/usr/bin/env pswd
############################################################################
# tools/testbuild.ps1
# PowerShell script for CI on Windows Native
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
# Set-PSDebug -Trace 0
$progname = $($MyInvocation.MyCommand.Name)
$WD = Resolve-Path("Get-Location\..\..\..\..")
$nuttx = "$WD\nuttx"
$global:fail = 0
$APPSDIR = "$WD\apps"
if ($null -eq $ARTIFACTDIR) {
$ARTIFACTDIR = "$WD\buildartifacts"
}
$PRINTLISTONLY = 0
$GITCLEAN = 0
$SAVEARTIFACTS = 0
$CHECKCLEAN = 1
$CODECHECKER = 0
$NINJACMAKE = 0
$RUN = 0
$MSVC = 0
function showusage {
Write-Host ""
Write-Host "USAGE: $progname -h [-n] [-A] [-G] [-N]"
Write-Host "Where:"
Write-Host " -h will show this help test and terminate"
Write-Host " -n selects Windows native"
Write-Host " -p only print the list of configs without running any builds"
Write-Host " -A store the build executable artifact in ARTIFACTDIR (defaults to ../buildartifacts"
Write-Host " -C Skip tree cleanness check."
Write-Host " -G Use `"git clean -xfdq`" instead of `"make distclean`" to clean the tree."
Write-Host " -N Use CMake with Ninja as the backend."
Write-Host " <testlist-file> selects the list of configurations to test. No default"
Write-Host ""
exit 1
}
# Define a function to search for Visual Studio 2022 installation
function Find-VisualStudio {
# Check common installation paths
$commonPaths = @(
"C:\Program Files\Microsoft Visual Studio\2022\Community",
"C:\Program Files\Microsoft Visual Studio\2022\Professional",
"C:\Program Files\Microsoft Visual Studio\2022\Enterprise"
)
foreach ($path in $commonPaths) {
if (Test-Path $path) {
$MSVC = 1
}
}
if ($MSVC -eq 1) {
Write-Host "Found Visual Studio 2022 installations"
return $MSVC = 1
}
else {
Write-Host "Visual Studio 2022 is not installed on this system."
return $MSVC = 0
}
}
$MSVC = Find-VisualStudio
if (!$args[0]) {
showusage
}
for ( $i = 0; $i -lt $args.count; $i++ ) {
switch -regex -casesensitive ($($args[$i])) {
'-h' {
showusage
}
'-p' {
$PRINTLISTONLY = 1
}
'-G' {
$GITCLEAN = 1
}
'-A' {
$SAVEARTIFACTS = 1
}
'-C' {
$CHECKCLEAN = 0
}
'-N' {
$NINJACMAKE = 1
}
default {
Write-Host "File $($args[$i])" -ForegroundColor Green
$testfile = $($args[$i])
}
}
}
# Check if testfile file exists
if (-not (Test-Path -Path "$testfile")) {
Write-Host "ERROR: Missing test list file" -ForegroundColor Red
showusage
}
# Check if nuttx directory exists
if (-Not (Test-Path -Path $nuttx)) {
Write-Host "ERROR: Expected to find nuttx/ at $nuttx" -ForegroundColor Red
showusage
}
# Check if apps directory exists
if (-Not (Test-Path -Path $APPSDIR)) {
Write-Host "ERROR: No directory found at $APPSDIR" -ForegroundColor Red
exit 1
}
$patternallitem = '^(-|\\)|^[C|c][M|m][A|a][K|k][E|e]'
$patterntestlist = '^\\'
$patternblacklist = '^-'
if ($NINJACMAKE -eq 1) {
$patterncmakelist = '^[C|c][M|m][A|a][K|k][E|e][,]'
}
$content = Get-Content .\$testfile
$content = $content -replace '/', '\'
Set-Location "$nuttx"
$listfull = $content | Select-String $patternallitem -AllMatches
$testlist = $listfull | Select-String $patterntestlist -AllMatches
$blacklist = $listfull | Select-String $patternblacklist -AllMatches
if ($NINJACMAKE -eq 1) {
$cmakelist = $listfull | Select-String $patterncmakelist -AllMatches
}
# Clean up after the last build
function distclean {
Write-Host " Cleaning..."
if ((Test-Path ".config") -or (Test-Path "build\.config")) {
if (($GITCLEAN -eq 1) -or ($cmake)) {
git -C $nuttx clean -xfdq
git -C $APPSDIR clean -xfdq
}
else {
# Remove .version manually because this file is shipped with
# the release package and then distclean has to keep it.
if ($CHECKCLEAN -ne 0) {
if ((Test-Path -Path "$nuttx\.git") -or (Test-Path -Path "$APPSDIR\.git")) {
try {
if (git -C $nuttx status --ignored -s 2>$null) {
git -C $nuttx status --ignored -s
$global:fail = 1
}
if (git -C $APPSDIR status --ignored -s 2>$null) {
git -C $APPSDIR status --ignored -s
$global:fail = 1
}
}
catch {
Write-Host "Git is not installed. Please install Git to use this script." -ForegroundColor Red
$global:fail = 1
}
}
}
}
}
}
function run_command ($command) {
invoke-expression "$command" *>$null
Write-Host "run_command $_"
return $_
}
function configure_cmake {
# Run CMake with specified configurations
try {
$tmpconfig = $config -replace '\\', ':'
# cmake -B vs2022 -DBOARD_CONFIG=sim/windows -G"Visual Studio 17 2022" -A Win32
# cmake --build vs2022
if (($tmpconfig -match "windows") -and ($MSVC -eq 1)) {
if (cmake -B build -DBOARD_CONFIG="$tmpconfig" -G"Visual Studio 17 2022" -A Win32 1>$null) {
cmake -B build -DBOARD_CONFIG="$tmpconfig" -G"Visual Studio 17 2022" -A Win32
$global:fail = 1
}
}
else {
if (cmake -B build -DBOARD_CONFIG="$tmpconfig" -GNinja 1> $null) {
cmake -B build -DBOARD_CONFIG="$tmpconfig" -GNinja
Write-Host "cmake -B build -DBOARD_CONFIG=$tmpconfig -GNinja"
$global:fail = 1
}
}
Write-Host " CMake configuration completed successfully."
}
catch {
Write-Host " CMake configuration failed: $_"
$global:fail = 1
}
if ($toolchain) {
$patternallitem = '_TOOLCHAIN_'
$contentconfig = Get-Content "$nuttx\build\.config"
$listtoolchain = $contentconfig | Select-String $patternallitem -AllMatches
$listtoolchain = $listtoolchain | Select-String 'CONFIG_TOOLCHAIN_WINDOWS', 'CONFIG_ARCH_TOOLCHAIN_*' -NotMatch | Select-String '=y' -AllMatches
$toolchainarr = $listtoolchain -split '='
$original_toolchain = $($toolchainarr[0])
if ($original_toolchain) {
Write-Host " Disabling $original_toolchain"
kconfig-tweak.ps1 --file "$nuttx\build\.config" -d $original_toolchain
}
Write-Host " Enabling $toolchain"
kconfig-tweak.ps1 --file "$nuttx\build\.config" -e $toolchain
}
}
function configure {
Write-Host " Configuring..."
if ($cmake) {
configure_cmake
}
else {
# configure_default to-do
Write-Host " configure_default" -ForegroundColor Green
}
}
# Perform the next build
function build_default {
# make build_default to-do
}
function build_cmake {
# Build the project
try {
if (cmake --build build 1> $null) {
cmake --build build
$global:fail = 1
}
Write-Host " Build completed successfully."
}
catch {
Write-Error "Build failed: $_"
$global:fail = 1
}
if ($SAVEARTIFACTS -eq 1) {
$artifactconfigdir = "$ARTIFACTDIR\$config"
# Write-Host "Copy in artifactconfigdir: $artifactconfigdir"
New-Item -Force -ItemType directory -Path $artifactconfigdir > $null
try {
$contentmanifest = $null
$contentmanifest = Get-Content "$nuttx\build\nuttx.manifest"
$tmpconfig = $config -replace '\\', ':'
if (($tmpconfig -match "windows") -and ($MSVC -eq 1)) {
Copy-Item -Path "$nuttx\build\Debug\nuttx.exe" -Destination $artifactconfigdir -Force -ErrorAction Stop
Copy-Item -Path "$nuttx\build\Debug\nuttx.pdb" -Destination $artifactconfigdir -Force -ErrorAction Stop
}
else {
foreach ($ma in $contentmanifest) {
Copy-Item -Path "$nuttx\build\$ma" -Destination $artifactconfigdir -Force -ErrorAction Stop
}
}
}
catch {
Write-Host " An error occurred while copying files: $_" -ForegroundColor Red
}
}
}
function build {
Write-Host " Building NuttX..."
if ($cmake) {
Write-Host " build_cmake" -ForegroundColor Green
build_cmake
}
else {
# make build_default to-do
Write-Host " build_default to-do" -ForegroundColor Green
}
}
function refresh_default {
# make refresh_default to-do
}
function refresh_cmake {
# Ensure defconfig in the canonical form
if ($toolchain) {
if ($original_toolchain) {
kconfig-tweak.ps1 --file "$nuttx\build\.config" -e $original_toolchain
}
kconfig-tweak.ps1 --file "$nuttx\build\.config" -d $toolchain
}
try {
if (cmake --build build -t refreshsilent 1> $null) {
cmake --build build -t refreshsilent
$global:fail = 1
}
Write-Host " Refresh completed successfully."
}
catch {
Write-Error "refresh failed: $_"
$global:fail = 1
}
try {
Remove-Item build -Recurse -Force
}
catch {
Write-Error "Remove-Item failed: $_"
}
# Ensure nuttx and apps directory in clean state
if ($CHECKCLEAN -ne 0) {
if ((Test-Path -Path "$nuttx\.git") -or (Test-Path -Path "$APPSDIR\.git")) {
try {
if (git -C $nuttx status -s 2> $null) {
Write-Host "Git $nuttx status " -ForegroundColor Yellow
git -C $nuttx status -s
$global:fail = 1
}
if (git -C $APPSDIR status -s 2> $null) {
Write-Host "Git $APPSDIR status " -ForegroundColor Yellow
git -C $APPSDIR status -s
$global:fail = 1
}
}
catch {
Write-Host "Git is not installed. Please install Git to use this script." -ForegroundColor Red
$global:fail = 1
}
}
}
# Use -f option twice to remove git sub-repository
git -C $nuttx clean -f -xfdq
git -C $APPSDIR clean -f -xfdq
}
function refresh {
if ($cmake) {
refresh_cmake
}
else {
# make refresh_default to-do
}
}
function run {
# run to-do
}
# Coordinate the steps for the next build test
function dotest {
param (
[string]$configfull
)
Write-Host "===================================================================================="
$configarr = $configfull -split ','
$config = $($configarr[0])
$check = "Windows," + $config -replace '\\', ':'
$skip = 0
foreach ($re in $blacklist) {
if ("-$check" -eq "$re") {
$skip = 1
}
}
$cmake = $null
if ($NINJACMAKE -eq 1) {
foreach ($l in $cmakelist) {
if ("Cmake," + $config -replace '\\', ':' -eq "$l") {
$cmake = 1
}
}
}
Write-Host "Configuration/Tool: $configfull" -ForegroundColor Yellow
if ($PRINTLISTONLY -eq 1) {
return
}
$tmparr = $config -split '\\'
$configdir = $($tmparr[1])
$boarddir = $($tmparr[0]).Trim()
if (($boarddir -eq "sim") -and ($MSVC -ne 1)) {
$skip = 1
}
$path = "$nuttx\boards\*\*\$boarddir\configs\$configdir"
if (-Not (Test-Path -Path $path)) {
Write-Host "ERROR: no configuration found at $path" -ForegroundColor Red
showusage
}
$toolchain = $null
$original_toolchain = $null
if ($config -ne $configfull) {
$toolchain = $($configarr[1])
}
Write-Host (Get-Date).ToString("yyyy-MM-dd HH:mm:ss") -ForegroundColor Yellow
Write-Host "------------------------------------------------------------------------------------"
distclean
if ($skip -ne 1 ) {
configure
build
refresh
}
else {
Write-Host " Skipping: $config" -ForegroundColor Green
}
}
foreach ($line in $testlist) {
$firstch = [string[]]$line | ForEach-Object { $_[0] }
$arr = $line -split ','
if ($firstch -eq '\') {
$dir = $arr
if (!$dir[1]) {
$cnftoolchain = ""
}
else {
$cnftoolchain = "," + $dir[1]
}
$filePath = Get-ChildItem -Path "boards$($dir[0])" -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.Name -eq "defconfig" }
if ($filePath) {
foreach ($i in $filePath) {
$arrpath = $($i.FullName) -split '\\'
$list = "$($arrpath[$arrpath.count - 4])\$($arrpath[$arrpath.count - 2])"
dotest "$list$cnftoolchain"
}
}
else {
Write-Host "File '$FileName' not found in '$list'." -ForegroundColor Yellow
}
}
else {
dotest "$line"
}
}
Write-Host "===================================================================================="
exit $global:fail