예제 #1
0
파일: CmdLine.py 프로젝트: saminigod/cygwin
def parse_command_line(args):
    from Pyrex.Compiler.Main import \
        CompilationOptions, default_options

    def pop_arg():
        if args:
            return args.pop(0)
        else:
            bad_usage()
    
    def get_param(option):
        tail = option[2:]
        if tail:
            return tail
        else:
            return pop_arg()

    options = CompilationOptions(default_options)
    sources = []
    while args:
        if args[0].startswith("-"):
            option = pop_arg()
            if option in ("-v", "--version"):
                options.show_version = 1
            elif option in ("-l", "--create-listing"):
                options.use_listing_file = 1
            elif option in ("-C", "--compile"):
                options.c_only = 0
            elif option in ("-X", "--link"):
                options.c_only = 0
                options.obj_only = 0
            elif option in ("-+", "--cplus"):
                options.cplus = 1
            elif option.startswith("-I"):
                options.include_path.append(get_param(option))
            elif option == "--include-dir":
                options.include_path.append(pop_arg())
            elif option in ("-o", "--output-file"):
                options.output_file = pop_arg()
            else:
                bad_usage()
        else:
            arg = pop_arg()
            if arg.endswith(".pyx"):
                sources.append(arg)
            elif arg.endswith(".o"):
                options.objects.append(arg)
            else:
                print >>sys.stderr, \
                    "pyrexc: %s: Unknown filename suffix" % arg
    if options.objects and len(sources) > 1:
        print >>sys.stderr, \
            "pyrexc: Only one source file allowed together with .o files"
    if options.use_listing_file and len(sources) > 1:
        print >>sys.stderr, \
            "pyrexc: Only one source file allowed when using -o"
        sys.exit(1)
    return options, sources
예제 #2
0
def parse_command_line(args):
    from Pyrex.Compiler.Main import \
     CompilationOptions, default_options

    def pop_arg(option=None):
        if args:
            return args.pop(0)
        elif option:
            fail("Missing argument for %s" % option)
        else:
            fail("Missing argument")

    def pop_option():
        option = args.pop(0)
        if option.startswith("--"):
            value = None
        else:
            value = option[2:]
            option = option[:2]
        return option, value

    def get_param(arg):
        option, value = arg
        if value:
            return value
        else:
            return pop_arg(option)

    options = CompilationOptions(default_options)
    sources = []
    while args:
        if args[0].startswith("-"):
            arg = pop_option()
            option, value = arg
            if option in ("-?", "--help"):
                show_usage()
            elif option in ("-V", "--version"):
                options.show_version = 1
            elif option in ("-v", "--verbose"):
                options.verbose = 1
            elif option in ("-e", "--create-listing"):
                options.use_listing_file = 1
            elif option in ("-C", "--compile"):
                options.c_only = 0
            elif option in ("-X", "--link"):
                options.c_only = 0
                options.obj_only = 0
            elif option in ("-+", "--cplus"):
                options.cplus = 1
            elif option in ("-I", "--include-dir"):
                options.include_path.append(get_param(arg))
            elif option in ("-o", "--output-file"):
                options.output_file = get_param(arg)
            elif option in ("-r", "--recursive"):
                options.recursive = 1
            elif option in ("-t", "--timestamps"):
                options.timestamps = 1
            elif option in ("-f", "--force"):
                options.timestamps = 0
            elif option in ("-N", "--numpy"):
                options.include_path.append(get_numpy_include_dir())
            elif option in ("-L", "--library_dir"):
                options.library_path.append(get_param(arg))
            elif option in ("-l", "--library"):
                options.libraries.append(get_param(arg))
            elif option in ("-F", "--framework_dir"):
                options.framework_path.append(get_param(arg))
            elif option == "--framework":
                options.frameworks.append(get_param(arg))
            else:
                bad_option(option)
        else:
            arg = pop_arg()
            if has_suffix(arg, pyx_suffixes):
                sources.append(arg)
            elif arg.endswith(".o"):
                options.objects.append(arg)
            else:
                print >>sys.stderr, \
                 "pyrexc: %s: Unknown filename suffix" % arg
    if options.objects and len(sources) > 1:
        print >>sys.stderr, \
         "pyrexc: Only one source file allowed together with .o files"
    if options.use_listing_file and len(sources) > 1:
        print >>sys.stderr, \
         "pyrexc: Only one source file allowed when using -o"
        sys.exit(1)
    return options, sources
예제 #3
0
파일: CmdLine.py 프로젝트: jwilk/Pyrex
def parse_command_line(args):
	from Pyrex.Compiler.Main import \
		CompilationOptions, default_options

	def pop_arg(option = None):
		if args:
			return args.pop(0)
		elif option:
			fail("Missing argument for %s" % option)
		else:
			fail("Missing argument")
	
	def pop_option():
		option = args.pop(0)
		if option.startswith("--"):
			value = None
		else:
			value = option[2:]
			option = option[:2]
		return option, value
	
	def get_param(arg):
		option, value = arg
		if value:
			return value
		else:
			return pop_arg(option)

	options = CompilationOptions(default_options)
	sources = []
	while args:
		if args[0].startswith("-"):
			arg = pop_option()
			option, value = arg
			if option in ("-?", "--help"):
				show_usage()
			elif option in ("-V", "--version"):
				options.show_version = 1
			elif option in ("-v", "--verbose"):
				options.verbose = 1
			elif option in ("-e", "--create-listing"):
				options.use_listing_file = 1
			elif option in ("-C", "--compile"):
				options.c_only = 0
			elif option in ("-X", "--link"):
				options.c_only = 0
				options.obj_only = 0
			elif option in ("-+", "--cplus"):
				options.cplus = 1
			elif option in ("-I", "--include-dir"):
				options.include_path.append(get_param(arg))
			elif option in ("-o", "--output-file"):
				options.output_file = get_param(arg)
			elif option in ("-r", "--recursive"):
				options.recursive = 1
			elif option in ("-t", "--timestamps"):
				options.timestamps = 1
			elif option in ("-f", "--force"):
				options.timestamps = 0
			elif option in ("-N", "--numpy"):
				options.include_path.append(get_numpy_include_dir())
			elif option in ("-L", "--library_dir"):
				options.library_path.append(get_param(arg))
			elif option in ("-l", "--library"):
				options.libraries.append(get_param(arg))
			elif option in ("-F", "--framework_dir"):
				options.framework_path.append(get_param(arg))
			elif option == "--framework":
				options.frameworks.append(get_param(arg))
			else:
				bad_option(option)
		else:
			arg = pop_arg()
			if has_suffix(arg, pyx_suffixes):
				sources.append(arg)
			elif arg.endswith(".o"):
				options.objects.append(arg)
			else:
				print >>sys.stderr, \
					"pyrexc: %s: Unknown filename suffix" % arg
	if options.objects and len(sources) > 1:
		print >>sys.stderr, \
			"pyrexc: Only one source file allowed together with .o files"
	if options.use_listing_file and len(sources) > 1:
		print >>sys.stderr, \
			"pyrexc: Only one source file allowed when using -o"
		sys.exit(1)
	return options, sources
예제 #4
0
    def pyrex_sources(self, sources, extension):
        """
        Walk the list of source files in 'sources', looking for Pyrex
        source (.pyx) files.  Run Pyrex on all that are found, and return
        a modified 'sources' list with Pyrex source files replaced by the
        generated C (or C++) files.
        """

        if PyrexError == None:
            raise DistutilsPlatformError, \
                  ("Pyrex does not appear to be installed "
                   "on platform '%s'") % os.name

        new_sources = []
        pyrex_sources = []
        pyrex_targets = {}

        # Setup create_list and cplus from the extension options if
        # Pyrex.Distutils.extension.Extension is used, otherwise just
        # use what was parsed from the command-line or the configuration file.
        # cplus will also be set to true is extension.language is equal to
        # 'C++' or 'c++'.
        #try:
        #	create_listing = self.pyrex_create_listing or \
        #						extension.pyrex_create_listing
        #	cplus = self.pyrex_cplus or \
        #				extension.pyrex_cplus or \
        #				(extension.language != None and \
        #					extension.language.lower() == 'c++')
        #except AttributeError:
        #	create_listing = self.pyrex_create_listing
        #	cplus = self.pyrex_cplus or \
        #				(extension.language != None and \
        #					extension.language.lower() == 'c++')

        create_listing = self.pyrex_create_listing or \
            getattr(extension, 'pyrex_create_listing', 0)
        cplus = self.pyrex_cplus or getattr(extension, 'pyrex_cplus', 0) or \
                (extension.language and extension.language.lower() == 'c++')
        pyrex_gen_pxi = self.pyrex_gen_pxi or getattr(extension,
                                                      'pyrex_gen_pxi', 0)

        # Set up the include_path for the Pyres compiler:
        #	1.	Start with the command line option.
        #	2.	Add in any (unique) paths from the extension
        #		pyrex_include_dirs (if Pyrex.Distutils.extension is used).
        #	3.	Add in any (unique) paths from the extension include_dirs
        includes = self.pyrex_include_dirs
        try:
            for i in extension.pyrex_include_dirs:
                if not i in includes:
                    includes.append(i)
        except AttributeError:
            pass
        for i in extension.include_dirs:
            if not i in includes:
                includes.append(i)

        # Set the target_ext to '.c'.  Pyrex will change this to '.cpp' if
        # needed.
        if cplus:
            target_ext = '.cpp'
        else:
            target_ext = '.c'

        # Decide whether to drop the generated C files into the temp dir
        # or the source tree.

        if not self.inplace and (self.pyrex_c_in_temp
                                 or getattr(extension, 'pyrex_c_in_temp', 0)):
            target_dir = os.path.join(self.build_temp, "pyrex")
        else:
            target_dir = ""

        for source in sources:
            (base, ext) = os.path.splitext(source)
            if ext == ".pyx":  # Pyrex source file
                new_sources.append(os.path.join(target_dir, base + target_ext))
                pyrex_sources.append(source)
                pyrex_targets[source] = new_sources[-1]
            else:
                new_sources.append(source)

        if not pyrex_sources:
            return new_sources

        for source in pyrex_sources:
            target = pyrex_targets[source]
            #			source_time = os.stat(source).st_mtime
            #			try:
            #				target_time = os.stat(target).st_mtime
            #				newer = source_time > target_time
            #			except EnvironmentError:
            #				newer = 1
            #			if newer:
            if self.force or newer(source, target):
                log.info("pyrexc %s --> %s", source, target)
                self.mkpath(os.path.dirname(target))
                options = CompilationOptions(pyrex_default_options,
                                             use_listing_file=create_listing,
                                             include_path=includes,
                                             output_file=target,
                                             cplus=cplus,
                                             generate_pxi=pyrex_gen_pxi)
                result = pyrex_compile(source, options=options)

        return new_sources
예제 #5
0
 def pyrex_compile(self, source):
     from Pyrex.Compiler.Main import CompilationOptions, default_options
     options = CompilationOptions(default_options)
     result = Pyrex.Compiler.Main.compile(source, options)
     if result.num_errors <> 0:
         sys.exit(1)
예제 #6
0
	def pyrex_compile(self, source):
		options = CompilationOptions(default_options,
			include_path = self.include_dirs)
		result = compile(source, options)
		if result.num_errors <> 0:
			sys.exit(1)