Makeprojects
Loading...
Searching...
No Matches
makeprojects.util Namespace Reference

The util module contains subroutines used everywhere. More...

Functions

 validate_enum_type (value, data_type)
 Verify a value is a specific data type.
 regex_dict (value)
 Convert *.cpp keys to regex keys.
 validate_boolean (value)
 Verify a value is a boolean.
 validate_string (value)
 Verify a value is a string.
 clear_build_rules_cache ()
 Clear the build rules cache.
 load_build_rules (path_name, clear_cache=False)
 Load build_rules using a cache.
 _do_getattr_build_rules (build_rules, attribute)
 Internal function to test attributes.
 getattr_build_rules (build_rules, attributes, fallback=None)
 Find an attribute in a build rules module.
 getattr_build_rules_list (build_rules_list, attributes, fallback)
 Find an attribute in a list of build rules.
 add_build_rules (build_rules_list, file_name, verbose, is_root, basename)
 Load in the file build_rules.py
 get_build_rules (working_directory, verbose, build_rules_name, basename)
 Find all build_rules.py files that apply to this directory.
 remove_ending_os_sep (input_list)
 Iterate over a string list and remove trailing os separator characters.
 was_processed (processed, path_name, verbose)
 Check if a file or directory has already been processed.
 fixup_args (args)
 Check unused args if they are directories, files or configurations.
 convert_file_name (item, source_file)
 Convert macros to literal filename strings.
 do_generate_build_rules (parsed, working_directory)
 Test if the parsed parameters have –generate-rules.
 iterate_configurations (solution)
 Iterate all configurations in a solution.

Variables

dict _BUILD_RULES_CACHE
 Dict of build rules loaded.

Detailed Description

The util module contains subroutines used everywhere.

Function Documentation

◆ _do_getattr_build_rules()

makeprojects.util._do_getattr_build_rules ( build_rules,
attribute )
protected

Internal function to test attributes.

Parameters
build_rulesModule of the build_rules.py to test
attributeAttribute string to test with
Returns
(None or found value, True if value is None)
See also
getattr_build_rules

◆ add_build_rules()

makeprojects.util.add_build_rules ( build_rules_list,
file_name,
verbose,
is_root,
basename )

Load in the file build_rules.py

Load the build_rules.py file. If the variable *_GENERIC is True or if is_root is True, append the module to build_rules_list. If the variable *_CONTINUE was found in the file, check if it is set to True. If so, return True to allow processing to continue. If the file is not found, return True to allow processing the parent folder.

Since this is called from buildme, cleanme, and makeprojects, the prefix needed for the tool is passed in basename. An example is "CLEANME".

Parameters
build_rules_listList to add build_rules.py instances.
file_nameFull path name of the build_rules.py to load.
verboseTrue for verbose output.
is_rootTrue if *_GENERIC is ignored.
basenameVariable prefix to substitute * in *_GENERIC
Returns
True if the parent folder should be checked, False if not.

◆ clear_build_rules_cache()

makeprojects.util.clear_build_rules_cache ( )

Clear the build rules cache.

util.load_build_rules uses a cache. Call this function to clear the cache without calling util.load_build_rules to do it.

See also
load_build_rules

◆ convert_file_name()

makeprojects.util.convert_file_name ( item,
source_file )

Convert macros to literal filename strings.

Parameters
itemFilename string
source_fileSourceFile object
Returns
String with converted macros

◆ do_generate_build_rules()

makeprojects.util.do_generate_build_rules ( parsed,
working_directory )

Test if the parsed parameters have –generate-rules.

If –generate-rules was not invoked, return None. Otherwise return a numeric error code.

Parameters
parsedAn ArgumentParser object with attribute generate_build_rules
working_directoryDirectory to store the build_rules.py
Returns
None or an integer error code

◆ fixup_args()

makeprojects.util.fixup_args ( args)

Check unused args if they are directories, files or configurations.

The args object has the attributes args, directories, configurations, and files. The attribute args has all the unparsed arguments that will be tested to see if they are a file, directory or a string. The entries will be added to their appropriate attribute, with strings appended to configurations. Attribute args is set to None.

Parameters
argsargs class from argparser

◆ get_build_rules()

makeprojects.util.get_build_rules ( working_directory,
verbose,
build_rules_name,
basename )

Find all build_rules.py files that apply to this directory.

If no files are found, return an empty list.

Parameters
working_directoryDirectory to scan for build_rules.py
verboseTrue if verbose output is desired
build_rules_namebuild_rules.py or an override
basename"CLEANME", "BUILDME", etc.
Returns
List of loaded build_rules.py file modules

◆ getattr_build_rules()

makeprojects.util.getattr_build_rules ( build_rules,
attributes,
fallback = None )

Find an attribute in a build rules module.

Scan the build rules until an attribute value is found. It will return the first one found. If none are found, this function returns fallback.

This function returns two values, the first is the attribute value, the second is a boolean of True meaning the attribute was found, or False if the default value was returned.

Parameters
build_rulesbuild_rules.py module instance.
attributesString or list of strings, attribute name(s).
fallbackValue to return if the attribute was not found.
Returns
Tuple of attribute value found in build_rules, or fallback and the second value is True if found, False if default was
used.

◆ getattr_build_rules_list()

makeprojects.util.getattr_build_rules_list ( build_rules_list,
attributes,
fallback )

Find an attribute in a list of build rules.

Iterate over the build rules list until an entry has an attribute value. It will return the first one found. If none are found, or there were no entries in build_rules_list, this function returns fallback.

Parameters
build_rules_listList of build_rules.py instances.
attributesString or list of strings, attribute name(s).
fallbackValue to return if the attribute was not found.
Returns
Attribute value found in build_rules_list entry, or fallback.

◆ iterate_configurations()

makeprojects.util.iterate_configurations ( solution)

Iterate all configurations in a solution.

Given a solution, iterate over all of the configurations within the solution and return each object.

Parameters
solutionSolution object.
Returns
Iterator that returns configuration objects.

◆ load_build_rules()

makeprojects.util.load_build_rules ( path_name,
clear_cache = False )

Load build_rules using a cache.

Check if the path was already loaded. If so, use the cached version, otherwise load and cache the build_rules.py script

Parameters
path_nameFull pathname to the build_rules.py script
clear_cacheBoolean, if true, clear the cache first
See also
clear_build_rules_cache

◆ regex_dict()

makeprojects.util.regex_dict ( value)

Convert *.cpp keys to regex keys.

Given a dict where the keys are all filenames with wildcards, convert only the keys into equivalent regexes and leave the values intact.

Examples

rules = {
"*.cpp":
{"a": "arf", "b": "bark", "c": "coo"},
"*.h":
{"h": "help"}
}
regex_keys = regex_dict(rules)
Parameters
valuedict to convert
Returns
dict with keys converted to regexes

◆ remove_ending_os_sep()

makeprojects.util.remove_ending_os_sep ( input_list)

Iterate over a string list and remove trailing os separator characters.

Each string is tested if its length is greater than one and if the last character is the pathname separator. If so, the pathname separator character is removed.

Parameters
input_listlist of strings
Returns
Processed list of strings
Exceptions
TypeError

◆ validate_boolean()

makeprojects.util.validate_boolean ( value)

Verify a value is a boolean.

Check if the value can be converted to a bool, if so, return the value as bool. None is converted to False.

Parameters
valueValue to check.
Returns
Value converted to data_type or None.
Exceptions
ValueError

◆ validate_enum_type()

makeprojects.util.validate_enum_type ( value,
data_type )

Verify a value is a specific data type.

Check if the value is either None or an instance of a specfic data type. If so, return immediately. If the value is a string, call the lookup() function of the data type for conversion.

Parameters
valueValue to check.
data_typeType instance of the class type to match.
Returns
Value converted to data_type or None.
Exceptions
TypeError

◆ validate_string()

makeprojects.util.validate_string ( value)

Verify a value is a string.

Check if the value is a string, if so, return the value as is or None.

Parameters
valueValue to check.
Returns
Value is string or None.
Exceptions
ValueError

◆ was_processed()

makeprojects.util.was_processed ( processed,
path_name,
verbose )

Check if a file or directory has already been processed.

To prevent recursion, expand the path name to an absolution path call this function with a set that will store all the entries and the entry to test. If the entry is already in the set, report the issue and return True. Otherwise, add the entry to the set and return False to allow the path to be processed.

Parameters
processedSet to store processed pathnames
path_namePath to a directory or file
verboseTrue if verbose output is requested
Returns
True if it's already in the set. False if not.