コード例 #1
0
ファイル: createvmap.py プロジェクト: RomanSaveljev/raptor
def main():

    try:
        global exitCode, printDebug

        # any exceptions make us traceback and exit

        parser = OptionParser(prog="createvmap.py")

        parser.add_option("-c",
                          "--cpploc",
                          action="store",
                          dest="cpplocation",
                          help="Full path of the preprocessor")
        parser.add_option("-d",
                          "--debug",
                          action="store_true",
                          default=False,
                          dest="debug",
                          help="Turn debug information on")
        parser.add_option("-D",
                          "--define",
                          action="append",
                          dest="defines",
                          help="Macro definition")
        parser.add_option("-f",
                          "--featurelist",
                          action="append",
                          dest="featurelistfile",
                          help="List of featureslist files")
        parser.add_option("-o",
                          "--output",
                          action="store",
                          dest="outputvmapfile",
                          help="Output VMAP file name")
        parser.add_option("-p",
                          "--preinclude",
                          action="store",
                          dest="preinclude",
                          help="Pre-include file ")
        parser.add_option("-s",
                          "--source",
                          action="append",
                          dest="sourcefiles",
                          help="List of source files")
        parser.add_option("-u",
                          "--userinc",
                          action="append",
                          dest="user_include",
                          help="User Include Folders")
        parser.add_option("-x",
                          "--systeminc",
                          action="append",
                          dest="system_include",
                          help="System Include Folders")

        # The following allows the use of the --command option.
        # The add_option() is redundant since --command  is
        # expanded well before it can take effect but it does
        # allow us to print out a useful help message.
        parser.add_option(
            "--command",
            action="store",
            dest="preinclude",
            help="""Specify a command file with more commandline options 
				in it (for very large components)""")
        expanded_args = expand_command_options(sys.argv[1:])

        (options, leftover_args) = parser.parse_args(expanded_args)

        if leftover_args:
            for invalids in leftover_args:
                warning("Unknown parameter '%s'" % invalids)

        printDebug = options.debug
        debug("Source Files     -> %s", options.sourcefiles)
        debug("Macro defines    -> %s", options.defines)
        debug("Features Files   -> %s", options.featurelistfile)
        debug("Pre-Include File -> %s", options.preinclude)
        debug("User Includes    -> %s", options.user_include)
        debug("System Includes  -> %s", options.system_include)
        debug("CPP Location     -> %s", options.cpplocation)
        debug("VMAP Output name -> %s", options.outputvmapfile)

        featurelist = []
        definelist = ""
        user_includeslist = ""
        system_includeslist = ""
        includeslist = ""

        # Some error checking code
        if not options.outputvmapfile:
            error("No output vmap file name supplied")

        # Source files must be supplied
        check_exists("source file", options.sourcefiles)

        # A valid preinclude file must be supplied
        check_exists("pre-include file", options.preinclude)

        # Some feature lists are required
        check_exists("feature list", options.featurelistfile)

        # A cpp tool is required
        check_exists("cpp tool", options.cpplocation)

        # if an essential option was missing then we should stop now
        if exitCode != 0:
            sys.exit(exitCode)

        # macro definitions
        if options.defines:
            for macro in options.defines:
                definelist += " -D" + macro.replace('__SBS__QUOTE__', '\\"')

        # Note that we have to use -isystem for user includes and system
        # includes to match what happens in the compiler. Long story.

        # Add each source directory as a user-include, so that our temporary
        # concatenated source file can find includes that were next to the
        # original source files.
        # Check that all the specified source files exist
        # and collect a set of all the source directories
        sourcedirs = set()
        for src in options.sourcefiles:
            sourcedirs.add(os.path.dirname(src))

        for srcdir in sourcedirs:
            user_includeslist += " -isystem " + srcdir

        # Convert the include list to a string to be passed to cpp
        if options.user_include:
            for userinc in options.user_include:
                user_includeslist += " -isystem " + userinc
        if options.system_include:
            for sysinc in options.system_include:
                system_includeslist += " -isystem " + sysinc

        includeslist = user_includeslist + system_includeslist

        # Get a list of all the features, from all the featurelist files
        featurelist = getFeatures(options.featurelistfile)

        # concatenate the source files together into a temporary file
        try:
            (tempfd, tempname) = tempfile.mkstemp()
            temp = os.fdopen(tempfd, "w")
            for src in options.sourcefiles:
                sfile = open(src, "r")
                for sline in sfile:
                    temp.write(sline)
                sfile.close()
            temp.close()
        except Exception as e:
            error("Could not write source files into temporary file %s : %s" %
                  (tempname, str(e)))
            return 1

        debug("Temporary file name : " + tempname)

        # extract the macros from the concatenated source files
        macro_dictionary = getVariationFeatures(featurelist,
                                                options.preinclude, tempname,
                                                options.cpplocation,
                                                definelist, includeslist)
        debug("Macros extracted:")
        for key, values in macro_dictionary.items():
            debug(key + " " + str(values))

        # if there were no macros then the vmap file will be empty...
        if not macro_dictionary['FEATURENAME']:
            warning("No feature macros were found in the source")

        # Get rid of the temporary file
        try:
            os.remove(tempname)
        except:
            error("Could not delete temporary %s" % tempname)

        createVmapFile(macro_dictionary, options.outputvmapfile)

        # exit with 0 if OK
        return exitCode

    except Exception as ex:
        traceback.print_exc()
        return 1
コード例 #2
0
ファイル: cli.py プロジェクト: RomanSaveljev/raptor
def DoBuild(build, args):
	"Process build arguments"
	#
	# This should parse the args list and call methods on
	# the build object to store the appropriate data.

	# Expand --command=file options, replacing them with the contents of the
	# command file.

	non_ascii_error = "Non-ASCII character in argument or command file"

	try:
		expanded_args = expand_command_options(args)
		for arg in expanded_args:
			if arg.startswith("?"):
				u = NonAsciiError(non_ascii_error+" : found an argument starting with ? which can indicate that non-ascii characters were used in the commandline: "+arg) 
				raise u
			for c in arg:
				if ord(c) > 127:
					build.Error(non_ascii_error)
					return False
	except IOError as e:
		build.Error(str(e))
		return False
	except NonAsciiError as e:
		build.Error(str(e))
		return False
	except UnicodeDecodeError:
		build.Error(non_ascii_error)
		return False

	# parse the full set of arguments
	(options, leftover_args) = parser.parse_args(expanded_args)

	# the leftover_args are target names.
	for leftover in leftover_args:
		build.AddTarget(leftover)

	# Define the dictionary of functions to be used.
	# Attributes and function names can be added easily.
	# The calling attribute should be the same
	# as specified when creating the add_option
	functions = {'config_name': build.AddConfigName,
				 'config_list':build.AddConfigList,
				 'sys_def_file' : build.SetSysDefFile,
				 'sys_def_base' : build.SetSysDefBase,
				 'sys_def_layer' : build.AddSysDefLayer,
				 'sys_def_order_layers' : build.SetSysDefOrderLayers,
				 'bld_inf_file' : build.AddBuildInfoFile,
				 'logfile' : build.SetLogFileName,
				 'makefile' : build.SetTopMakefile,
				 'qt_pro_file' : build.AddQtProFile,
				 'quiet' : build.RunQuietly,
				 'debugoutput' : build.SetDebugOutput,
				 'doExportOnly' : build.SetExportOnly,
				 'doExport' : build.SetNoExport,
				 'keepgoing': build.SetKeepGoing,
				 'nobuild' : build.SetNoBuild,
				 'make_engine': build.SetMakeEngine,
				 'make_option': build.AddMakeOption,
				 'noDependInclude': build.SetNoDependInclude,
				 'noDependGenerate': build.SetNoDependGenerate,
				 'number_of_jobs': build.SetJobs,
				 'project_name' :  build.AddProject,
				 'query' : build.AddQuery,
				 'filter_list' : build.FilterList,
				 'ignore_os_detection': build.IgnoreOsDetection,
				 'check' :  build.SetCheck,
				 'what' :  build.SetWhat,
				 'tries' : build.SetTries,
				 'toolcheck' : build.SetToolCheck,
				 'timing' : build.SetTiming,
				 'source_target' : build.AddSourceTarget,
				 'command_file' : CommandFile,
				 'parallel_parsing' : build.SetParallelParsing,
				 'resource_rsg_casefolding' : build.SetRsgCaseFolding,
				 'incremental_parsing' : build.SetIncrementalParsing,
				 'no_metadata_depend' : build.SetNoMetadataDepend,
			 	 'version' : build.PrintVersion
				}

	# Check if Quiet mode has been specified (otherwise we will make noise)
	if parser.values.quiet:
		build.RunQuietly(True)

	# only return True if there are no command-line errors
	keepGoing = True

	# Parse through the command line arguments passed, and call the
	# corresponding function with the correct parameter.
	# Since options is a OptParse.Value instance, it can be iterated over.
	# This implementation helps avoid lengthy if-else statements
	for opt in options.__dict__.items():
		call_function = functions[str(opt[0])]
		values = opt[1]
		if not values:
			pass
		else:
			if type(values) is list: # Check if the argument type is a list or a string. If list, then iterate through it and call the functions
				for val in values:
					keepGoing = (call_function(val) and keepGoing)
			else:
					keepGoing = (call_function(values) and keepGoing)

	return keepGoing
コード例 #3
0
ファイル: createvmap.py プロジェクト: RomanSaveljev/raptor
def main():

	try:
		global exitCode, printDebug
		
		# any exceptions make us traceback and exit

		parser = OptionParser(prog = "createvmap.py")
	
		parser.add_option("-c","--cpploc",action="store",dest="cpplocation",help="Full path of the preprocessor")
		parser.add_option("-d","--debug",action="store_true",default=False,dest="debug",help="Turn debug information on")
		parser.add_option("-D","--define",action="append",dest="defines",help="Macro definition")
		parser.add_option("-f","--featurelist",action="append",dest="featurelistfile",help="List of featureslist files")
		parser.add_option("-o","--output",action="store",dest="outputvmapfile",help="Output VMAP file name")
		parser.add_option("-p","--preinclude",action="store",dest="preinclude",help="Pre-include file ")
		parser.add_option("-s","--source",action="append",dest="sourcefiles",help="List of source files")
		parser.add_option("-u","--userinc",action="append",dest="user_include",help="User Include Folders")
		parser.add_option("-x","--systeminc",action="append",dest="system_include",help="System Include Folders")


		# The following allows the use of the --command option.
		# The add_option() is redundant since --command  is
		# expanded well before it can take effect but it does
		# allow us to print out a useful help message.
		parser.add_option("--command",action="store",
			dest="preinclude",
			help="""Specify a command file with more commandline options 
				in it (for very large components)""")
		expanded_args = expand_command_options(sys.argv[1:])

		(options, leftover_args) = parser.parse_args(expanded_args)

		if leftover_args:
			for invalids in leftover_args:
				warning("Unknown parameter '%s'" % invalids)
		
		printDebug = options.debug
		debug("Source Files     -> %s", options.sourcefiles)
		debug("Macro defines    -> %s", options.defines)
		debug("Features Files   -> %s", options.featurelistfile)
		debug("Pre-Include File -> %s", options.preinclude)
		debug("User Includes    -> %s", options.user_include)
		debug("System Includes  -> %s", options.system_include)
		debug("CPP Location     -> %s", options.cpplocation)
		debug("VMAP Output name -> %s", options.outputvmapfile)
			
		featurelist = []
		definelist = ""
		user_includeslist = ""
		system_includeslist = ""
		includeslist = ""

		# Some error checking code
		if not options.outputvmapfile:
			error("No output vmap file name supplied")
	
		# Source files must be supplied
		check_exists("source file", options.sourcefiles)
	
		# A valid preinclude file must be supplied
		check_exists("pre-include file", options.preinclude)
	
		# Some feature lists are required
		check_exists("feature list", options.featurelistfile)
	
		# A cpp tool is required
		check_exists("cpp tool", options.cpplocation)

		# if an essential option was missing then we should stop now
		if exitCode != 0:
			sys.exit(exitCode)
			
		# macro definitions
		if options.defines:
			for macro in options.defines:
				definelist += " -D" + macro.replace('__SBS__QUOTE__', '\\"')

		# Note that we have to use -isystem for user includes and system
		# includes to match what happens in the compiler. Long story.

		# Add each source directory as a user-include, so that our temporary
		# concatenated source file can find includes that were next to the
		# original source files.
		# Check that all the specified source files exist
		# and collect a set of all the source directories
		sourcedirs = set()
		for src in options.sourcefiles:
			sourcedirs.add(os.path.dirname(src))
			
		for srcdir in sourcedirs:
			user_includeslist += " -isystem " + srcdir

		# Convert the include list to a string to be passed to cpp
		if options.user_include:
			for userinc in options.user_include:
				user_includeslist += " -isystem " + userinc
		if options.system_include:
			for sysinc in options.system_include:
				system_includeslist += " -isystem " + sysinc
	
		includeslist = user_includeslist + system_includeslist

		# Get a list of all the features, from all the featurelist files
		featurelist = getFeatures(options.featurelistfile)

		# concatenate the source files together into a temporary file
		try:
			(tempfd, tempname) = tempfile.mkstemp()
			temp = os.fdopen(tempfd, "w")
			for src in options.sourcefiles:
				sfile = open(src, "r")
				for sline in sfile:
					temp.write(sline)
				sfile.close()
			temp.close()
		except Exception as e:
			error("Could not write source files into temporary file %s : %s" % (tempname, str(e)))
			return 1
		
		debug("Temporary file name : " + tempname)

		# extract the macros from the concatenated source files
		macro_dictionary = getVariationFeatures(featurelist,
		                                        options.preinclude,
								                tempname,
								                options.cpplocation,
								                definelist,
								                includeslist)
		debug("Macros extracted:") 
		for key,values in macro_dictionary.items():
			debug(key + " " + str(values))

		# if there were no macros then the vmap file will be empty...
		if not macro_dictionary['FEATURENAME']:
			warning("No feature macros were found in the source")
			
		# Get rid of the temporary file
		try:
			os.remove(tempname)
		except:
			error("Could not delete temporary %s" % tempname) 

		createVmapFile(macro_dictionary, options.outputvmapfile)
		
		# exit with 0 if OK
		return exitCode

	except Exception as ex:
		traceback.print_exc()
		return 1
コード例 #4
0
ファイル: cli.py プロジェクト: RomanSaveljev/raptor
def DoBuild(build, args):
    "Process build arguments"
    #
    # This should parse the args list and call methods on
    # the build object to store the appropriate data.

    # Expand --command=file options, replacing them with the contents of the
    # command file.

    non_ascii_error = "Non-ASCII character in argument or command file"

    try:
        expanded_args = expand_command_options(args)
        for arg in expanded_args:
            if arg.startswith("?"):
                u = NonAsciiError(
                    non_ascii_error +
                    " : found an argument starting with ? which can indicate that non-ascii characters were used in the commandline: "
                    + arg)
                raise u
            for c in arg:
                if ord(c) > 127:
                    build.Error(non_ascii_error)
                    return False
    except IOError as e:
        build.Error(str(e))
        return False
    except NonAsciiError as e:
        build.Error(str(e))
        return False
    except UnicodeDecodeError:
        build.Error(non_ascii_error)
        return False

    # parse the full set of arguments
    (options, leftover_args) = parser.parse_args(expanded_args)

    # the leftover_args are target names.
    for leftover in leftover_args:
        build.AddTarget(leftover)

    # Define the dictionary of functions to be used.
    # Attributes and function names can be added easily.
    # The calling attribute should be the same
    # as specified when creating the add_option
    functions = {
        'config_name': build.AddConfigName,
        'config_list': build.AddConfigList,
        'sys_def_file': build.SetSysDefFile,
        'sys_def_base': build.SetSysDefBase,
        'sys_def_layer': build.AddSysDefLayer,
        'sys_def_order_layers': build.SetSysDefOrderLayers,
        'bld_inf_file': build.AddBuildInfoFile,
        'logfile': build.SetLogFileName,
        'makefile': build.SetTopMakefile,
        'qt_pro_file': build.AddQtProFile,
        'quiet': build.RunQuietly,
        'debugoutput': build.SetDebugOutput,
        'doExportOnly': build.SetExportOnly,
        'doExport': build.SetNoExport,
        'keepgoing': build.SetKeepGoing,
        'nobuild': build.SetNoBuild,
        'make_engine': build.SetMakeEngine,
        'make_option': build.AddMakeOption,
        'noDependInclude': build.SetNoDependInclude,
        'noDependGenerate': build.SetNoDependGenerate,
        'number_of_jobs': build.SetJobs,
        'project_name': build.AddProject,
        'query': build.AddQuery,
        'filter_list': build.FilterList,
        'ignore_os_detection': build.IgnoreOsDetection,
        'check': build.SetCheck,
        'what': build.SetWhat,
        'tries': build.SetTries,
        'toolcheck': build.SetToolCheck,
        'timing': build.SetTiming,
        'source_target': build.AddSourceTarget,
        'command_file': CommandFile,
        'parallel_parsing': build.SetParallelParsing,
        'resource_rsg_casefolding': build.SetRsgCaseFolding,
        'incremental_parsing': build.SetIncrementalParsing,
        'no_metadata_depend': build.SetNoMetadataDepend,
        'version': build.PrintVersion
    }

    # Check if Quiet mode has been specified (otherwise we will make noise)
    if parser.values.quiet:
        build.RunQuietly(True)

    # only return True if there are no command-line errors
    keepGoing = True

    # Parse through the command line arguments passed, and call the
    # corresponding function with the correct parameter.
    # Since options is a OptParse.Value instance, it can be iterated over.
    # This implementation helps avoid lengthy if-else statements
    for opt in options.__dict__.items():
        call_function = functions[str(opt[0])]
        values = opt[1]
        if not values:
            pass
        else:
            if type(
                    values
            ) is list:  # Check if the argument type is a list or a string. If list, then iterate through it and call the functions
                for val in values:
                    keepGoing = (call_function(val) and keepGoing)
            else:
                keepGoing = (call_function(values) and keepGoing)

    return keepGoing