-
Notifications
You must be signed in to change notification settings - Fork 8
/
stat_makefile_project.py
77 lines (60 loc) · 2.1 KB
/
stat_makefile_project.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
# SPDX-FileCopyrightText: (c) 2020 Western Digital Corporation or its affiliates,
# Arseniy Aharonov <[email protected]>
#
# SPDX-License-Identifier: MIT
import os
import stat_attributes as attributes
from directory_tree_node import DirectoryTreeNode
from stat_makefile import StatMakefile
from itertools import chain
class StatMakefileProject(object):
"""
Constructs a STAT project built based on STAT makefile
"""
def __init__(self, fileName):
self.__fileName = fileName
self.__makefile = StatMakefile(fileName)
self.__tree = None
@property
def makefile(self):
return self.__fileName
@property
def name(self):
return self.__makefile.name
@property
def outputName(self):
return self.__makefile[StatMakefile.NAME]
@property
def tree(self):
if self.__tree is None:
self.__tree = self.__buildFileTree()
return self.__tree
@property
def definitions(self):
return self.__makefile[StatMakefile.DEFINES].split()
def files(self):
return chain(self.sources(), self.__headerFiles())
def sources(self):
for source in self.__makefile[StatMakefile.SOURCES].split():
yield source
def __getitem__(self, key):
return self.__makefile[key]
def __iter__(self):
return iter(self.__makefile)
def __buildFileTree(self):
tree = DirectoryTreeNode()
for _file in self.files():
tree.addFile(_file)
return tree
def __headerFiles(self):
files = []
for _file in self.__makefile[StatMakefile.INTERFACES].split():
filePath = os.path.join(attributes.DUMMIES_DIRECTORY, _file)
files.append(os.path.basename(filePath))
yield filePath
for pathName in self.__makefile[StatMakefile.INCLUDES].split():
for _file in os.listdir(pathName):
if _file.endswith('.h') and _file not in files:
files.append(_file)
yield os.path.join(pathName, _file)