-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Refactor option getting v2 #13441
base: master
Are you sure you want to change the base?
Refactor option getting v2 #13441
Changes from all commits
569536a
7f8ba9b
a8fa34c
d2a3f91
39c4129
bd96bfb
6045f22
d176894
32a7b6d
3b693ad
c1fc3e4
84ce0f9
cdf8b2e
e9257c2
1d1a5fd
2a8ba99
21586c0
4cd8d9e
fe34853
8d5b189
a7ce0e6
ca35970
2e3382a
8dca103
551211e
ed65bac
486b2ac
9cddcad
dfd1406
ff4ed1d
efbdd74
2e21f8a
b15ccb1
3213b5d
0e63815
ce772b5
1cc1a1e
95426e0
45eb7c2
137c9b4
e069a11
8aee56d
00668ce
24aeb65
a92a602
fd010ef
a05481d
7b04d91
1443791
3f6d7cb
5d4c834
0e66574
9c3bb68
070c19e
090ce81
b69d95f
a7f4186
60734d0
7beadc1
caf5947
4157e87
0050d68
745ad65
6e0e998
a5d1dc1
db4a992
f5e4476
61ca065
94aabdf
cdff21d
7e5e1b0
27acdca
df00872
ba346ed
3d862fc
91a4eca
35cad78
82ce69e
79aa83c
46753dc
5c02f72
eb855f1
49ee948
498e7f7
aa91c02
7c523e6
2aae29a
128bf39
fab5a01
25b1005
2002cdb
4c481c4
8caafa4
6ab4d31
b011005
2613d7c
34fe03d
8211f75
cd64e53
518a1d9
134e70a
3a139b5
0fe1254
9d5594c
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## Per project subproject options rewrite | ||
|
||
You can now define per-subproject values for all shared configuration | ||
options. As an example you might want to enable optimizations on only | ||
one subproject: | ||
|
||
meson configure -Dnumbercruncher:optimization=3 | ||
|
||
Subproject specific values can be removed with -U | ||
|
||
meson configure -Unumbercruncher:optimization | ||
|
||
This is a major change in how options are handled. Current | ||
per-subproject options are converted to augments on the fly. It is | ||
expected that the logic might be changed in the next few releases as | ||
logic errors are discovered. | ||
|
||
We have tried to keep backwards compatibility as much as possible, but | ||
this may lead to some build breakage. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,9 +36,9 @@ | |
from .._typing import ImmutableListProtocol | ||
from ..arglist import CompilerArgs | ||
from ..compilers import Compiler | ||
from ..environment import Environment | ||
Check failure Code scanning / CodeQL Module-level cyclic import Error
'Environment' may not be defined if module
mesonbuild.environment Error loading related location Loading mesonbuild.backend.backends Error loading related location Loading definition Error loading related location Loading import Error loading related location Loading 'Environment' may not be defined if module mesonbuild.environment Error loading related location Loading mesonbuild.backend.backends Error loading related location Loading definition Error loading related location Loading import Error loading related location Loading 'Environment' may not be defined if module mesonbuild.environment Error loading related location Loading mesonbuild.backend.backends Error loading related location Loading definition Error loading related location Loading import Error loading related location Loading 'Environment' may not be defined if module mesonbuild.environment Error loading related location Loading mesonbuild.backend.backends Error loading related location Loading definition Error loading related location Loading import Error loading related location Loading 'Environment' may not be defined if module mesonbuild.environment Error loading related location Loading mesonbuild.backend.backends Error loading related location Loading definition Error loading related location Loading import Error loading related location Loading 'Environment' may not be defined if module mesonbuild.environment Error loading related location Loading mesonbuild.backend.backends Error loading related location Loading definition Error loading related location Loading import Error loading related location Loading 'Environment' may not be defined if module mesonbuild.environment Error loading related location Loading mesonbuild.backend.backends Error loading related location Loading definition Error loading related location Loading import Error loading related location Loading 'Environment' may not be defined if module mesonbuild.environment Error loading related location Loading mesonbuild.backend.backends Error loading related location Loading definition Error loading related location Loading import Error loading related location Loading 'Environment' may not be defined if module mesonbuild.environment Error loading related location Loading mesonbuild.backend.backends Error loading related location Loading definition Error loading related location Loading import Error loading related location Loading 'Environment' may not be defined if module mesonbuild.environment Error loading related location Loading mesonbuild.backend.backends Error loading related location Loading definition Error loading related location Loading import Error loading related location Loading 'Environment' may not be defined if module mesonbuild.environment Error loading related location Loading mesonbuild.backend.backends Error loading related location Loading definition Error loading related location Loading import Error loading related location Loading |
||
from ..interpreter import Interpreter, Test | ||
from ..linkers.linkers import StaticLinker | ||
Check failure Code scanning / CodeQL Module-level cyclic import Error
'StaticLinker' may not be defined if module
mesonbuild.linkers.linkers Error loading related location Loading mesonbuild.backend.backends Error loading related location Loading definition Error loading related location Loading import Error loading related location Loading 'StaticLinker' may not be defined if module mesonbuild.linkers.linkers Error loading related location Loading mesonbuild.backend.backends Error loading related location Loading definition Error loading related location Loading import Error loading related location Loading 'StaticLinker' may not be defined if module mesonbuild.linkers.linkers Error loading related location Loading mesonbuild.backend.backends Error loading related location Loading definition Error loading related location Loading import Error loading related location Loading 'StaticLinker' may not be defined if module mesonbuild.linkers.linkers Error loading related location Loading mesonbuild.backend.backends Error loading related location Loading definition Error loading related location Loading import Error loading related location Loading 'StaticLinker' may not be defined if module mesonbuild.linkers.linkers Error loading related location Loading mesonbuild.backend.backends Error loading related location Loading definition Error loading related location Loading import Error loading related location Loading 'StaticLinker' may not be defined if module mesonbuild.linkers.linkers Error loading related location Loading mesonbuild.backend.backends Error loading related location Loading definition Error loading related location Loading import Error loading related location Loading |
||
from ..mesonlib import FileMode, FileOrString | ||
|
||
from typing_extensions import TypedDict | ||
|
@@ -422,7 +422,7 @@ | |
abs_files: T.List[str] = [] | ||
result: T.List[mesonlib.File] = [] | ||
compsrcs = classify_unity_sources(target.compilers.values(), unity_src) | ||
unity_size = target.get_option(OptionKey('unity_size')) | ||
unity_size = self.get_target_option(target, 'unity_size') | ||
assert isinstance(unity_size, int), 'for mypy' | ||
|
||
def init_language_file(suffix: str, unity_file_number: int) -> T.TextIO: | ||
|
@@ -908,10 +908,10 @@ | |
# With unity builds, sources don't map directly to objects, | ||
# we only support extracting all the objects in this mode, | ||
# so just return all object files. | ||
if extobj.target.is_unity: | ||
if self.is_unity(extobj.target): | ||
compsrcs = classify_unity_sources(extobj.target.compilers.values(), sources) | ||
sources = [] | ||
unity_size = extobj.target.get_option(OptionKey('unity_size')) | ||
unity_size = self.get_target_option(extobj.target, 'unity_size') | ||
assert isinstance(unity_size, int), 'for mypy' | ||
|
||
for comp, srcs in compsrcs.items(): | ||
|
@@ -964,7 +964,7 @@ | |
|
||
def target_uses_pch(self, target: build.BuildTarget) -> bool: | ||
try: | ||
return T.cast('bool', target.get_option(OptionKey('b_pch'))) | ||
return T.cast('bool', self.get_target_option(target, 'b_pch')) | ||
except (KeyError, AttributeError): | ||
return False | ||
|
||
|
@@ -990,30 +990,29 @@ | |
# starting from hard-coded defaults followed by build options and so on. | ||
commands = compiler.compiler_args() | ||
|
||
copt_proxy = target.get_options() | ||
# First, the trivial ones that are impossible to override. | ||
# | ||
# Add -nostdinc/-nostdinc++ if needed; can't be overridden | ||
commands += self.get_no_stdlib_args(target, compiler) | ||
# Add things like /NOLOGO or -pipe; usually can't be overridden | ||
commands += compiler.get_always_args() | ||
# warning_level is a string, but mypy can't determine that | ||
commands += compiler.get_warn_args(T.cast('str', target.get_option(OptionKey('warning_level')))) | ||
commands += compiler.get_warn_args(T.cast('str', self.get_target_option(target, 'warning_level'))) | ||
# Add -Werror if werror=true is set in the build options set on the | ||
# command-line or default_options inside project(). This only sets the | ||
# action to be done for warnings if/when they are emitted, so it's ok | ||
# to set it after or get_warn_args(). | ||
if target.get_option(OptionKey('werror')): | ||
if self.get_target_option(target, 'werror'): | ||
commands += compiler.get_werror_args() | ||
# Add compile args for c_* or cpp_* build options set on the | ||
# command-line or default_options inside project(). | ||
commands += compiler.get_option_compile_args(copt_proxy) | ||
commands += compiler.get_option_compile_args(target, self.environment, target.subproject) | ||
|
||
optimization = target.get_option(OptionKey('optimization')) | ||
optimization = self.get_target_option(target, 'optimization') | ||
assert isinstance(optimization, str), 'for mypy' | ||
commands += compiler.get_optimization_args(optimization) | ||
|
||
debug = target.get_option(OptionKey('debug')) | ||
debug = self.get_target_option(target, 'debug') | ||
assert isinstance(debug, bool), 'for mypy' | ||
commands += compiler.get_debug_args(debug) | ||
|
||
|
@@ -1738,7 +1737,7 @@ | |
# TODO: Create GNUStrip/AppleStrip/etc. hierarchy for more | ||
# fine-grained stripping of static archives. | ||
can_strip = not isinstance(t, build.StaticLibrary) | ||
should_strip = can_strip and t.get_option(OptionKey('strip')) | ||
should_strip = can_strip and self.get_target_option(t, 'strip') | ||
assert isinstance(should_strip, bool), 'for mypy' | ||
# Install primary build output (library/executable/jar, etc) | ||
# Done separately because of strip/aliases/rpath | ||
|
@@ -2062,3 +2061,25 @@ | |
all_sources = T.cast('_ALL_SOURCES_TYPE', target.sources) + T.cast('_ALL_SOURCES_TYPE', target.generated) | ||
return self.compiler_to_generator(target, target.compiler, all_sources, | ||
target.output_templ, target.depends) | ||
|
||
def is_unity(self, target: build.BuildTarget) -> bool: | ||
if isinstance(target, build.CompileTarget): | ||
return False | ||
val = self.get_target_option(target, 'unity') | ||
if val == 'on': | ||
return True | ||
if val == 'off': | ||
return False | ||
if val == 'subprojects': | ||
return target.subproject != '' | ||
Comment on lines
+2068
to
+2074
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. Why is the business logic coming out of the Target and into the Backend? This means that we later have to pass the unity information back into the Target for extract_objects. Wouldn't it be cleaner for 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. The change I have consistently gone to was to separate "data storage" from "evaluation code". Before this the logic of how option values were evaluated was all over the place. Not to mention that some of the data transformations were silently lossy. This made it hard to answer questions like "where exactly does the value of option X for Y come from". Because of this all data containers like build targets only store the original data they were given as close to the original form as possible. They do not have logic. They do not do transformations. All that is computed in one place and if you ever need to debug issues with it you know exactly the one place where you should set your debugger breakpoint. This is a bit unfortunate for Unity since it has the "for subprojects" value. If we had had this functionality already it would never have been needed. But it's there now, so we have to deal with it and eventually deprecate and remove the "for subprojects only" value from it. |
||
raise MesonException(f'Internal error: invalid option type for "unity": {val}') | ||
|
||
def get_target_option(self, target: build.BuildTarget, name: T.Union[str, OptionKey]) -> T.Union[str, int, bool, T.List[str]]: | ||
if isinstance(name, str): | ||
key = OptionKey(name, subproject=target.subproject) | ||
elif isinstance(name, OptionKey): | ||
key = name | ||
else: | ||
import sys | ||
sys.exit('Internal error: invalid option type.') | ||
return self.environment.coredata.get_option_for_target(target, key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the type warning being ignored?