From 776deb54b33692243e3bd2d2db4887cbc28ce897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurko=20Gospodneti=C4=87?= Date: Thu, 19 Jul 2012 03:47:31 +0000 Subject: [PATCH] Boost Build code cleanup - minor stylistic changes (trimmed trailing spaces, corrected a typo in the main module comment). [SVN r79594] --- v2/build/virtual_target.py | 174 ++++++++++++++++++------------------- 1 file changed, 87 insertions(+), 87 deletions(-) diff --git a/v2/build/virtual_target.py b/v2/build/virtual_target.py index 9668eef71..c44559f5b 100644 --- a/v2/build/virtual_target.py +++ b/v2/build/virtual_target.py @@ -1,6 +1,6 @@ # Status: ported. # Base revision: 64488. -# +# # Copyright (C) Vladimir Prus 2002. Permission to copy, use, modify, sell and # distribute this software is granted provided this copyright notice appears in # all copies. This software is provided "as is" without express or implied @@ -13,7 +13,7 @@ # # # +--------------------------+ -# | VirtualTarget | +# | VirtualTarget | # +==========================+ # | actualize | # +--------------------------+ @@ -85,7 +85,7 @@ __re_starts_with_at = re.compile ('^@(.*)') class VirtualTargetRegistry: def __init__ (self, manager): self.manager_ = manager - + # A cache for FileTargets self.files_ = {} @@ -98,12 +98,12 @@ class VirtualTargetRegistry: self.actual_ = {} self.recent_targets_ = [] - + # All targets ever registed self.all_targets_ = [] self.next_id_ = 0 - + def register (self, target): """ Registers a new virtual target. Checks if there's already registered target, with the same name, type, project and subvariant properties, and also with the same sources @@ -137,7 +137,7 @@ class VirtualTargetRegistry: b2.util.set.difference(ps2.dependency(), ps2.incidental()) if p1 == p2: result = t - + if not result: self.cache_ [signature].append (target) result = target @@ -145,7 +145,7 @@ class VirtualTargetRegistry: # TODO: Don't append if we found pre-existing target? self.recent_targets_.append(result) self.all_targets_.append(result) - + return result def from_file (self, file, file_location, project): @@ -166,9 +166,9 @@ class VirtualTargetRegistry: file_type = b2.build.type.type (file) result = FileTarget (file, file_type, project, - None, file_location) + None, file_location) self.files_ [path] = result - + return result def recent_targets(self): @@ -196,11 +196,11 @@ class VirtualTargetRegistry: cs1 = self.actual_ [actual_name].creating_subvariant () cs2 = virtual_target.creating_subvariant () cmt1 = cs1.main_target () - cmt2 = cs2.main_target () - + cmt2 = cs2.main_target () + action1 = self.actual_ [actual_name].action () action2 = virtual_target.action () - + properties_added = [] properties_removed = [] if action1 and action2: @@ -208,7 +208,7 @@ class VirtualTargetRegistry: p1 = p1.raw () p2 = action2.properties () p2 = p2.raw () - + properties_removed = set.difference (p1, p2) if not properties_removed: properties_removed = "none" @@ -217,7 +217,7 @@ class VirtualTargetRegistry: # FIXME: Revive printing of real location. get_manager().errors()( - "Duplicate name of actual target: '%s'\n" + "Duplicate name of actual target: '%s'\n" "previous virtual target '%s'\n" "created from '%s'\n" "another virtual target '%s'\n" @@ -226,13 +226,13 @@ class VirtualTargetRegistry: "removed properties: '%s'\n" % (actual_name, self.actual_ [actual_name], "loc", #cmt1.location (), - virtual_target, + virtual_target, "loc", #cmt2.location (), properties_added, properties_removed)) else: self.actual_ [actual_name] = virtual_target - + def add_suffix (self, specified_name, file_type, prop_set): """ Appends the suffix appropriate to 'type/property_set' combination @@ -245,7 +245,7 @@ class VirtualTargetRegistry: else: return specified_name - + class VirtualTarget: """ Potential target. It can be converted into jam target and used in building, if needed. However, it can be also dropped, which allows @@ -258,7 +258,7 @@ class VirtualTarget: self.project_ = project self.dependencies_ = [] self.always_ = False - + # Caches if dapendencies for scanners have already been set. self.made_ = {} @@ -293,13 +293,13 @@ class VirtualTarget: def actualize (self, scanner = None): """ Generates all the actual targets and sets up build actions for this target. - + If 'scanner' is specified, creates an additional target with the same location as actual target, which will depend on the actual target and be associated with 'scanner'. That additional target is returned. See the docs (#dependency_scanning) for rationale. Target must correspond to a file if 'scanner' is specified. - + If scanner is not specified, then actual target is returned. """ actual_name = self.actualize_no_scanner () @@ -339,13 +339,13 @@ class VirtualTarget: """ Sets up variables on 'target' which specify its location. """ raise BaseException ("method should be defined in derived classes") - + def path (self): """ If the target is generated one, returns the path where it will be generated. Otherwise, returns empty list. """ raise BaseException ("method should be defined in derived classes") - + def actual_name (self): """ Return that actual target name that should be used (for the case where no scanner is involved) @@ -357,41 +357,41 @@ class AbstractFileTarget (VirtualTarget): """ Target which correspond to a file. The exact mapping for file is not yet specified in this class. (TODO: Actually, the class name could be better...) - + May be a source file (when no action is specified), or derived file (otherwise). - + The target's grist is concatenation of project's location, properties of action (for derived files), and, optionally, value identifying the main target. - + exact: If non-empty, the name is exactly the name created file should have. Otherwise, the '__init__' method will add suffix obtained from 'type' by calling 'type.generated-target-suffix'. - + type: optional type of this target. """ def __init__ (self, name, type, project, action = None, exact=False): VirtualTarget.__init__ (self, name, project) - + self.type_ = type self.action_ = action self.exact_ = exact - + if action: action.add_targets ([self]) - + if self.type and not exact: self.__adjust_name (name) - + self.actual_name_ = None self.path_ = None self.intermediate_ = False self.creating_subvariant_ = None - + # True if this is a root target. self.root_ = False @@ -420,7 +420,7 @@ class AbstractFileTarget (VirtualTarget): def creating_subvariant (self, s = None): """ Gets or sets the subvariant which created this target. Subvariant is set when target is brought into existance, and is never changed - after that. In particual, if target is shared by subvariant, only + after that. In particual, if target is shared by subvariant, only the first is stored. s: If specified, specified the value to set, which should be instance of 'subvariant' class. @@ -456,11 +456,11 @@ class AbstractFileTarget (VirtualTarget): if a: action_name = a.action_name() ss = [ s.str() for s in a.sources()] - + return "{ %s-%s %s}" % (action_name, name_dot_type, str(ss)) else: return "{ " + name_dot_type + " }" - + # private: def actual_name (self): @@ -475,10 +475,10 @@ class AbstractFileTarget (VirtualTarget): file. """ # Depending on target, there may be different approaches to generating - # unique prefixes. We'll generate prefixes in the form + # unique prefixes. We'll generate prefixes in the form # path = self.path () - + if path: # The target will be generated to a known path. Just use the path # for identification, since path is as unique as it can get. @@ -490,7 +490,7 @@ class AbstractFileTarget (VirtualTarget): project_location = self.project_.get ('location') path_components = b2.util.path.split(project_location) location_grist = '!'.join (path_components) - + if self.action_: ps = self.action_.properties () property_grist = ps.as_path () @@ -498,20 +498,20 @@ class AbstractFileTarget (VirtualTarget): # property set. if property_grist: location_grist = location_grist + '/' + property_grist - + return 'l' + location_grist def __adjust_name(self, specified_name): """Given the target name specified in constructor, returns the name which should be really used, by looking at the properties. The tag properties come in two flavour: - - value, + - value, - @rule-name In the first case, value is just added to name In the second case, the specified rule is called with specified name, target type and properties and should return the new name. If not property is specified, or the rule specified by - returns nothing, returns the result of calling + returns nothing, returns the result of calling virtual-target.add-suffix""" if self.action_: @@ -529,9 +529,9 @@ class AbstractFileTarget (VirtualTarget): #~ --grafik #ps = property_set.create(ps.raw() + ["%s" % "XXXX"]) #ps = [ property-set.create [ $(ps).raw ] $(__name__) ] ; - + tag = ps.get("") - + if tag: if len(tag) > 1: @@ -550,7 +550,7 @@ class AbstractFileTarget (VirtualTarget): tag[1:], specified_name, self.type_, exported_ps) if self.name_: self.name_ = self.name_[0] - + # If there's no tag or the tag rule returned nothing. if not tag or not self.name_: self.name_ = add_prefix_and_suffix(specified_name, self.type_, ps) @@ -562,7 +562,7 @@ class AbstractFileTarget (VirtualTarget): if not self.made_: self.made_[name] = True - if self.action_: + if self.action_: # For non-derived target, we don't care if there # are several virtual targets that refer to the same name. # One case when this is unavoidable is when file name is @@ -575,7 +575,7 @@ class AbstractFileTarget (VirtualTarget): self.actualize_location(name) self.actualize_action(name) - + return name @bjam_signature((["specified_name"], ["type"], ["property_set"])) @@ -588,7 +588,7 @@ def add_prefix_and_suffix(specified_name, type, property_set): suffix = "" if type: suffix = b2.build.type.generated_target_suffix(type, property_set) - + # Handle suffixes for which no leading dot is desired. Those are # specified by enclosing them in <...>. Needed by python so it # can create "_d.so" extensions, for example. @@ -621,7 +621,7 @@ class FileTarget (AbstractFileTarget): are not equal to the project's reference properties an element with name of main target is added. - for source files, project's source dir - + The file suffix is - the value passed to the 'suffix' method, if any, or - the suffix which correspond to the target's type. @@ -640,7 +640,7 @@ class FileTarget (AbstractFileTarget): def clone_with_different_type(self, new_type): return FileTarget(self.name_, new_type, self.project_, self.action_, self.path_, exact=True) - + def actualize_location (self, target): engine = self.project_.manager_.engine () @@ -667,7 +667,7 @@ class FileTarget (AbstractFileTarget): # # bjam hello.o # - # without trying to guess the name of the real target. + # without trying to guess the name of the real target. # Note the that target has no directory name, and a special # grist . # @@ -685,25 +685,25 @@ class FileTarget (AbstractFileTarget): # possible ways to refer to the path (relative/absolute, extra ".", # various "..", but should help in obvious cases. engine.add_dependency("%s" % (os.path.join(path, get_value(target))), target) - + else: # This is a source file. engine.set_target_variable (target, 'SEARCH', self.project_.get ('source-location')) - + def path (self): """ Returns the directory for this target. """ if not self.path_: if self.action_: - p = self.action_.properties () + p = self.action_.properties () (target_path, relative_to_build_dir) = p.target_path () - + if relative_to_build_dir: # Indicates that the path is relative to # build dir. target_path = os.path.join (self.project_.build_dir (), target_path) - + # Store the computed path, so that it's not recomputed # any more self.path_ = target_path @@ -752,11 +752,11 @@ class Action: # Indicates whether this has been actualized or not. self.actualized_ = False - + self.dependency_only_sources_ = [] self.actual_sources_ = [] - - + + def add_targets (self, targets): self.targets_ += targets @@ -781,7 +781,7 @@ class Action: """ if self.actualized_: return - + self.actualized_ = True ps = self.properties () @@ -789,7 +789,7 @@ class Action: actual_targets = [] - + for i in self.targets (): actual_targets.append (i.actualize ()) @@ -803,17 +803,17 @@ class Action: # FIXME: breaking circular dependency import toolset toolset.set_target_variables (self.manager_, self.action_name_, actual_targets, properties) - + engine = self.manager_.engine () # FIXME: this is supposed to help --out-xml option, but we don't # implement that now, and anyway, we should handle it in Python, # not but putting variables on bjam-level targets. bjam.call("set-target-variable", actual_targets, ".action", repr(self)) - + self.manager_.engine ().set_update_action (self.action_name_, actual_targets, self.actual_sources_, properties) - + # Since we set up creating action here, we also set up # action for cleaning up self.manager_.engine ().set_update_action ('common.Clean', 'clean-all', @@ -833,27 +833,27 @@ class Action: # FIXME: what's this? # if isinstance (i, str): # i = self.manager_.get_object (i) - + if i.type (): scanner = b2.build.type.get_scanner (i.type (), prop_set) r = i.actualize (scanner) result.append (r) - + return result - + def actualize_sources (self, sources, prop_set): """ Creates actual jam targets for sources. Initializes two member variables: 'self.actual_sources_' -- sources which are passed to updating action 'self.dependency_only_sources_' -- sources which are made dependencies, but are not used otherwise. - + New values will be *appended* to the variables. They may be non-empty, if caller wants it. """ dependencies = self.properties_.get ('') - + self.dependency_only_sources_ += self.actualize_source_type (dependencies, prop_set) self.actual_sources_ += self.actualize_source_type (sources, prop_set) @@ -885,12 +885,12 @@ class Action: class NullAction (Action): """ Action class which does nothing --- it produces the targets with specific properties out of nowhere. It's needed to distinguish virtual - targets with different properties that are known to exist, and have no + targets with different properties that are known to exist, and have no actions which create them. """ def __init__ (self, manager, prop_set): Action.__init__ (self, manager, [], None, prop_set) - + def actualize (self): if not self.actualized_: self.actualized_ = True @@ -921,10 +921,10 @@ def traverse (target, include_roots = False, include_sources = False): value of 'include_roots'. In either case, sources of root are not traversed. """ result = [] - + if target.action (): action = target.action () - + # This includes 'target' as well result += action.targets () @@ -934,7 +934,7 @@ def traverse (target, include_roots = False, include_sources = False): # TODO: see comment in Manager.register_object () #if not isinstance (t, VirtualTarget): # t = target.project_.manager_.get_object (t) - + if not t.root (): result += traverse (t, include_roots, include_sources) @@ -960,7 +960,7 @@ def clone_action (action, new_project, new_action_name, new_properties): cloned_action = action.__class__(action.manager_, action.sources(), new_action_name, new_properties) - + cloned_targets = [] for target in action.targets(): @@ -980,9 +980,9 @@ def clone_action (action, new_project, new_action_name, new_properties): return cloned_action class Subvariant: - + def __init__ (self, main_target, prop_set, sources, build_properties, sources_usage_requirements, created_targets): - """ + """ main_target: The instance of MainTarget class prop_set: Properties requested for this target sources: @@ -998,11 +998,11 @@ class Subvariant: self.created_targets_ = created_targets self.usage_requirements_ = None - + # Pre-compose the list of other dependency graphs, on which this one # depends deps = build_properties.get('') - + self.other_dg_ = [] for d in deps: self.other_dg_.append(d.creating_subvariant ()) @@ -1011,25 +1011,25 @@ class Subvariant: self.implicit_includes_cache_ = {} self.target_directories_ = None - + def main_target (self): return self.main_target_ - + def created_targets (self): return self.created_targets_ - + def requested_properties (self): return self.properties_ - + def build_properties (self): return self.build_properties_ - + def sources_usage_requirements (self): return self.sources_usage_requirements_ - + def set_usage_requirements (self, usage_requirements): self.usage_requirements_ = usage_requirements - + def usage_requirements (self): return self.usage_requirements_ @@ -1042,7 +1042,7 @@ class Subvariant: # Find directly referenced targets. deps = self.build_properties().dependency() all_targets = self.sources_ + deps - + # Find other subvariants. r = [] for e in all_targets: @@ -1052,7 +1052,7 @@ class Subvariant: t = e.value() else: t = e - + # FIXME: how can this be? cs = t.creating_subvariant() if cs: @@ -1077,7 +1077,7 @@ class Subvariant: else: key = feature + "-" + target_type - + result = self.implicit_includes_cache_.get(key) if not result: target_paths = self.all_target_directories(target_type)