mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-28 09:17:17 +00:00
try to improve parser
This commit is contained in:
parent
4938f8ffe7
commit
405af4da5b
@ -96,12 +96,13 @@ class Task(LazyLogging):
|
|||||||
if self.include_debug_packages or not package.name.startswith(debug_package_prefix)
|
if self.include_debug_packages or not package.name.startswith(debug_package_prefix)
|
||||||
]
|
]
|
||||||
|
|
||||||
def build(self, sources_dir: Path, **kwargs: str | None) -> list[Path]:
|
def build(self, sources_dir: Path, *, dry_run: bool = False, **kwargs: str | None) -> list[Path]:
|
||||||
"""
|
"""
|
||||||
run package build
|
run package build
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
sources_dir(Path): path to where sources are
|
sources_dir(Path): path to where sources are
|
||||||
|
dry_run(bool, optional): do not perform build itself (Default value = False)
|
||||||
**kwargs(str | None): environment variables to be passed to build processes
|
**kwargs(str | None): environment variables to be passed to build processes
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@ -111,6 +112,8 @@ class Task(LazyLogging):
|
|||||||
command.extend(self.archbuild_flags)
|
command.extend(self.archbuild_flags)
|
||||||
command.extend(["--"] + self.makechrootpkg_flags)
|
command.extend(["--"] + self.makechrootpkg_flags)
|
||||||
command.extend(["--"] + self.makepkg_flags)
|
command.extend(["--"] + self.makepkg_flags)
|
||||||
|
if dry_run:
|
||||||
|
command.extend(["--nobuild"])
|
||||||
self.logger.info("using %s for %s", command, self.package.base)
|
self.logger.info("using %s for %s", command, self.package.base)
|
||||||
|
|
||||||
environment: dict[str, str] = {
|
environment: dict[str, str] = {
|
||||||
@ -157,25 +160,3 @@ class Task(LazyLogging):
|
|||||||
patch.write(sources_dir / "PKGBUILD")
|
patch.write(sources_dir / "PKGBUILD")
|
||||||
|
|
||||||
return last_commit_sha
|
return last_commit_sha
|
||||||
|
|
||||||
def setup(self, sources_dir: Path) -> None:
|
|
||||||
"""
|
|
||||||
setup chroot environment without building package itself. This function, in particular, useful in case if it is
|
|
||||||
required to refresh pkgver to the actual value without package building
|
|
||||||
|
|
||||||
Args:
|
|
||||||
sources_dir(Path): path to where sources are
|
|
||||||
"""
|
|
||||||
command = [self.build_command, "-r", str(self.paths.chroot)]
|
|
||||||
command.extend(self.archbuild_flags)
|
|
||||||
command.extend(["--"] + self.makechrootpkg_flags)
|
|
||||||
command.extend(["--"] + self.makepkg_flags + ["--nobuild"])
|
|
||||||
self.logger.info("using %s for %s", command, self.package.base)
|
|
||||||
|
|
||||||
check_output(
|
|
||||||
*command,
|
|
||||||
exception=BuildError.from_process(self.package.base),
|
|
||||||
cwd=sources_dir,
|
|
||||||
logger=self.logger,
|
|
||||||
user=self.uid,
|
|
||||||
)
|
|
||||||
|
@ -435,7 +435,7 @@ class Package(LazyLogging):
|
|||||||
try:
|
try:
|
||||||
# create fresh chroot environment, fetch sources and - automagically - update PKGBUILD
|
# create fresh chroot environment, fetch sources and - automagically - update PKGBUILD
|
||||||
task.init(paths.cache_for(self.base), [], None)
|
task.init(paths.cache_for(self.base), [], None)
|
||||||
task.setup(paths.cache_for(self.base))
|
task.build(paths.cache_for(self.base), dry_run=False)
|
||||||
|
|
||||||
pkgbuild = Pkgbuild.from_file(paths.cache_for(self.base) / "PKGBUILD")
|
pkgbuild = Pkgbuild.from_file(paths.cache_for(self.base) / "PKGBUILD")
|
||||||
|
|
||||||
|
@ -39,11 +39,11 @@ class PkgbuildToken(StrEnum):
|
|||||||
well-known tokens dictionary
|
well-known tokens dictionary
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
ArrayStarts(PkgbuildToken): (class attribute) array starts token
|
|
||||||
ArrayEnds(PkgbuildToken): (class attribute) array ends token
|
ArrayEnds(PkgbuildToken): (class attribute) array ends token
|
||||||
|
ArrayStarts(PkgbuildToken): (class attribute) array starts token
|
||||||
FunctionDeclaration(PkgbuildToken): (class attribute) function declaration token
|
FunctionDeclaration(PkgbuildToken): (class attribute) function declaration token
|
||||||
FunctionStarts(PkgbuildToken): (class attribute) function starts token
|
|
||||||
FunctionEnds(PkgbuildToken): (class attribute) function ends token
|
FunctionEnds(PkgbuildToken): (class attribute) function ends token
|
||||||
|
FunctionStarts(PkgbuildToken): (class attribute) function starts token
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ArrayStarts = "("
|
ArrayStarts = "("
|
||||||
@ -113,6 +113,10 @@ class Pkgbuild(Mapping[str, str | list[str]]):
|
|||||||
fields = {}
|
fields = {}
|
||||||
|
|
||||||
parser = shlex.shlex(stream, posix=True, punctuation_chars=True)
|
parser = shlex.shlex(stream, posix=True, punctuation_chars=True)
|
||||||
|
# ignore substitution and extend bash symbols
|
||||||
|
parser.wordchars += "${}#:+"
|
||||||
|
# in case of default behaviour, it will ignore, for example, segment part of url outside of quotes
|
||||||
|
parser.commenters = ""
|
||||||
while token := parser.get_token():
|
while token := parser.get_token():
|
||||||
try:
|
try:
|
||||||
key, value = cls._parse_token(token, parser)
|
key, value = cls._parse_token(token, parser)
|
||||||
@ -180,7 +184,7 @@ class Pkgbuild(Mapping[str, str | list[str]]):
|
|||||||
raise ValueError("Function body wasn't found")
|
raise ValueError("Function body wasn't found")
|
||||||
|
|
||||||
# read the specified interval from source stream
|
# read the specified interval from source stream
|
||||||
io.seek(start_position - 1) # start from the previous symbol ({)
|
io.seek(start_position - 1) # start from the previous symbol ("{")
|
||||||
content = io.read(end_position - start_position + 1)
|
content = io.read(end_position - start_position + 1)
|
||||||
|
|
||||||
return content
|
return content
|
||||||
@ -198,7 +202,7 @@ class Pkgbuild(Mapping[str, str | list[str]]):
|
|||||||
tuple[str, PkgbuildPatch]: extracted a pair of key and its value
|
tuple[str, PkgbuildPatch]: extracted a pair of key and its value
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
StopIteration: if iteration reaches the end of the file'
|
StopIteration: if iteration reaches the end of the file
|
||||||
"""
|
"""
|
||||||
# simple assignment rule
|
# simple assignment rule
|
||||||
if (match := Pkgbuild._STRING_ASSIGNMENT.match(token)) is not None:
|
if (match := Pkgbuild._STRING_ASSIGNMENT.match(token)) is not None:
|
||||||
@ -219,6 +223,14 @@ class Pkgbuild(Mapping[str, str | list[str]]):
|
|||||||
value = Pkgbuild._parse_function(parser)
|
value = Pkgbuild._parse_function(parser)
|
||||||
return token, PkgbuildPatch(key, value) # this is not mistake, assign to token without ()
|
return token, PkgbuildPatch(key, value) # this is not mistake, assign to token without ()
|
||||||
|
|
||||||
|
# special function case, where "(" and ")" are separated tokens, e.g. "pkgver ( )"
|
||||||
|
case PkgbuildToken.ArrayStarts if Pkgbuild._FUNCTION_DECLARATION.match(token):
|
||||||
|
next_token = parser.get_token()
|
||||||
|
if next_token == PkgbuildToken.ArrayEnds: # replace closing bracket with "()"
|
||||||
|
next_token = PkgbuildToken.FunctionDeclaration
|
||||||
|
parser.push_token(next_token) # type: ignore[arg-type]
|
||||||
|
return Pkgbuild._parse_token(token, parser)
|
||||||
|
|
||||||
# some random token received without continuation, lets guess it is empty assignment (i.e. key=)
|
# some random token received without continuation, lets guess it is empty assignment (i.e. key=)
|
||||||
case other if other is not None:
|
case other if other is not None:
|
||||||
return Pkgbuild._parse_token(other, parser)
|
return Pkgbuild._parse_token(other, parser)
|
||||||
|
Loading…
Reference in New Issue
Block a user