Move Kconfig, defconfig and make filters to new filter interface
This commit is contained in:
parent
da18c75560
commit
3cbbf58414
17 changed files with 340 additions and 211 deletions
|
|
@ -1,4 +1,8 @@
|
|||
# Elixir Python definitions for Barebox
|
||||
|
||||
exec(open('makefilesubdir.py').read())
|
||||
from filters.makefilesubdir import MakefileSubdirFilter
|
||||
|
||||
new_filters.extend([
|
||||
MakefileSubdirFilter(),
|
||||
])
|
||||
|
||||
|
|
|
|||
|
|
@ -4,16 +4,30 @@ from filters.dtsi import DtsiFilter
|
|||
|
||||
from filters.cpppathinc import CppPathIncFilter
|
||||
|
||||
exec(open('commonkconfig.py').read())
|
||||
exec(open('makefileo.py').read())
|
||||
exec(open('makefiledtb.py').read())
|
||||
exec(open('makefiledir.py').read())
|
||||
exec(open('makefilefile.py').read())
|
||||
exec(open('makefilesubdir.py').read())
|
||||
exec(open('makefilesrctree.py').read())
|
||||
from filters.kconfig import KconfigFilter
|
||||
from filters.kconfigidents import KconfigIdentsFilter
|
||||
from filters.defconfig import DefConfigIdentsFilter
|
||||
|
||||
from filters.makefileo import MakefileOFilter
|
||||
from filters.makefiledtb import MakefileDtbFilter
|
||||
from filters.makefiledir import MakefileDirFilter
|
||||
from filters.makefilesubdir import MakefileSubdirFilter
|
||||
from filters.makefilefile import MakefileFileFilter
|
||||
from filters.makefilesrctree import MakefileSrcTreeFilter
|
||||
|
||||
new_filters.extend([
|
||||
DtsiFilter(),
|
||||
|
||||
CppPathIncFilter(),
|
||||
|
||||
KconfigFilter(),
|
||||
KconfigIdentsFilter(),
|
||||
DefConfigIdentsFilter(),
|
||||
|
||||
MakefileOFilter(),
|
||||
MakefileDtbFilter(),
|
||||
MakefileDirFilter(),
|
||||
MakefileSubdirFilter(),
|
||||
MakefileFileFilter(),
|
||||
MakefileSrcTreeFilter(),
|
||||
])
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
# Common filters for Kconfig
|
||||
|
||||
exec(open('kconfig.py').read())
|
||||
exec(open('kconfigidents.py').read())
|
||||
exec(open('defconfig.py').read())
|
||||
|
|
@ -2,9 +2,15 @@
|
|||
|
||||
from filters.dtsi import DtsiFilter
|
||||
|
||||
exec(open('commonkconfig.py').read())
|
||||
from filters.kconfig import KconfigFilter
|
||||
from filters.kconfigidents import KconfigIdentsFilter
|
||||
from filters.defconfig import DefConfigIdentsFilter
|
||||
|
||||
new_filters.extend([
|
||||
DtsiFilter(),
|
||||
|
||||
KconfigFilter(),
|
||||
KconfigIdentsFilter(),
|
||||
DefConfigIdentsFilter(),
|
||||
])
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,30 @@
|
|||
import re
|
||||
from filters.utils import Filter, FilterContext, encode_number, decode_number, extension_matches
|
||||
|
||||
# Filter for kconfig identifier in defconfigs
|
||||
# Replaces defconfig identifiers with links to definitions/references
|
||||
# `CONFIG_OPTION=y`
|
||||
# Example: u-boot/v2023.10/source/configs/A13-OLinuXino_defconfig#L1
|
||||
class DefConfigIdentsFilter(Filter):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.defconfigidents = []
|
||||
|
||||
defconfigidents = []
|
||||
def check_if_applies(self, ctx) -> bool:
|
||||
return super().check_if_applies(ctx) and \
|
||||
ctx.filepath.endswith('defconfig')
|
||||
|
||||
def keep_defconfigidents(m):
|
||||
defconfigidents.append(m.group(1))
|
||||
return '__KEEPDEFCONFIGIDENTS__' + encode_number(len(defconfigidents))
|
||||
def transform_raw_code(self, ctx, code: str) -> str:
|
||||
def keep_defconfigidents(m):
|
||||
self.defconfigidents.append(m.group(1))
|
||||
return '__KEEPDEFCONFIGIDENTS__' + encode_number(len(self.defconfigidents))
|
||||
|
||||
def replace_defconfigidents(m):
|
||||
i = defconfigidents[decode_number(m.group(1)) - 1]
|
||||
return re.sub('(CONFIG_[\w]+)', keep_defconfigidents, code, flags=re.MULTILINE)
|
||||
|
||||
return '<a class="ident" href="/'+project+'/'+version+'/K/ident/'+i+'">'+i+'</a>'
|
||||
def untransform_formatted_code(self, ctx: FilterContext, html: str) -> str:
|
||||
def replace_defconfigidents(m):
|
||||
i = self.defconfigidents[decode_number(m.group(1)) - 1]
|
||||
return f'<a class="ident" href="{ ctx.get_ident_url(i, "K") }">{ i }</a>'
|
||||
|
||||
defconfigident_filters = {
|
||||
'case': 'filename_extension',
|
||||
'match': {'defconfig'},
|
||||
'prerex': '(CONFIG_[\w]+)',
|
||||
'prefunc': keep_defconfigidents,
|
||||
'postrex': '__KEEPDEFCONFIGIDENTS__([A-J]+)',
|
||||
'postfunc': replace_defconfigidents
|
||||
}
|
||||
return re.sub('__KEEPDEFCONFIGIDENTS__([A-J]+)', replace_defconfigidents, html, flags=re.MULTILINE)
|
||||
|
||||
filters.append(defconfigident_filters)
|
||||
|
|
|
|||
|
|
@ -1,22 +1,30 @@
|
|||
import re
|
||||
from filters.utils import Filter, FilterContext, encode_number, decode_number, filename_without_ext_matches
|
||||
|
||||
# Filters for Kconfig includes
|
||||
# Replaces KConfig includes (source keyword) with links to included files
|
||||
# `source "path/file"`
|
||||
# Example: u-boot/v2023.10/source/Kconfig#L10
|
||||
class KconfigFilter(Filter):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.kconfig = []
|
||||
|
||||
kconfig = []
|
||||
def check_if_applies(self, ctx) -> bool:
|
||||
return super().check_if_applies(ctx) and \
|
||||
filename_without_ext_matches(ctx.filepath, {'Kconfig'})
|
||||
|
||||
def keep_kconfig(m):
|
||||
kconfig.append(m.group(4))
|
||||
return m.group(1) + m.group(2) + m.group(3) + '"__KEEPKCONFIG__' + encode_number(len(kconfig)) + '"'
|
||||
def transform_raw_code(self, ctx, code: str) -> str:
|
||||
def keep_kconfig(m):
|
||||
self.kconfig.append(m.group(4))
|
||||
return f'{ m.group(1) }{ m.group(2) }{ m.group(3) }"__KEEPKCONFIG__{ encode_number(len(self.kconfig)) }"'
|
||||
|
||||
def replace_kconfig(m):
|
||||
w = kconfig[decode_number(m.group(1)) - 1]
|
||||
return '<a href="/'+project+'/'+version+'/source/'+w+'">'+w+'</a>'
|
||||
return re.sub('^(\s*)(source)(\s*)\"([\w/_\.-]+)\"', keep_kconfig, code, flags=re.MULTILINE)
|
||||
|
||||
kconfig_filters = {
|
||||
'case': 'filename',
|
||||
'match': {'Kconfig'},
|
||||
'prerex': '^(\s*)(source)(\s*)\"([\w/_\.-]+)\"',
|
||||
'prefunc': keep_kconfig,
|
||||
'postrex': '__KEEPKCONFIG__([A-J]+)',
|
||||
'postfunc': replace_kconfig
|
||||
}
|
||||
def untransform_formatted_code(self, ctx: FilterContext, html: str) -> str:
|
||||
def replace_kconfig(m):
|
||||
w = self.kconfig[decode_number(m.group(1)) - 1]
|
||||
return f'<a href="{ ctx.get_absolute_source_url(w) }">{ w }</a>'
|
||||
|
||||
return re.sub('__KEEPKCONFIG__([A-J]+)', replace_kconfig, html, flags=re.MULTILINE)
|
||||
|
||||
filters.append(kconfig_filters)
|
||||
|
|
|
|||
|
|
@ -1,27 +1,33 @@
|
|||
import re
|
||||
from filters.utils import Filter, FilterContext, encode_number, decode_number
|
||||
|
||||
# Filter for kconfig identifier links
|
||||
# Replaces KConfig identifiers with links to definitions and references
|
||||
# `config OPTION`
|
||||
# Example: u-boot/v2023.10/source/Kconfig#L17
|
||||
# Note: Prepends identifier with CONFIG_
|
||||
class KconfigIdentsFilter(Filter):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.kconfigidents = []
|
||||
|
||||
kconfigidents = []
|
||||
def transform_raw_code(self, ctx, code: str) -> str:
|
||||
def keep_kconfigidents(m):
|
||||
self.kconfigidents.append(m.group(1))
|
||||
return f'__KEEPKCONFIGIDENTS__{ encode_number(len(self.kconfigidents)) }'
|
||||
|
||||
def keep_kconfigidents(m):
|
||||
kconfigidents.append(m.group(1))
|
||||
return '__KEEPKCONFIGIDENTS__' + encode_number(len(kconfigidents))
|
||||
return re.sub('\033\[31m(?=CONFIG_)(.*?)\033\[0m', keep_kconfigidents, code, flags=re.MULTILINE)
|
||||
|
||||
def replace_kconfigidents(m):
|
||||
i = kconfigidents[decode_number(m.group(2)) - 1]
|
||||
def untransform_formatted_code(self, ctx: FilterContext, html: str) -> str:
|
||||
def replace_kconfigidents(m):
|
||||
i = self.kconfigidents[decode_number(m.group(2)) - 1]
|
||||
|
||||
n = i
|
||||
#Remove the CONFIG_ when we are in a Kconfig file
|
||||
if family == 'K':
|
||||
n = n[7:]
|
||||
n = i
|
||||
#Remove the CONFIG_ when we are in a Kconfig file
|
||||
if ctx.family == 'K':
|
||||
n = n[7:]
|
||||
|
||||
return str(m.group(1) or '') + '<a class="ident" href="/'+project+'/'+version+'/K/ident/'+i+'">'+n+'</a>'
|
||||
return f'{ m.group(1) or "" }<a class="ident" href="{ ctx.get_ident_url(i, "K") }">{ n }</a>'
|
||||
|
||||
kconfigident_filters = {
|
||||
'case': 'any',
|
||||
'prerex': '\033\[31m(?=CONFIG_)(.*?)\033\[0m',
|
||||
'prefunc': keep_kconfigidents,
|
||||
'postrex': '__(<.+?>)?KEEPKCONFIGIDENTS__([A-J]+)',
|
||||
'postfunc': replace_kconfigidents
|
||||
}
|
||||
return re.sub('__(<.+?>)?KEEPKCONFIGIDENTS__([A-J]+)', replace_kconfigidents, html, flags=re.MULTILINE)
|
||||
|
||||
filters.append(kconfigident_filters)
|
||||
|
|
|
|||
|
|
@ -3,18 +3,31 @@
|
|||
from filters.dtsi import DtsiFilter
|
||||
from filters.cpppathinc import CppPathIncFilter
|
||||
|
||||
exec(open('commonkconfig.py').read())
|
||||
from filters.kconfig import KconfigFilter
|
||||
from filters.kconfigidents import KconfigIdentsFilter
|
||||
from filters.defconfig import DefConfigIdentsFilter
|
||||
|
||||
exec(open('makefileo.py').read())
|
||||
exec(open('makefiledtb.py').read())
|
||||
exec(open('makefiledir.py').read())
|
||||
exec(open('makefilefile.py').read())
|
||||
exec(open('makefilesubdir.py').read())
|
||||
exec(open('makefilesrctree.py').read())
|
||||
from filters.makefileo import MakefileOFilter
|
||||
from filters.makefiledtb import MakefileDtbFilter
|
||||
from filters.makefiledir import MakefileDirFilter
|
||||
from filters.makefilesubdir import MakefileSubdirFilter
|
||||
from filters.makefilefile import MakefileFileFilter
|
||||
from filters.makefilesrctree import MakefileSrcTreeFilter
|
||||
|
||||
new_filters.extend([
|
||||
DtsiFilter(),
|
||||
|
||||
KconfigFilter(),
|
||||
KconfigIdentsFilter(),
|
||||
DefConfigIdentsFilter(),
|
||||
|
||||
MakefileOFilter(),
|
||||
MakefileDtbFilter(),
|
||||
MakefileDirFilter(),
|
||||
MakefileSubdirFilter(),
|
||||
MakefileFileFilter(),
|
||||
MakefileSrcTreeFilter(),
|
||||
|
||||
# include/uapi contains includes to user headers under #ifndef __KERNEL__
|
||||
# Our solution is to ignore all includes in such paths
|
||||
CppPathIncFilter(path_exceptions={'^/include/uapi/.*'}),
|
||||
|
|
|
|||
|
|
@ -1,36 +1,45 @@
|
|||
from os.path import dirname
|
||||
import re
|
||||
from filters.utils import Filter, FilterContext, decode_number, encode_number, filename_without_ext_matches
|
||||
|
||||
# Filters for Makefile directory includes as follows:
|
||||
# obj-$(VALUE) += dir/
|
||||
# Example: u-boot/v2023.10/source/Makefile#L867
|
||||
class MakefileDirFilter(Filter):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.makefiledir = []
|
||||
|
||||
makefiledir = []
|
||||
def check_if_applies(self, ctx) -> bool:
|
||||
return super().check_if_applies(ctx) and \
|
||||
filename_without_ext_matches(ctx.filepath, {'Makefile'})
|
||||
|
||||
def keep_makefiledir(m):
|
||||
dir_name = os.path.dirname(path)
|
||||
def transform_raw_code(self, ctx, code: str) -> str:
|
||||
def keep_makefiledir(m):
|
||||
filedir = dirname(ctx.filepath)
|
||||
|
||||
if dir_name != '/':
|
||||
dir_name += '/'
|
||||
if filedir != '/':
|
||||
filedir += '/'
|
||||
|
||||
if q.query('exist', tag, dir_name + m.group(1) + '/Makefile'):
|
||||
makefiledir.append(m.group(1))
|
||||
return '__KEEPMAKEFILEDIR__' + encode_number(len(makefiledir)) + '/' + m.group(2)
|
||||
else:
|
||||
return m.group(0)
|
||||
if ctx.query.query('exist', ctx.tag, filedir + m.group(1) + '/Makefile'):
|
||||
self.makefiledir.append(m.group(1))
|
||||
return f'__KEEPMAKEFILEDIR__{ encode_number(len(self.makefiledir)) }/{ m.group(2) }'
|
||||
else:
|
||||
return m.group(0)
|
||||
|
||||
def replace_makefiledir(m):
|
||||
w = makefiledir[decode_number(m.group(1)) - 1]
|
||||
dir_name = os.path.dirname(path)
|
||||
|
||||
if dir_name != '/':
|
||||
dir_name += '/'
|
||||
return re.sub('(?<=\s)([-\w/]+)/(\s+|$)', keep_makefiledir, code, flags=re.MULTILINE)
|
||||
|
||||
return '<a href="/'+project+'/'+version+'/source'+dir_name+w+'/Makefile">'+w+'/</a>'
|
||||
def untransform_formatted_code(self, ctx: FilterContext, html: str) -> str:
|
||||
def replace_makefiledir(m):
|
||||
w = self.makefiledir[decode_number(m.group(1)) - 1]
|
||||
filedir = dirname(ctx.filepath)
|
||||
|
||||
makefiledir_filters = {
|
||||
'case': 'filename',
|
||||
'match': {'Makefile'},
|
||||
'prerex': '(?<=\s)([-\w/]+)/(\s+|$)',
|
||||
'prefunc': keep_makefiledir,
|
||||
'postrex': '__KEEPMAKEFILEDIR__([A-J]+)/',
|
||||
'postfunc': replace_makefiledir
|
||||
}
|
||||
if filedir != '/':
|
||||
filedir += '/'
|
||||
|
||||
fpath = f'{ filedir }{ w }/Makefile'
|
||||
|
||||
return f'<a href="{ ctx.get_absolute_source_url(fpath) }">{ w }/</a>'
|
||||
|
||||
return re.sub('__KEEPMAKEFILEDIR__([A-J]+)/', replace_makefiledir, html, flags=re.MULTILINE)
|
||||
|
||||
filters.append(makefiledir_filters)
|
||||
|
|
|
|||
|
|
@ -1,29 +1,36 @@
|
|||
from os.path import dirname
|
||||
import re
|
||||
from filters.utils import Filter, FilterContext, decode_number, encode_number, filename_without_ext_matches
|
||||
|
||||
# Filters for Makefile file includes like these:
|
||||
# dtb-y += file.dtb
|
||||
# Example: u-boot/v2023.10/source/Makefile#L992
|
||||
class MakefileDtbFilter(Filter):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.makefiledtb = []
|
||||
|
||||
makefiledtb = []
|
||||
def check_if_applies(self, ctx) -> bool:
|
||||
return super().check_if_applies(ctx) and \
|
||||
filename_without_ext_matches(ctx.filepath, {'Makefile'})
|
||||
|
||||
def keep_makefiledtb(m):
|
||||
makefiledtb.append(m.group(1))
|
||||
return '__KEEPMAKEFILEDTB__' + encode_number(len(makefiledtb)) + '.dtb'
|
||||
def transform_raw_code(self, ctx, code: str) -> str:
|
||||
def keep_makefiledtb(m):
|
||||
self.makefiledtb.append(m.group(1))
|
||||
return f'__KEEPMAKEFILEDTB__{ encode_number(len(self.makefiledtb)) }.dtb'
|
||||
|
||||
def replace_makefiledtb(m):
|
||||
w = makefiledtb[decode_number(m.group(1)) - 1]
|
||||
return re.sub('(?<=\s)([-\w/+\.]+)\.dtb', keep_makefiledtb, code, flags=re.MULTILINE)
|
||||
|
||||
dir_name = os.path.dirname(path)
|
||||
|
||||
if dir_name != '/':
|
||||
dir_name += '/'
|
||||
def untransform_formatted_code(self, ctx: FilterContext, html: str) -> str:
|
||||
def replace_makefiledtb(m):
|
||||
w = self.makefiledtb[decode_number(m.group(1)) - 1]
|
||||
filedir = dirname(ctx.filepath)
|
||||
|
||||
return '<a href="/'+project+'/'+version+'/source'+dir_name+w+'.dts">'+w+'.dtb</a>'
|
||||
if filedir != '/':
|
||||
filedir += '/'
|
||||
|
||||
makefiledtb_filters = {
|
||||
'case': 'filename',
|
||||
'match': {'Makefile'},
|
||||
'prerex': '(?<=\s)([-\w/+\.]+)\.dtb',
|
||||
'prefunc': keep_makefiledtb,
|
||||
'postrex': '__KEEPMAKEFILEDTB__([A-J]+)\.dtb',
|
||||
'postfunc': replace_makefiledtb
|
||||
}
|
||||
npath = f'{ filedir }{ w }.dts'
|
||||
return f'<a href="{ ctx.get_absolute_source_url(npath) }">{ w }.dtb</a>'
|
||||
|
||||
return re.sub('__KEEPMAKEFILEDTB__([A-J]+)\.dtb', replace_makefiledtb, html, flags=re.MULTILINE)
|
||||
|
||||
filters.append(makefiledtb_filters)
|
||||
|
|
|
|||
|
|
@ -1,35 +1,44 @@
|
|||
from os.path import dirname
|
||||
import re
|
||||
from filters.utils import Filter, FilterContext, decode_number, encode_number, filename_without_ext_matches
|
||||
|
||||
# Filters for files listed in Makefiles
|
||||
# path/file
|
||||
# Example: u-boot/v2023.10/source/Makefile#L1509
|
||||
class MakefileFileFilter(Filter):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.makefilefile = []
|
||||
|
||||
makefilefile = []
|
||||
def check_if_applies(self, ctx) -> bool:
|
||||
return super().check_if_applies(ctx) and \
|
||||
filename_without_ext_matches(ctx.filepath, {'Makefile'})
|
||||
|
||||
def keep_makefilefile(m):
|
||||
dir_name = os.path.dirname(path)
|
||||
def transform_raw_code(self, ctx, code: str) -> str:
|
||||
def keep_makefilefile(m):
|
||||
filedir = dirname(ctx.filepath)
|
||||
|
||||
if dir_name != '/':
|
||||
dir_name += '/'
|
||||
if filedir != '/':
|
||||
filedir += '/'
|
||||
|
||||
if q.query('exist', tag, dir_name + m.group(1)):
|
||||
makefilefile.append(m.group(1))
|
||||
return '__KEEPMAKEFILEFILE__' + encode_number(len(makefilefile)) + m.group(2)
|
||||
else:
|
||||
return m.group(0)
|
||||
if ctx.query.query('exist', ctx.tag, filedir + m.group(1)):
|
||||
self.makefilefile.append(m.group(1))
|
||||
return f'__KEEPMAKEFILEFILE__{ encode_number(len(self.makefilefile)) }{ m.group(2) }'
|
||||
else:
|
||||
return m.group(0)
|
||||
|
||||
def replace_makefilefile(m):
|
||||
w = makefilefile[decode_number(m.group(1)) - 1]
|
||||
dir_name = os.path.dirname(path)
|
||||
|
||||
if dir_name != '/':
|
||||
dir_name += '/'
|
||||
return re.sub('(?:(?<=\s|=)|(?<=-I))(?!/)([-\w/]+/[-\w\.]+)(\s+|\)|$)', keep_makefilefile, code, flags=re.MULTILINE)
|
||||
|
||||
return '<a href="/'+project+'/'+version+'/source'+dir_name+w+'">'+w+'</a>'
|
||||
def untransform_formatted_code(self, ctx: FilterContext, html: str) -> str:
|
||||
def replace_makefilefile(m):
|
||||
w = self.makefilefile[decode_number(m.group(1)) - 1]
|
||||
filedir = dirname(ctx.filepath)
|
||||
|
||||
makefilefile_filters = {
|
||||
'case': 'filename',
|
||||
'match': {'Makefile'},
|
||||
'prerex': '(?:(?<=\s|=)|(?<=-I))(?!/)([-\w/]+/[-\w\.]+)(\s+|\)|$)',
|
||||
'prefunc': keep_makefilefile,
|
||||
'postrex': '__KEEPMAKEFILEFILE__([A-J]+)',
|
||||
'postfunc': replace_makefilefile
|
||||
}
|
||||
if filedir != '/':
|
||||
filedir += '/'
|
||||
|
||||
npath = filedir + w
|
||||
return f'<a href="{ ctx.get_absolute_source_url(npath) }">{ w }</a>'
|
||||
|
||||
return re.sub('__KEEPMAKEFILEFILE__([A-J]+)', replace_makefilefile, html, flags=re.MULTILINE)
|
||||
|
||||
filters.append(makefilefile_filters)
|
||||
|
|
|
|||
|
|
@ -1,29 +1,36 @@
|
|||
from os.path import dirname
|
||||
import re
|
||||
from filters.utils import Filter, FilterContext, decode_number, encode_number, filename_without_ext_matches
|
||||
|
||||
# Filters for Makefile file includes like these:
|
||||
# file.o
|
||||
# Example: u-boot/v2023.10/source/Makefile#L1767
|
||||
class MakefileOFilter(Filter):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.makefileo = []
|
||||
|
||||
makefileo = []
|
||||
def check_if_applies(self, ctx) -> bool:
|
||||
return super().check_if_applies(ctx) and \
|
||||
filename_without_ext_matches(ctx.filepath, {'Makefile'})
|
||||
|
||||
def keep_makefileo(m):
|
||||
makefileo.append(m.group(1))
|
||||
return '__KEEPMAKEFILEO__' + encode_number(len(makefileo)) + '.o'
|
||||
def transform_raw_code(self, ctx, code: str) -> str:
|
||||
def keep_makefileo(m):
|
||||
self.makefileo.append(m.group(1))
|
||||
return f'__KEEPMAKEFILEO__{ encode_number(len(self.makefileo)) }.o'
|
||||
|
||||
def replace_makefileo(m):
|
||||
w = makefileo[decode_number(m.group(1)) - 1]
|
||||
return re.sub('(?<=\s)([-\w/]+)\.o(?!\w)(?! :?=)', keep_makefileo, code, flags=re.MULTILINE)
|
||||
|
||||
dir_name = os.path.dirname(path)
|
||||
def untransform_formatted_code(self, ctx: FilterContext, html: str) -> str:
|
||||
def replace_makefileo(m):
|
||||
w = self.makefileo[decode_number(m.group(1)) - 1]
|
||||
|
||||
if dir_name != '/':
|
||||
dir_name += '/'
|
||||
filedir = dirname(ctx.filepath)
|
||||
if filedir != '/':
|
||||
filedir += '/'
|
||||
|
||||
return '<a href="/'+project+'/'+version+'/source'+dir_name+w+'.c">'+w+'.o</a>'
|
||||
npath = f'{ filedir }{ w }.c'
|
||||
return f'<a href="{ ctx.get_absolute_source_url(npath) }">{ w }.o</a>'
|
||||
|
||||
makefileo_filters = {
|
||||
'case': 'filename',
|
||||
'match': {'Makefile'},
|
||||
'prerex': '(?<=\s)([-\w/]+)\.o(?!\w)(?! :?=)',
|
||||
'prefunc': keep_makefileo,
|
||||
'postrex': '__KEEPMAKEFILEO__([A-J]+)\.o',
|
||||
'postfunc': replace_makefileo
|
||||
}
|
||||
return re.sub('__KEEPMAKEFILEO__([A-J]+)\.o', replace_makefileo, html, flags=re.MULTILINE)
|
||||
|
||||
filters.append(makefileo_filters)
|
||||
|
|
|
|||
|
|
@ -1,25 +1,34 @@
|
|||
import re
|
||||
from filters.utils import Filter, FilterContext, decode_number, encode_number, filename_without_ext_matches
|
||||
|
||||
# Filters for files listed in Makefiles using $(srctree)
|
||||
# $(srctree)/Makefile
|
||||
# Example: u-boot/v2023.10/source/Makefile#L1983
|
||||
class MakefileSrcTreeFilter(Filter):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.makefilesrctree = []
|
||||
|
||||
makefilesrctree = []
|
||||
def check_if_applies(self, ctx) -> bool:
|
||||
return super().check_if_applies(ctx) and \
|
||||
filename_without_ext_matches(ctx.filepath, {'Makefile'})
|
||||
|
||||
def keep_makefilesrctree(m):
|
||||
if q.query('exist', tag, '/' + m.group(1)):
|
||||
makefilesrctree.append(m.group(1))
|
||||
return '__KEEPMAKEFILESRCTREE__' + encode_number(len(makefilesrctree)) + m.group(2)
|
||||
else:
|
||||
return m.group(0)
|
||||
def transform_raw_code(self, ctx, code: str) -> str:
|
||||
def keep_makefilesrctree(m):
|
||||
if ctx.query.query('exist', ctx.tag, '/' + m.group(1)):
|
||||
self.makefilesrctree.append(m.group(1))
|
||||
return f'__KEEPMAKEFILESRCTREE__{ encode_number(len(self.makefilesrctree)) }{ m.group(2) }'
|
||||
else:
|
||||
return m.group(0)
|
||||
|
||||
def replace_makefilesrctree(m):
|
||||
w = makefilesrctree[decode_number(m.group(1)) - 1]
|
||||
return '<a href="/'+project+'/'+version+'/source'+'/'+w+'">'+'$(srctree)/'+w+'</a>'
|
||||
return re.sub('(?:(?<=\s|=)|(?<=-I))(?!/)\$\(srctree\)/((?:[-\w/]+/)?[-\w\.]+)(\s+|\)|$)',
|
||||
keep_makefilesrctree, code, flags=re.MULTILINE)
|
||||
|
||||
makefilesrctree_filters = {
|
||||
'case': 'filename',
|
||||
'match': {'Makefile'},
|
||||
'prerex': '(?:(?<=\s|=)|(?<=-I))(?!/)\$\(srctree\)/((?:[-\w/]+/)?[-\w\.]+)(\s+|\)|$)',
|
||||
'prefunc': keep_makefilesrctree,
|
||||
'postrex': '__KEEPMAKEFILESRCTREE__([A-J]+)',
|
||||
'postfunc': replace_makefilesrctree
|
||||
}
|
||||
def untransform_formatted_code(self, ctx: FilterContext, html: str) -> str:
|
||||
def replace_makefilesrctree(m):
|
||||
w = self.makefilesrctree[decode_number(m.group(1)) - 1]
|
||||
url = ctx.get_absolute_source_url(w)
|
||||
return f'<a href="{ url }">$(srctree)/{ w }</a>'
|
||||
|
||||
return re.sub('__KEEPMAKEFILESRCTREE__([A-J]+)', replace_makefilesrctree, html, flags=re.MULTILINE)
|
||||
|
||||
filters.append(makefilesrctree_filters)
|
||||
|
|
|
|||
|
|
@ -1,29 +1,37 @@
|
|||
from os.path import dirname
|
||||
import re
|
||||
from filters.utils import Filter, FilterContext, decode_number, encode_number, filename_without_ext_matches
|
||||
|
||||
# Filters for Makefile directory includes as follows:
|
||||
# subdir-y += dir
|
||||
# Example: u-boot/v2023.10/source/examples/Makefile#L9
|
||||
class MakefileSubdirFilter(Filter):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.makefilesubdir = []
|
||||
|
||||
makefilesubdir = []
|
||||
def check_if_applies(self, ctx) -> bool:
|
||||
return super().check_if_applies(ctx) and \
|
||||
filename_without_ext_matches(ctx.filepath, {'Makefile'})
|
||||
|
||||
def keep_makefilesubdir(m):
|
||||
makefilesubdir.append(m.group(5))
|
||||
return m.group(1)+m.group(2)+m.group(3)+m.group(4)+'__KEEPMAKESUBDIR__' + encode_number(len(makefilesubdir)) + m.group(6)
|
||||
def transform_raw_code(self, ctx, code: str) -> str:
|
||||
def keep_makefilesubdir(m):
|
||||
self.makefilesubdir.append(m.group(5))
|
||||
n = encode_number(len(self.makefilesubdir))
|
||||
return f'{ m.group(1) }{ m.group(2) }{ m.group(3) }{ m.group(4) }__KEEPMAKESUBDIR__{ n }{ m.group(6) }'
|
||||
|
||||
def replace_makefilesubdir(m):
|
||||
w = makefilesubdir[decode_number(m.group(1)) - 1]
|
||||
return re.sub('(subdir-y)(\s+)(\+=|:=)(\s+)([-\w]+)(\s*|$)', keep_makefilesubdir, code, flags=re.MULTILINE)
|
||||
|
||||
dir_name = os.path.dirname(path)
|
||||
|
||||
if dir_name != '/':
|
||||
dir_name += '/'
|
||||
def untransform_formatted_code(self, ctx: FilterContext, html: str) -> str:
|
||||
def replace_makefilesubdir(m):
|
||||
w = self.makefilesubdir[decode_number(m.group(1)) - 1]
|
||||
filedir = dirname(ctx.filepath)
|
||||
|
||||
return '<a href="/'+project+'/'+version+'/source'+dir_name+w+'/Makefile">'+w+'</a>'
|
||||
if filedir != '/':
|
||||
filedir += '/'
|
||||
|
||||
makefilesubdir_filters = {
|
||||
'case': 'filename',
|
||||
'match': {'Makefile'},
|
||||
'prerex': '(subdir-y)(\s+)(\+=|:=)(\s+)([-\w]+)(\s*|$)',
|
||||
'prefunc': keep_makefilesubdir,
|
||||
'postrex': '__KEEPMAKESUBDIR__([A-J]+)',
|
||||
'postfunc': replace_makefilesubdir
|
||||
}
|
||||
npath = f'{ filedir }{ w }/Makefile'
|
||||
return f'<a href="{ ctx.get_absolute_source_url(npath) }">{ w }</a>'
|
||||
|
||||
return re.sub('__KEEPMAKESUBDIR__([A-J]+)', replace_makefilesubdir, html, flags=re.MULTILINE)
|
||||
|
||||
filters.append(makefilesubdir_filters)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,12 @@
|
|||
# Elixir Python definitions for qemu
|
||||
|
||||
exec(open('commonkconfig.py').read())
|
||||
from filters.kconfig import KconfigFilter
|
||||
from filters.kconfigidents import KconfigIdentsFilter
|
||||
from filters.defconfig import DefConfigIdentsFilter
|
||||
|
||||
new_filters.extend([
|
||||
KconfigFilter(),
|
||||
KconfigIdentsFilter(),
|
||||
DefConfigIdentsFilter(),
|
||||
])
|
||||
|
||||
|
|
|
|||
|
|
@ -3,18 +3,31 @@
|
|||
from filters.dtsi import DtsiFilter
|
||||
from filters.cpppathinc import CppPathIncFilter
|
||||
|
||||
exec(open('commonkconfig.py').read())
|
||||
from filters.kconfig import KconfigFilter
|
||||
from filters.kconfigidents import KconfigIdentsFilter
|
||||
from filters.defconfig import DefConfigIdentsFilter
|
||||
|
||||
exec(open('makefileo.py').read())
|
||||
exec(open('makefiledtb.py').read())
|
||||
exec(open('makefiledir.py').read())
|
||||
exec(open('makefilefile.py').read())
|
||||
exec(open('makefilesubdir.py').read())
|
||||
exec(open('makefilesrctree.py').read())
|
||||
from filters.makefileo import MakefileOFilter
|
||||
from filters.makefiledtb import MakefileDtbFilter
|
||||
from filters.makefiledir import MakefileDirFilter
|
||||
from filters.makefilesubdir import MakefileSubdirFilter
|
||||
from filters.makefilefile import MakefileFileFilter
|
||||
from filters.makefilesrctree import MakefileSrcTreeFilter
|
||||
|
||||
new_filters.extend([
|
||||
DtsiFilter(),
|
||||
|
||||
CppPathIncFilter(),
|
||||
|
||||
KconfigFilter(),
|
||||
KconfigIdentsFilter(),
|
||||
DefConfigIdentsFilter(),
|
||||
|
||||
MakefileOFilter(),
|
||||
MakefileDtbFilter(),
|
||||
MakefileDirFilter(),
|
||||
MakefileSubdirFilter(),
|
||||
MakefileFileFilter(),
|
||||
MakefileSrcTreeFilter(),
|
||||
])
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,17 @@ from filters.dtsi import DtsiFilter
|
|||
|
||||
from filters.cpppathinc import CppPathIncFilter
|
||||
|
||||
exec(open('commonkconfig.py').read())
|
||||
from filters.kconfig import KconfigFilter
|
||||
from filters.kconfigidents import KconfigIdentsFilter
|
||||
from filters.defconfig import DefConfigIdentsFilter
|
||||
|
||||
new_filters.extend([
|
||||
DtsiFilter(),
|
||||
|
||||
CppPathIncFilter(),
|
||||
|
||||
KconfigFilter(),
|
||||
KconfigIdentsFilter(),
|
||||
DefConfigIdentsFilter(),
|
||||
])
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue