Compile a single source files with a Unix-style compiler.
(self, obj, src, ext, cc_args, extra_postargs, pp_opts)
| 15 | |
| 16 | # Note that UnixCCompiler._compile appeared in Python 2.3 |
| 17 | def UnixCCompiler__compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): |
| 18 | """Compile a single source files with a Unix-style compiler.""" |
| 19 | # HP ad-hoc fix, see ticket 1383 |
| 20 | ccomp = self.compiler_so |
| 21 | if ccomp[0] == 'aCC': |
| 22 | # remove flags that will trigger ANSI-C mode for aCC |
| 23 | if '-Ae' in ccomp: |
| 24 | ccomp.remove('-Ae') |
| 25 | if '-Aa' in ccomp: |
| 26 | ccomp.remove('-Aa') |
| 27 | # add flags for (almost) sane C++ handling |
| 28 | ccomp += ['-AA'] |
| 29 | self.compiler_so = ccomp |
| 30 | # ensure OPT environment variable is read |
| 31 | if 'OPT' in os.environ: |
| 32 | # XXX who uses this? |
| 33 | from sysconfig import get_config_vars |
| 34 | opt = shlex.join(shlex.split(os.environ['OPT'])) |
| 35 | gcv_opt = shlex.join(shlex.split(get_config_vars('OPT')[0])) |
| 36 | ccomp_s = shlex.join(self.compiler_so) |
| 37 | if opt not in ccomp_s: |
| 38 | ccomp_s = ccomp_s.replace(gcv_opt, opt) |
| 39 | self.compiler_so = shlex.split(ccomp_s) |
| 40 | llink_s = shlex.join(self.linker_so) |
| 41 | if opt not in llink_s: |
| 42 | self.linker_so = self.linker_so + shlex.split(opt) |
| 43 | |
| 44 | display = '%s: %s' % (os.path.basename(self.compiler_so[0]), src) |
| 45 | |
| 46 | # gcc style automatic dependencies, outputs a makefile (-MF) that lists |
| 47 | # all headers needed by a c file as a side effect of compilation (-MMD) |
| 48 | if getattr(self, '_auto_depends', False): |
| 49 | deps = ['-MMD', '-MF', obj + '.d'] |
| 50 | else: |
| 51 | deps = [] |
| 52 | |
| 53 | try: |
| 54 | self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + deps + |
| 55 | extra_postargs, display = display) |
| 56 | except DistutilsExecError as e: |
| 57 | msg = str(e) |
| 58 | raise CompileError(msg) from None |
| 59 | |
| 60 | # add commandline flags to dependency file |
| 61 | if deps: |
| 62 | # After running the compiler, the file created will be in EBCDIC |
| 63 | # but will not be tagged as such. This tags it so the file does not |
| 64 | # have multiple different encodings being written to it |
| 65 | if sys.platform == 'zos': |
| 66 | subprocess.check_output(['chtag', '-tc', 'IBM1047', obj + '.d']) |
| 67 | with open(obj + '.d', 'a') as f: |
| 68 | f.write(_commandline_dep_string(cc_args, extra_postargs, pp_opts)) |
| 69 | |
| 70 | replace_method(UnixCCompiler, '_compile', UnixCCompiler__compile) |
| 71 |
nothing calls this directly
no test coverage detected