Skip to content

Commit 338be0b

Browse files
committed
Detect os family automatically
1 parent 3748977 commit 338be0b

File tree

4 files changed

+30
-24
lines changed

4 files changed

+30
-24
lines changed

.github/workflows/opencv-rust.yml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,10 @@ jobs:
4747
key: build-${{ matrix.opencv-version }}-${{ matrix.linkage }}-${{ matrix.os-image }}
4848

4949
- name: Install dependencies
50-
env:
51-
OS_FAMILY: ${{ runner.os }}
5250
run: ci/install.sh
5351
shell: bash
5452

5553
- name: Test project
56-
env:
57-
OS_FAMILY: ${{ runner.os }}
5854
run: ci/script.sh
5955
shell: bash
6056

@@ -83,14 +79,10 @@ jobs:
8379
key: vcpkg-${{ matrix.vcpkg-version }}-${{ matrix.os-image }}
8480

8581
- name: Install dependencies
86-
env:
87-
OS_FAMILY: ${{ runner.os }}
8882
run: ci/install.sh
8983
shell: bash
9084

9185
- name: Test project
92-
env:
93-
OS_FAMILY: ${{ runner.os }}
9486
run: ci/script.sh
9587
shell: bash
9688

@@ -125,14 +117,10 @@ jobs:
125117
- uses: mozilla-actions/sccache-action@v0.0.5
126118

127119
- name: Install dependencies
128-
env:
129-
OS_FAMILY: ${{ runner.os }}
130120
run: ci/install.sh
131121
shell: bash
132122

133123
- name: Test project
134-
env:
135-
OS_FAMILY: ${{ runner.os }}
136124
run: ci/script.sh
137125
shell: bash
138126

@@ -177,13 +165,9 @@ jobs:
177165
toolchain: ${{ steps.metadata.outputs.msrv }}
178166

179167
- name: Install dependencies
180-
env:
181-
OS_FAMILY: ${{ runner.os }}
182168
run: ci/install.sh
183169
shell: bash
184170

185171
- name: Check project
186-
env:
187-
OS_FAMILY: ${{ runner.os }}
188172
run: ci/msrv.sh
189173
shell: bash

ci/install.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,35 @@ set -xeu
44

55
ci_dir="$(dirname "$0")"
66

7-
if [[ "$OS_FAMILY" == "Linux" ]]; then
7+
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
8+
os_family="Linux"
9+
elif [[ "$OSTYPE" == "darwin"* ]]; then
10+
os_family="macOS"
11+
elif [[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
12+
os_family="Windows"
13+
elif [[ "$OSTYPE" == "freebsd"* ]]; then
14+
exit "FreeBSD is not supported"
15+
else
16+
exit "Unknown OS: $OSTYPE"
17+
fi
18+
19+
if [[ "$os_family" == "Linux" ]]; then
820
# free up disk space in Github Actions image: https://github.com/actions/runner-images/issues/2840
921
sudo rm -rf /usr/share/dotnet /opt/ghc /usr/local/share/boost
1022
if [[ "${VCPKG_VERSION:-}" != "" ]]; then # vcpkg build
1123
"$ci_dir/install-ubuntu-vcpkg.sh"
1224
else
1325
"$ci_dir/install-ubuntu.sh"
1426
fi
15-
elif [[ "$OS_FAMILY" == "macOS" ]]; then
27+
elif [[ "$os_family" == "macOS" ]]; then
1628
if [[ "${BREW_OPENCV_VERSION:-}" != "" ]]; then # brew build
1729
"$ci_dir/install-macos-brew.sh"
1830
elif [[ "${VCPKG_VERSION:-}" != "" ]]; then # vcpkg build
1931
"$ci_dir/install-macos-vcpkg.sh"
2032
else
2133
"$ci_dir/install-macos-framework.sh"
2234
fi
23-
elif [[ "$OS_FAMILY" == "Windows" ]]; then
35+
elif [[ "$os_family" == "Windows" ]]; then
2436
export CHOCO_LLVM_VERSION=18.1.6
2537
if [[ "${VCPKG_VERSION:-}" != "" ]]; then # vcpkg build
2638
"$ci_dir/install-windows-vcpkg.sh"

ci/script.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,19 @@
22

33
set -xeu
44

5-
if [[ "$OS_FAMILY" == "Windows" ]]; then
5+
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
6+
os_family="Linux"
7+
elif [[ "$OSTYPE" == "darwin"* ]]; then
8+
os_family="macOS"
9+
elif [[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
10+
os_family="Windows"
11+
elif [[ "$OSTYPE" == "freebsd"* ]]; then
12+
exit "FreeBSD is not supported"
13+
else
14+
exit "Unknown OS: $OSTYPE"
15+
fi
16+
17+
if [[ "$os_family" == "Windows" ]]; then
618
export PATH="/C/Program Files/LLVM/bin:$PATH"
719
export LIBCLANG_PATH="C:/Program Files/LLVM/bin"
820
if [[ "${VCPKG_VERSION:-}" != "" ]]; then # vcpkg build
@@ -18,7 +30,7 @@ if [[ "$OS_FAMILY" == "Windows" ]]; then
1830
fi
1931
echo "=== Installed chocolatey packages:"
2032
choco list
21-
elif [[ "$OS_FAMILY" == "macOS" ]]; then
33+
elif [[ "$os_family" == "macOS" ]]; then
2234
xcode_select="xcode-select" # IDEA code highlighting workaround
2335
toolchain_path="$($xcode_select --print-path)/Toolchains/XcodeDefault.xctoolchain/"
2436
export DYLD_FALLBACK_LIBRARY_PATH="$toolchain_path/usr/lib/"
@@ -37,7 +49,7 @@ elif [[ "$OS_FAMILY" == "macOS" ]]; then
3749
fi
3850
echo "=== Installed brew packages:"
3951
brew list --versions
40-
elif [[ "$OS_FAMILY" == "Linux" ]]; then
52+
elif [[ "$os_family" == "Linux" ]]; then
4153
if [[ "${VCPKG_VERSION:-}" != "" ]]; then # vcpkg build
4254
export VCPKG_ROOT="$HOME/build/vcpkg"
4355
echo "=== Installed vcpkg packages:"

tools/test.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ set -eu
55
script_dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
66
cd "$script_dir/.."
77

8-
export OS_FAMILY="linux"
9-
108
(
119
. "$script_dir/env-34.sh"
1210
ci/script.sh

0 commit comments

Comments
 (0)