-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Cleanups for IncludeDirs
#15180
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
base: master
Are you sure you want to change the base?
Cleanups for IncludeDirs
#15180
Changes from all commits
0a2f706
1f1f7fc
2725ff5
b63b62e
9f5f0ea
70822bd
83dc0e0
7b559ec
126b6ad
1e5b4c3
b7395d1
f2f5696
d03a5a1
94dbaea
5e20232
f6c53bc
6dd09a6
92b5b50
985f8f6
57bf28d
c1ad5aa
12e57ad
bccbcfc
0fb2710
51ba29f
49b03d8
b22a7b5
816e56f
6dd594b
9fc7c24
8a38912
ba554a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
|
|
@@ -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] | ||
|
|
@@ -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 = [] | ||
|
|
@@ -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) | ||
|
|
@@ -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. | ||
|
|
@@ -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): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That causes the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
@@ -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())) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.