Skip to content

Commit

Permalink
Refactor build workflow and tests to remove profiling.json uploads, a…
Browse files Browse the repository at this point in the history
…dd Visual Studio setup, and enhance generator handling in tests
  • Loading branch information
zchrissirhcz committed Nov 22, 2024
1 parent 6188dfa commit 9e717c0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 48 deletions.
31 changes: 12 additions & 19 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ jobs:
- name: Build
run: python test.py

- name: Upload profiling.json
uses: actions/upload-artifact@v4
with:
name: profiling-linux
path: profiling.json

build_windows:
runs-on: windows-latest
steps:
Expand All @@ -42,14 +36,19 @@ jobs:
cmakeVersion: "~3.31.0"
ninjaVersion: "^1.12.1"

- name: Build
run: python test.py
- name: Setup VS2022 Developer Command Prompt
run: |
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" x64
echo "VS2022 Developer Command Prompt is ready."
- name: Upload profiling.json
uses: actions/upload-artifact@v4
with:
name: profiling-windows
path: profiling.json
- name: Test Visual Studio
run: python test.py

- name: Test Ninja
run: python test.py -G Ninja

- name: Test Ninja Multi-Config
run: python test.py -G "Ninja Multi-Config"

build_macos:
runs-on: macos-latest
Expand All @@ -65,9 +64,3 @@ jobs:

- name: Build
run: python test.py

- name: Upload profiling.json
uses: actions/upload-artifact@v4
with:
name: profiling-macos
path: profiling.json
77 changes: 48 additions & 29 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import platform
import shutil
import os
import argparse


generator = None


if platform.system() == 'Windows':
Expand Down Expand Up @@ -30,15 +34,18 @@ def check_output(cmd):


class RocBuildTest(unittest.TestCase):

def setUp(self):
pass
if generator:
self.default_configure_args = f'-G "{generator}"'
else:
self.default_configure_args = ''

def tearDown(self):
pass

def check_generate(self, project_name, expected_ret=0, args=''):
cmd = f'cmake -S tests/{project_name} -B build/{project_name} {args}'
cmd = f'cmake -S tests/{project_name} -B build/{project_name} {self.default_configure_args} {args}'
ret, out = check_output(cmd)
self.assertEqual(expected_ret, ret, out)
return out.replace('\r\n', '\n')
Expand All @@ -51,29 +58,35 @@ def check_build(self, project_name, args=''):

def test_artifact_path(self):
if PLATFORM.startswith('vs'):
# Ninja Multi-Config
# self.check_generate('artifacts_path', args='-G "Ninja Multi-Config" -DCMAKE_TOOLCHAIN_FILE="../../toolchains/Windows.MSVC.toolchain.cmake"')
# self.check_build('artifacts_path', '--config Release')
# self.assertTrue(os.path.exists('build/artifacts_path/Release/foo_static.lib'))
# self.assertTrue(os.path.exists('build/artifacts_path/Release/foo_shared.dll'))
# self.assertTrue(os.path.exists('build/artifacts_path/Release/hello.exe'))
# self.assertTrue(os.path.exists('build/artifacts_path/Release/subfoo_static.lib'))
# self.assertTrue(os.path.exists('build/artifacts_path/Release/subfoo_shared.dll'))
# self.assertTrue(os.path.exists('build/artifacts_path/Release/subhello.exe'))
# shutil.rmtree('build/artifacts_path')

# Ninja
out = self.check_generate('artifacts_path', args='-G Ninja -DCMAKE_TOOLCHAIN_FILE="../../toolchains/Windows.MSVC.toolchain.cmake"')
print(out)
self.check_build('artifacts_path', '--config Release')
self.assertTrue(os.path.exists('build/artifacts_path/foo_static.lib'))
self.assertTrue(os.path.exists('build/artifacts_path/foo_shared.dll'))
self.assertTrue(os.path.exists('build/artifacts_path/hello.exe'))
self.assertTrue(os.path.exists('build/artifacts_path/subfoo_static.lib'))
self.assertTrue(os.path.exists('build/artifacts_path/subfoo_shared.dll'))
self.assertTrue(os.path.exists('build/artifacts_path/subhello.exe'))
if generator == 'Ninja Multi-Config':
self.check_generate('artifacts_path')
self.check_build('artifacts_path', '--config Release')
self.assertTrue(os.path.exists('build/artifacts_path/Release/foo_static.lib'))
self.assertTrue(os.path.exists('build/artifacts_path/Release/foo_shared.dll'))
self.assertTrue(os.path.exists('build/artifacts_path/Release/hello.exe'))
self.assertTrue(os.path.exists('build/artifacts_path/Release/subfoo_static.lib'))
self.assertTrue(os.path.exists('build/artifacts_path/Release/subfoo_shared.dll'))
self.assertTrue(os.path.exists('build/artifacts_path/Release/subhello.exe'))
elif generator == 'Ninja':
self.check_generate('artifacts_path')
self.check_build('artifacts_path', '--config Release')
self.assertTrue(os.path.exists('build/artifacts_path/foo_static.lib'))
self.assertTrue(os.path.exists('build/artifacts_path/foo_shared.dll'))
self.assertTrue(os.path.exists('build/artifacts_path/hello.exe'))
self.assertTrue(os.path.exists('build/artifacts_path/subfoo_static.lib'))
self.assertTrue(os.path.exists('build/artifacts_path/subfoo_shared.dll'))
self.assertTrue(os.path.exists('build/artifacts_path/subhello.exe'))
elif generator is None:
self.check_generate('artifacts_path')
self.check_build('artifacts_path', '--config Release')
self.assertTrue(os.path.exists('build/artifacts_path/foo_static.lib'))
self.assertTrue(os.path.exists('build/artifacts_path/foo_shared.dll'))
self.assertTrue(os.path.exists('build/artifacts_path/hello.exe'))
self.assertTrue(os.path.exists('build/artifacts_path/subfoo_static.lib'))
self.assertTrue(os.path.exists('build/artifacts_path/subfoo_shared.dll'))
self.assertTrue(os.path.exists('build/artifacts_path/subhello.exe'))
elif PLATFORM == 'linux':
self.check_generate('artifacts_path', args='-G Ninja --profiling-output=profiling.json --profiling-format=google-trace')
self.check_generate('artifacts_path')
self.check_build('artifacts_path')
self.assertTrue(os.path.exists('build/artifacts_path/libfoo_static.a'))
self.assertTrue(os.path.exists('build/artifacts_path/libfoo_shared.so'))
Expand All @@ -82,18 +95,24 @@ def test_artifact_path(self):
self.assertTrue(os.path.exists('build/artifacts_path/libsubfoo_shared.so'))
self.assertTrue(os.path.exists('build/artifacts_path/subhello'))
elif PLATFORM == 'mac':
self.check_generate('artifacts_path', args='-G Ninja --profiling-output=profiling.json --profiling-format=google-trace')
self.check_generate('artifacts_path')
self.check_build('artifacts_path')
self.assertTrue(os.path.exists('build/artifacts_path/libfoo_static.a'))
self.assertTrue(os.path.exists('build/artifacts_path/libfoo_shared.dylib'))
self.assertTrue(os.path.exists('build/artifacts_path/hello'))
self.assertTrue(os.path.exists('build/artifacts_path/libsubfoo_static.a'))
self.assertTrue(os.path.exists('build/artifacts_path/libsubfoo_shared.dylib'))
self.assertTrue(os.path.exists('build/artifacts_path/subhello'))

shutil.rmtree('build/artifacts_path')

shutil.rmtree('build/artifacts_path')


if __name__ == "__main__":
unittest.main()
parser = argparse.ArgumentParser(description="Run tests with custom parameters.")
parser.add_argument("-G", "--generator", type=str, help="Specify the generator (e.g., Ninja, Ninja Multi-Config).")
args, unittest_args = parser.parse_known_args()

if args.generator:
generator = args.generator

unittest.main(argv=[__file__] + unittest_args)

0 comments on commit 9e717c0

Please sign in to comment.