(
flat_list, targets, dependency_nodes, sort_dependencies
)
| 2071 | |
| 2072 | |
| 2073 | def AdjustStaticLibraryDependencies( |
| 2074 | flat_list, targets, dependency_nodes, sort_dependencies |
| 2075 | ): |
| 2076 | # Recompute target "dependencies" properties. For each static library |
| 2077 | # target, remove "dependencies" entries referring to other static libraries, |
| 2078 | # unless the dependency has the "hard_dependency" attribute set. For each |
| 2079 | # linkable target, add a "dependencies" entry referring to all of the |
| 2080 | # target's computed list of link dependencies (including static libraries |
| 2081 | # if no such entry is already present. |
| 2082 | for target in flat_list: |
| 2083 | target_dict = targets[target] |
| 2084 | target_type = target_dict["type"] |
| 2085 | |
| 2086 | if target_type == "static_library": |
| 2087 | if "dependencies" not in target_dict: |
| 2088 | continue |
| 2089 | |
| 2090 | target_dict["dependencies_original"] = target_dict.get("dependencies", [])[ |
| 2091 | : |
| 2092 | ] |
| 2093 | |
| 2094 | # A static library should not depend on another static library unless |
| 2095 | # the dependency relationship is "hard," which should only be done when |
| 2096 | # a dependent relies on some side effect other than just the build |
| 2097 | # product, like a rule or action output. Further, if a target has a |
| 2098 | # non-hard dependency, but that dependency exports a hard dependency, |
| 2099 | # the non-hard dependency can safely be removed, but the exported hard |
| 2100 | # dependency must be added to the target to keep the same dependency |
| 2101 | # ordering. |
| 2102 | dependencies = dependency_nodes[target].DirectAndImportedDependencies( |
| 2103 | targets |
| 2104 | ) |
| 2105 | index = 0 |
| 2106 | while index < len(dependencies): |
| 2107 | dependency = dependencies[index] |
| 2108 | dependency_dict = targets[dependency] |
| 2109 | |
| 2110 | # Remove every non-hard static library dependency and remove every |
| 2111 | # non-static library dependency that isn't a direct dependency. |
| 2112 | if ( |
| 2113 | dependency_dict["type"] == "static_library" |
| 2114 | and not dependency_dict.get("hard_dependency", False) |
| 2115 | ) or ( |
| 2116 | dependency_dict["type"] != "static_library" |
| 2117 | and dependency not in target_dict["dependencies"] |
| 2118 | ): |
| 2119 | # Take the dependency out of the list, and don't increment index |
| 2120 | # because the next dependency to analyze will shift into the index |
| 2121 | # formerly occupied by the one being removed. |
| 2122 | del dependencies[index] |
| 2123 | else: |
| 2124 | index = index + 1 |
| 2125 | |
| 2126 | # Update the dependencies. If the dependencies list is empty, it's not |
| 2127 | # needed, so unhook it. |
| 2128 | if len(dependencies) > 0: |
| 2129 | target_dict["dependencies"] = dependencies |
| 2130 | else: |
no test coverage detected