How to use _split_env method in tox

Best Python code snippet using tox_python

unixccompiler.py

Source:unixccompiler.py Github

copy

Full Screen

...33# line, whatever. As long as these options come from something on the34# current system, they can be as system-dependent as they like, and we35# should just happily stuff them into the preprocessor/compiler/linker36# options and carry on.37def _split_env(cmd):38 """39 For macOS, split command into 'env' portion (if any)40 and the rest of the linker command.41 >>> _split_env(['a', 'b', 'c'])42 ([], ['a', 'b', 'c'])43 >>> _split_env(['/usr/bin/env', 'A=3', 'gcc'])44 (['/usr/bin/env', 'A=3'], ['gcc'])45 """46 pivot = 047 if os.path.basename(cmd[0]) == "env":48 pivot = 149 while '=' in cmd[pivot]:50 pivot += 151 return cmd[:pivot], cmd[pivot:]52def _split_aix(cmd):53 """54 AIX platforms prefix the compiler with the ld_so_aix55 script, so split that from the linker command.56 >>> _split_aix(['a', 'b', 'c'])57 ([], ['a', 'b', 'c'])58 >>> _split_aix(['/bin/foo/ld_so_aix', 'gcc'])59 (['/bin/foo/ld_so_aix'], ['gcc'])60 """61 pivot = os.path.basename(cmd[0]) == 'ld_so_aix'62 return cmd[:pivot], cmd[pivot:]63def _linker_params(linker_cmd, compiler_cmd):64 """65 The linker command usually begins with the compiler66 command (possibly multiple elements), followed by zero or more67 params for shared library building.68 If the LDSHARED env variable overrides the linker command,69 however, the commands may not match.70 Return the best guess of the linker parameters by stripping71 the linker command. If the compiler command does not72 match the linker command, assume the linker command is73 just the first element.74 >>> _linker_params('gcc foo bar'.split(), ['gcc'])75 ['foo', 'bar']76 >>> _linker_params('gcc foo bar'.split(), ['other'])77 ['foo', 'bar']78 >>> _linker_params('ccache gcc foo bar'.split(), 'ccache gcc'.split())79 ['foo', 'bar']80 >>> _linker_params(['gcc'], ['gcc'])81 []82 """83 c_len = len(compiler_cmd)84 pivot = c_len if linker_cmd[:c_len] == compiler_cmd else 185 return linker_cmd[pivot:]86class UnixCCompiler(CCompiler):87 compiler_type = 'unix'88 # These are used by CCompiler in two places: the constructor sets89 # instance attributes 'preprocessor', 'compiler', etc. from them, and90 # 'set_executable()' allows any of these to be set. The defaults here91 # are pretty generic; they will probably have to be set by an outsider92 # (eg. using information discovered by the sysconfig about building93 # Python extensions).94 executables = {'preprocessor' : None,95 'compiler' : ["cc"],96 'compiler_so' : ["cc"],97 'compiler_cxx' : ["cc"],98 'linker_so' : ["cc", "-shared"],99 'linker_exe' : ["cc"],100 'archiver' : ["ar", "-cr"],101 'ranlib' : None,102 }103 if sys.platform[:6] == "darwin":104 executables['ranlib'] = ["ranlib"]105 # Needed for the filename generation methods provided by the base106 # class, CCompiler. NB. whoever instantiates/uses a particular107 # UnixCCompiler instance should set 'shared_lib_ext' -- we set a108 # reasonable common default here, but it's not necessarily used on all109 # Unices!110 src_extensions = [".c",".C",".cc",".cxx",".cpp",".m"]111 obj_extension = ".o"112 static_lib_extension = ".a"113 shared_lib_extension = ".so"114 dylib_lib_extension = ".dylib"115 xcode_stub_lib_extension = ".tbd"116 static_lib_format = shared_lib_format = dylib_lib_format = "lib%s%s"117 xcode_stub_lib_format = dylib_lib_format118 if sys.platform == "cygwin":119 exe_extension = ".exe"120 def preprocess(self, source, output_file=None, macros=None,121 include_dirs=None, extra_preargs=None, extra_postargs=None):122 fixed_args = self._fix_compile_args(None, macros, include_dirs)123 ignore, macros, include_dirs = fixed_args124 pp_opts = gen_preprocess_options(macros, include_dirs)125 pp_args = self.preprocessor + pp_opts126 if output_file:127 pp_args.extend(['-o', output_file])128 if extra_preargs:129 pp_args[:0] = extra_preargs130 if extra_postargs:131 pp_args.extend(extra_postargs)132 pp_args.append(source)133 # We need to preprocess: either we're being forced to, or we're134 # generating output to stdout, or there's a target output file and135 # the source file is newer than the target (or the target doesn't136 # exist).137 if self.force or output_file is None or newer(source, output_file):138 if output_file:139 self.mkpath(os.path.dirname(output_file))140 try:141 self.spawn(pp_args)142 except DistutilsExecError as msg:143 raise CompileError(msg)144 def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):145 compiler_so = compiler_fixup(146 self.compiler_so, cc_args + extra_postargs)147 try:148 self.spawn(compiler_so + cc_args + [src, '-o', obj] +149 extra_postargs)150 except DistutilsExecError as msg:151 raise CompileError(msg)152 def create_static_lib(self, objects, output_libname,153 output_dir=None, debug=0, target_lang=None):154 objects, output_dir = self._fix_object_args(objects, output_dir)155 output_filename = \156 self.library_filename(output_libname, output_dir=output_dir)157 if self._need_link(objects, output_filename):158 self.mkpath(os.path.dirname(output_filename))159 self.spawn(self.archiver +160 [output_filename] +161 objects + self.objects)162 # Not many Unices required ranlib anymore -- SunOS 4.x is, I163 # think the only major Unix that does. Maybe we need some164 # platform intelligence here to skip ranlib if it's not165 # needed -- or maybe Python's configure script took care of166 # it for us, hence the check for leading colon.167 if self.ranlib:168 try:169 self.spawn(self.ranlib + [output_filename])170 except DistutilsExecError as msg:171 raise LibError(msg)172 else:173 log.debug("skipping %s (up-to-date)", output_filename)174 def link(self, target_desc, objects,175 output_filename, output_dir=None, libraries=None,176 library_dirs=None, runtime_library_dirs=None,177 export_symbols=None, debug=0, extra_preargs=None,178 extra_postargs=None, build_temp=None, target_lang=None):179 objects, output_dir = self._fix_object_args(objects, output_dir)180 fixed_args = self._fix_lib_args(libraries, library_dirs,181 runtime_library_dirs)182 libraries, library_dirs, runtime_library_dirs = fixed_args183 lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs,184 libraries)185 if not isinstance(output_dir, (str, type(None))):186 raise TypeError("'output_dir' must be a string or None")187 if output_dir is not None:188 output_filename = os.path.join(output_dir, output_filename)189 if self._need_link(objects, output_filename):190 ld_args = (objects + self.objects +191 lib_opts + ['-o', output_filename])192 if debug:193 ld_args[:0] = ['-g']194 if extra_preargs:195 ld_args[:0] = extra_preargs196 if extra_postargs:197 ld_args.extend(extra_postargs)198 self.mkpath(os.path.dirname(output_filename))199 try:200 # Select a linker based on context: linker_exe when201 # building an executable or linker_so (with shared options)202 # when building a shared library.203 building_exe = target_desc == CCompiler.EXECUTABLE204 linker = (self.linker_exe if building_exe else self.linker_so)[:]205 if target_lang == "c++" and self.compiler_cxx:206 env, linker_ne = _split_env(linker)207 aix, linker_na = _split_aix(linker_ne)208 _, compiler_cxx_ne = _split_env(self.compiler_cxx)209 _, linker_exe_ne = _split_env(self.linker_exe)210 params = _linker_params(linker_na, linker_exe_ne)211 linker = env + aix + compiler_cxx_ne + params212 linker = compiler_fixup(linker, ld_args)213 self.spawn(linker + ld_args)214 except DistutilsExecError as msg:215 raise LinkError(msg)216 else:217 log.debug("skipping %s (up-to-date)", output_filename)218 # -- Miscellaneous methods -----------------------------------------219 # These are all used by the 'gen_lib_options() function, in220 # ccompiler.py.221 def library_dir_option(self, dir):222 return "-L" + dir223 def _is_gcc(self, compiler_name):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tox automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful