| 1 |
# Detect whether or not the source tree for this build is the upstream |
| 2 |
# monorepository or a sparse export of it. Returns (via `<varname>`) the slug of |
| 3 |
# the sparse export, if detected, or `NONE` if this is the monorepo. |
| 4 |
# |
| 5 |
# Usage: |
| 6 |
# ~~~ |
| 7 |
# detect_sparse_export(<varname>) |
| 8 |
# ~~~ |
| 9 |
function(detect_sparse_export varname) |
| 10 |
if("${TANGENT_BUILD_CONTEXT}" STREQUAL DEBIAN_PACKAGE) |
| 11 |
set(${varname} |
| 12 |
NONE |
| 13 |
PARENT_SCOPE) |
| 14 |
return() |
| 15 |
endif() |
| 16 |
|
| 17 |
if(EXISTS ${CMAKE_SOURCE_DIR}/.sparse-export) |
| 18 |
file(STRINGS ${CMAKE_SOURCE_DIR}/.sparse-export _sparse_export) |
| 19 |
set(${varname} |
| 20 |
"${_sparse_export}" |
| 21 |
PARENT_SCOPE) |
| 22 |
return() |
| 23 |
endif() |
| 24 |
|
| 25 |
set(exportsdir ${CMAKE_SOURCE_DIR}/tangent/tooling/sparse-exports/) |
| 26 |
if(EXISTS ${exportsdir}/iamgroot.txt) |
| 27 |
set(${varname} |
| 28 |
"groot" |
| 29 |
PARENT_SCOPE) |
| 30 |
return() |
| 31 |
endif() |
| 32 |
|
| 33 |
file( |
| 34 |
GLOB _children |
| 35 |
RELATIVE ${exportsdir} |
| 36 |
${exportsdir}/*) |
| 37 |
list(LENGTH _children num_children) |
| 38 |
|
| 39 |
if("${num_children}" EQUAL 0) |
| 40 |
message(FATAL_ERROR " Invalid sparse export. ${exportsdir} is empty" |
| 41 |
" and .sparse-export is missing") |
| 42 |
return() |
| 43 |
endif() |
| 44 |
|
| 45 |
if("${num_children}" GREATER 1) |
| 46 |
string(REPLACE ";" "\n " _children "${_children}") |
| 47 |
message(FATAL_ERROR " Invalid sparse export. ${exportsdir} contains" |
| 48 |
" too many children:\n ${_children}") |
| 49 |
endif() |
| 50 |
|
| 51 |
list(GET _children 0 this_export) |
| 52 |
set(${varname} |
| 53 |
${this_export} |
| 54 |
PARENT_SCOPE) |
| 55 |
endfunction() |
| 56 |
|
| 57 |
# Detect the build environment that is running cmake. Returns in the calling |
| 58 |
# scope the following variables: |
| 59 |
# |
| 60 |
# * IS_TRAVIS_CI - TRUE if this is on travis |
| 61 |
# * IS_PULL_REQUEST - TRUE if this is a travis pull request build |
| 62 |
# * TANGENT_IS_DEBIAN_BUILD - TRUE if this is a pbuilder/pbuild or launchpad |
| 63 |
# execution |
| 64 |
# * TANGENT_SPARSE_EXPORT - set to the slug of the sparse export or `NONE` if |
| 65 |
# this is the monorepo |
| 66 |
# |
| 67 |
# Usage: |
| 68 |
# ~~~ |
| 69 |
# include(environment.cmake) |
| 70 |
# ~~~ |
| 71 |
set(IS_TRAVIS_CI FALSE) |
| 72 |
if("$ENV{CI}" STREQUAL "true" |
| 73 |
AND "$ENV{TRAVIS}" STREQUAL "true") |
| 74 |
set(IS_TRAVIS_CI TRUE CACHE BOOL "This build is on travis" FORCE) |
| 75 |
endif() |
| 76 |
|
| 77 |
set(IS_PULL_REQUEST FALSE) |
| 78 |
if(DEFINED ENV{TRAVIS_PULL_REQUEST} AND "$ENV{TRAVIS_PULL_REQUEST}" STREQUAL |
| 79 |
"true") |
| 80 |
set(IS_PULL_REQUEST TRUE) |
| 81 |
endif() |
| 82 |
|
| 83 |
set(TANGENT_IS_DEBIAN_BUILD FALSE) |
| 84 |
if("${TANGENT_BUILD_CONTEXT}" STREQUAL DEBIAN_PACKAGE) |
| 85 |
set(TANGENT_IS_DEBIAN_BUILD TRUE) |
| 86 |
endif() |
| 87 |
|
| 88 |
detect_sparse_export(_sparse_export) |
| 89 |
set(TANGENT_SPARSE_EXPORT "${_sparse_export}") |
| 90 |
|
| 91 |
foreach(key ID RELEASE CODENAME DESCRIPTION) |
| 92 |
unset("BUILDENV_DISTRIB_${key}") |
| 93 |
endforeach() |
| 94 |
if(EXISTS "/etc/lsb-release") |
| 95 |
file(STRINGS "/etc/lsb-release" _lines) |
| 96 |
foreach(line ${_lines}) |
| 97 |
if("${line}" MATCHES "^([^=]+)=(.+)") |
| 98 |
# cmake-lint: disable=C0103 |
| 99 |
set("BUILDENV_${CMAKE_MATCH_1}" "${CMAKE_MATCH_2}") |
| 100 |
set_property(GLOBAL PROPERTY "BUILDENV_${CMAKE_MATCH_1}" |
| 101 |
"${CMAKE_MATCH_2}") |
| 102 |
endif() |
| 103 |
endforeach() |
| 104 |
else() |
| 105 |
message(WARNING "Can't query lsb-release") |
| 106 |
endif() |
| 107 |
|
| 108 |
unset(BUILDENV_DPKG_ARCHITECTURE) |
| 109 |
execute_process( |
| 110 |
COMMAND dpkg --print-architecture |
| 111 |
RESULT_VARIABLE _returncode |
| 112 |
OUTPUT_VARIABLE _this_arch |
| 113 |
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 114 |
if(_returncode EQUAL 0) |
| 115 |
set(BUILDENV_DPKG_ARCHITECTURE "${_this_arch}") |
| 116 |
set_property(GLOBAL PROPERTY BUILDENV_DPKG_ARCHITECTURE "${_this_arch}") |
| 117 |
else() |
| 118 |
message(WARNING "Failed to query current distribution architecture") |
| 119 |
endif() |