Skip to content

Commit

Permalink
ci/windows: code cleanup, fix typo
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Stanea <[email protected]>
  • Loading branch information
Adrian-Stanea committed Nov 16, 2023
1 parent c29e247 commit b244959
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 147 deletions.
3 changes: 1 addition & 2 deletions CI/windows/create_installer.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$ErrorActionPreference = "Stop"
$ErrorView = "NormalView"

$SRC_DIR = Get-Location
$SRC_DIR = Get-Item -Path $env:BUILD_SOURCESDIRECTORY # path to repo

function Get-Dll-Paths() {
$vsPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
Expand Down Expand Up @@ -30,7 +30,6 @@ function Get-Dll-Paths() {
return $result
}


Set-Location $SRC_DIR

$ddlPaths = Get-Dll-Paths
Expand Down
4 changes: 2 additions & 2 deletions CI/windows/create_zips.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ $COMPILER = $Env:COMPILER
$ARCH = $Env:ARCH
$PLATFORM = "win64"

$SRC_DIR = Get-Location
$SRC_DIR = Get-Item -Path $env:BUILD_SOURCESDIRECTORY # path to repo
$BUILD_DIR = Join-Path $SRC_DIR "build-$PLATFORM\dist"

$OUTSIDE_BUILD = [System.IO.Path]::GetDirectoryName($SRC_DIR.Path)
$OUTSIDE_BUILD = $SRC_DIR.Parent.FullName
$DEST_LIBM2K = Join-Path $OUTSIDE_BUILD "libm2k-$PLATFORM"
$DEST_LIBM2K_DIST = Join-Path $DEST_LIBM2K "dist$PLATFORM"

Expand Down
160 changes: 65 additions & 95 deletions CI/windows/install_deps.ps1
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
$ErrorActionPreference = "Stop"
$ErrorView = "NormalView"

# NOTE: this is needed for the Invoke-WebRequest to work
# [Net.ServicePointManager]::SecurityProtocol = "Tls, Tls11, Tls12, Ssl3"

$COMPILER = $Env:COMPILER
$ARCH = $Env:ARCH
$PLATFORM = $Env:PLATFORM
$LIBIIO_VERSION = $env:LIBIIO_VERSION

$SRC_DIR = Get-Location

$OUTSIDE_BUILD = [System.IO.Path]::GetDirectoryName($SRC_DIR.Path)
$DEPS_DIR = Join-Path $OUTSIDE_BUILD "deps" # save deps outside libm2k repo
$SRC_DIR = Get-Item -Path $env:BUILD_SOURCESDIRECTORY # path to repo
$OUTSIDE_BUILD = $SRC_DIR.Parent.FullName
$DEPS_DIR = Join-Path $OUTSIDE_BUILD "deps"

# $BUILD_DIR = Join-Path $SRC_DIR "build-$ARCH" #libm2k build dir - WAS NOT BEING USED
$LIBIIO_VERSION = "libiio-v0"

$DEST_LIBIIO = Join-Path $OUTSIDE_BUILD "libiio-$ARCH"
$LIBIIO_COMPILE_OUTPUT = Join-Path $OUTSIDE_BUILD "libiio-$ARCH"

Write-Output "Python located at:"
Get-Command python
Expand All @@ -25,119 +22,95 @@ Write-Output "COMPILER = $COMPILER"
Write-Output "ARCH = $ARCH"
Write-Output "SRC_DIR to $SRC_DIR"
Write-Output "DEPS_DIR to $DEPS_DIR"
# Write-Output "BUILD_DIR = $BUILD_DIR"
Write-Output "OUTSIDE_BUILD to $OUTSIDE_BUILD"
Write-Output "DEST_LIBIIO = $DEST_LIBIIO"

Get-ChildItem
Write-Output "LIBIIO_COMPILE_OUTPUT = $LIBIIO_COMPILE_OUTPUT"

if (-not (Test-Path -Path ($DEPS_DIR))) {
New-Item -Path ($DEPS_DIR) -ItemType Directory
}

# if (-not (Test-Path -Path ($BUILD_DIR))) {
# New-Item -Path ($BUILD_DIR) -ItemType Directory
# }

function Get-Libiio-Deps { #CHECKED
function Get-Libiio-Deps {
param (
[string]$SRC_DIR
[string]$DIR_PATH
)
Write-Output "# Building libiio dependencies"

# migh be able to skip this step since libiio deps already contains it
Write-Output "## Installing libxml"
New-Item -Path (Join-Path $SRC_DIR "libxml") -ItemType Directory
Set-Location (Join-Path $SRC_DIR "libxml")
$LIBXML_DIR = Join-Path $DIR_PATH "libxml"
New-Item -Path $LIBXML_DIR -ItemType Directory
Set-Location $LIBXML_DIR
Invoke-WebRequest -Uri "https://www.zlatkovic.com/pub/libxml/64bit/libxml2-2.9.3-win32-x86_64.7z" -OutFile "libxml.7z"
7z x -y "libxml.7z"
Remove-Item "libxml.7z"

Get-ChildItem

# NOTE: this archive contains all he files needed
Write-Output "## Installing libiio-deps"
New-Item -Path (Join-Path $SRC_DIR "libiio-deps") -ItemType Directory
Set-Location (Join-Path $SRC_DIR "libiio-deps")
# NOTE: might only need this zip for libiio deps
Write-Output "## Installing libiio-deps"
$LIBIIO_DEPS_DIR = Join-Path $DIR_PATH "libiio-deps"
New-Item -Path $LIBIIO_DEPS_DIR -ItemType Directory
Set-Location $LIBIIO_DEPS_DIR
Invoke-WebRequest -Uri "http://swdownloads.analog.com/cse/build/libiio-win-deps-libusb1.0.24.zip " -OutFile "libiio-win-deps.zip"
7z x -y "libiio-win-deps.zip"
Remove-Item "libiio-win-deps.zip"

# recreate the folder structure needed in the cmake
# NOTE: cmake needs this folder structure
Set-Location "include"
New-Item -Path (Join-Path $SRC_DIR "libiio-deps\include\libserialport") -ItemType Directory
New-Item -Path (Join-Path $LIBIIO_DEPS_DIR "include\libserialport") -ItemType Directory
Move-Item -Path ./libserialport.h -Destination libserialport

Get-ChildItem
}

function Install-Libiiio {
param (
[string]$SRC_DIR,
[string]$DIR_PATH,
[string]$GENERATOR,
[string]$ARCH
)
Write-Output "# Installing libiio"
Set-Location $SRC_DIR
Set-Location $DIR_PATH

git clone "https://github.com/analogdevicesinc/libiio" -b $LIBIIO_VERSION "libiio"
Set-Location (Join-Path $SRC_DIR "libiio")
Set-Location (Join-Path $DIR_PATH "libiio")
git submodule update --init

Write-Output "## Running cmake for $COMPILER on $ARCH..." # x64 instead of ARCH in example
New-Item -Path (Join-Path $SRC_DIR "libiio\build-$ARCH") -ItemType Directory
Copy-Item -Path ".\libiio.iss.cmakein" -Destination (Join-Path $SRC_DIR "libiio\build-$ARCH")


Set-Location (Join-Path $SRC_DIR "libiio\build-$ARCH")

Write-Output "## Inside build-$ARCH before cmake"
Get-ChildItem

# NOTE: this is the old cmake command
# cmake -G $GENERATOR -A $ARCH -DCMAKE_CONFIGURATION_TYPES=$CONFIGURATION -DWITH_TESTS=OFF -DENABLE_IPV6:BOOL=OFF -DCMAKE_SYSTEM_PREFIX_PATH="C:" -DCSHARP_BINDINGS:BOOL=OFF -DPYTHON_BINDINGS:BOOL=OFF -DLIBXML2_LIBRARIES="$LIBIIO_DEPS_LIBS_PATH\libxml2.lib" -DLIBUSB_LIBRARIES="$LIBIIO_DEPS_LIBS_PATH\libusb-1.0.lib" ..
Write-Output "## Running cmake for LIBIIO $COMPILER on $ARCH..." # x64 instead of ARCH in example
New-Item -Path (Join-Path $DIR_PATH "libiio\build-$ARCH") -ItemType Directory
Copy-Item -Path ".\libiio.iss.cmakein" -Destination (Join-Path $DIR_PATH "libiio\build-$ARCH")
Set-Location (Join-Path $DIR_PATH "libiio\build-$ARCH")

# Try the cmake config from libiio CI scripts
# cmake config from libiio CI scripts
$pythonExecutable = (python -c "import sys; print(sys.executable)") -replace '\\', '/'
$PATH_LIBXML2_LIB = (Join-Path $SRC_DIR "libiio-deps\libs\64\libxml2.lib") -replace '\\', '/'
$PATH_LIBUSB_LIB = (Join-Path $SRC_DIR "libiio-deps\libs\64\libusb-1.0.lib") -replace '\\', '/'
$PATH_LIBSERIALPORT_LIB = (Join-Path $SRC_DIR "libiio-deps\libs\64\libserialport.dll.a") -replace '\\', '/'
$PATH_LIBXML2_LIB = (Join-Path $DIR_PATH "libiio-deps\libs\64\libxml2.lib") -replace '\\', '/'
$PATH_LIBUSB_LIB = (Join-Path $DIR_PATH "libiio-deps\libs\64\libusb-1.0.lib") -replace '\\', '/'
$PATH_LIBSERIALPORT_LIB = (Join-Path $DIR_PATH "libiio-deps\libs\64\libserialport.dll.a") -replace '\\', '/'
$PATH_LIBUSB_INCLUDE = (Join-Path $DIR_PATH "libiio-deps\include\libusb-1.0") -replace '\\', '/'
$PATH_LIBXML2_INCLUDE = (Join-Path $DIR_PATH "libiio-deps\include\libxml2") -replace '\\', '/'
$PATH_LIBSERIALPORT_INCLUDE = (Join-Path $DIR_PATH "libiio-deps\include\libserialport") -replace '\\', '/'

$PATH_LIBUSB_INCLUDE = (Join-Path $SRC_DIR "libiio-deps\include\libusb-1.0") -replace '\\', '/'
$PATH_LIBXML2_INCLUDE = (Join-Path $SRC_DIR "libiio-deps\include\libxml2") -replace '\\', '/'
$PATH_LIBSERIALPORT_INCLUDE = (Join-Path $SRC_DIR "libiio-deps\include\libserialport") -replace '\\', '/'

Write-Output "## pythonExecutable = $pythonExecutable "

cmake -G "$COMPILER" -DPYTHON_EXECUTABLE:FILEPATH="$pythonExecutable" -DCMAKE_SYSTEM_PREFIX_PATH="C:" -Werror=dev -DCOMPILE_WARNING_AS_ERROR=ON -DENABLE_IPV6=ON -DWITH_USB_BACKEND=ON -DWITH_SERIAL_BACKEND=ON -DPYTHON_BINDINGS=ON -DCSHARP_BINDINGS:BOOL=OFF -DLIBXML2_LIBRARIES="$PATH_LIBXML2_LIB" -DLIBUSB_LIBRARIES="$PATH_LIBUSB_LIB" -DLIBSERIALPORT_LIBRARIES="$PATH_LIBSERIALPORT_LIB" -DLIBUSB_INCLUDE_DIR="$PATH_LIBUSB_INCLUDE" -DLIBXML2_INCLUDE_DIR="$PATH_LIBXML2_INCLUDE" -DLIBSERIALPORT_INCLUDE_DIR="$PATH_LIBSERIALPORT_INCLUDE" ..
cmake --build . --config Release

Get-ChildItem

if ($LASTEXITCODE -ne 0) {
Write-Output "## cmake failed with exit code $LASTEXITCODE"
exit $LASTEXITCODE
}
# TODO: REVIEW THIS: is the executable installed? if so do i need it in the build dir / artifacts staging directory ?
# same steps as in libiio ci build
# cp .\libiio.iss $env:BUILD_ARTIFACTSTAGINGDIRECTORY # TODO: IS THIS NEEDED??

# NOTE: inside build-x64 there is a Release folder with the .dll
# TODO: copy the results in another folder as it s done in the appveyor script => $DEST_LIBIIO
New-Item -Path ($DEST_LIBIIO) -ItemType Directory

Copy-Item -Path ".\Release\*.dll" -Destination ($DEST_LIBIIO)
Copy-Item -Path ".\Release\*.lib" -Destination ($DEST_LIBIIO)
Copy-Item -Path "*.iss" -Destination ($DEST_LIBIIO)

# After building libiio, copy files to a known directory
if (-not (Test-Path -Path ($LIBIIO_COMPILE_OUTPUT))) {
New-Item -Path ($LIBIIO_COMPILE_OUTPUT) -ItemType Directory
}
Copy-Item -Path ".\Release\*.dll" -Destination ($LIBIIO_COMPILE_OUTPUT)
Copy-Item -Path ".\Release\*.lib" -Destination ($LIBIIO_COMPILE_OUTPUT)
Copy-Item -Path "*.iss" -Destination ($LIBIIO_COMPILE_OUTPUT)
Set-Location -Path ..
Copy-Item -Path "iio.h" -Destination ($DEST_LIBIIO)
Copy-Item -Path "iio.h" -Destination ($LIBIIO_COMPILE_OUTPUT)
Copy-Item -Path ".\*.dll" -Destination ($LIBIIO_COMPILE_OUTPUT) # might not need this: no .dll files in libiio sources
# copy .dll used to build libiio
Copy-Item -Path (Join-Path $libiio-deps "libs\64/*.dll") -Destination ($LIBIIO_COMPILE_OUTPUT)

# Note: also copy the dll from the libiio dependencies inside the DEST_LIBIIO folder -> used while making the installer through the .iss file
Set-Location (Join-Path $DEPS_DIR "libiio-deps\libs\64")
Copy-Item -Path ".\*.dll" -Destination ($DEST_LIBIIO)

# NOTE: the result of these commands is a .tar.gz file
Set-Location (Join-Path $SRC_DIR "libiio\build-$ARCH")

# NOTE: the result of these commands is a .tar.gz file -> copied from LIBIIO CI scripts
Set-Location (Join-Path $DIR_PATH "libiio\build-$ARCH")

Set-Location -Path .\bindings\python
python.exe setup.py sdist
Expand All @@ -149,10 +122,10 @@ function Install-Libiiio {

function Install-Swig {
param (
[string]$SRC_DIR
[string]$DIR_PATH
)
Write-Output "# Installing swig"
Set-Location $SRC_DIR
Set-Location $DIR_PATH
# NOTE: -UserAgent "NativeHost" solved the issue with the download - wait timeout before the download starts
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri "https://sourceforge.net/projects/swig/files/swigwin/swigwin-4.0.0/swigwin-4.0.0.zip/download" -OutFile "swigwin-4.0.0.zip" -UserAgent "NativeHost"
Expand All @@ -165,52 +138,49 @@ function Install-Swig {

function Install-Inno-Setup {
Write-Output "# Installing inno-setup"

choco install InnoSetup -y
$NEW_PATH = "C:\Program Files (x86)\Inno Setup 6"
$CRNT_PATH = [System.Environment]::GetEnvironmentVariable('PATH', [System.EnvironmentVariableTarget]::Machine)


if ($CRNT_PATH -notcontains $NEW_PATH) {
Write-Output "## Adding inno-setup to PATH"
$CRNT_PATH = [System.Environment]::GetEnvironmentVariable('PATH', [System.EnvironmentVariableTarget]::Machine)
$NEW_PATH = "C:\Program Files (x86)\Inno Setup 6"
$NEW_PATH = $CRNT_PATH + ";" + $NEW_PATH
[System.Environment]::SetEnvironmentVariable('PATH', $NEW_PATH, [System.EnvironmentVariableTarget]::Machine)
}
Get-ChildItem
}

function Install-Glog {
param (
[string]$SRC_DIR,
[string]$DIR_PATH,
[string]$CONFIGURATION,
[string]$ARCH,
[string]$GENERATOR
)
Write-Output "# Installing glog"
Set-Location $SRC_DIR
Set-Location $DIR_PATH

if (-not (Test-Path -Path (Join-Path $SRC_DIR "glog"))) {
if (-not (Test-Path -Path (Join-Path $DIR_PATH "glog"))) {
git clone --branch v0.3.5 --depth 1 https://github.com/google/glog
}
Set-Location (Join-Path $SRC_DIR "glog")
Set-Location (Join-Path $DIR_PATH "glog")
git checkout "tags/v0.3.5"

if (-not (Test-Path -Path (Join-Path $SRC_DIR "glog\build_0_4_0-$ARCH"))) {
New-Item -Path (Join-Path $SRC_DIR "glog\build_0_4_0-$ARCH") -ItemType Directory
if (-not (Test-Path -Path (Join-Path $DIR_PATH "glog\build_0_4_0-$ARCH"))) {
New-Item -Path (Join-Path $DIR_PATH "glog\build_0_4_0-$ARCH") -ItemType Directory
}
Set-Location ((Join-Path $SRC_DIR "glog\build_0_4_0-$ARCH"))
Set-Location ((Join-Path $DIR_PATH "glog\build_0_4_0-$ARCH"))

cmake -DWITH_GFLAGS=off -DBUILD_SHARED_LIBS=on -G "$GENERATOR" -A "$ARCH" ..
cmake --build . --target install --config "$CONFIGURATION"
Get-ChildItem
}

function Install-All {
Install-Inno-Setup
Install-Glog -SRC_DIR $DEPS_DIR -CONFIGURATION "Release" -GENERATOR $COMPILER -ARCH "x64"
Install-Swig -SRC_DIR $DEPS_DIR
Get-Libiio-Deps -SRC_DIR $DEPS_DIR
Install-Libiiio -SRC_DIR $DEPS_DIR -GENERATOR $COMPILER -ARCH $ARCH
Set-Location $SRC_DIR
Install-Glog -DIR_PATH $DEPS_DIR -CONFIGURATION "Release" -GENERATOR $COMPILER -ARCH $ARCH
Install-Swig -DIR_PATH $DEPS_DIR
Get-Libiio-Deps -DIR_PATH $DEPS_DIR
Install-Libiiio -DIR_PATH $DEPS_DIR -GENERATOR $COMPILER -ARCH $ARCH
}

Install-All
Set-Location $SRC_DIR
42 changes: 3 additions & 39 deletions CI/windows/make_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ $COMPILER = $Env:COMPILER
$ARCH = $Env:ARCH
$PLATFORM = $Env:PLATFORM

$SRC_DIR = Get-Location
$OUTSIDE_BUILD = [System.IO.Path]::GetDirectoryName($SRC_DIR.Path)
$SRC_DIR = Get-Item -Path $env:BUILD_SOURCESDIRECTORY # path to repo
$OUTSIDE_BUILD = $SRC_DIR.Parent.FullName
$DEPS_DIR= Join-Path $OUTSIDE_BUILD "deps"

$DIST_DIR = Join-Path $SRC_DIR "build-$PLATFORM/dist"
Expand All @@ -17,26 +17,10 @@ $DEST_LIBIIO = Join-Path $OUTSIDE_BUILD "libiio-$ARCH"
Write-Output "SRC DIR = $SRC_DIR"
Write-Output "COMPILER = $COMPILER"
Write-Output "ARCH = $ARCH"
Write-Output "DIST_DIR = $DIST_DIR"
Write-Output "TEMP_BUILD_DIR = $TEMP_BUILD_DIR"
Write-Output "DEST_LIBIIO = $DEST_LIBIIO"


function Build-Python-Wheel {
param(
[string]$PLATFORM
)
Set-Location $TEMP_BUILD_DIR

python.exe -m pip install --user --upgrade pip setuptools wheel twine build virtualenv
$env:COMPILE_BINDINGS = $true
python.exe -m build
Remove-Item Env:\COMPILE_BINDINGS

$DEST = Join-Path $SRC_DIR "build-$PLATFORM\dist"
Copy-Item -Path "dist/libm2k*.whl" -Destination $DEST
}

function Build-Libm2k {
param(
[string]$PLATFORM,
Expand Down Expand Up @@ -84,28 +68,8 @@ function Build-Libm2k {
exit $LASTEXITCODE
}
Get-ChildItem


Get-Content setup.py
}

function Move-to-Build-Dir {
param(
[string]$PLATFORM
)
$DEST_DIR = Join-Path $SRC_DIR "build-$PLATFORM\dist"
$TEMP_BUILD_DIR = Join-Path $SRC_DIR "tmp-build-$PLATFORM"

Set-Location $TEMP_BUILD_DIR
Copy-Item -Path "*.dll" -Destination $DEST_DIR
Copy-Item -Path "*.exe" -Destination $DEST_DIR
Copy-Item -Path "*.lib" -Destination $DEST_DIR
Copy-Item -Path "*.iss" -Destination $DEST_DIR
Set-Location ..
}

# Build-Libm2k -PLATFORM $PLATFORM -GENERATOR $COMPILER -ARCH $ARCH
# Build-Python-Wheel -PLATFORM $PLATFORM
# Move-to-Build-Dir -PLATFORM $PLATFORM

Build-Libm2k -PLATFORM $PLATFORM -GENERATOR $COMPILER -ARCH $ARCH
Set-Location $SRC_DIR
Loading

0 comments on commit b244959

Please sign in to comment.