<s> """<STR_LIT>""" <EOL> import distutils . spawn <EOL> import os <EOL> import shlex <EOL> import sys <EOL> sys . path . append ( os . path . join ( os . path . dirname ( __file__ ) , os . pardir ) ) <EOL> import buildutil . common as common <EOL> _CMAKE_PATH_ENV_VAR = '<STR_LIT>' <EOL> _CMAKE_FLAGS_ENV_VAR = '<STR_LIT>' <EOL> _CMAKE_PATH = '<STR_LIT>' <EOL> _CMAKE_FLAGS = '<STR_LIT>' <EOL> class BuildEnvironment ( common . BuildEnvironment ) : <EOL> """<STR_LIT>""" <EOL> CMAKE = '<STR_LIT>' <EOL> def __init__ ( self , arguments ) : <EOL> """<STR_LIT>""" <EOL> super ( BuildEnvironment , self ) . __init__ ( arguments ) <EOL> if type ( arguments ) is dict : <EOL> args = arguments <EOL> else : <EOL> args = vars ( arguments ) <EOL> self . cmake_path = args [ _CMAKE_PATH ] <EOL> self . cmake_flags = args [ _CMAKE_FLAGS ] <EOL> @ staticmethod <EOL> def build_defaults ( ) : <EOL> """<STR_LIT>""" <EOL> args = common . BuildEnvironment . build_defaults ( ) <EOL> args [ _CMAKE_PATH ] = ( os . getenv ( _CMAKE_PATH_ENV_VAR ) or <EOL> distutils . spawn . find_executable ( '<STR_LIT>' ) ) <EOL> args [ _CMAKE_FLAGS ] = os . getenv ( _CMAKE_FLAGS_ENV_VAR ) <EOL> return args <EOL> @ staticmethod <EOL> def add_arguments ( parser ) : <EOL> """<STR_LIT>""" <EOL> defaults = BuildEnvironment . build_defaults ( ) <EOL> common . BuildEnvironment . add_arguments ( parser ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' + _CMAKE_PATH , <EOL> help = '<STR_LIT>' , dest = _CMAKE_PATH , <EOL> default = defaults [ _CMAKE_PATH ] ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , '<STR_LIT>' + _CMAKE_FLAGS , help = '<STR_LIT>' , <EOL> dest = _CMAKE_FLAGS , default = defaults [ _CMAKE_FLAGS ] ) <EOL> def _find_binary ( self , binary , additional_paths = None ) : <EOL> """<STR_LIT>""" <EOL> search_dict = { BuildEnvironment . CMAKE : [ self . cmake_path ] } <EOL> if additional_paths : <EOL> search_dict . update ( additional_paths ) <EOL> return BuildEnvironment . _check_binary ( binary , search_dict [ binary ] ) <EOL> def run_cmake ( self , gen = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> cmake_path = self . _find_binary ( BuildEnvironment . CMAKE ) <EOL> args = [ cmake_path , '<STR_LIT>' , gen ] <EOL> if self . cmake_flags : <EOL> args += shlex . split ( self . cmake_flags , posix = self . _posix ) <EOL> args . append ( self . project_directory ) <EOL> self . run_subprocess ( args , cwd = self . project_directory ) </s>
