Skip to content

Commit

Permalink
fix: replacement of include paths (#14)
Browse files Browse the repository at this point in the history
* test: add new case for multiple includes

* fix: include paths which are a subset of another include path now replaced correctly
  • Loading branch information
t-bre authored Aug 21, 2023
1 parent 79e9b2f commit 387b5aa
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions ccdgen/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,16 @@ def replace_relative_paths(command: str) -> str:
Command with relative paths replaced
"""

# capture does not include the -I
matches = re.findall(r'-I([^\s]+)', command)

for m in matches:
relative_path = m # capture does not include the -I
# space in replacement ensures that include paths which are a subset of
# another include path are not replaced in that path
# TODO: regex replace might remove need for this^
relative_path = m
absolute_path = os.path.abspath(relative_path)
command = command.replace(m, absolute_path)
command = command.replace(m + ' ', absolute_path + ' ')

return command

Expand Down
2 changes: 1 addition & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ BUILD_DIR = build

C_SOURCES = src/test.c src/foo/foo.c
C_FLAGS = -Wall -Werror -std=c11 -O3
C_INCLUDES = -Isrc/foo
C_INCLUDES = -Isrc/foo -Isrc/bar
CC = gcc
EXE = $(BUILD_DIR)/test

Expand Down
1 change: 1 addition & 0 deletions test/src/bar/bar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define BAR
1 change: 1 addition & 0 deletions test/src/foo/foo.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdio.h>
#include "bar.h"

void foo()
{
Expand Down

0 comments on commit 387b5aa

Please sign in to comment.