Skip to content

Commit

Permalink
Detect os family automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
twistedfall committed Jul 17, 2024
1 parent 3748977 commit 338be0b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
16 changes: 0 additions & 16 deletions .github/workflows/opencv-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,10 @@ jobs:
key: build-${{ matrix.opencv-version }}-${{ matrix.linkage }}-${{ matrix.os-image }}

- name: Install dependencies
env:
OS_FAMILY: ${{ runner.os }}
run: ci/install.sh
shell: bash

- name: Test project
env:
OS_FAMILY: ${{ runner.os }}
run: ci/script.sh
shell: bash

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

- name: Install dependencies
env:
OS_FAMILY: ${{ runner.os }}
run: ci/install.sh
shell: bash

- name: Test project
env:
OS_FAMILY: ${{ runner.os }}
run: ci/script.sh
shell: bash

Expand Down Expand Up @@ -125,14 +117,10 @@ jobs:
- uses: mozilla-actions/[email protected]

- name: Install dependencies
env:
OS_FAMILY: ${{ runner.os }}
run: ci/install.sh
shell: bash

- name: Test project
env:
OS_FAMILY: ${{ runner.os }}
run: ci/script.sh
shell: bash

Expand Down Expand Up @@ -177,13 +165,9 @@ jobs:
toolchain: ${{ steps.metadata.outputs.msrv }}

- name: Install dependencies
env:
OS_FAMILY: ${{ runner.os }}
run: ci/install.sh
shell: bash

- name: Check project
env:
OS_FAMILY: ${{ runner.os }}
run: ci/msrv.sh
shell: bash
18 changes: 15 additions & 3 deletions ci/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,35 @@ set -xeu

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

if [[ "$OS_FAMILY" == "Linux" ]]; then
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
os_family="Linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
os_family="macOS"
elif [[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
os_family="Windows"
elif [[ "$OSTYPE" == "freebsd"* ]]; then
exit "FreeBSD is not supported"
else
exit "Unknown OS: $OSTYPE"
fi

if [[ "$os_family" == "Linux" ]]; then
# free up disk space in Github Actions image: https://github.com/actions/runner-images/issues/2840
sudo rm -rf /usr/share/dotnet /opt/ghc /usr/local/share/boost
if [[ "${VCPKG_VERSION:-}" != "" ]]; then # vcpkg build
"$ci_dir/install-ubuntu-vcpkg.sh"
else
"$ci_dir/install-ubuntu.sh"
fi
elif [[ "$OS_FAMILY" == "macOS" ]]; then
elif [[ "$os_family" == "macOS" ]]; then
if [[ "${BREW_OPENCV_VERSION:-}" != "" ]]; then # brew build
"$ci_dir/install-macos-brew.sh"
elif [[ "${VCPKG_VERSION:-}" != "" ]]; then # vcpkg build
"$ci_dir/install-macos-vcpkg.sh"
else
"$ci_dir/install-macos-framework.sh"
fi
elif [[ "$OS_FAMILY" == "Windows" ]]; then
elif [[ "$os_family" == "Windows" ]]; then
export CHOCO_LLVM_VERSION=18.1.6
if [[ "${VCPKG_VERSION:-}" != "" ]]; then # vcpkg build
"$ci_dir/install-windows-vcpkg.sh"
Expand Down
18 changes: 15 additions & 3 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@

set -xeu

if [[ "$OS_FAMILY" == "Windows" ]]; then
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
os_family="Linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
os_family="macOS"
elif [[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
os_family="Windows"
elif [[ "$OSTYPE" == "freebsd"* ]]; then
exit "FreeBSD is not supported"
else
exit "Unknown OS: $OSTYPE"
fi

if [[ "$os_family" == "Windows" ]]; then
export PATH="/C/Program Files/LLVM/bin:$PATH"
export LIBCLANG_PATH="C:/Program Files/LLVM/bin"
if [[ "${VCPKG_VERSION:-}" != "" ]]; then # vcpkg build
Expand All @@ -18,7 +30,7 @@ if [[ "$OS_FAMILY" == "Windows" ]]; then
fi
echo "=== Installed chocolatey packages:"
choco list
elif [[ "$OS_FAMILY" == "macOS" ]]; then
elif [[ "$os_family" == "macOS" ]]; then
xcode_select="xcode-select" # IDEA code highlighting workaround
toolchain_path="$($xcode_select --print-path)/Toolchains/XcodeDefault.xctoolchain/"
export DYLD_FALLBACK_LIBRARY_PATH="$toolchain_path/usr/lib/"
Expand All @@ -37,7 +49,7 @@ elif [[ "$OS_FAMILY" == "macOS" ]]; then
fi
echo "=== Installed brew packages:"
brew list --versions
elif [[ "$OS_FAMILY" == "Linux" ]]; then
elif [[ "$os_family" == "Linux" ]]; then
if [[ "${VCPKG_VERSION:-}" != "" ]]; then # vcpkg build
export VCPKG_ROOT="$HOME/build/vcpkg"
echo "=== Installed vcpkg packages:"
Expand Down
2 changes: 0 additions & 2 deletions tools/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ set -eu
script_dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
cd "$script_dir/.."

export OS_FAMILY="linux"

(
. "$script_dir/env-34.sh"
ci/script.sh
Expand Down

0 comments on commit 338be0b

Please sign in to comment.