Skip to content

Commit

Permalink
Add cmake build test and path normalization test for Windows
Browse files Browse the repository at this point in the history
Signed-off-by: javrin <jawabiscuit@users.noreply.github.com>
  • Loading branch information
Jawabiscuit committed Sep 15, 2023
1 parent ac3ff37 commit d0958cd
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/rez/data/tests/builds/packages/winning/9.6/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 2.8)

# On Linux defining a project name is usually not necessary for rez packages which simply use cmake
# as a Makefile recipe generator, however to be cross-compatible with Windows we can define it to
# get the same functionality.
#
# Here we are telling cmake this is not a compiled project by providing NONE for the second argument.
#
# The project function is only being used in this in case because we are on Windows and want to use
# the gnu make utility provided by a `make` rez package or configuring a path to `make.exe` in rez config.
# This bypasses having to use the default `nmake` on Windows which requires the Windows compiler and
# linker and attempts to build a simple c++ executable during a build.
#
project($ENV{REZ_BUILD_PROJECT_NAME}, NONE)

include(RezBuild)

file(GLOB_RECURSE py_files "python/*.py")

# Not using rez_install_python b/c we don't want to require python for this test package
rez_install_files(
${py_files}
DESTINATION .
)
15 changes: 15 additions & 0 deletions src/rez/data/tests/builds/packages/winning/9.6/package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name = "winning"
version = "9.6"
description = (
"Test cmake builds especially on Windows with Unix Makefiles generator. "
"This is a handy workflow to have on Windows b/c it supports rez + cmake with "
"minimal effort and w/o the overhead of Visual Studio. "
"Note: Using cmake on Windows requires path normalization to be enabled. "
)

build_requires = [
# make and cmake need to be installed locally for this test to build and succeed
]

def commands():
env.PYTHONPATH.append("{root}/python")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This file is intentionally left blank
32 changes: 31 additions & 1 deletion src/rez/tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
from rez.build_process import create_build_process
from rez.build_system import create_build_system
from rez.resolved_context import ResolvedContext
from rez.shells import get_shell_class
from rez.exceptions import BuildError, BuildContextResolveError,\
PackageFamilyNotFoundError
import unittest
from rez.tests.util import TestBase, TempdirMixin, find_file_in_path, \
per_available_shell, install_dependent, program_dependent
per_available_shell, install_dependent, platform_dependent, program_dependent
from rez.utils.platform_ import platform_
import shutil
import os.path
Expand Down Expand Up @@ -134,6 +135,35 @@ def _test_build_sup_world(self):
stdout = proc.communicate()[0]
self.assertEqual('hola amigo', stdout.strip())

@per_available_shell(include=["cmd", "gitbash"])
@program_dependent("cmake", "make")
@platform_dependent(["windows"])
@install_dependent()
def test_build_winning(self, shell):
"""Build, install, test the winning package."""
sh_cls = get_shell_class(shell)

cmake_exe = sh_cls.find_executable("cmake")
make_exe = sh_cls.find_executable("make")

self.update_settings(
dict(
default_shell=shell,
enable_path_normalization=True,
plugins=dict(
build_system=dict(
cmake=dict(
install_pyc=False,
build_system="make",
cmake_binary=cmake_exe,
make_binary=make_exe,
)
)
)
)
)
self._test_build("winning", "9.6")

@per_available_shell()
@install_dependent()
def test_build_whack(self, shell):
Expand Down
15 changes: 14 additions & 1 deletion src/rez/tests/test_shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from rez.utils.execution import ExecutableScriptMode, _get_python_script_files
from rez.utils.filesystem import canonical_path
from rez.tests.util import TestBase, TempdirMixin, per_available_shell, \
install_dependent
install_dependent, platform_dependent
from rez.bind import hello_world
from rez.config import config
import unittest
Expand Down Expand Up @@ -552,6 +552,19 @@ def test_root_normalization(self, shell):
)
)

@per_available_shell(include=["cmd", "powershell", "pwsh"])
@platform_dependent(["windows"])
def test_enabled_path_normalization(self, shell):
"""Test enabling path normalization via the config."""
config.override('enable_path_normalization', True)

sh = create_shell(shell)
test_path = r'C:\foo\bar\spam'
normalized_path = sh.normalize_path(test_path)
expected_path = 'C:/foo/bar/spam'

self.assertEqual(normalized_path, expected_path)

@per_available_shell()
def test_disabled_path_normalization(self, shell):
"""Test disabling path normalization via the config."""
Expand Down

0 comments on commit d0958cd

Please sign in to comment.