Last active
May 9, 2018 03:25
-
-
Save ChronoMonochrome/a6f12a86b2b2958edcdfe8753afba4fd to your computer and use it in GitHub Desktop.
A script to produce an unique list of the Linux kernel headers used by the given source files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" The purpose of this script is to produce an unique list of the Linux kernel headers used by the given source files.""" | |
import os.path | |
class Header: | |
bLocal = False | |
sLocalPath = "" | |
incPath = "" | |
pathMap = {"asm": "asm-generic"} | |
specialChars = ["\"", "<", ">"] | |
def __init__(self, incPath, incUserPath): | |
if incPath.count("\"") == 2: | |
self.bLocal = True | |
self.sLocalPath = os.path.split(incUserPath)[0] + "/" | |
for char in self.specialChars: | |
incPath = incPath.replace(char, "") | |
self.incPath = self.sLocalPath + incPath | |
def toAbsPath(self): | |
res = self.incPath | |
for k, v in self.pathMap.items(): | |
res = res.replace(k, v) | |
if not self.bLocal: | |
res = "include/" + res | |
return res | |
class Headers: | |
_headers = [] | |
def __init__(self, lHeaders): | |
for h in lHeaders: | |
self.append(h) | |
def listIncPaths(self): | |
return [i.incPath for i in self._headers] | |
def listAbsIncPaths(self): | |
return [i.toAbsPath() for i in self._headers] | |
def append(self, oHeader): | |
if not oHeader.incPath in self.listIncPaths(): | |
#print oHeader.toAbsPath() | |
self._headers.append(oHeader) | |
class File: | |
_path = "" | |
_headers = [] | |
def __init__(self, sPath): | |
INCLUDE = "#include " | |
INCLUDE_LEN = len(INCLUDE) | |
headers = [i[INCLUDE_LEN:] for i in open(sPath).readlines() if i.startswith(INCLUDE)] | |
self._headers = [(i[:-1] if i[-1] == "\n" else i) for i in headers] | |
self._path = sPath | |
if __name__ == "__main__": | |
files_paths = ["C:/tests/dev.c", "C:/tests/skbuff.c"] # put paths to files here | |
files = [File(i) for i in files_paths if os.path.exists(i)] | |
all_headers = [] | |
for file in files: | |
all_headers += [Header(h, file._path) for h in file._headers] | |
headers = Headers(all_headers) | |
print headers.listAbsIncPaths() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment