Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
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
53 changes: 53 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,59 @@ jobs:
- run: pytest -x -s
working-directory: objdir

CI-windows:
runs-on: windows-latest

steps:
- uses: actions/checkout@v4
- name: Setup Conda
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: '3.12'
activate-environment: cvise-env
- name: Create DIA SDK junction
shell: cmd
run: |
setlocal enabledelayedexpansion
set "CURR_DRIVE=%CD:~0,2%"
for /d %%i in ("C:\Program Files\Microsoft Visual Studio\2022\Enterprise", "C:\Program Files\Microsoft Visual Studio\2022\Community", "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise", "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community") do (
if exist "%%~i\DIA SDK" (
if exist "C:\DIA SDK" rmdir "C:\DIA SDK"
mklink /J "C:\DIA SDK" "%%~i\DIA SDK"
if /i NOT "!CURR_DRIVE!"=="C:" (
if exist "!CURR_DRIVE!\DIA SDK" rmdir "!CURR_DRIVE!\DIA SDK"
mklink /J "!CURR_DRIVE!\DIA SDK" "%%~i\DIA SDK"
)
goto :done
)
)
:done
- name: Install dependencies
shell: bash -l {0}
run: |
conda install -y -c conda-forge llvmdev clangdev winflexbison \
chardet jsonschema msgspec pebble psutil pytest pytest-mock pytest-subprocess zstandard
- name: Configure
shell: bash -l {0}
run: |
CONDA_PREFIX_UNIX=$(cygpath -m "$CONDA_PREFIX")
cmake -S . -B objdir \
-DCMAKE_PREFIX_PATH="$CONDA_PREFIX_UNIX/Library" \
-DLLVM_DIR="$CONDA_PREFIX_UNIX/Library/lib/cmake/llvm" \
-DClang_DIR="$CONDA_PREFIX_UNIX/Library/lib/cmake/clang" \
-DFLEX_EXECUTABLE="$CONDA_PREFIX_UNIX/Library/bin/win_flex.exe" \
-DPython3_EXECUTABLE="$CONDA_PREFIX_UNIX/python.exe" \
-DCLANG_FORMAT_PATH="$CONDA_PREFIX_UNIX/Library/bin/clang-format.exe"
- name: Build
shell: bash -l {0}
run: cmake --build objdir --config Release --parallel $NUMBER_OF_PROCESSORS
- name: Test
shell: bash -l {0}
run: |
cd objdir
pytest -x -s

CI-python:
runs-on: ubuntu-latest
container:
Expand Down
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,14 @@ add_subdirectory(clang_include_graph)
add_subdirectory(clex)
add_subdirectory(cvise)
add_subdirectory(delta)
add_subdirectory(treesitter_delta)
# add_subdirectory(treesitter_delta)

# Always link statically against Tree-sitter.
set(BUILD_SHARED_LIBS_SAVED "${BUILD_SHARED_LIBS}")
set(BUILD_SHARED_LIBS OFF)
add_subdirectory(tree-sitter EXCLUDE_FROM_ALL)
add_subdirectory(tree-sitter-cpp EXCLUDE_FROM_ALL)
set(BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS_SAVED}")
# set(BUILD_SHARED_LIBS_SAVED "${BUILD_SHARED_LIBS}")
# set(BUILD_SHARED_LIBS OFF)
# add_subdirectory(tree-sitter EXCLUDE_FROM_ALL)
# add_subdirectory(tree-sitter-cpp EXCLUDE_FROM_ALL)
# set(BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS_SAVED}")

# Copy top-level cvise script
configure_file(
Expand Down
4 changes: 2 additions & 2 deletions clang_delta/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function(configure_one_file path)
configure_file(
"${clang_delta_SOURCE_DIR}/${path}"
"${clang_delta_BINARY_DIR}/${path}"
COPYONLY
@ONLY
)
endfunction(configure_one_file)

Expand Down Expand Up @@ -679,7 +679,7 @@ set_target_properties(clang_delta

# On Windows, we also need to link with "Version.dll" system library.
# See <https://github.com/csmith-project/creduce/pull/126>.
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
if(MSVC)
target_link_libraries(clang_delta Version)
endif()

Expand Down
29 changes: 18 additions & 11 deletions clang_delta/tests/test_clang_delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@


def get_clang_version():
current = os.path.dirname(__file__)
binary = os.path.join(current, '../clang_delta')
output = subprocess.check_output(f'{binary} --version', shell=True, text=True)
binary = get_clang_delta_path()
output = subprocess.check_output(f'"{binary}" --version', shell=True, text=True)
for line in output.splitlines():
m = re.match(r'clang version (?P<version>[0-9]+)\.', line)
if m:
Expand All @@ -30,7 +29,15 @@ def get_clang_version():


def get_clang_delta_path() -> Path:
return Path(__file__).parent.parent / 'clang_delta'
current = Path(__file__).parent.parent.resolve()
binary_name = 'clang_delta' + '@CMAKE_EXECUTABLE_SUFFIX@'
p = current / binary_name
if not p.exists():
for cfg in ['Release', 'Debug', 'RelWithDebInfo', 'MinSizeRel']:
p_cfg = current / cfg / binary_name
if p_cfg.exists():
return p_cfg
return p


def get_testcase_path(testcase: str) -> Path:
Expand Down Expand Up @@ -78,18 +85,18 @@ def check_clang_delta_hints(
@classmethod
def check_query_instances(cls, testcase, arguments, expected):
current = os.path.dirname(__file__)
binary = os.path.join(current, '../clang_delta')
cmd = f'{binary} {os.path.join(current, testcase)} {arguments}'
binary = get_clang_delta_path()
cmd = f'"{binary}" {os.path.join(current, testcase)} {arguments}'
output = subprocess.check_output(cmd, shell=True, encoding='utf8')
assert output.strip() == expected

@classmethod
def check_error_message(cls, testcase, arguments, error_message):
current = os.path.dirname(__file__)
binary = os.path.join(current, '../clang_delta')
cmd = f'{binary} {os.path.join(current, testcase)} {arguments}'
binary = get_clang_delta_path()
cmd = f'"{binary}" {os.path.join(current, testcase)} {arguments}'
proc = subprocess.run(cmd, shell=True, encoding='utf8', stdout=subprocess.PIPE)
assert proc.returncode == 255
assert proc.returncode in (255, 4294967295)
assert proc.stdout.strip() == error_message

def test_aggregate_to_scalar_cast(self):
Expand Down Expand Up @@ -1326,9 +1333,9 @@ def test_union_to_struct_union3(self):

def test_piggypacking(self):
current = os.path.dirname(__file__)
binary = os.path.join(current, '../clang_delta')
binary = get_clang_delta_path()
args = '--transformation=remove-unused-function --counter=111 --to-counter=222 --warn-on-counter-out-of-bounds --report-instances-count'
cmd = '{} {} {}'.format(binary, os.path.join(current, 'remove-unused-function/macro2.cc'), args)
cmd = f'"{binary}" {os.path.join(current, "remove-unused-function/macro2.cc")} {args}'
run = subprocess.run(cmd, shell=True, encoding='utf8', capture_output=True)
assert 'Available transformation instances: 1' in run.stderr
assert 'Warning: number of transformation instances exceeded' in run.stderr
Expand Down
7 changes: 7 additions & 0 deletions clex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
set_source_files_properties(clex.c PROPERTIES COMPILE_FLAGS "-Wno-unused-function -Wno-sign-compare")
set_source_files_properties(strlex.c PROPERTIES COMPILE_FLAGS "-Wno-unused-function -Wno-sign-compare")
endif()

# Serialize flex execution to avoid potential race conditions with temporary files
add_custom_command(OUTPUT ${FLEX_strlex_scanner_OUTPUTS}
APPEND
DEPENDS ${FLEX_clex_scanner_OUTPUTS}
)

if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set_source_files_properties(clex.c PROPERTIES COMPILE_FLAGS -DYY_NO_UNISTD_H)
set_source_files_properties(strlex.c PROPERTIES COMPILE_FLAGS -DYY_NO_UNISTD_H)
Expand Down
35 changes: 35 additions & 0 deletions cmake_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,38 @@
/* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a
`char[]'. */
#cmakedefine YYTEXT_POINTER 1

#ifdef _WIN32
#include <io.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define isatty _isatty
#define fileno _fileno
#define read _read
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;

static inline ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream) {
if (lineptr == NULL || n == NULL || stream == NULL) return -1;
if (*lineptr == NULL) {
*n = 128;
*lineptr = (char *)malloc(*n);
if (*lineptr == NULL) return -1;
}
int c;
size_t i = 0;
while ((c = getc(stream)) != EOF) {
if (i + 1 >= *n) {
*n *= 2;
char *next = (char *)realloc(*lineptr, *n);
if (next == NULL) return -1;
*lineptr = next;
}
(*lineptr)[i++] = (char)c;
if (c == delim) break;
}
(*lineptr)[i] = '\0';
return (i == 0 && c == EOF) ? -1 : (ssize_t)i;
}
#endif
5 changes: 4 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import multiprocessing

import platform

import pytest


Expand All @@ -12,4 +14,5 @@ def mp_start_method():
The "forkserver" mode is the same as the one used by the C-Vise CLI.
"""
# Enforce the method selection, in case the test framework previously set a different one.
multiprocessing.set_start_method('forkserver', force=True)
method = 'spawn' if platform.system() == 'Windows' else 'forkserver'
multiprocessing.set_start_method(method, force=True)
9 changes: 8 additions & 1 deletion cvise/tests/test_balanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,14 @@ def test_parens_dir(self):
state = self._pass_new()
all_transforms = collect_all_transforms_dir(self.pass_, state, self.input_path)

self.assertIn((('a.txt', b'This is a test!\n'), ('b.txt', b'This \n')), all_transforms)
# Normalize line endings for Windows compatibility
normalized_transforms = set()
for t in all_transforms:
normalized_transforms.add(
tuple((name, content.replace(b'\r\n', b'\n')) for name, content in t)
)

self.assertIn((('a.txt', b'This is a test!\n'), ('b.txt', b'This \n')), normalized_transforms)


class BalancedParensOnlyTestCase(unittest.TestCase):
Expand Down
3 changes: 3 additions & 0 deletions delta/topformflat.l
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* very heuristic... */

%{
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <assert.h>
#include <limits.h>
#include <stdlib.h> // atoi
Expand Down
14 changes: 8 additions & 6 deletions tree-sitter-cpp/CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion tree-sitter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ target_include_directories(tree-sitter
PRIVATE lib/src
PUBLIC lib/include
)
target_compile_options(tree-sitter PRIVATE -std=gnu99)
if(NOT MSVC)
target_compile_options(tree-sitter PRIVATE -std=gnu99)
endif()
Loading