depfile: type annotate

pull/9807/head
Dylan Baker 3 years ago committed by Eli Schwartz
parent 4b351aef26
commit fe51450970
  1. 35
      mesonbuild/depfile.py
  2. 1
      run_mypy.py

@ -11,12 +11,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import collections
import typing as T
def parse(lines):
rules = []
targets = []
deps = []
def parse(lines: T.Iterable[str]) -> T.List[T.Tuple[T.List[str], T.List[str]]]:
rules: T.List[T.Tuple[T.List[str], T.List[str]]] = []
targets: T.List[str] = []
deps: T.List[str] = []
in_deps = False
out = ''
for line in lines:
@ -56,12 +57,15 @@ def parse(lines):
out += c
return rules
Target = collections.namedtuple('Target', ['deps'])
class Target(T.NamedTuple):
deps: T.Set[str]
class DepFile:
def __init__(self, lines):
def __init__(self, lines: T.Iterable[str]):
rules = parse(lines)
depfile = {}
depfile: T.Dict[str, Target] = {}
for (targets, deps) in rules:
for target in targets:
t = depfile.setdefault(target, Target(deps=set()))
@ -69,16 +73,17 @@ class DepFile:
t.deps.add(dep)
self.depfile = depfile
def get_all_dependencies(self, target, visited=None):
deps = set()
def get_all_dependencies(self, name: str, visited: T.Optional[T.Set[str]] = None) -> T.List[str]:
deps: T.Set[str] = set()
if not visited:
visited = set()
if target in visited:
return set()
visited.add(target)
target = self.depfile.get(target)
if name in visited:
return []
visited.add(name)
target = self.depfile.get(name)
if not target:
return set()
return []
deps.update(target.deps)
for dep in target.deps:
deps.update(self.get_all_dependencies(dep, visited))

@ -25,6 +25,7 @@ modules = [
'mesonbuild/arglist.py',
'mesonbuild/backend/backends.py',
# 'mesonbuild/coredata.py',
'mesonbuild/depfile.py',
'mesonbuild/envconfig.py',
'mesonbuild/interpreter/compiler.py',
'mesonbuild/interpreter/mesonmain.py',

Loading…
Cancel
Save