-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06ca77f
commit 4e82da2
Showing
14 changed files
with
538 additions
and
41 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import sys | ||
|
||
# we run this script once every build, and we'd rather | ||
# have much smaller image sizes, so copying without | ||
# any bytecode is a better idea. | ||
sys.dont_write_bytecode = True | ||
|
||
__all__ = [ | ||
"make", | ||
"soong", | ||
] |
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
''' | ||
make | ||
==== | ||
utilities to process makefiles | ||
''' | ||
|
||
import re | ||
|
||
from . import util | ||
|
||
class Section: | ||
def __init__(self, title, contents): | ||
self.title = title | ||
self.contents = contents | ||
|
||
def is_test(self): | ||
return self.title is not None and 'test' in self.title.lower() | ||
|
||
def is_benchmark(self): | ||
return self.title is not None and 'benchmark' in self.title.lower() | ||
|
||
def is_dev(self): | ||
return self.is_test() or self.is_benchmark() | ||
|
||
def __repr__(self): | ||
return self.contents | ||
|
||
class Makefile: | ||
def __init__(self, sections): | ||
self.sections = sections | ||
|
||
@staticmethod | ||
def parse(path): | ||
with open(path, 'r') as f: | ||
contents = f.read() | ||
|
||
sep1 = r'#\s+=+' | ||
sep2 = r'#\s+-+' | ||
comment = r'[A-Za-z0-9._ -]+' | ||
pat1 = fr'(?:{sep1}\n)?#\s+({comment})\n{sep1}' | ||
pat2 = fr'(?:{sep2}\n)?#\s+({comment})\n{sep2}' | ||
pattern = fr'(?:{pat1})|(?:{pat2})' | ||
|
||
sections = [] | ||
matches = list(re.finditer(pattern, contents)) | ||
if len(matches) == 0: | ||
sections.append(Section(None, contents)) | ||
else: | ||
first = matches[0] | ||
last = matches[-1] | ||
if first.start() != 0: | ||
sections.append(Section(None, contents[:first.start()])) | ||
for (prev, nxt) in util.windows(matches, 2): | ||
title = prev.group(1) or prev.group(2) | ||
sections.append(Section(title, contents[prev.start():nxt.start()])) | ||
title = last.group(1) or prev.group(2) | ||
sections.append(Section(title, contents[last.start():])) | ||
|
||
return Makefile(sections) | ||
|
||
def filter_dev(self): | ||
return Makefile([i for i in self.sections if not i.is_dev()]) | ||
|
||
def __repr__(self): | ||
return ''.join([str(i) for i in self.sections]) |
Oops, something went wrong.