Skip to content

Commit

Permalink
[WIP] Start fixing include paths
Browse files Browse the repository at this point in the history
  • Loading branch information
oleavr committed Mar 18, 2024
1 parent e86fbf9 commit a8b329c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 26 deletions.
30 changes: 4 additions & 26 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2784,28 +2784,6 @@ def generate_llvm_ir_compile(self, target, src):
self.add_build(element)
return (rel_obj, rel_src)

@lru_cache(maxsize=None)
def generate_inc_dir(self, compiler: 'Compiler', d: str, basedir: str, is_system: bool) -> \
T.Tuple['ImmutableListProtocol[str]', 'ImmutableListProtocol[str]']:
# Avoid superfluous '/.' at the end of paths when d is '.'
if d not in ('', '.'):
expdir = os.path.normpath(os.path.join(basedir, d))
else:
expdir = basedir
srctreedir = os.path.normpath(os.path.join(self.build_to_src, expdir))
sargs = compiler.get_include_args(srctreedir, is_system)
# There may be include dirs where a build directory has not been
# created for some source dir. For example if someone does this:
#
# inc = include_directories('foo/bar/baz')
#
# But never subdir()s into the actual dir.
if os.path.isdir(os.path.join(self.environment.get_build_dir(), expdir)):
bargs = compiler.get_include_args(expdir, is_system)
else:
bargs = []
return (sargs, bargs)

def _generate_single_compile(self, target: build.BuildTarget, compiler: Compiler) -> CompilerArgs:
commands = self._generate_single_compile_base_args(target, compiler)
commands += self._generate_single_compile_target_args(target, compiler)
Expand Down Expand Up @@ -2848,11 +2826,11 @@ def _generate_single_compile_target_args(self, target: build.BuildTarget, compil
# We should iterate include dirs in reversed orders because
# -Ipath will add to begin of array. And without reverse
# flags will be added in reversed order.
for d in reversed(i.get_incdirs()):
for d in reversed(i.expand_incdirs(self.environment.get_build_dir())):
# Add source subdir first so that the build subdir overrides it
(compile_obj, includeargs) = self.generate_inc_dir(compiler, d, basedir, i.is_system)
commands += compile_obj
commands += includeargs
commands += compiler.get_include_args(os.path.normpath(os.path.join(self.build_to_src, d.srcdir)), i.is_system)
if d.builddir is not None:
commands += compiler.get_include_args(d.builddir, i.is_system)
for d in i.get_extra_build_dirs():
commands += compiler.get_include_args(d, i.is_system)
# Add per-target compile args, f.ex, `c_args : ['-DFOO']`. We set these
Expand Down
41 changes: 41 additions & 0 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,45 @@ def get_curdir(self) -> str:
def get_incdirs(self) -> T.List[str]:
return self.incdirs

def expand_incdirs(self, builddir: str) -> T.List[IncludeDirPair]:
result = []

curdir = self.curdir
bsubdir = compute_build_subdir(curdir, self.is_build_only_subproject)
for d in self.incdirs:
# Avoid superfluous '/.' at the end of paths when d is '.'
if d not in ('', '.'):
sdir = os.path.normpath(os.path.join(curdir, d))
bdir = os.path.normpath(os.path.join(bsubdir, d))
else:
sdir = curdir
bdir = bsubdir

# There may be include dirs where a build directory has not been
# created for some source dir. For example if someone does this:
#
# inc = include_directories('foo/bar/baz')
#
# But never subdir()s into the actual dir.
if not os.path.isdir(os.path.join(builddir, bdir)):
bdir = None

result.append(IncludeDirPair(sdir, bdir))

return result

def get_extra_build_dirs(self) -> T.List[str]:
return self.extra_build_dirs

def expand_extra_build_dirs(self) -> T.List[str]:
result = []

bsubdir = compute_build_subdir(self.curdir, self.is_build_only_subproject)
for d in self.extra_build_dirs:
result.append(os.path.normpath(os.path.join(bsubdir, d)))

return result

def to_string_list(self, sourcedir: str, builddir: str) -> T.List[str]:
"""Convert IncludeDirs object to a list of strings.
Expand All @@ -468,6 +504,11 @@ def to_string_list(self, sourcedir: str, builddir: str) -> T.List[str]:
strlist.append(os.path.join(builddir, bsubdir, idir))
return strlist

@dataclass
class IncludeDirPair:
srcdir: str
builddir: T.Optional[str]

@dataclass(eq=False)
class ExtractedObjects(HoldableObject):
'''
Expand Down

0 comments on commit a8b329c

Please sign in to comment.