Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

Commit

Permalink
ci: pass tests on Windows (#49)
Browse files Browse the repository at this point in the history
* build: copy opencv.BUILD from MediaPipeUnityPlugin

* chore: current end_of_line is LF

* build: remove opencv_deps option

* ci: enable Windows

* build: pass environment variables to build OpenCV

* ci: disable LAPACK

* ci: ignore SignalAbortTest on Windows

* test: fix tests on Windows

* doc: remove an incorrect line

* Do not upload contents of build/

We already have Bazel Caching so I doubt we even needed this.

Co-authored-by: Capuccino <ayane@vignetteapp.org>
  • Loading branch information
homuler and sr229 authored Oct 11, 2021
1 parent cc56f53 commit c0fbc4a
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 202 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ root = true

[*]
indent_style = space
end_of_line = crlf
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
Expand Down
192 changes: 96 additions & 96 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,96 +1,96 @@
on: [push, pull_request]
name: Continuous Integration

jobs:
test:
name: Test
runs-on: ${{matrix.os.fullname}}
env:
PROJECT_NAME: Akihabara
NET_ENV: net5.0
strategy:
fail-fast: false
matrix:
os:
# - { prettyname: Windows, fullname: windows-latest }
- { prettyname: Linux, fullname: ubuntu-latest }
steps:
- name: Cache Bazel directory
uses: actions/cache@v2
if: ${{ always() }}
env:
cache-name: bazel-cache
with:
path: ~/.cache/bazel
key: ${{runner.os}}-${{env.cache-name}}-dev

- name: Cache build directory
uses: actions/cache@v2
env:
cache-name: build-cache
with:
path: build
key: ${{runner.os}}-${{env.cache-name}}-dev

- name: Checkout
uses: actions/checkout@v2

- name: Install .NET 5.0.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: "5.0.x"

# FIXME: Setup will fail if you use a Python version lower than 3.9
- name: Force Python 3.9
uses: actions/setup-python@v2
with:
python-version: "3.9"
architecture: "x64"

- name: Set up MinGW
if: ${{ matrix.os.prettyname == 'Windows' }}
uses: egor-tensin/setup-mingw@v2
with:
platform: x64

- name: Build (Native, Windows)
if: ${{ matrix.os.prettyname == 'Windows' }}
run: |
echo "Setting PYTHON_BIN_PATH to python in PATH"
$env:PYTHON_BIN_PATH=(Get-Command python).Path
echo $env:PYTHON_BIN_PATH
pip install numpy
python build.py build --desktop cpu --opencv=local -vv
- name: Build (Native, *nix)
if: ${{ matrix.os.prettyname != 'Windows' }}
run: |
pip install numpy
python build.py build --desktop cpu --opencv=cmake -vv
- name: Build (.NET)
run: dotnet build -c Debug src/${{env.PROJECT_NAME}}.sln

- name: Copy libmediapipe_c.* into Akihabara.tests
run: cp $pwd/src/${{env.PROJECT_NAME}}/bin/Debug/${{env.NET_ENV}}/libmediapipe_c.* $pwd/src/${{env.PROJECT_NAME}}.Tests/bin/Debug/${{env.NET_ENV}}/
shell: pwsh

- name: Test (CPU)
run: dotnet test --filter TestCategory!=GpuOnlyTest "$pwd/src/${{env.PROJECT_NAME}}.Tests" --logger "trx;LogFileName=TestResults-${{matrix.os.prettyname}}.trx"
shell: pwsh

# Attempt to upload results even if test fails.
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#always
- name: Upload Test Results (${{matrix.os.prettyname}})
uses: actions/upload-artifact@v2
if: ${{ always() }}
with:
name: TestResults-${{matrix.os.prettyname}}
path: ${{github.workspace}}/src/Akihabara.Tests/TestResults/TestResults-${{matrix.os.prettyname}}.trx

# The contents of the build folder
- name: Upload Build Artifacts (${{matrix.os.prettyname}})
uses: actions/upload-artifact@v2
with:
name: build-artifacts-${{matrix.os.prettyname}}
path: build/
on: [push, pull_request]
name: Continuous Integration

jobs:
test:
name: Test
runs-on: ${{matrix.os.fullname}}
env:
PROJECT_NAME: Akihabara
NET_ENV: net5.0
strategy:
fail-fast: false
matrix:
os:
- { prettyname: Windows, fullname: windows-latest }
- { prettyname: Linux, fullname: ubuntu-latest }
steps:
- name: Cache Bazel directory
uses: actions/cache@v2
if: ${{ always() }}
env:
cache-name: bazel-cache
with:
path: ~/.cache/bazel
key: ${{runner.os}}-${{env.cache-name}}-dev

- name: Cache build directory
uses: actions/cache@v2
env:
cache-name: build-cache
with:
path: build
key: ${{runner.os}}-${{env.cache-name}}-dev

- name: Checkout
uses: actions/checkout@v2

- name: Install .NET 5.0.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: "5.0.x"

# FIXME: Setup will fail if you use a Python version lower than 3.9
- name: Force Python 3.9
uses: actions/setup-python@v2
with:
python-version: "3.9"
architecture: "x64"

- name: Set up MinGW
if: ${{ matrix.os.prettyname == 'Windows' }}
uses: egor-tensin/setup-mingw@v2
with:
platform: x64

- name: Build (Native, Windows)
if: ${{ matrix.os.prettyname == 'Windows' }}
run: |
echo "Setting PYTHON_BIN_PATH to python in PATH"
$env:PYTHON_BIN_PATH=(Get-Command python).Path
echo $env:PYTHON_BIN_PATH
pip install numpy
python build.py build --desktop cpu --opencv=cmake -vv
- name: Build (Native, *nix)
if: ${{ matrix.os.prettyname != 'Windows' }}
run: |
pip install numpy
python build.py build --desktop cpu --opencv=cmake -vv
- name: Build (.NET)
run: dotnet build -c Debug src/${{env.PROJECT_NAME}}.sln

- name: Copy libmediapipe_c.* into Akihabara.tests
run: cp $pwd/src/${{env.PROJECT_NAME}}/bin/Debug/${{env.NET_ENV}}/libmediapipe_c.* $pwd/src/${{env.PROJECT_NAME}}.Tests/bin/Debug/${{env.NET_ENV}}/
shell: pwsh

# On Windows, ignore tests that can signal SIGABRT because it will abort the process.
- name: Test (CPU, Windows)
if: ${{ matrix.os.prettyname == 'Windows' }}
run: dotnet test --filter "TestCategory!=GpuOnlyTest&TestCategory!=SignalAbortTest" "$pwd/src/${{env.PROJECT_NAME}}.Tests" --logger "trx;LogFileName=TestResults-${{matrix.os.prettyname}}.trx"
shell: pwsh

- name: Test (CPU, *nix)
if: ${{ matrix.os.prettyname != 'Windows' }}
run: dotnet test --filter TestCategory!=GpuOnlyTest "$pwd/src/${{env.PROJECT_NAME}}.Tests" --logger "trx;LogFileName=TestResults-${{matrix.os.prettyname}}.trx"
shell: pwsh

# Attempt to upload results even if test fails.
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#always
- name: Upload Test Results (${{matrix.os.prettyname}})
uses: actions/upload-artifact@v2
if: ${{ always() }}
with:
name: TestResults-${{matrix.os.prettyname}}
path: ${{github.workspace}}/src/Akihabara.Tests/TestResults/TestResults-${{matrix.os.prettyname}}.trx
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ build.py build --desktop gpu --vv
- .NET 5.0 or .NET 6.0 LTS
- GCC-9 (GCC-10 also works but not guranteed to work since Mediapipe uses a lot of deprecated syntax).
- Bazel
- CMake (Needed if you wanna compile opencv locally with `build.py --opencv=cmake`.

43 changes: 33 additions & 10 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, command_args):
self.verbose = command_args.args.verbose
self.console = Console(self.verbose)

def _run_command(self, command_list, shell=False):
def _run_command(self, command_list, shell=True):
self.console.v(f"Running `{' '.join(command_list)}`")

if shell:
Expand Down Expand Up @@ -69,7 +69,7 @@ def _copytree(self, source, dest):
os.makedirs(dest, 0o755)

# `shutil.copytree` fails on Windows if target file exists, so run `cp -r` instead.
self._run_command(['cp', '-r', f'{source}/*', dest], shell=True)
self._run_command(['cp', '-r', f'{source}/*', dest])

def _remove(self, path):
self.console.v(f"Removing '{path}'...")
Expand Down Expand Up @@ -98,7 +98,6 @@ def __init__(self, command_args):
# self.ios= command_args.args.ios
self.resources = command_args.args.resources
self.opencv = command_args.args.opencv
self.opencv_deps = command_args.args.opencv_deps
self.include_opencv_libs = command_args.args.include_opencv_libs

self.compilation_mode = command_args.args.compilation_mode
Expand Down Expand Up @@ -163,7 +162,7 @@ def run(self):
# os.path.join(_BAZEL_BIN_PATH, 'mediapipe_api', 'objc', 'MediaPipeUnity.zip'),
# os.path.join(_BUILD_PATH, 'Plugins', 'iOS'))



self.console.info('Printing build path...')
for root, directories, files in os.walk(_BUILD_PATH, topdown=False):
Expand Down Expand Up @@ -197,8 +196,36 @@ def _build_common_commands(self):
commands += self._build_linkopt()

if self._is_windows():
python_bin_path = os.environ['PYTHON_BIN_PATH'].replace('\\', '//')
commands += ['--action_env', f'PYTHON_BIN_PATH={python_bin_path}']
python_bin_path_key = 'PYTHON_BIN_PATH'
if python_bin_path_key not in os.environ:
raise RuntimeError(f'`{python_bin_path_key}` is not set')

python_bin_path = os.environ[python_bin_path_key].replace('\\', '//')
commands += ['--action_env', f'{python_bin_path_key}="{python_bin_path}"']

# Required to compile OpenCV
# Without this environment variable, Visual Studio instances won't be found
# cf. https://github.com/bazelbuild/rules_foreign_cc/issues/793
program_data_key = 'ProgramData'
if program_data_key in os.environ:
commands += ['--action_env', program_data_key]

# Enable CMake to detect processors when configuring OpenCV
processor_architecture_key = 'PROCESSOR_ARCHITECTURE'
if processor_architecture_key in os.environ:
commands += ['--action_env', processor_architecture_key]

processor_identifier_key = 'PROCESSOR_IDENTIFIER'
if processor_identifier_key in os.environ:
commands += ['--action_env', processor_identifier_key]

processor_level_key = 'PROCESSOR_LEVEL'
if processor_level_key in os.environ:
commands += ['--action_env', processor_level_key]

processor_revision_key = 'PROCESSOR_REVISION'
if processor_revision_key in os.environ:
commands += ['--action_env', processor_revision_key]

if self.verbose > 1:
commands.append('--verbose_failures')
Expand All @@ -217,9 +244,6 @@ def _build_linkopt(self):
def _build_opencv_switch(self):
commands = [f'--@opencv//:switch={self.opencv}']

if self.opencv == 'cmake':
commands += [f'--@opencv//:deps={switch}' for switch in self.opencv_deps]

return commands

def _build_desktop_options(self):
Expand Down Expand Up @@ -372,7 +396,6 @@ def __init__(self):
build_command_parser.add_argument('--resources', '-R', action=argparse.BooleanOptionalAction)
build_command_parser.add_argument('--compilation_mode', '-c', choices=['fastbuild', 'opt', 'dbg'], default='opt')
build_command_parser.add_argument('--opencv', choices=['local', 'cmake'], default='local', help='Decide to which OpenCV to link for Desktop native libraries')
build_command_parser.add_argument('--opencv_deps', action='append', choices=['ffmpeg'], default=[], help='OpenCV Dependencies (only used when `--opencv=cmake`)')
build_command_parser.add_argument('--include_opencv_libs', action='store_true', help='Include OpenCV\'s native libraries for Desktop')
build_command_parser.add_argument('--linkopt', '-l', action='append', help='Linker options')
build_command_parser.add_argument('--verbose', '-v', action='count', default=0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void Ctor_ShouldInstantiateImageFrame_When_CalledWithPixelData()
}
}

[Test]
[Test, SignalAbort]
public void Ctor_ShouldThrowMediaPipeException_When_CalledWithInvalidArgument()
{
Assert.Throws<MediapipeException>(() => { new ImageFrame(ImageFormat.Format.Sbgra, 640, 480, 0); });
Expand Down
9 changes: 8 additions & 1 deletion src/Akihabara.Tests/Framework/Packet/FloatArrayPacketTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,14 @@ public void DebugTypeName_ShouldReturnFloat_When_ValueIsSet()
float[] array = { 0.01f };
var packet = new FloatArrayPacket(array);

Assert.AreEqual(packet.DebugTypeName(), "float []");
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
Assert.AreEqual(packet.DebugTypeName(), "float [0]");
}
else
{
Assert.AreEqual(packet.DebugTypeName(), "float []");
}
}
#endregion
}
Expand Down
10 changes: 9 additions & 1 deletion src/Akihabara.Tests/Framework/Packet/ImageFramePacketTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Akihabara.Framework.Packet;
using Akihabara.Framework.Port;
using NUnit.Framework;
using System;

namespace Akihabara.Tests.Framework.Packet
{
Expand Down Expand Up @@ -121,7 +122,14 @@ public void DebugTypeName_ShouldReturnFloat_When_ValueIsSet()
{
var packet = new ImageFramePacket(new ImageFrame());

Assert.AreEqual(packet.DebugTypeName(), "mediapipe::ImageFrame");
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
Assert.AreEqual(packet.DebugTypeName(), "class mediapipe::ImageFrame");
}
else
{
Assert.AreEqual(packet.DebugTypeName(), "mediapipe::ImageFrame");
}
}
#endregion
}
Expand Down
2 changes: 1 addition & 1 deletion src/Akihabara/Native/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public partial class NativeMethods
// variant we're basing off, which you can find here: https://git.io/Jc3y1
//
// However, since we're targeting PC for now, we'll go for mediapipe_c for now.
internal const string MediaPipeLibrary = "mediapipe_c";
internal const string MediaPipeLibrary = "libmediapipe_c";
}
}
Loading

0 comments on commit c0fbc4a

Please sign in to comment.