Skip to content

Commit

Permalink
Set up CI with Azure Pipelines (#11)
Browse files Browse the repository at this point in the history
* Set up CI with Azure Pipelines

* Testing a Windows pipeline

* Add CI script

* Better Python finding to support Windows

* No chocolatey Python install

* No libman generator for now

* Use Ninja in CI

* Don't always run the Docker tests

* Source VS environment

* No YAML anchors

* Get Ninja for Linux

* Fix python find failure when Python outputs version to stderr

* More tests for CI

* Try a PowerShell script

* Real PowerShell CI script

* Use PowerShell CI in all jobs

* Disable `ci/` tests directory for Linux

* Add macOS job

* tweak path to gcc on macOS

* Enable debug output in CI tests

* Print vcpkg output when in debug mode

* Smarter GCC finding

* More verbose GCC finding

* Tweak CC and CXX logic

* More precise gcc

* Auto-determine the target triplet when installing VCPKG packages

* Remove misplaced line

* Wrong spelling of osx triplet

* Fix arch detection when using voidptr size

* Remove old CI cmakek script
  • Loading branch information
azure-pipelines[bot] authored and vector-of-bool committed Dec 10, 2018
1 parent ae9a642 commit 6c289c0
Show file tree
Hide file tree
Showing 13 changed files with 307 additions and 7 deletions.
53 changes: 53 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

jobs:
- job: MSVC
pool:
vmImage: vs2017-win2016
steps:
- script: choco install ninja
displayName: Install Ninja
- script: >
call "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\Common7\\Tools\\vsdevcmd" -arch=x64 &&
powershell ./ci.ps1 -ForceMSVC
displayName: Run tests
- job: MinGW
pool:
vmImage: vs2017-win2016
steps:
- script: choco install ninja
displayName: Install Ninja
- script: >
call "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\Common7\\Tools\\vsdevcmd" -arch=x64 &&
powershell ./ci.ps1
displayName: Run tests
- job: LinuxDocker
pool:
vmImage: ubuntu-16.04

steps:
- script: |
curl -Ls https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-linux.zip -o ninja-linux.zip
unzip ninja-linux.zip
sudo cp -v ninja /usr/local/bin/
sudo apt-get install -y python3-venv
displayName: Prepare System
- script: pwsh ./ci.ps1 -RunDockerTests -NoCITestDir
displayName: Run tests

- job: macOS
pool:
vmImage: macos-10.13
steps:
- script: |
curl -Ls https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-mac.zip -o ninja-mac.zip
unzip ninja-mac.zip
sudo cp -v ninja /usr/local/bin/
displayName: Prepare System
- script: pwsh ./ci.ps1
displayName: Run tests
76 changes: 76 additions & 0 deletions ci.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
param(
# Run the Docker tests
[switch]
$RunDockerTests,
# Forcibly set CC and CXX to MSVC cl.exe
[switch]
$ForceMSVC,
# Ignore the `ci/` tests directory
[switch]
$NoCITestDir
)

$ErrorActionPreference = "Stop"

if ($PSVersionTable.OS -and $PSVersionTable.OS.StartsWith("Darwin")) {
# We're on macOS, and we need a newer GCC for the FS TS
& brew install gcc6
if ($LASTEXITCODE) {
throw "Brew installation failed!"
}
$cc = Get-ChildItem '/usr/local/Cellar/gcc@6/*/bin/gcc-6'
$cxx = Get-ChildItem '/usr/local/Cellar/gcc@6/*/bin/g++-6'
$env:CC = $cc.FullName
$env:CXX = $cxx.FullName
}

if ($ForceMSVC) {
$env:CC = "cl"
$env:CXX = "cl"
}

$cmake = (Get-Command -Name cmake).Source
$ninja = (Get-Command -Name ninja).Source

if (! $cmake) {
throw "No CMake installed?"
}
if (! $ninja) {
throw "No Ninja found?"
}

$source_dir = $PSScriptRoot
$bin_dir = Join-Path $source_dir "ci-build"

if (Test-Path $bin_dir) {
Remove-Item -Recurse $bin_dir -Force
}

$run_docker_tests = "FALSE"
if ($RunDockerTests) {
$run_docker_tests = "TRUE"
}
$no_ci_test_dir = "FALSE"
if ($NoCITestDir) {
$no_ci_test_dir = "TRUE"
}

& $cmake -GNinja `
"-DRUN_DOCKER_TESTS:BOOL=$run_docker_tests" `
"-DNO_CI_TEST_DIR:BOOL=$no_ci_test_dir" `
"-H$source_dir" "-B$bin_dir"
if ($LASTEXITCODE) {
throw "CMake configure failed [$LASTEXITCODE]"
}

& $cmake --build $bin_dir
if ($LASTEXITCODE) {
throw "CMake build failed [$LASTEXITCODE]"
}

$cm_dir = Split-Path $cmake -Parent
$ctest = Join-Path $cm_dir "ctest"
& $cmake -E chdir $bin_dir $ctest -j6 --output-on-failure
if ($LASTEXITCODE) {
throw "CTest failed [$LASTEXITCODE]"
}
9 changes: 5 additions & 4 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ class PMM(conans.ConanFile):
version = '1.1.1'
settings = None
exports_sources = '*'
build_requires = (
'libman-generator/[*]@vector-of-bool/test'
)
generators = 'cmake', 'LibMan'
generators = 'cmake'
# build_requires = (
# 'libman-generator/[*]@vector-of-bool/test'
# )
# generators = 'cmake', 'LibMan'

def build(self):
cmake = conans.CMake(self)
Expand Down
76 changes: 74 additions & 2 deletions pmm/vcpkg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,73 @@ function(_pmm_ensure_vcpkg dir rev)
_pmm_log("vcpkg successfully bootstrapped to ${dir}")
endfunction()

function(_pmm_vcpkg_default_triplet out)
string(TOLOWER "${CMAKE_GENERATOR_PLATFORM}" plat)
string(TOLOWER "${CMAKE_GENERATOR}" gen)
set(compiler "${CMAKE_CXX_COMPILER}")
if(NOT compiler)
set(compiler "${CMAKE_C_COMPILER}")
endif()
# Determine that thing!
if(FALSE)
# Just for alignment
elseif(plat STREQUAL "win32")
set(arch x86)
elseif(plat STREQUAL "x64")
set(arch x64)
elseif(plat STREQUAL "arm")
set(arch arm)
elseif(plat STREQUAL "arm64")
set(arch arm64)
else()
if(gen MATCHES "^Visual Studio 1. 20.. Win64$")
set(arch x64)
elseif(gen MATCHES "^Visual Studio 1. 20.. ARM$")
set(arch arm)
elseif(gen MATCHES "^Visual Studio 1. 20..$")
set(arch x86)
else()
if(compiler MATCHES "(amd64|x64)/cl.exe$")
set(arch x64)
elseif(compiler MATCHES "arm/cl.exe$")
set(arch arm)
elseif(compiler MATCHES "arm64/cl.exe$")
set(arch arm64)
elseif(compiler MATCHES "(bin|x64)/cl.exe$")
set(arch x86)
elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(arch x64)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(arch x86)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(arch x64)
else()
message(FATAL_ERROR "Unable to determine target triple for vcpkg.")
endif()
endif()
endif()

set(sysname "${CMAKE_SYSTEM_NAME}")
if(NOT sysname AND CMAKE_HOST_SYSTEM_NAME)
set(sysname "${CMAKE_HOST_SYSTEM_NAME}")
endif()
if(sysname MATCHES "^Windows(Store|Phone)$")
set(platform uwp)
elseif(sysname STREQUAL "Linux")
set(platform linux)
elseif(sysname STREQUAL "Darwin")
set(platform osx)
elseif(sysname STREQUAL "Windows")
set(platform windows)
elseif(sysname STREQUAL "FreeBSD")
set(platform freebsd)
endif()
set(${out} "${arch}-${platform}" PARENT_SCOPE)
endfunction()

function(_pmm_vcpkg)
_pmm_parse_args(
- REVISION
- REVISION TRIPLET
+ REQUIRES
)

Expand All @@ -90,6 +154,10 @@ function(_pmm_vcpkg)
# repository. (https://github.com/Microsoft/vcpkg)
message(FATAL_ERROR "Using pmm(VCPKG) requires a REVISION argument. Try `REVISION 2a283bd5224b5335a90539faa1b0ac7260411465`")
endif()
if(NOT DEFINED ARG_TRIPLET)
_pmm_vcpkg_default_triplet(ARG_TRIPLET)
endif()
_pmm_log(VERBOSE "Using vcpkg target triplet ${ARG_TRIPLET}")
get_filename_component(vcpkg_inst_dir "${_PMM_USER_DATA_DIR}/vcpkg-${ARG_REVISION}" ABSOLUTE)
_pmm_log(DEBUG "vcpkg directory is ${vcpkg_inst_dir}")
set(prev "${PMM_VCPKG_EXECUTABLE}")
Expand All @@ -102,12 +170,16 @@ function(_pmm_vcpkg)
set(cmd ${CMAKE_COMMAND} -E env
CC=${CMAKE_C_COMPILER}
CXX=${CMAKE_CXX_COMPILER}
"${PMM_VCPKG_EXECUTABLE}" install ${ARG_REQUIRES}
"${PMM_VCPKG_EXECUTABLE}" install
--triplet "${ARG_TRIPLET}"
${ARG_REQUIRES}
)
_pmm_log(VERBOSE "Run vcpkg command: ${cmd}")
_pmm_exec(${cmd})
if(_PMM_RC)
message(FATAL_ERROR "Failed to install requirements with vcpkg [${_PMM_RC}]:\n${_PMM_OUTPUT}")
else()
_pmm_log(DEBUG "vcpkg output:\n${_PMM_OUTPUT}")
endif()
endif()
set(_PMM_INCLUDE "${vcpkg_inst_dir}/scripts/buildsystems/vcpkg.cmake" PARENT_SCOPE)
Expand Down
7 changes: 6 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ set(DOCKER_TESTS

get_filename_component(DOCKER_TEST_SCRIPT RunDockerTest.cmake ABSOLUTE)

if(DOCKER_EXECUTABLE)
option(RUN_DOCKER_TESTS "Should we run the Docker tests?" TRUE)
if(DOCKER_EXECUTABLE AND RUN_DOCKER_TESTS)
foreach(test IN LISTS DOCKER_TESTS)
add_test(
NAME docker.${test}
Expand All @@ -20,3 +21,7 @@ if(DOCKER_EXECUTABLE)
)
endforeach()
endif()

if(NOT NO_CI_TEST_DIR)
add_subdirectory(ci)
endif()
16 changes: 16 additions & 0 deletions tests/ci/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
foreach(subdir
conan
vcpkg
)
get_filename_component(fulldir ${subdir} ABSOLUTE)
add_test(
NAME "pmm.test.ci.${subdir}"
COMMAND "${CMAKE_COMMAND}"
-D "PMM_URL=file://${PROJECT_SOURCE_DIR}/pmm"
-D "PMM_INCLUDE=${PROJECT_SOURCE_DIR}/pmm.cmake"
-D GENERATOR=${CMAKE_GENERATOR}
-D "BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR}/${subdir}"
-D SOURCE_DIR=${fulldir}
-P "${CMAKE_CURRENT_SOURCE_DIR}/RunCITest.cmake"
)
endforeach()
25 changes: 25 additions & 0 deletions tests/ci/RunCITest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
file(REMOVE_RECURSE "${BUILD_DIR}")

execute_process(
COMMAND ${CMAKE_COMMAND}
-D PMM_URL=${PMM_URL}
-D PMM_INCLUDE=${PMM_INCLUDE}
-D PMM_DEBUG=TRUE
-G ${GENERATOR}
"-H${SOURCE_DIR}"
"-B${BUILD_DIR}"
RESULT_VARIABLE retc
)

if(retc)
message(FATAL_ERROR "Configure failed [${retc}]")
endif()

exec_program(
COMMAND ${CMAKE_COMMAND} --build ${BUILD_DIR}
RESULT_VARIABLE retc
)

if(retc)
message(FATAL_ERROR "Build failed [${retc}]")
endif()
9 changes: 9 additions & 0 deletions tests/ci/conan/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.10)
project(TestProject)

message(STATUS "PMM URL is ${PMM_URL}")
include(${PMM_INCLUDE})
pmm(CONAN DEBUG)

add_executable(dummy main.cpp)
target_link_libraries(dummy PRIVATE CONAN_PKG::spdlog)
8 changes: 8 additions & 0 deletions tests/ci/conan/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import conans


class CITestConanProject(conans.ConanFile):
name = 'CITestProject'
version = '1.2.3'
generators = 'cmake'
requires = ('spdlog/1.1.0@bincrafters/stable')
6 changes: 6 additions & 0 deletions tests/ci/conan/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <spdlog/spdlog.h>

int main() {
auto console = spdlog::stdout_color_mt("console");
console->info("Hello!");
}
15 changes: 15 additions & 0 deletions tests/ci/vcpkg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.10)
project(TestProject)

message(STATUS "PMM URL is ${PMM_URL}")
include(${PMM_INCLUDE})
pmm(VCPKG
REVISION 2a283bd5224b5335a90539faa1b0ac7260411465
REQUIRES spdlog
DEBUG
)

find_package(spdlog REQUIRED CONFIG)

add_executable(dummy main.cpp)
target_link_libraries(dummy PRIVATE spdlog::spdlog)
8 changes: 8 additions & 0 deletions tests/ci/vcpkg/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import conans


class CITestConanProject(conans.ConanFile):
name = 'CITestProject'
version = '1.2.3'
generators = 'cmake'
requires = ('spdlog/1.1.0@bincrafters/stable')
6 changes: 6 additions & 0 deletions tests/ci/vcpkg/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <spdlog/spdlog.h>

int main() {
auto console = spdlog::stdout_color_mt("console");
console->info("Hello!");
}

0 comments on commit 6c289c0

Please sign in to comment.