15
15
from .. import dependencies
16
16
from .. import mesonlib
17
17
from .. import mlog
18
- from ..compilers import SUFFIX_TO_LANG
18
+ from ..compilers import SUFFIX_TO_LANG , RunResult
19
19
from ..compilers .compilers import CompileCheckMode
20
20
from ..interpreterbase import (ObjectHolder , noPosargs , noKwargs ,
21
21
FeatureNew , FeatureNewKwargs , disablerIfNotFound ,
27
27
28
28
if T .TYPE_CHECKING :
29
29
from ..interpreter import Interpreter
30
- from ..compilers import Compiler , RunResult
30
+ from ..compilers import Compiler
31
31
from ..interpreterbase import TYPE_var , TYPE_kwargs
32
32
from .kwargs import ExtractRequired , ExtractSearchDirs
33
33
from .interpreter import SourceOutputs
@@ -50,7 +50,7 @@ class BaseCompileKW(TypedDict):
50
50
include_directories : T .List [build .IncludeDirs ]
51
51
args : T .List [str ]
52
52
53
- class CompileKW (BaseCompileKW ):
53
+ class CompileKW (BaseCompileKW , ExtractRequired ):
54
54
55
55
name : str
56
56
dependencies : T .List [dependencies .Dependency ]
@@ -178,7 +178,8 @@ def stderr_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs') -> str:
178
178
179
179
# Common methods of compiles, links, runs, and similar
180
180
_COMPILES_KWS : T .List [KwargInfo ] = [_NAME_KW , _ARGS_KW , _DEPENDENCIES_KW , _INCLUDE_DIRS_KW , _NO_BUILTIN_ARGS_KW ,
181
- _WERROR_KW ]
181
+ _WERROR_KW ,
182
+ REQUIRED_KW .evolve (since = '1.5.0' , default = False )]
182
183
183
184
_HEADER_KWS : T .List [KwargInfo ] = [REQUIRED_KW .evolve (since = '0.50.0' , default = False ), * _COMMON_KWS ]
184
185
_HAS_REQUIRED_KW = REQUIRED_KW .evolve (since = '1.3.0' , default = False )
@@ -306,15 +307,25 @@ def run_method(self, args: T.Tuple['mesonlib.FileOrString'], kwargs: 'CompileKW'
306
307
FeatureNew .single_use (f'compiler.run for { self .compiler .get_display_language ()} language' ,
307
308
'1.5.0' , self .subproject , location = self .current_node )
308
309
code = args [0 ]
310
+ testname = kwargs ['name' ]
311
+
312
+ disabled , required , feature = extract_required_kwarg (kwargs , self .subproject , default = False )
313
+ if disabled :
314
+ if testname :
315
+ mlog .log ('Checking if' , mlog .bold (testname , True ), 'runs:' , 'skipped: feature' , mlog .bold (feature ), 'disabled' )
316
+ return RunResult (compiled = True , returncode = 0 , stdout = '' , stderr = '' , cached = False )
317
+
309
318
if isinstance (code , mesonlib .File ):
310
319
self .interpreter .add_build_def_file (code )
311
320
code = mesonlib .File .from_absolute_file (
312
321
code .rel_to_builddir (self .environment .source_dir ))
313
- testname = kwargs ['name' ]
314
322
extra_args = functools .partial (self ._determine_args , kwargs )
315
323
deps , msg = self ._determine_dependencies (kwargs ['dependencies' ], compile_only = False , endl = None )
316
324
result = self .compiler .run (code , self .environment , extra_args = extra_args ,
317
325
dependencies = deps )
326
+ if required and result .returncode != 0 :
327
+ raise InterpreterException (f'Could not run { testname if testname else "code" } ' )
328
+
318
329
if testname :
319
330
if not result .compiled :
320
331
h = mlog .red ('DID NOT COMPILE' )
@@ -510,19 +521,29 @@ def has_define_method(self, args: T.Tuple[str], kwargs: 'CommonKW') -> bool:
510
521
@typed_kwargs ('compiler.compiles' , * _COMPILES_KWS )
511
522
def compiles_method (self , args : T .Tuple ['mesonlib.FileOrString' ], kwargs : 'CompileKW' ) -> bool :
512
523
code = args [0 ]
524
+ testname = kwargs ['name' ]
525
+
526
+ disabled , required , feature = extract_required_kwarg (kwargs , self .subproject , default = False )
527
+ if disabled :
528
+ if testname :
529
+ mlog .log ('Checking if' , mlog .bold (testname , True ), 'compiles:' , 'skipped: feature' , mlog .bold (feature ), 'disabled' )
530
+ return False
531
+
513
532
if isinstance (code , mesonlib .File ):
514
533
if code .is_built :
515
534
FeatureNew .single_use ('compiler.compiles with file created at setup time' , '1.2.0' , self .subproject ,
516
535
'It was broken and either errored or returned false.' , self .current_node )
517
536
self .interpreter .add_build_def_file (code )
518
537
code = mesonlib .File .from_absolute_file (
519
538
code .absolute_path (self .environment .source_dir , self .environment .build_dir ))
520
- testname = kwargs ['name' ]
521
539
extra_args = functools .partial (self ._determine_args , kwargs )
522
540
deps , msg = self ._determine_dependencies (kwargs ['dependencies' ], endl = None )
523
541
result , cached = self .compiler .compiles (code , self .environment ,
524
542
extra_args = extra_args ,
525
543
dependencies = deps )
544
+ if required and not result :
545
+ raise InterpreterException (f'Could not compile { testname } ' )
546
+
526
547
if testname :
527
548
if result :
528
549
h = mlog .green ('YES' )
@@ -536,6 +557,14 @@ def compiles_method(self, args: T.Tuple['mesonlib.FileOrString'], kwargs: 'Compi
536
557
@typed_kwargs ('compiler.links' , * _COMPILES_KWS )
537
558
def links_method (self , args : T .Tuple ['mesonlib.FileOrString' ], kwargs : 'CompileKW' ) -> bool :
538
559
code = args [0 ]
560
+ testname = kwargs ['name' ]
561
+
562
+ disabled , required , feature = extract_required_kwarg (kwargs , self .subproject , default = False )
563
+ if disabled :
564
+ if testname :
565
+ mlog .log ('Checking if' , mlog .bold (testname , True ), 'links:' , 'skipped: feature' , mlog .bold (feature ), 'disabled' )
566
+ return False
567
+
539
568
compiler = None
540
569
if isinstance (code , mesonlib .File ):
541
570
if code .is_built :
@@ -556,19 +585,21 @@ def links_method(self, args: T.Tuple['mesonlib.FileOrString'], kwargs: 'CompileK
556
585
else :
557
586
compiler = clist [SUFFIX_TO_LANG [suffix ]]
558
587
559
- testname = kwargs ['name' ]
560
588
extra_args = functools .partial (self ._determine_args , kwargs )
561
589
deps , msg = self ._determine_dependencies (kwargs ['dependencies' ], compile_only = False )
562
590
result , cached = self .compiler .links (code , self .environment ,
563
591
compiler = compiler ,
564
592
extra_args = extra_args ,
565
593
dependencies = deps )
566
- cached_msg = mlog .blue ('(cached)' ) if cached else ''
594
+ if required and not result :
595
+ raise InterpreterException (f'Could not link { testname if testname else "code" } ' )
596
+
567
597
if testname :
568
598
if result :
569
599
h = mlog .green ('YES' )
570
600
else :
571
601
h = mlog .red ('NO' )
602
+ cached_msg = mlog .blue ('(cached)' ) if cached else ''
572
603
mlog .log ('Checking if' , mlog .bold (testname , True ), msg , 'links:' , h , cached_msg )
573
604
return result
574
605
0 commit comments