@ -1,5 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2016-2018 The Meson development team
# Copyright © 2023-2024 Intel Corporation
from __future__ import annotations
@ -11,6 +12,21 @@ import typing as T
from . import build , coredata , environment , interpreter , mesonlib , mintro , mlog
from . mesonlib import MesonException
if T . TYPE_CHECKING :
from typing_extensions import Protocol
from . coredata import SharedCMDOptions
class CMDOptions ( SharedCMDOptions , Protocol ) :
profile : bool
fatal_warnings : bool
reconfigure : bool
wipe : bool
clearcache : bool
builddir : str
sourcedir : str
pager : bool
git_ignore_file = ''' # This file is autogenerated by Meson. If you change or delete it, it won ' t be recreated.
*
'''
@ -53,7 +69,7 @@ def add_arguments(parser: argparse.ArgumentParser) -> None:
parser . add_argument ( ' sourcedir ' , nargs = ' ? ' , default = None )
class MesonApp :
def __init__ ( self , options : argparse . Namespace ) - > None :
def __init__ ( self , options : CMDOptions ) - > None :
self . options = options
( self . source_dir , self . build_dir ) = self . validate_dirs ( )
if options . wipe :
@ -173,7 +189,7 @@ class MesonApp:
def _generate ( self , env : environment . Environment , capture : bool , vslite_ctx : T . Optional [ dict ] ) - > T . Optional [ dict ] :
# Get all user defined options, including options that have been defined
# during a previous invocation or using meson configure.
user_defined_options = argparse . Namespace ( * * vars ( self . options ) )
user_defined_options = T . cast ( ' CMDOptions ' , argparse . Namespace ( * * vars ( self . options ) ) )
coredata . read_cmd_line_file ( self . build_dir , user_defined_options )
mlog . debug ( ' Build started at ' , datetime . datetime . now ( ) . isoformat ( ) )
@ -294,7 +310,7 @@ class MesonApp:
for mod in intr . modules . values ( ) :
mod . postconf_hook ( b )
def run_genvslite_setup ( options : argparse . Namespace ) - > None :
def run_genvslite_setup ( options : CMDOptions ) - > None :
# With --genvslite, we essentially want to invoke multiple 'setup' iterations. I.e. -
# meson setup ... builddirprefix_debug
# meson setup ... builddirprefix_debugoptimized
@ -328,13 +344,18 @@ def run_genvslite_setup(options: argparse.Namespace) -> None:
app = MesonApp ( options )
app . generate ( capture = False , vslite_ctx = vslite_ctx )
def run ( options : T . Union [ argparse . Namespace , T . List [ str ] ] ) - > int :
if not isinstance ( options , argparse . Namespace ) :
def run ( options : T . Union [ CMDOptions , T . List [ str ] ] ) - > int :
if isinstance ( options , list ) :
parser = argparse . ArgumentParser ( )
add_arguments ( parser )
options = parser . parse_args ( options )
options = T . cast ( ' CMDOptions ' , parser . parse_args ( options ) )
coredata . parse_cmd_line_options ( options )
# Msetup doesn't actually use this option, but we pass msetup options to
# mconf, and it does. We won't actally hit the path that uses it, but don't
# lie
options . pager = False
if mesonlib . OptionKey ( ' genvslite ' ) in options . cmd_line_options . keys ( ) :
run_genvslite_setup ( options )
else :