Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0a2f706
dependencies: Annotate the DependencyPackages class
dcbaker Oct 24, 2025
1f1f7fc
dependencies: Move type_name to class level
dcbaker Oct 24, 2025
2725ff5
dependencies: Pass the `name` to `ExternalDependency` constructor
dcbaker Oct 24, 2025
b63b62e
dependencies/framework: remove useless stringlistify call
dcbaker Oct 24, 2025
9f5f0ea
dependencies: stop passing "language" as a keyword argument
dcbaker Oct 24, 2025
70822bd
dependencies/python: Don't pass embed as a keyword to PythonPkgConfig…
dcbaker Oct 24, 2025
83dc0e0
dependencies: Don't pass for_machine by keyword
dcbaker Oct 24, 2025
7b559ec
dependencies: Require 'native' be passed in kwargs
dcbaker Oct 24, 2025
126b6ad
dependencies: Add a wrapper class for Dependency candidates
dcbaker Oct 24, 2025
1e5b4c3
Dependencies: Make use of the DependencyCandidate class
dcbaker Oct 24, 2025
b7395d1
dependencies: Catch non MesonException in detect and give better message
dcbaker Oct 27, 2025
f2f5696
dependencies/detect: simplify logging tried methods
dcbaker Oct 27, 2025
d03a5a1
dependencies: Remove `log_tried` method
dcbaker Oct 27, 2025
94dbaea
dependencies/coarrays: Remove dead code
dcbaker Oct 29, 2025
5e20232
WIP: add back the cmake_name parameter to DependencyFactory
dcbaker Oct 29, 2025
f6c53bc
backend/ninja: Annotate `generate_swift_target`
dcbaker Oct 27, 2025
6dd09a6
backend/ninja: Annotate determine_java_compile_args
dcbaker Oct 27, 2025
92b5b50
build: Add docstring for `IncludeDirs`
dcbaker Oct 27, 2025
985f8f6
build: Remove IncludeDirs.__repr__
dcbaker Oct 28, 2025
57bf28d
build: Remove IncludeDirs.get_extra_build_dirs
dcbaker Oct 27, 2025
c1ad5aa
build: Remove IncludeDirs.get_curdir()
dcbaker Oct 27, 2025
12e57ad
modules/hotdoc: Make use of IncludeDirs.to_string_list
dcbaker Oct 27, 2025
bccbcfc
build: Include `extra_build_directories` in to_string_list
dcbaker Oct 27, 2025
0fb2710
build: remove IncludeDirs.get_inc_dirs()
dcbaker Oct 27, 2025
51ba29f
modules/pkgconfig: Correctly handle IncludeDirs.extra_build_dirs
dcbaker Oct 27, 2025
49b03d8
backend/ninja: Use list and join on os.pathsep instead of string concat
dcbaker Oct 27, 2025
b22a7b5
backend/ninja: Use IncludeDir.to_string_list for Java sources
dcbaker Oct 27, 2025
816e56f
backend/ninja: Use IncludeDirs.to_string_list for swift targets
dcbaker Oct 28, 2025
6dd594b
build: Rename IncludeDirs.to_string_list -> abs_string_list
dcbaker Oct 28, 2025
9fc7c24
build: Add IncludeDirs.rel_string_list
dcbaker Oct 28, 2025
8a38912
backend/ninja: Extend InlcudeDirs.rel_string_list for backend use
dcbaker Oct 28, 2025
ba554a1
wip: maybe this fixes stuff?
dcbaker Nov 5, 2025
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
79 changes: 25 additions & 54 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from ..compilers.cs import CsCompiler
from ..compilers.fortran import FortranCompiler
from ..compilers.rust import RustCompiler
from ..compilers.swift import SwiftCompiler
from ..mesonlib import FileOrString
from .backends import TargetIntrospectionData

Expand Down Expand Up @@ -1569,20 +1570,18 @@ def generate_cs_target(self, target: build.BuildTarget) -> None:

self.create_target_source_introspection(target, compiler, commands, rel_srcs, generated_rel_srcs)

def determine_java_compile_args(self, target, compiler) -> T.List[str]:
args = []
def determine_java_compile_args(self, target: build.Jar, compiler: Compiler) -> T.List[str]:
args = self.generate_basic_compiler_args(target, compiler)
args += target.get_java_args()
args += compiler.get_output_args(self.get_target_private_dir(target))
args += target.get_classpath_args()
curdir = target.get_subdir()
sourcepath = os.path.join(self.build_to_src, curdir) + os.pathsep
sourcepath += os.path.normpath(curdir) + os.pathsep
sourcepaths = [os.path.join(self.build_to_src, curdir)]
sourcepaths.append(os.path.normpath(curdir))
for i in target.include_dirs:
for idir in i.get_incdirs():
sourcepath += os.path.join(self.build_to_src, i.curdir, idir) + os.pathsep
args += ['-sourcepath', sourcepath]
return args
sourcepaths.extend(i.abs_string_list(self.source_dir, self.build_dir))
args += ['-sourcepath', os.pathsep.join(sourcepaths)]
return list(args)

def generate_java_compile(self, srcs, target, compiler, args) -> str:
deps = [os.path.join(self.get_target_dir(l), l.get_filename()) for l in target.link_targets]
Expand Down Expand Up @@ -2273,20 +2272,17 @@ def get_swift_link_deps(self, target) -> T.List[str]:
result.append(self.get_target_filename(l))
return result

def split_swift_generated_sources(self, target):
def split_swift_generated_sources(self, target: build.BuildTarget) -> T.List[str]:
all_srcs = self.get_target_generated_sources(target)
srcs = []
others = []
srcs: T.List[str] = []
for i in all_srcs:
if i.endswith('.swift'):
srcs.append(i)
else:
others.append(i)
return srcs, others
return srcs

def generate_swift_target(self, target) -> None:
def generate_swift_target(self, target: build.BuildTarget) -> None:
module_name = target.swift_module_name
swiftc = target.compilers['swift']
swiftc = T.cast('SwiftCompiler', target.compilers['swift'])
abssrc = []
relsrc = []
abs_headers = []
Expand Down Expand Up @@ -2332,15 +2328,8 @@ def generate_swift_target(self, target) -> None:
if len(abssrc) == 1 and os.path.basename(abssrc[0]) != 'main.swift':
compile_args += swiftc.get_library_args()
for i in reversed(target.get_include_dirs()):
basedir = i.get_curdir()
for d in i.get_incdirs():
if d not in ('', '.'):
expdir = os.path.join(basedir, d)
else:
expdir = basedir
srctreedir = os.path.normpath(os.path.join(self.environment.get_build_dir(), self.build_to_src, expdir))
sargs = swiftc.get_include_args(srctreedir, False)
compile_args += sargs
for path in i.abs_string_list(self.source_dir, self.build_dir):
compile_args.extend(swiftc.get_include_args(path, False))
compile_args += target.get_extra_args('swift')
link_args = swiftc.get_output_args(os.path.join(self.environment.get_build_dir(), self.get_target_filename(target)))
link_args += self.build.get_project_link_args(swiftc, target.subproject, target.for_machine)
Expand All @@ -2359,7 +2348,7 @@ def generate_swift_target(self, target) -> None:
if reldir == '':
reldir = '.'
link_args += ['-L', os.path.normpath(os.path.join(self.environment.get_build_dir(), reldir))]
(rel_generated, _) = self.split_swift_generated_sources(target)
rel_generated = self.split_swift_generated_sources(target)
abs_generated = [os.path.join(self.environment.get_build_dir(), x) for x in rel_generated]
# We need absolute paths because swiftc needs to be invoked in a subdir
# and this is the easiest way about it.
Expand Down Expand Up @@ -2999,26 +2988,15 @@ def generate_llvm_ir_compile(self, target, src: FileOrString) -> T.Tuple[str, st
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_inc_dir(self, compiler: 'Compiler', inc: build.IncludeDirs
) -> ImmutableListProtocol[str]:
# 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.
args: T.List[str] = []
for p in inc.rel_string_list(self.build_to_src, self.build_dir):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing reverse=True?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That causes the test_internal_include_order test to fail, so I think I ported the comment over incorrectly

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which doesn't make sense.

I need to think about this one more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, after a lot of head scratching and confusion, I have an answer: rel_string_list returns the stringlist in the order that this code expects already, so no reversing required. The reason the previous code reversed the iteration was to get build directory before source directory, which this does by default.

args.extend(compiler.get_include_args(p, inc.is_system))
return args

def _generate_single_compile(self, target: build.BuildTarget, compiler: Compiler) -> CompilerArgs:
commands = self._generate_single_compile_base_args(target, compiler)
Expand Down Expand Up @@ -3057,17 +3035,10 @@ def _generate_single_compile_target_args(self, target: build.BuildTarget, compil
# external deps and must maintain the order in which they are specified.
# Hence, we must reverse the list so that the order is preserved.
for i in reversed(target.get_include_dirs()):
basedir = i.get_curdir()
# 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()):
# 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
for d in i.get_extra_build_dirs():
commands += compiler.get_include_args(d, i.is_system)
commands += self.generate_inc_dir(compiler, i)
# Add per-target compile args, f.ex, `c_args : ['-DFOO']`. We set these
# near the end since these are supposed to override everything else.
commands += self.escape_extra_args(target.get_extra_args(compiler.get_language()))
Expand Down
8 changes: 4 additions & 4 deletions mesonbuild/backend/vs2010backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,17 +1063,17 @@ def get_args_defines_and_inc_dirs(self, target, compiler, generated_files_includ
# need them to be looked in first.
for d in reversed(target.get_include_dirs()):
# reversed is used to keep order of includes
for i in reversed(d.get_incdirs()):
curdir = os.path.join(d.get_curdir(), i)
for i in reversed(d.incdirs):
curdir = os.path.join(d.curdir, i)
try:
# Add source subdir first so that the build subdir overrides it
args.append('-I' + os.path.join(proj_to_src_root, curdir)) # src dir
args.append('-I' + self.relpath(curdir, target.subdir)) # build dir
except ValueError:
# Include is on different drive
args.append('-I' + os.path.normpath(curdir))
for i in d.get_extra_build_dirs():
curdir = os.path.join(d.get_curdir(), i)
for i in d.extra_build_dirs:
curdir = os.path.join(d.curdir, i)
args.append('-I' + self.relpath(curdir, target.subdir)) # build dir
# Add per-target compile args, f.ex, `c_args : ['/DFOO']`. We set these
# near the end since these are supposed to override everything else.
Expand Down
7 changes: 1 addition & 6 deletions mesonbuild/backend/xcodebackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1653,12 +1653,7 @@ def generate_single_build_target(self, objects_dict: PbxDict, target_name: str,
is_swift = self.is_swift_target(target)
langs = set()
for d in target.include_dirs:
for sd in d.incdirs:
cd = os.path.join(d.curdir, sd)
headerdirs.append(os.path.join(self.environment.get_source_dir(), cd))
headerdirs.append(os.path.join(self.environment.get_build_dir(), cd))
for extra in d.extra_build_dirs:
headerdirs.append(os.path.join(self.environment.get_build_dir(), extra))
headerdirs.extend(d.abs_string_list(self.environment.get_source_dir(), self.environment.get_build_dir()))
# Swift can import declarations from C-based code using bridging headers.
# There can only be one header, and it must be included as a source file.
for i in target.get_sources():
Expand Down
55 changes: 36 additions & 19 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,30 +481,21 @@ def get_project_link_args(self, compiler: 'Compiler', project: str, for_machine:
@dataclass(eq=False)
class IncludeDirs(HoldableObject):

"""Internal representation of an include_directories call."""
"""Internal representation of an include_directories call.

:param curdir: The directory from which this IncludeDirs is declared
:param incdirs: The paths relative to curdir the include
:param is_system: Should these be treated as `-isystem` (true) or `-I
:param extra_build_dirs: Extra build directories to include
"""

curdir: str
incdirs: T.List[str]
is_system: bool
# Interpreter has validated that all given directories
# actually exist.
extra_build_dirs: T.List[str] = field(default_factory=list)

def __repr__(self) -> str:
r = '<{} {}/{}>'
return r.format(self.__class__.__name__, self.curdir, self.incdirs)

def get_curdir(self) -> str:
return self.curdir

def get_incdirs(self) -> T.List[str]:
return self.incdirs

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

def to_string_list(self, sourcedir: str, builddir: str) -> T.List[str]:
"""Convert IncludeDirs object to a list of strings.
def abs_string_list(self, sourcedir: str, builddir: str) -> T.List[str]:
"""Convert IncludeDirs object to a list of absolute string paths.

:param sourcedir: The absolute source directory
:param builddir: The absolute build directory, option, build dir will not
Expand All @@ -515,8 +506,34 @@ def to_string_list(self, sourcedir: str, builddir: str) -> T.List[str]:
for idir in self.incdirs:
strlist.append(os.path.join(sourcedir, self.curdir, idir))
strlist.append(os.path.join(builddir, self.curdir, idir))
for idir in self.extra_build_dirs:
strlist.append(os.path.join(builddir, self.curdir, idir))
return strlist

def rel_string_list(self, build_to_src: str, build_root: T.Optional[str] = None) -> T.List[str]:
"""Convert IncludeDirs object to a list of relative string paths.

:param build_to_src: The relative path from the build dir to source dir
:param build_root: The absolute build root. When provided, build
directories that have not been created will be ignored. Default: None.
:return: A list if strings (without compiler argument)
"""
strlist: T.List[str] = []
for idirs, add_src in [(self.incdirs, True), (self.extra_build_dirs, False)]:
for idir in idirs:
bld_dir = os.path.normpath(os.path.join(self.curdir, idir))
if idir not in {'', '.'}:
expdir = bld_dir
else:
expdir = self.curdir
if build_root is None or os.path.isdir(os.path.join(build_root, expdir)):
strlist.append(bld_dir)
if add_src:
strlist.append(os.path.normpath(os.path.join(build_to_src, expdir)))

return strlist


@dataclass(eq=False)
class ExtractedObjects(HoldableObject):
'''
Expand Down Expand Up @@ -1643,7 +1660,7 @@ def add_include_dirs(self, args: T.Sequence['IncludeDirs'], set_is_system: T.Opt
set_is_system = 'preserve'
if set_is_system != 'preserve':
is_system = set_is_system == 'system'
ids = [IncludeDirs(x.get_curdir(), x.get_incdirs(), is_system, x.get_extra_build_dirs()) for x in ids]
ids = [IncludeDirs(x.curdir, x.incdirs, is_system, x.extra_build_dirs) for x in ids]
self.include_dirs += ids

def get_aliases(self) -> T.List[T.Tuple[str, str, str]]:
Expand Down
14 changes: 1 addition & 13 deletions mesonbuild/compilers/d.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,20 +513,8 @@ def get_feature_args(self, kwargs: DFeatures, build_to_src: str) -> T.List[str]:
import_dir_arg = d_feature_args[self.id]['import_dir']
if not import_dir_arg:
raise EnvironmentException('D compiler %s does not support the "string import directories" feature.' % self.name_string())
# TODO: ImportDirs.to_string_list(), but we need both the project source
# root and project build root for that.
for idir_obj in kwargs['import_dirs']:
basedir = idir_obj.get_curdir()
for idir in idir_obj.get_incdirs():
bldtreedir = os.path.join(basedir, idir)
# Avoid superfluous '/.' at the end of paths when d is '.'
if idir not in ('', '.'):
expdir = bldtreedir
else:
expdir = basedir
srctreedir = os.path.join(build_to_src, expdir)
res.append(f'{import_dir_arg}{srctreedir}')
res.append(f'{import_dir_arg}{bldtreedir}')
res.extend(f'{import_dir_arg}{i}' for i in idir_obj.rel_string_list(build_to_src))

return res

Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/compilers/mixins/clike.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def build_wrapper_args(self, env: 'Environment',
cargs += d.get_compile_args()
system_incdir = d.get_include_type() == 'system'
for i in d.get_include_dirs():
for idir in i.to_string_list(env.get_source_dir(), env.get_build_dir()):
for idir in i.abs_string_list(env.get_source_dir(), env.get_build_dir()):
cargs.extend(self.get_include_args(idir, system_incdir))
if mode is CompileCheckMode.LINK:
# Add link flags needed to find dependencies
Expand Down
Loading
Loading