Example #1
0
 def compile(self, source, options = None):
     # Compile a Pyrex implementation file in this context
     # and return a CompilationResult.
     if not options:
         options = default_options
     result = CompilationResult()
     cwd = os.getcwd()
     source = os.path.join(cwd, source)
     if options.use_listing_file:
         result.listing_file = replace_suffix(source, ".lis")
         Errors.open_listing_file(result.listing_file,
             echo_to_stderr = options.errors_to_stderr)
     else:
         Errors.open_listing_file(None)
     if options.output_file:
         result.c_file = os.path.join(cwd, options.output_file)
     else:
         result.c_file = replace_suffix(source, ".c")
     module_name = self.extract_module_name(source)
     initial_pos = (source, 1, 0)
     scope = self.find_module(module_name, pos = initial_pos, need_pxd = 0)
     try:
         tree = self.parse(source, scope.type_names, pxd = 0)
         tree.process_implementation(scope, result)
     except CompileError:
         result.c_file = None
     Errors.close_listing_file()
     result.num_errors = Errors.num_errors
     if result.num_errors > 0:
         result.c_file = None
     if result.c_file and not options.c_only and c_compile:
         result.object_file = c_compile(result.c_file)
         if not options.obj_only and c_link:
             result.extension_file = c_link(result.object_file)
     return result
Example #2
0
 def compile(self, source, options=None):
     # Compile a Pyrex implementation file in this context
     # and return a CompilationResult.
     if not options:
         options = default_options
     result = CompilationResult()
     cwd = os.getcwd()
     source = os.path.join(cwd, source)
     if options.use_listing_file:
         result.listing_file = replace_suffix(source, ".lis")
         Errors.open_listing_file(result.listing_file,
                                  echo_to_stderr=options.errors_to_stderr)
     else:
         Errors.open_listing_file(None)
     if options.output_file:
         result.c_file = os.path.join(cwd, options.output_file)
     else:
         if options.cplus:
             result.c_file = replace_suffix(source, cplus_suffix)
         else:
             result.c_file = map_suffix(source, pyx_to_c_suffix, ".c")
     module_name = self.extract_module_name(source)
     initial_pos = (source, 1, 0)
     def_scope = self.find_module(module_name, pos=initial_pos, need_pxd=0)
     imp_scope = ImplementationScope(def_scope)
     errors_occurred = False
     try:
         tree = self.parse(source, imp_scope, pxd=0)
         tree.process_implementation(imp_scope, options, result)
     except CompileError:
         errors_occurred = True
     Errors.close_listing_file()
     result.num_errors = Errors.num_errors
     if result.num_errors > 0:
         errors_occurred = True
     if errors_occurred and result.c_file:
         try:
             st = os.stat(source)
             castrate_file(result.c_file, st)
         except EnvironmentError:
             pass
         result.c_file = None
     if result.c_file and not options.c_only and c_compile:
         result.object_file = c_compile(result.c_file,
                                        verbose_flag=options.show_version,
                                        cplus=options.cplus)
         if not options.obj_only and c_link:
             result.extension_file = c_link(
                 result.object_file,
                 extra_objects=options.objects,
                 verbose_flag=options.show_version,
                 cplus=options.cplus)
     return result
Example #3
0
 def compile(self, source, options = None):
     # Compile a Pyrex implementation file in this context
     # and return a CompilationResult.
     if not options:
         options = default_options
     result = CompilationResult()
     cwd = os.getcwd()
     source = os.path.join(cwd, source)
     if options.use_listing_file:
         result.listing_file = replace_suffix(source, ".lis")
         Errors.open_listing_file(result.listing_file,
             echo_to_stderr = options.errors_to_stderr)
     else:
         Errors.open_listing_file(None)
     if options.output_file:
         result.c_file = os.path.join(cwd, options.output_file)
     else:
         if options.cplus:
             result.c_file = replace_suffix(source, cplus_suffix)
         else:
             result.c_file = map_suffix(source, pyx_to_c_suffix, ".c")
     module_name = self.extract_module_name(source)
     initial_pos = (source, 1, 0)
     def_scope = self.find_module(module_name, pos = initial_pos, need_pxd = 0)
     imp_scope = ImplementationScope(def_scope)
     errors_occurred = False
     try:
         tree = self.parse(source, imp_scope, pxd = 0)
         tree.process_implementation(imp_scope, options, result)
     except CompileError:
         errors_occurred = True
     Errors.close_listing_file()
     result.num_errors = Errors.num_errors
     if result.num_errors > 0:
         errors_occurred = True
     if errors_occurred and result.c_file:
         try:
             st = os.stat(source)
             castrate_file(result.c_file, st)
         except EnvironmentError:
             pass
         result.c_file = None
     if result.c_file and not options.c_only and c_compile:
         result.object_file = c_compile(result.c_file,
             verbose_flag = options.show_version,
             cplus = options.cplus)
         if not options.obj_only and c_link:
             result.extension_file = c_link(result.object_file,
                 extra_objects = options.objects,
                 verbose_flag = options.show_version,
                 cplus = options.cplus)
     return result
Example #4
0
 def c_compile_link(self, options, result, timestamps=0):
     if result.c_file and not options.c_only and c_compile:
         result.object_file = c_compile(result.c_file,
                                        verbose_flag=options.verbose,
                                        cplus=options.cplus,
                                        use_timestamps=timestamps,
                                        options=options)
     if result.object_file and not options.obj_only and c_link:
         result.extension_file = c_link(result.object_file,
                                        extra_objects=options.objects,
                                        verbose_flag=options.verbose,
                                        cplus=options.cplus,
                                        use_timestamps=timestamps,
                                        options=options)
Example #5
0
def run_compile_test(item, link=0):
    """Run a single compile-only or compile-and-link test.
	   If linking, the linked extension module is kept for use by later tests.
	"""
    try:
        mark_item(item, "failed")
        dir = path.dirname(item)
        name = path.basename(item)
        global mangled_module_name
        module_name, _ = os.path.splitext(name)
        mangled_module_name = "%d%s_" % (len(module_name), module_name)
        produces_include_files = name.startswith("i_") or name.startswith(
            "ia_")
        produces_api_file = name.startswith("a_") or name.startswith("ia_")
        is_error_test = (name[:2] == "e_" or name[:3] == "se_")
        options = Main.CompilationOptions(Main.default_options)
        if is_error_test:
            options.use_listing_file = 1
            options.errors_to_stderr = 0
        try:
            result = Main.compile(item, options)
        except CCompilerError:
            fail("C compilation error.")
        except:
            fail_with_exception("Exception raised in Pyrex compiler.")
        #print "result =", result.__dict__ ###
        if is_error_test:
            if result.num_errors == 0:
                fail("No errors produced, expected some")
            if result.listing_file is None:
                fail("No listing file produced")
            compare_with_reference(result.listing_file,
                                   show_diffs=0,
                                   line_munger=munge_error_line)
            remove_file(replace_suffix(item, ".c"))
            remove_file(replace_suffix(item, ".cpp"))
        else:
            if result.num_errors <> 0:
                #display_files(replace_suffix(item, ".lis"))
                fail("%s errors reported, expected none" % result.num_errors)
            if result.c_file is None:
                fail("No C file produced")
            compare_with_reference(result.c_file,
                                   show_diffs=1,
                                   line_munger=munge_c_line)
            if produces_include_files:
                if result.h_file is None:
                    fail("No header file produced")
                compare_with_reference(result.h_file,
                                       show_diffs=1,
                                       line_munger=munge_c_line)
                if result.i_file is None:
                    pass
                    # .pxi files no longer produced by default
                    #fail("No include file produced")
                else:
                    compare_with_reference(result.i_file,
                                           show_diffs=1,
                                           line_munger=None)
            if produces_api_file:
                if result.api_file is None:
                    fail("No api header file produced")
                compare_with_reference(result.api_file,
                                       show_diffs=1,
                                       line_munger=munge_c_line)
            try:
                result.object_file = c_compile(result.c_file)
            except CCompilerError:
                fail("C compilation error.")
            except:
                fail_with_exception("C compiler failed.")
            try:
                cplus_object_file = c_compile(result.c_file,
                                              cplus=1,
                                              obj_suffix=".cplus.o")
            except CCompilerError:
                fail("C++ compilation error.")
            except:
                fail_with_exception("C++ compiler failed.")
            if link:
                try:
                    c_link(result.object_file)
                except CCompilerError:
                    fail("C linking error.")
            remove_file(result.listing_file)
            remove_file(result.object_file)
            remove_file(cplus_object_file)
        mark_item(item, "passed")
        return "passed"
    except FailureError:
        return "failed"
Example #6
0
def run_compile_test(item, link = 0):
	"""Run a single compile-only or compile-and-link test.
	   If linking, the linked extension module is kept for use by later tests.
	"""
	try:
		mark_item(item, "failed")
		dir = path.dirname(item)
		name = path.basename(item)
		global mangled_module_name
		module_name, _ = os.path.splitext(name)
		mangled_module_name = "%d%s_" % (len(module_name), module_name)
		produces_include_files = name.startswith("i_") or name.startswith("ia_")
		produces_api_file = name.startswith("a_") or name.startswith("ia_")
		is_error_test = (
			name[:2] == "e_" or
			name[:3] == "se_")
		options = Main.CompilationOptions(Main.default_options)
		if is_error_test:
			options.use_listing_file = 1
			options.errors_to_stderr = 0
		try:
			result = Main.compile(item, options)
		except CCompilerError:
			fail("C compilation error.")
		except:
			fail_with_exception("Exception raised in Pyrex compiler.")
		#print "result =", result.__dict__ ###
		if is_error_test:
			if result.num_errors == 0:
				fail("No errors produced, expected some")
			if result.listing_file is None:
				fail("No listing file produced")
			compare_with_reference(result.listing_file, show_diffs = 0,
				line_munger = munge_error_line)
			remove_file(replace_suffix(item, ".c"))
			remove_file(replace_suffix(item, ".cpp"))
		else:
			if result.num_errors <> 0:
				#display_files(replace_suffix(item, ".lis"))
				fail("%s errors reported, expected none" %
					result.num_errors)
			if result.c_file is None:
				fail("No C file produced")
			compare_with_reference(result.c_file, show_diffs = 1,
				line_munger = munge_c_line)
			if produces_include_files:
				if result.h_file is None:
					fail("No header file produced")
				compare_with_reference(result.h_file, show_diffs = 1,
					line_munger = munge_c_line)
				if result.i_file is None:
					pass
					# .pxi files no longer produced by default
					#fail("No include file produced")
				else:
					compare_with_reference(result.i_file, show_diffs = 1,
						line_munger = None)
			if produces_api_file:
				if result.api_file is None:
					fail("No api header file produced")
				compare_with_reference(result.api_file, show_diffs = 1,
					line_munger = munge_c_line)
			try:
				result.object_file = c_compile(result.c_file)
			except CCompilerError:
				fail("C compilation error.")
			except:
				fail_with_exception("C compiler failed.")
			try:
				cplus_object_file = c_compile(result.c_file, cplus = 1, obj_suffix = ".cplus.o")
			except CCompilerError:
				fail("C++ compilation error.")
			except:
				fail_with_exception("C++ compiler failed.")
			if link:
				try:
					c_link(result.object_file)
				except CCompilerError:
					fail("C linking error.")
			remove_file(result.listing_file)
			remove_file(result.object_file)
			remove_file(cplus_object_file)
		mark_item(item, "passed")
		return "passed"
	except FailureError:
		return "failed"