def preprocess(self, source, output_file=None, macros=None, include_dirs=None, extra_preargs=None, extra_postargs=None): fixed_args = self._fix_compile_args(None, macros, include_dirs) ignore, macros, include_dirs = fixed_args pp_opts = gen_preprocess_options(macros, include_dirs) pp_args = self.preprocessor + pp_opts if output_file: pp_args.extend(['-o', output_file]) if extra_preargs: pp_args[:0] = extra_preargs if extra_postargs: pp_args.extend(extra_postargs) pp_args.append(source) # We need to preprocess: either we're being forced to, or we're # generating output to stdout, or there's a target output file and # the source file is newer than the target (or the target doesn't # exist). if self.force or output_file is None or newer(source, output_file): if output_file: self.mkpath(os.path.dirname(output_file)) try: # iOS: since clang is not available, we send a nicer error message: if (sys.platform == 'darwin' and os.uname().machine.startswith('iP')): raise DistutilsExecError("There are no preprocessors available on iOS, sorry. Command was: ", pp_args) # self.spawn(pp_args) except DistutilsExecError as msg: raise CompileError(msg)
def _msvc_preprocess(self, source, output_file=None, macros=None, include_dirs=None, extra_preargs=None, extra_postargs=None): """Replacement for default (no-op) distutils.msvccompiler.MSVCCompiler.preprocess() """ # validate and normalize ignore, macros, include_dirs = self._fix_compile_args( None, macros, include_dirs) # translate macros/include_dirs into -D/-U/-I strings pp_args = [self.preprocessor] + gen_preprocess_options( macros, include_dirs) # output to file or stdout if output_file: pp_args.extend(['/P', '/Fi' + output_file]) else: pp_args.extend(['/E']) if extra_preargs: pp_args[:0] = extra_preargs if extra_postargs: pp_args.extend(extra_postargs) pp_args.append('/TP') # treat as c++ pp_args.append(source) if self.force or output_file is None or newer(source, output_file): if output_file: self.mkpath(os.path.dirname(output_file)) try: self.spawn(pp_args) except DistutilsExecError as msg: raise CompileError(msg)
def preprocess(self, source, output_file=None, macros=None, include_dirs=None, extra_preargs=None, extra_postargs=None): fixed_args = self._fix_compile_args(None, macros, include_dirs) ignore, macros, include_dirs = fixed_args pp_opts = gen_preprocess_options(macros, include_dirs) pp_args = self.preprocessor + pp_opts if output_file: pp_args.extend(['-o', output_file]) if extra_preargs: pp_args[:0] = extra_preargs if extra_postargs: pp_args.extend(extra_postargs) pp_args.append(source) if self.force or output_file is None or newer(source, output_file): if output_file: self.mkpath(os.path.dirname(output_file)) try: self.spawn(pp_args) except DistutilsExecError as msg: raise CompileError(msg)
def preprocess(self, source, output_file=None, macros=None, include_dirs=None, extra_preargs=None, extra_postargs=None): (_, macros, include_dirs) = \ self._fix_compile_args(None, macros, include_dirs) pp_opts = gen_preprocess_options(macros, include_dirs) pp_args = ['cpp32.exe'] + pp_opts if output_file is not None: pp_args.append('-o' + output_file) if extra_preargs: pp_args[:0] = extra_preargs if extra_postargs: pp_args.extend(extra_postargs) pp_args.append(source) # We need to preprocess: either we're being forced to, or the # source file is newer than the target (or the target doesn't # exist). if self.force or output_file is None or newer(source, output_file): if output_file: self.mkpath(os.path.dirname(output_file)) try: self.spawn(pp_args) except DistutilsExecError, msg: print msg raise CompileError, msg
def preprocess (self, source, output_file=None, macros=None, include_dirs=None, extra_preargs=None, extra_postargs=None): (_, macros, include_dirs) = \ self._fix_compile_args(None, macros, include_dirs) pp_opts = gen_preprocess_options(macros, include_dirs) pp_args = ['cpp32.exe'] + pp_opts if output_file is not None: pp_args.append('-o' + output_file) if extra_preargs: pp_args[:0] = extra_preargs if extra_postargs: pp_args.extend(extra_postargs) pp_args.append(source) # We need to preprocess: either we're being forced to, or the # source file is newer than the target (or the target doesn't # exist). if self.force or output_file is None or newer(source, output_file): if output_file: self.mkpath(os.path.dirname(output_file)) try: self.spawn(pp_args) except DistutilsExecError, msg: shout msg raise CompileError, msg
def preprocess(self, source, output_file=None, macros=None, include_dirs=None, extra_preargs=None, extra_postargs=None): ignore, macros, include_dirs = \ self._fix_compile_args(None, macros, include_dirs) pp_opts = gen_preprocess_options(macros, include_dirs) pp_args = self.preprocessor + pp_opts if output_file: pp_args.extend(['-o', output_file]) if extra_preargs: pp_args[:0] = extra_preargs if extra_postargs: pp_args.extend(extra_postargs) pp_args.append(source) # We need to preprocess: either we're being forced to, or we're # generating output to stdout, or there's a target output file and # the source file is newer than the target (or the target doesn't # exist). if self.force or output_file is None or newer(source, output_file): if output_file: self.mkpath(os.path.dirname(output_file)) try: self.spawn(pp_args) except DistutilsExecError, msg: raise CompileError, msg
def preprocess(self, source, output_file=None, macros=None, include_dirs=None, extra_preargs=None, extra_postargs=None): _, macros, include_dirs = self._fix_compile_args( None, macros, include_dirs) pp_opts = gen_preprocess_options(macros, include_dirs) pp_args = ['cpp32.exe'] + pp_opts if output_file is not None: pp_args.append('-o' + output_file) if extra_preargs: pp_args[:0] = extra_preargs if extra_postargs: pp_args.extend(extra_postargs) pp_args.append(source) if self.force or output_file is None or newer(source, output_file): if output_file: self.mkpath(os.path.dirname(output_file)) try: self.spawn(pp_args) except DistutilsExecError as msg: print msg raise CompileError, msg return
def preprocess(self, source, output_file=None, macros=None, include_dirs=None, extra_preargs=None, extra_postargs=None): fixed_args = self._fix_compile_args(None, macros, include_dirs) ignore, macros, include_dirs = fixed_args pp_opts = gen_preprocess_options(macros, include_dirs) pp_args = self.preprocessor + pp_opts if output_file: pp_args.extend(['-o', output_file]) if extra_preargs: pp_args[:0] = extra_preargs if extra_postargs: pp_args.extend(extra_postargs) pp_args.append(source) # We need to preprocess: either we're being forced to, or we're # generating output to stdout, or there's a target output file and # the source file is newer than the target (or the target doesn't # exist). if self.force or output_file is None or newer(source, output_file): if output_file: self.mkpath(os.path.dirname(output_file)) try: self.spawn(pp_args) except DistutilsExecError as msg: raise CompileError(msg)
def compile(self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None): (output_dir, macros, include_dirs) = \ self._fix_compile_args (output_dir, macros, include_dirs) (objects, skip_sources) = self._prep_compile(sources, output_dir) if extra_postargs is None: extra_postargs = [] pp_opts = gen_preprocess_options(macros, include_dirs) compile_opts = extra_preargs or [] compile_opts.append('-c') if debug: compile_opts.extend(self.compile_options_debug) else: compile_opts.extend(self.compile_options) for i in range(len(sources)): src = sources[i] obj = objects[i] ext = (os.path.splitext(src))[1] if skip_sources[src]: self.announce("skipping %s (%s up-to-date)" % (src, obj)) else: if ext in self._c_extensions: input_opt = "" elif ext in self._cpp_extensions: input_opt = "-P" src = os.path.normpath(src) obj = os.path.normpath(obj) output_opt = "-o" + obj self.mkpath(os.path.dirname(obj)) # Compiler command line syntax is: "bcc32 [options] file(s)". # Note that the source file names must appear at the end of # the command line. try: self.spawn([self.cc] + compile_opts + pp_opts + [input_opt, output_opt] + extra_postargs + [src]) except DistutilsExecError, msg: raise CompileError, msg
def compile (self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None): (output_dir, macros, include_dirs) = \ self._fix_compile_args (output_dir, macros, include_dirs) (objects, skip_sources) = self._prep_compile (sources, output_dir) if extra_postargs is None: extra_postargs = [] pp_opts = gen_preprocess_options (macros, include_dirs) compile_opts = extra_preargs or [] compile_opts.append ('-c') if debug: compile_opts.extend (self.compile_options_debug) else: compile_opts.extend (self.compile_options) for i in range (len (sources)): src = sources[i] ; obj = objects[i] ext = (os.path.splitext (src))[1] if skip_sources[src]: self.announce ("skipping %s (%s up-to-date)" % (src, obj)) else: if ext in self._c_extensions: input_opt = "" elif ext in self._cpp_extensions: input_opt = "-P" src = os.path.normpath(src) obj = os.path.normpath(obj) output_opt = "-o" + obj self.mkpath(os.path.dirname(obj)) # Compiler command line syntax is: "bcc32 [options] file(s)". # Note that the source file names must appear at the end of # the command line. try: self.spawn ([self.cc] + compile_opts + pp_opts + [input_opt, output_opt] + extra_postargs + [src]) except DistutilsExecError, msg: raise CompileError, msg
def compile(self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None, depends=None): if output_dir is None: output_dir = self.output_dir if macros is None: macros = self.macros elif type(macros) is ListType: macros = macros + (self.macros or []) if include_dirs is None: include_dirs = self.include_dirs elif type(include_dirs) in (ListType, TupleType): include_dirs = list(include_dirs) + (self.include_dirs or []) if extra_preargs is None: extra_preargs=[] display = [] for fc in ['f77','f90','fix']: fcomp = getattr(self,'compiler_'+fc) if fcomp is None: continue display.append("%s(%s) options: '%s'" \ % (os.path.basename(fcomp[0]), fc, ' '.join(fcomp[1:]))) display = '\n'.join(display) log.info(display) from distutils.sysconfig import python_build objects = self.object_filenames(sources,strip_dir=python_build, output_dir=output_dir) from distutils.ccompiler import gen_preprocess_options pp_opts = gen_preprocess_options(macros, include_dirs) build = {} for i in range(len(sources)): src,obj = sources[i],objects[i] ext = os.path.splitext(src)[1] self.mkpath(os.path.dirname(obj)) build[obj] = src, ext cc_args = self._get_cc_args(pp_opts, debug, extra_preargs) display = "compile options: '%s'" % (' '.join(cc_args)) if extra_postargs: display += "\nextra options: '%s'" % (' '.join(extra_postargs)) log.info(display) objects_to_build = build.keys() for obj in objects: if obj in objects_to_build: src, ext = build[obj] if self.compiler_type=='absoft': obj = cyg2win32(obj) src = cyg2win32(src) self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) return objects
def preprocess(self, source, output_file=None, macros=None, include_dirs=None, extra_preargs=None, extra_postargs=None): if self.initialized is False: self.initialize() (_, macros, include_dirs) = \ self._fix_compile_args(None, macros, include_dirs) pp_opts = gen_preprocess_options(macros, include_dirs) preprocess_options = ['-E'] source_basename = None if output_file is not None: preprocess_options.append('-P') source_basename = self._get_file_basename(source) cpp_args = self.cc.split() if extra_preargs is not None: cpp_args[:0] = extra_preargs if extra_postargs is not None: preprocess_options.extend(extra_postargs) cpp_args.extend(preprocess_options) cpp_args.extend(pp_opts) cpp_args.append(source) # We need to preprocess: either we're being forced to, or the # source file is newer than the target (or the target doesn't # exist). if self.force or output_file is None or newer(source, output_file): try: self.spawn(cpp_args) except (DistutilsExecError, msg): print(msg) raise CompileError # The /P option for the MSVC preprocessor will output the results # of the preprocessor to a file, as <source_without_extension>.i, # so in order to output the specified filename, we need to rename # that file if output_file is not None: if output_file != source_basename + '.i': os.rename(source_basename + '.i', output_file)
def compile(self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None): (output_dir, macros, include_dirs) = \ self._fix_compile_args (output_dir, macros, include_dirs) (objects, skip_sources) = self._prep_compile(sources, output_dir) # Figure out the options for the compiler command line. pp_opts = gen_preprocess_options(macros, include_dirs) cc_args = pp_opts + ['-c'] if debug: cc_args[:0] = ['-g'] if extra_preargs: cc_args[:0] = extra_preargs if extra_postargs is None: extra_postargs = [] # Compile all source files that weren't eliminated by # '_prep_compile()'. for i in range(len(sources)): src = sources[i] obj = objects[i] ext = (os.path.splitext(src))[1] if skip_sources[src]: self.announce("skipping %s (%s up-to-date)" % (src, obj)) else: self.mkpath(os.path.dirname(obj)) if ext == '.rc' or ext == '.res': # gcc needs '.res' and '.rc' compiled to object files !!! try: self.spawn(["windres", "-i", src, "-o", obj]) except DistutilsExecError, msg: raise CompileError, msg else: # for other files use the C-compiler try: self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + extra_postargs) except DistutilsExecError, msg: raise CompileError, msg
def preprocess(self, source, output_file=None, macros=None, include_dirs=None, extra_preargs=None, extra_postargs=None): if self.initialized is False: self.initialize() (_, macros, include_dirs) = \ self._fix_compile_args(None, macros, include_dirs) pp_opts = gen_preprocess_options(macros, include_dirs) preprocess_options = ['-E'] source_basename = None if output_file is not None: preprocess_options.append('-P') source_basename = self._get_file_basename(source) cpp_args = self.cc.split() if extra_preargs is not None: cpp_args[:0] = extra_preargs if extra_postargs is not None: preprocess_options.extend(extra_postargs) cpp_args.extend(preprocess_options) cpp_args.extend(pp_opts) cpp_args.append(source) # We need to preprocess: either we're being forced to, or the # source file is newer than the target (or the target doesn't # exist). if self.force or output_file is None or newer(source, output_file): try: self.spawn(cpp_args) except DistutilsExecError as msg: print(msg) raise CompileError # The /P option for the MSVC preprocessor will output the results # of the preprocessor to a file, as <source_without_extension>.i, # so in order to output the specified filename, we need to rename # that file if output_file is not None: if output_file != source_basename + '.i': os.rename(source_basename + '.i', output_file)
def compile (self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None): (output_dir, macros, include_dirs) = \ self._fix_compile_args (output_dir, macros, include_dirs) (objects, skip_sources) = self._prep_compile (sources, output_dir) # Figure out the options for the compiler command line. pp_opts = gen_preprocess_options (macros, include_dirs) cc_args = pp_opts + ['-c'] if debug: cc_args[:0] = ['-g'] if extra_preargs: cc_args[:0] = extra_preargs if extra_postargs is None: extra_postargs = [] # Compile all source files that weren't eliminated by # '_prep_compile()'. for i in range (len (sources)): src = sources[i] ; obj = objects[i] ext = (os.path.splitext (src))[1] if skip_sources[src]: self.announce ("skipping %s (%s up-to-date)" % (src, obj)) else: self.mkpath (os.path.dirname (obj)) if ext == '.rc' or ext == '.res': # gcc needs '.res' and '.rc' compiled to object files !!! try: self.spawn (["windres","-i",src,"-o",obj]) except DistutilsExecError, msg: raise CompileError, msg else: # for other files use the C-compiler try: self.spawn (self.compiler_so + cc_args + [src, '-o', obj] + extra_postargs) except DistutilsExecError, msg: raise CompileError, msg
def compile (self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None): (output_dir, macros, include_dirs) = \ self._fix_compile_args (output_dir, macros, include_dirs) (objects, skip_sources) = self._prep_compile (sources, output_dir) if extra_postargs is None: extra_postargs = [] pp_opts = gen_preprocess_options (macros, include_dirs) compile_opts = extra_preargs or [] compile_opts.append ('/c') if debug: compile_opts.extend (self.compile_options_debug) else: compile_opts.extend (self.compile_options) for i in range (len (sources)): src = sources[i] ; obj = objects[i] ext = (os.path.splitext (src))[1] if skip_sources[src]: self.announce ("skipping %s (%s up-to-date)" % (src, obj)) else: if ext in self._c_extensions: input_opt = "/Tc" + src elif ext in self._cpp_extensions: input_opt = "/Tp" + src output_opt = "/Fo" + obj self.mkpath (os.path.dirname (obj)) try: self.spawn ([self.cc] + compile_opts + pp_opts + [input_opt, output_opt] + extra_postargs) except DistutilsExecError, msg: raise CompileError, msg
def compile(self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None): (output_dir, macros, include_dirs) = \ self._fix_compile_args (output_dir, macros, include_dirs) (objects, skip_sources) = self._prep_compile(sources, output_dir) if extra_postargs is None: extra_postargs = [] pp_opts = gen_preprocess_options(macros, include_dirs) compile_opts = extra_preargs or [] compile_opts.append('/c') if debug: compile_opts.extend(self.compile_options_debug) else: compile_opts.extend(self.compile_options) for i in range(len(sources)): src = sources[i] obj = objects[i] ext = (os.path.splitext(src))[1] if skip_sources[src]: self.announce("skipping %s (%s up-to-date)" % (src, obj)) else: if ext in self._c_extensions: input_opt = "/Tc" + src elif ext in self._cpp_extensions: input_opt = "/Tp" + src output_opt = "/Fo" + obj self.mkpath(os.path.dirname(obj)) try: self.spawn([self.cc] + compile_opts + pp_opts + [input_opt, output_opt] + extra_postargs) except DistutilsExecError, msg: raise CompileError, msg
def get_setuptools_options(): build_ext = get_prepared_build_ext() compiler = build_ext.compiler options = [] if compiler: if compiler.compiler_so: options.extend(compiler.compiler_so[1:]) options.extend(ccompiler.gen_preprocess_options( macros=compiler.macros, include_dirs=compiler.include_dirs)) options.extend(ccompiler.gen_lib_options( compiler=compiler, library_dirs=compiler.library_dirs, runtime_library_dirs=compiler.runtime_library_dirs, libraries=compiler.libraries)) if build_ext.extensions: for ext in build_ext.extensions: options.extend(ext.extra_compile_args) return options
def preprocess(self, source, output_file = None, macros = None, include_dirs = None, extra_preargs = None, extra_postargs = None): ignore, macros, include_dirs = self._fix_compile_args(None, macros, include_dirs) pp_opts = gen_preprocess_options(macros, include_dirs) pp_args = self.preprocessor + pp_opts if output_file: pp_args.extend(['-o', output_file]) if extra_preargs: pp_args[:0] = extra_preargs if extra_postargs: pp_args.extend(extra_postargs) pp_args.append(source) if self.force or output_file is None or newer(source, output_file): if output_file: self.mkpath(os.path.dirname(output_file)) try: self.spawn(pp_args) except DistutilsExecError as msg: raise CompileError, msg return
def main(): _include_dir_flags = ccompiler.gen_preprocess_options( macros=[], include_dirs=INCLUDE_DIRS ) setuptools.setup( ext_modules=[ setuptools.Extension( name='_graphkernels', sources=[str(GK_PATH / 'graphkernels.i'), *CPP_SOURCES], include_dirs=INCLUDE_DIRS, libraries=LIBRARIES, swig_opts=[*SWIG_OPTS, *_include_dir_flags], extra_compile_args=CPP_FLAGS, extra_link_args=CPP_FLAGS, language='c++', optional=False, ) ], version=graphkernels.__version__, )
def get_setuptools_options(): build_ext = get_prepared_build_ext() compiler = build_ext.compiler options = [] if compiler: if compiler.compiler_so: options.extend(compiler.compiler_so[1:]) options.extend( ccompiler.gen_preprocess_options( macros=compiler.macros, include_dirs=compiler.include_dirs)) options.extend( ccompiler.gen_lib_options( compiler=compiler, library_dirs=compiler.library_dirs, runtime_library_dirs=compiler.runtime_library_dirs, libraries=compiler.libraries)) if build_ext.extensions: for ext in build_ext.extensions: options.extend(ext.extra_compile_args) return options
def preprocess( self, source, output_file=None, macros=None, include_dirs=None, extra_preargs=None, extra_postargs=None, ): fixed_args = self._fix_compile_args(None, macros, include_dirs) ignore, macros, include_dirs = fixed_args pp_opts = gen_preprocess_options(macros, include_dirs) pp_args = self.preprocessor + pp_opts if output_file: pp_args.extend(['-o', output_file]) if extra_preargs: pp_args[:0] = extra_preargs if extra_postargs: pp_args.extend(extra_postargs) pp_args.append(source) # reasons to preprocess: # - force is indicated # - output is directed to stdout # - source file is newer than the target preprocess = self.force or output_file is None or newer( source, output_file) if not preprocess: return if output_file: self.mkpath(os.path.dirname(output_file)) try: self.spawn(pp_args) except DistutilsExecError as msg: raise CompileError(msg)
def preprocess(self, source, output_file=None, macros=None, include_dirs=None, extra_preargs=None, extra_postargs=None): if self.initialized is False: self.initialize() (_, macros, include_dirs) = \ self._fix_compile_args(None, macros, include_dirs) pp_opts = gen_preprocess_options(macros, include_dirs) preprocess_options = ['-E'] source_basename = None if output_file is not None: preprocess_options.append('-P') source_basename = self._get_file_basename(source) cpp_args = self.cc.split() if extra_preargs is not None: cpp_args[:0] = extra_preargs if extra_postargs is not None: preprocess_options.extend(extra_postargs) cpp_args.extend(preprocess_options) cpp_args.extend(pp_opts) cpp_args.append(source) # We need to preprocess: either we're being forced to, or the # source file is newer than the target (or the target doesn't # exist). if self.force or output_file is None or newer(source, output_file): try: self.spawn(cpp_args) except DistutilsExecError, msg: print msg raise CompileError
def compile (self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None): (output_dir, macros, include_dirs) = \ self._fix_compile_args(output_dir, macros, include_dirs) (objects, skip_sources) = self._prep_compile(sources, output_dir) # Figure out the options for the compiler command line. pp_opts = gen_preprocess_options(macros, include_dirs) cc_args = pp_opts + ['-c'] if debug: cc_args[:0] = ['-g'] if extra_preargs: cc_args[:0] = extra_preargs if extra_postargs is None: extra_postargs = [] # Compile all source files that weren't eliminated by # '_prep_compile()'. for i in range(len(sources)): src = sources[i] ; obj = objects[i] if skip_sources[src]: self.announce("skipping %s (%s up-to-date)" % (src, obj)) else: self.mkpath(os.path.dirname(obj)) try: self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + extra_postargs) except DistutilsExecError, msg: raise CompileError, msg
"""distutils.bcppcompiler
def build(self, directory='output', compile=True, run=True, debug=False, clean=True, with_output=True, native=True, additional_source_files=None, run_args=None, **kwds): ''' Build the project TODO: more details Parameters ---------- directory : str The output directory to write the project to, any existing files will be overwritten. compile : bool Whether or not to attempt to compile the project run : bool Whether or not to attempt to run the built project if it successfully builds. debug : bool Whether to compile in debug mode. with_output : bool Whether or not to show the ``stdout`` of the built program when run. native : bool Whether or not to compile for the current machine's architecture (best for speed, but not portable) clean : bool Whether or not to clean the project before building additional_source_files : list of str A list of additional ``.cpp`` files to include in the build. ''' renames = { 'project_dir': 'directory', 'compile_project': 'compile', 'run_project': 'run' } if len(kwds): msg = '' for kwd in kwds: if kwd in renames: msg += ("Keyword argument '%s' has been renamed to " "'%s'. ") % (kwd, renames[kwd]) else: msg += "Unknown keyword argument '%s'. " % kwd raise TypeError(msg) if additional_source_files is None: additional_source_files = [] if run_args is None: run_args = [] self.project_dir = directory ensure_directory(directory) compiler, extra_compile_args = get_compiler_and_args() compiler_obj = ccompiler.new_compiler(compiler=compiler) compiler_flags = (ccompiler.gen_preprocess_options( prefs['codegen.cpp.define_macros'], prefs['codegen.cpp.include_dirs']) + extra_compile_args) linker_flags = (ccompiler.gen_lib_options( compiler_obj, library_dirs=prefs['codegen.cpp.library_dirs'], runtime_library_dirs=prefs['codegen.cpp.runtime_library_dirs'], libraries=prefs['codegen.cpp.libraries']) + prefs['codegen.cpp.extra_link_args']) for d in ['code_objects', 'results', 'static_arrays']: ensure_directory(os.path.join(directory, d)) writer = CPPWriter(directory) # Get the number of threads if specified in an openmp context nb_threads = prefs.devices.cpp_standalone.openmp_threads # If the number is negative, we need to throw an error if (nb_threads < 0): raise ValueError( 'The number of OpenMP threads can not be negative !') logger.debug("Writing C++ standalone project to directory " + os.path.normpath(directory)) self.check_openmp_compatible(nb_threads) arange_arrays = sorted( [(var, start) for var, start in self.arange_arrays.iteritems()], key=lambda (var, start): var.name) self.write_static_arrays(directory) self.find_synapses() # Not sure what the best place is to call Network.after_run -- at the # moment the only important thing it does is to clear the objects stored # in magic_network. If this is not done, this might lead to problems # for repeated runs of standalone (e.g. in the test suite). for net in self.networks: net.after_run() # Check that all names are globally unique names = [obj.name for net in self.networks for obj in net.objects] non_unique_names = [ name for name, count in Counter(names).iteritems() if count > 1 ] if len(non_unique_names): formatted_names = ', '.join("'%s'" % name for name in non_unique_names) raise ValueError( 'All objects need to have unique names in ' 'standalone mode, the following name(s) were used ' 'more than once: %s' % formatted_names) self.generate_objects_source(writer, arange_arrays, self.net_synapses, self.static_array_specs, self.networks) self.generate_main_source(writer) self.generate_codeobj_source(writer) self.generate_network_source(writer, compiler) self.generate_synapses_classes_source(writer) self.generate_run_source(writer) self.copy_source_files(writer, directory) writer.source_files.extend(additional_source_files) self.generate_makefile(writer, compiler, native=native, compiler_flags=' '.join(compiler_flags), linker_flags=' '.join(linker_flags), nb_threads=nb_threads) if compile: self.compile_source(directory, compiler, debug, clean, native) if run: self.run(directory, with_output, run_args)
def old_setup_compile(self, outdir, macros, incdirs, sources, depends, extra): """Process arguments and decide which source files to compile. Merges _fix_compile_args() and _prep_compile(). """ if outdir is None: outdir = self.output_dir elif type(outdir) is not StringType: raise TypeError, "'output_dir' must be a string or None" if macros is None: macros = self.macros elif type(macros) is ListType: macros = macros + (self.macros or []) else: raise TypeError, "'macros' (if supplied) must be a list of tuples" if incdirs is None: incdirs = self.include_dirs elif type(incdirs) in (ListType, TupleType): incdirs = list(incdirs) + (self.include_dirs or []) else: raise TypeError, \ "'include_dirs' (if supplied) must be a list of strings" if extra is None: extra = [] # Get the list of expected output (object) files objects = self.object_filenames(sources, strip_dir=0, output_dir=outdir) assert len(objects) == len(sources) # XXX should redo this code to eliminate skip_source entirely. # XXX instead create build and issue skip messages inline if self.force: skip_source = {} # rebuild everything for source in sources: skip_source[source] = 0 elif depends is None: # If depends is None, figure out which source files we # have to recompile according to a simplistic check. We # just compare the source and object file, no deep # dependency checking involving header files. skip_source = {} # rebuild everything for source in sources: # no wait, rebuild nothing skip_source[source] = 1 n_sources, n_objects = newer_pairwise(sources, objects) for source in n_sources: # no really, only rebuild what's skip_source[source] = 0 # out-of-date else: # If depends is a list of files, then do a different # simplistic check. Assume that each object depends on # its source and all files in the depends list. skip_source = {} # L contains all the depends plus a spot at the end for a # particular source file L = depends[:] + [None] for i in range(len(objects)): source = sources[i] L[-1] = source if newer_group(L, objects[i]): skip_source[source] = 0 else: skip_source[source] = 1 pp_opts = gen_preprocess_options(macros, incdirs) build = {} for i in range(len(sources)): src = sources[i] obj = objects[i] ext = os.path.splitext(src)[1] self.mkpath(os.path.dirname(obj)) if skip_source[src]: log.debug("skipping %s (%s up-to-date)", src, obj) else: build[obj] = src, ext return macros, objects, extra, pp_opts, build
def compile (self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None): (output_dir, macros, include_dirs) = \ self._fix_compile_args (output_dir, macros, include_dirs) (objects, skip_sources) = self._prep_compile (sources, output_dir) if extra_postargs is None: extra_postargs = [] pp_opts = gen_preprocess_options (macros, include_dirs) compile_opts = extra_preargs or [] compile_opts.append ('/c') if debug: compile_opts.extend (self.compile_options_debug) else: compile_opts.extend (self.compile_options) for i in range (len (sources)): src = sources[i] ; obj = objects[i] ext = (os.path.splitext (src))[1] if skip_sources[src]: self.announce ("skipping %s (%s up-to-date)" % (src, obj)) else: self.mkpath (os.path.dirname (obj)) if ext in self._c_extensions: input_opt = "/Tc" + src elif ext in self._cpp_extensions: input_opt = "/Tp" + src elif ext in self._rc_extensions: # compile .RC to .RES file input_opt = src output_opt = "/fo" + obj try: self.spawn ([self.rc] + [output_opt] + [input_opt]) except DistutilsExecError, msg: raise CompileError, msg continue elif ext in self._mc_extensions: # Compile .MC to .RC file to .RES file. # * '-h dir' specifies the directory for the # generated include file # * '-r dir' specifies the target directory of the # generated RC file and the binary message resource # it includes # # For now (since there are no options to change this), # we use the source-directory for the include file and # the build directory for the RC file and message # resources. This works at least for win32all. h_dir = os.path.dirname (src) rc_dir = os.path.dirname (obj) try: # first compile .MC to .RC and .H file self.spawn ([self.mc] + ['-h', h_dir, '-r', rc_dir] + [src]) base, _ = os.path.splitext (os.path.basename (src)) rc_file = os.path.join (rc_dir, base + '.rc') # then compile .RC to .RES file self.spawn ([self.rc] + ["/fo" + obj] + [rc_file]) except DistutilsExecError, msg: raise CompileError, msg continue
def compile(self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None): (output_dir, macros, include_dirs) = \ self._fix_compile_args (output_dir, macros, include_dirs) (objects, skip_sources) = self._prep_compile(sources, output_dir) if extra_postargs is None: extra_postargs = [] pp_opts = gen_preprocess_options(macros, include_dirs) compile_opts = extra_preargs or [] compile_opts.append('-c') if debug: compile_opts.extend(self.compile_options_debug) else: compile_opts.extend(self.compile_options) for i in range(len(sources)): src = sources[i] obj = objects[i] ext = (os.path.splitext(src))[1] if skip_sources[src]: self.announce("skipping %s (%s up-to-date)" % (src, obj)) else: src = os.path.normpath(src) obj = os.path.normpath(obj) self.mkpath(os.path.dirname(obj)) if ext == '.res': # This is already a binary file -- skip it. continue # the 'for' loop if ext == '.rc': # This needs to be compiled to a .res file -- do it now. try: self.spawn(["brcc32", "-fo", obj, src]) except DistutilsExecError, msg: raise CompileError, msg continue # the 'for' loop # The next two are both for the real compiler. if ext in self._c_extensions: input_opt = "" elif ext in self._cpp_extensions: input_opt = "-P" else: # Unknown file type -- no extra options. The compiler # will probably fail, but let it just in case this is a # file the compiler recognizes even if we don't. input_opt = "" output_opt = "-o" + obj # Compiler command line syntax is: "bcc32 [options] file(s)". # Note that the source file names must appear at the end of # the command line. try: self.spawn([self.cc] + compile_opts + pp_opts + [input_opt, output_opt] + extra_postargs + [src]) except DistutilsExecError, msg: raise CompileError, msg
"""distutils.unixccompiler
def compile(self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None): (output_dir, macros, include_dirs) = \ self._fix_compile_args (output_dir, macros, include_dirs) (objects, skip_sources) = self._prep_compile(sources, output_dir) if extra_postargs is None: extra_postargs = [] pp_opts = gen_preprocess_options(macros, include_dirs) compile_opts = extra_preargs or [] compile_opts.append('/c') if debug: compile_opts.extend(self.compile_options_debug) else: compile_opts.extend(self.compile_options) for i in range(len(sources)): src = sources[i] obj = objects[i] ext = (os.path.splitext(src))[1] if skip_sources[src]: self.announce("skipping %s (%s up-to-date)" % (src, obj)) else: self.mkpath(os.path.dirname(obj)) if ext in self._c_extensions: input_opt = "/Tc" + src elif ext in self._cpp_extensions: input_opt = "/Tp" + src elif ext in self._rc_extensions: # compile .RC to .RES file input_opt = src output_opt = "/fo" + obj try: self.spawn([self.rc] + [output_opt] + [input_opt]) except DistutilsExecError, msg: raise CompileError, msg continue elif ext in self._mc_extensions: # Compile .MC to .RC file to .RES file. # * '-h dir' specifies the directory for the # generated include file # * '-r dir' specifies the target directory of the # generated RC file and the binary message resource # it includes # # For now (since there are no options to change this), # we use the source-directory for the include file and # the build directory for the RC file and message # resources. This works at least for win32all. h_dir = os.path.dirname(src) rc_dir = os.path.dirname(obj) try: # first compile .MC to .RC and .H file self.spawn([self.mc] + ['-h', h_dir, '-r', rc_dir] + [src]) base, _ = os.path.splitext(os.path.basename(src)) rc_file = os.path.join(rc_dir, base + '.rc') # then compile .RC to .RES file self.spawn([self.rc] + ["/fo" + obj] + [rc_file]) except DistutilsExecError, msg: raise CompileError, msg continue
def build(self, directory='output', compile=True, run=True, debug=False, clean=True, with_output=True, native=True, additional_source_files=None, run_args=None, **kwds): ''' Build the project TODO: more details Parameters ---------- directory : str The output directory to write the project to, any existing files will be overwritten. compile : bool Whether or not to attempt to compile the project run : bool Whether or not to attempt to run the built project if it successfully builds. debug : bool Whether to compile in debug mode. with_output : bool Whether or not to show the ``stdout`` of the built program when run. Output will be shown in case of compilation or runtime error. native : bool Whether or not to compile for the current machine's architecture (best for speed, but not portable) clean : bool Whether or not to clean the project before building additional_source_files : list of str A list of additional ``.cpp`` files to include in the build. ''' renames = {'project_dir': 'directory', 'compile_project': 'compile', 'run_project': 'run'} if len(kwds): msg = '' for kwd in kwds: if kwd in renames: msg += ("Keyword argument '%s' has been renamed to " "'%s'. ") % (kwd, renames[kwd]) else: msg += "Unknown keyword argument '%s'. " % kwd raise TypeError(msg) if additional_source_files is None: additional_source_files = [] if run_args is None: run_args = [] self.project_dir = directory ensure_directory(directory) compiler, extra_compile_args = get_compiler_and_args() compiler_obj = ccompiler.new_compiler(compiler=compiler) compiler_flags = (ccompiler.gen_preprocess_options(prefs['codegen.cpp.define_macros'], prefs['codegen.cpp.include_dirs']) + extra_compile_args) linker_flags = (ccompiler.gen_lib_options(compiler_obj, library_dirs=prefs['codegen.cpp.library_dirs'], runtime_library_dirs=prefs['codegen.cpp.runtime_library_dirs'], libraries=prefs['codegen.cpp.libraries']) + prefs['codegen.cpp.extra_link_args']) for d in ['code_objects', 'results', 'static_arrays']: ensure_directory(os.path.join(directory, d)) writer = CPPWriter(directory) # Get the number of threads if specified in an openmp context nb_threads = prefs.devices.cpp_standalone.openmp_threads # If the number is negative, we need to throw an error if (nb_threads < 0): raise ValueError('The number of OpenMP threads can not be negative !') logger.debug("Writing C++ standalone project to directory "+os.path.normpath(directory)) self.check_openmp_compatible(nb_threads) arange_arrays = sorted([(var, start) for var, start in self.arange_arrays.iteritems()], key=lambda (var, start): var.name) self.write_static_arrays(directory) self.find_synapses() # Not sure what the best place is to call Network.after_run -- at the # moment the only important thing it does is to clear the objects stored # in magic_network. If this is not done, this might lead to problems # for repeated runs of standalone (e.g. in the test suite). for net in self.networks: net.after_run() # Check that all names are globally unique names = [obj.name for net in self.networks for obj in net.objects] non_unique_names = [name for name, count in Counter(names).iteritems() if count > 1] if len(non_unique_names): formatted_names = ', '.join("'%s'" % name for name in non_unique_names) raise ValueError('All objects need to have unique names in ' 'standalone mode, the following name(s) were used ' 'more than once: %s' % formatted_names) self.generate_objects_source(writer, arange_arrays, self.net_synapses, self.static_array_specs, self.networks) self.generate_main_source(writer) self.generate_codeobj_source(writer) self.generate_network_source(writer, compiler) self.generate_synapses_classes_source(writer) self.generate_run_source(writer) self.copy_source_files(writer, directory) writer.source_files.extend(additional_source_files) self.generate_makefile(writer, compiler, native=native, compiler_flags=' '.join(compiler_flags), linker_flags=' '.join(linker_flags), nb_threads=nb_threads) if compile: self.compile_source(directory, compiler, debug, clean, native) if run: self.run(directory, with_output, run_args)
"""distutils.cygwinccompiler
def compile (self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None): (output_dir, macros, include_dirs) = \ self._fix_compile_args (output_dir, macros, include_dirs) (objects, skip_sources) = self._prep_compile (sources, output_dir) if extra_postargs is None: extra_postargs = [] pp_opts = gen_preprocess_options (macros, include_dirs) compile_opts = extra_preargs or [] compile_opts.append ('-c') if debug: compile_opts.extend (self.compile_options_debug) else: compile_opts.extend (self.compile_options) for i in range (len (sources)): src = sources[i] ; obj = objects[i] ext = (os.path.splitext (src))[1] if skip_sources[src]: self.announce ("skipping %s (%s up-to-date)" % (src, obj)) else: src = os.path.normpath(src) obj = os.path.normpath(obj) self.mkpath(os.path.dirname(obj)) if ext == '.res': # This is already a binary file -- skip it. continue # the 'for' loop if ext == '.rc': # This needs to be compiled to a .res file -- do it now. try: self.spawn (["brcc32", "-fo", obj, src]) except DistutilsExecError, msg: raise CompileError, msg continue # the 'for' loop # The next two are both for the real compiler. if ext in self._c_extensions: input_opt = "" elif ext in self._cpp_extensions: input_opt = "-P" else: # Unknown file type -- no extra options. The compiler # will probably fail, but let it just in case this is a # file the compiler recognizes even if we don't. input_opt = "" output_opt = "-o" + obj # Compiler command line syntax is: "bcc32 [options] file(s)". # Note that the source file names must appear at the end of # the command line. try: self.spawn ([self.cc] + compile_opts + pp_opts + [input_opt, output_opt] + extra_postargs + [src]) except DistutilsExecError, msg: raise CompileError, msg