Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make aspect integrations tests wotk on Windows #207

Merged
merged 2 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,23 @@ jobs:
integration-tests-aspect:
strategy:
matrix:
os: [ ubuntu-22.04, macos-12 ]
os: [ ubuntu-22.04, macos-12, windows-2022 ]
runs-on: ${{ matrix.os }}
needs: [ fast-tests ]
steps:
- uses: actions/checkout@v4
- name: Integration tests - Aspect
if: runner.os != 'Windows'
run: |
cd test
cd aspect
python execute_tests.py
- name: Integration tests - Aspect
if: runner.os == 'Windows'
run: |
cd test
cd aspect
python execute_tests.py -b 7.0.0 -p 3.8.18

integration-tests-apply-fixes:
runs-on: ubuntu-22.04
Expand Down
7 changes: 5 additions & 2 deletions src/aspect/dwyu.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,15 @@ def extract_defines_from_compiler_flags(compiler_flags):
defines = {}

for cflag in compiler_flags:
if cflag.startswith("-U"):
# gcc/clang use '-U'. MSVC uses '/U'.
if cflag.startswith(("-U", "/U")):
undefine = cflag[2:]
undefine_name = undefine.split("=", 1)[0]
if undefine_name in defines.keys():
defines.pop(undefine_name)
if cflag.startswith("-D"):

# gcc/clang use '-D'. MSVC uses '/D'.
if cflag.startswith(("-D", "/D")):
define = cflag[2:]
define_name = define.split("=", 1)[0]
defines[define_name] = define
Expand Down
7 changes: 7 additions & 0 deletions src/aspect/test/dwyu_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ def _extract_defines_from_compiler_flags_test_impl(ctx):
extract_defines_from_compiler_flags(["-DFoo=BAR=42", "-DTick 42", '-DRiff "Raff"']),
)

# MSVC syntax
asserts.equals(
env,
["Bar", "FooBar=42"],
extract_defines_from_compiler_flags(["/DFoo", "/UFoo", "/DBar", "/DFooBar=42"]),
)

return unittest.end(env)

extract_defines_from_compiler_flags_test = unittest.make(_extract_defines_from_compiler_flags_test_impl)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

from result import ExpectedResult, Result
from test_case import TestCaseBase

Expand All @@ -6,7 +8,7 @@ class TestCase(TestCaseBase):
def execute_test_logic(self) -> Result:
expected = ExpectedResult(
success=False,
invalid_includes=["File='alias/use_a_and_b.cpp', include='alias/a.h'"],
invalid_includes=[f"File='{Path('alias/use_a_and_b.cpp')}', include='alias/a.h'"],
)
actual = self._run_dwyu(target="//alias:use_a_transitively", aspect=self.default_aspect)

Expand Down
6 changes: 5 additions & 1 deletion test/aspect/defines/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ cc_library(
cc_library(
name = "defines_from_bazel_target",
hdrs = ["defines_from_bazel_target.h"],
copts = ["-DSOME_COPT 42"],
copts = select({
# Strictly speaking Windows does not automatically equal MSVC, but does so in our integration tests
"@platforms//os:windows": ["/DSOME_COPT 42"],
"//conditions:default": ["-DSOME_COPT 42"],
}),
defines = ["SOME_DEFINE"],
local_defines = ["LOCAL_DEFINE"],
deps = ["//defines/support:lib_a"],
Expand Down
6 changes: 3 additions & 3 deletions test/aspect/defines/defines_from_bazel_target.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#ifdef SOME_DEFINE
#include "defines/support/a.h"
#else
#include "defines/support/b.h"
#include "non/existing/a.h"
#endif

#ifdef LOCAL_DEFINE
#include "defines/support/a.h"
#else
#include "defines/support/b.h"
#include "non/existing/b.h"
#endif

#if SOME_COPT > 40
#include "defines/support/a.h"
#else
#include "defines/support/b.h"
#include "non/existing/c.h"
#endif
6 changes: 3 additions & 3 deletions test/aspect/defines/transitive_defines_from_bazel_target.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifdef TRANSITIVE_DEFINE
#include "defines/support/a.h"
#else
#include "defines/support/b.h"
#include "non/existing/a.h"
#endif

#include "defines/support/a.h"
Expand All @@ -13,9 +13,9 @@
// 'local_defines' which should not leak to users of the target

#ifdef LOCAL_DEFINE
#include "defines/support/b.h"
#include "non/existing/b.h"
#endif

#ifdef LOCAL_COPT
#include "defines/support/b.h"
#include "non/existing/c.h"
#endif
3 changes: 1 addition & 2 deletions test/aspect/execution_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging
import subprocess
from importlib.machinery import SourceFileLoader
from os import environ
from pathlib import Path
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -75,7 +74,7 @@ def main(
versions = [TestedVersions(bazel=bazel, python=python)] if bazel and python else tested_versions

failed_tests = []
output_root = Path(environ["HOME"]) / ".cache" / "bazel" / workspace_path.relative_to("/")
output_root = Path.home() / ".cache" / "bazel" / "dwyu"
for version in versions:
output_base = output_root / f"aspect_integration_tests_bazel_{version.bazel}_python_{version.python}"
output_base.mkdir(parents=True, exist_ok=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

from result import ExpectedResult, Result
from test_case import TestCaseBase

Expand All @@ -7,7 +9,7 @@ def execute_test_logic(self) -> Result:
expected = ExpectedResult(
success=False,
invalid_includes=[
"File='ignore_includes/use_not_ignored_header.h', include='example_substring_matching_does_not_work_here.h'"
f"File='{Path('ignore_includes/use_not_ignored_header.h')}', include='example_substring_matching_does_not_work_here.h'"
],
)
actual = self._run_dwyu(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

from result import ExpectedResult, Result
from test_case import TestCaseBase

Expand All @@ -6,7 +8,7 @@ class TestCase(TestCaseBase):
def execute_test_logic(self) -> Result:
expected = ExpectedResult(
success=False,
invalid_includes=["File='target_mapping/use_lib_c.cpp', include='target_mapping/libs/c.h'"],
invalid_includes=[f"File='{Path('target_mapping/use_lib_c.cpp')}', include='target_mapping/libs/c.h'"],
unused_public_deps=["//target_mapping/libs:a"],
)
actual = self._run_dwyu(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

from result import ExpectedResult, Result
from test_case import TestCaseBase

Expand All @@ -6,7 +8,7 @@ class TestCase(TestCaseBase):
def execute_test_logic(self) -> Result:
expected = ExpectedResult(
success=False,
invalid_includes=["File='target_mapping/use_lib_c.cpp', include='target_mapping/libs/c.h'"],
invalid_includes=[f"File='{Path('target_mapping/use_lib_c.cpp')}', include='target_mapping/libs/c.h'"],
unused_public_deps=["//target_mapping/libs:a"],
)
actual = self._run_dwyu(
Expand Down
6 changes: 5 additions & 1 deletion test/aspect/tree_artifact/test_invalid_tree_artifact.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

from result import ExpectedResult, Result
from test_case import TestCaseBase

Expand All @@ -7,7 +9,9 @@ def execute_test_logic(self) -> Result:
expected = ExpectedResult(
success=False,
# We omit "File='bazel-out/<compilation_mode_and_platform> to allow testing in various environments
invalid_includes=["/bin/tree_artifact/sources.cc/tree_lib.cc', include='tree_artifact/some_lib.h'"],
invalid_includes=[
f"{Path('/bin/tree_artifact/sources.cc/tree_lib.cc')}', include='tree_artifact/some_lib.h'"
],
)
actual = self._run_dwyu(
target="//tree_artifact:tree_artifact_library",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

from result import ExpectedResult, Result
from test_case import TestCaseBase

Expand All @@ -6,7 +8,7 @@ class TestCase(TestCaseBase):
def execute_test_logic(self) -> Result:
expected = ExpectedResult(
success=False,
invalid_includes=["File='using_transitive_dep/main.cpp', include='using_transitive_dep/foo.h'"],
invalid_includes=[f"File='{Path('using_transitive_dep/main.cpp')}', include='using_transitive_dep/foo.h'"],
)
actual = self._run_dwyu(target="//using_transitive_dep:main", aspect=self.default_aspect)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

from result import ExpectedResult, Result
from test_case import TestCaseBase

Expand All @@ -7,7 +9,7 @@ def execute_test_logic(self) -> Result:
expected = ExpectedResult(
success=False,
invalid_includes=[
"File='using_transitive_dep/transitive_usage_through_impl_deps.h', include='using_transitive_dep/foo.h'"
f"File='{Path('using_transitive_dep/transitive_usage_through_impl_deps.h')}', include='using_transitive_dep/foo.h'"
],
)
actual = self._run_dwyu(
Expand Down