From f0618326675801522f82697b825f71e24194910e Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 10 Sep 2011 22:15:51 +0200 Subject: [PATCH] Slight modification of the makefile format. --- macros/templates.macro | 88 +++++++++++++------------- pakfire/packages/lexer.py | 130 ++++++++++++++++++++++++++++++-------- pakfire/packages/make.py | 4 +- po/pakfire.pot | 8 +-- 4 files changed, 156 insertions(+), 74 deletions(-) diff --git a/macros/templates.macro b/macros/templates.macro index ac850f6ed..84822589a 100644 --- a/macros/templates.macro +++ b/macros/templates.macro @@ -4,59 +4,61 @@ _release = %{release}.%{DISTRO_DISTTAG} thisapp = %{name}-%{version} thisver = %{version}-%{_release} -template MAIN - def files - / - end +packages + template MAIN + def files + / + end - def configfiles + def configfiles + end end -end -template LIBS - summary = Library files of %{thisapp}. - description = Runtime library files of the package %{thisapp}. + template LIBS + summary = Library files of %{thisapp}. + description = Runtime library files of the package %{thisapp}. - def files - /lib/lib*.so.* - /usr/lib*/lib*.so.* - end + def files + /lib/lib*.so.* + /usr/lib*/lib*.so.* + end - def configfiles - end + def configfiles + end - script postin - # Update linker cache. - /sbin/ldconfig 2>/dev/null || true - end + script postin + # Update linker cache. + /sbin/ldconfig 2>/dev/null || true + end - script postup - /sbin/ldconfig 2>/dev/null || true - end + script postup + /sbin/ldconfig 2>/dev/null || true + end - script postun - /sbin/ldconfig 2>/dev/null || true + script postun + /sbin/ldconfig 2>/dev/null || true + end end -end -template DEVEL - summary = Development files of %{thisapp}. - description = %{summary} - - def files - /usr/bin/*-config - /usr/include - /usr/lib/*.a - /usr/lib/pkgconfig - /usr/share/aclocal - /usr/lib/*.so - /usr/share/*/cmake - /usr/share/man/man2 - /usr/share/man/man3 - /usr/share/pkgconfig - /usr/share/vala - end + template DEVEL + summary = Development files of %{thisapp}. + description = %{summary} + + def files + /usr/bin/*-config + /usr/include + /usr/lib/*.a + /usr/lib/pkgconfig + /usr/share/aclocal + /usr/lib/*.so + /usr/share/*/cmake + /usr/share/man/man2 + /usr/share/man/man3 + /usr/share/pkgconfig + /usr/share/vala + end - def configfiles + def configfiles + end end end diff --git a/pakfire/packages/lexer.py b/pakfire/packages/lexer.py index bb32300cb..b6c96fe9f 100644 --- a/pakfire/packages/lexer.py +++ b/pakfire/packages/lexer.py @@ -38,7 +38,7 @@ LEXER_BLOCK_LINE_INDENT = "\t" LEXER_BLOCK_LINE = re.compile(r"^\t(.*)$") LEXER_BLOCK_END = re.compile(r"^end$") -LEXER_DEFINE_BEGIN = re.compile(r"^def ([A-Za-z0-9_\-]+)$") +LEXER_DEFINE_BEGIN = re.compile(r"^(def)?\s?([A-Za-z0-9_\-]+)$") LEXER_DEFINE_LINE = LEXER_BLOCK_LINE LEXER_DEFINE_END = LEXER_BLOCK_END @@ -67,6 +67,10 @@ LEXER_DISTRO_BEGIN = re.compile(r"^distribution$") LEXER_DISTRO_LINE = LEXER_BLOCK_LINE LEXER_DISTRO_END = LEXER_BLOCK_END +LEXER_PACKAGES_BEGIN = re.compile(r"^packages$") +LEXER_PACKAGES_LINE = LEXER_BLOCK_LINE +LEXER_PACKAGES_END = LEXER_BLOCK_END + LEXER_PACKAGE2_BEGIN = re.compile(r"^package$") LEXER_PACKAGE2_LINE = LEXER_BLOCK_LINE LEXER_PACKAGE2_END = LEXER_BLOCK_END @@ -77,6 +81,7 @@ LEXER_UNEXPORT = re.compile(r"^unexport ([A-Za-z0-9_\-]+)$") LEXER_INCLUDE = re.compile(r"^include (.+)$") LEXER_VARIABLE = re.compile(r"\%\{([A-Za-z0-9_\-]+)\}") +LEXER_SHELL = re.compile(r"\%\(.*\)") class Lexer(object): @@ -210,6 +215,9 @@ class Lexer(object): (LEXER_COMMENT, self.parse_comment), (LEXER_DEFINITION, self.parse_definition), (LEXER_DEFINE_BEGIN, self.parse_define), + # Needs to be done. + #(LEXER_EXPORT, self.parse_export), + #(LEXER_UNEXPORT, self.parse_unexport), ] def get_parsers(self): @@ -223,7 +231,7 @@ class Lexer(object): line = self.get_line(self._lineno) - parsers = self.get_default_parsers() + self.get_parsers() + parsers = self.get_parsers() + self.get_default_parsers() found = False for pattern, func in parsers: @@ -333,10 +341,34 @@ class Lexer(object): if not m: raise Exception, "XXX not a define" + # Check content of next line. + found = None + i = 1 + while True: + line = self.get_line(self._lineno + i) + + # Skip empty lines. + empty = re.match(LEXER_EMPTY_LINE, line) + if empty: + i += 1 + continue + + for pattern in (LEXER_DEFINE_LINE, LEXER_DEFINE_END): + found = re.match(pattern, line) + if found: + break + + if found: + break + + if found is None: + line = self.get_line(self._lineno) + raise LexerUnhandledLine, "%d: %s" % (self.lineno, line) + # Go in to next line. self._lineno += 1 - key = m.group(1) + key = m.group(2) assert key value = [] @@ -450,6 +482,8 @@ class PackageLexer(TemplateLexer): self._template = "MAIN" + assert isinstance(self.parent, PackagesLexer) + @property def definitions(self): definitions = {} @@ -466,21 +500,16 @@ class PackageLexer(TemplateLexer): if not self._template: return None - # Get templates from root. - assert self.root - templates = self.root.templates - + # Get template from parent. try: - return templates[self._template] + return self.root.templates[self._template] except KeyError: raise LexerError, "Template does not exist: %s" % self._template def get_parsers(self): - parsers = TemplateLexer.get_parsers(self) - - parsers += [ + parsers = [ (LEXER_PACKAGE_INHERIT, self.parse_inherit), - ] + ] + TemplateLexer.get_parsers(self) return parsers @@ -521,6 +550,9 @@ class RootLexer(DefaultLexer): # environment. self.exports = [] + # A place to store all packages and templates. + self.packages = PackagesLexer([], parent=self) + # Import all environment variables. if environ: for k, v in environ.items(): @@ -528,12 +560,6 @@ class RootLexer(DefaultLexer): self.exports.append(k) - # A place to store all packages. - self.packages = [] - - # A place to store all templates. - self.templates = {} - # Place for build instructions self.build = BuildLexer([], parent=self) @@ -556,18 +582,20 @@ class RootLexer(DefaultLexer): self._definitions.update(other._definitions) self.build.inherit(other.build) - self.templates.update(other.templates) - self.packages += other.packages + self.packages.inherit(other.packages) for export in other.exports: if not export in self.exports: self.exports.append(export) + @property + def templates(self): + return self.packages.templates + def get_parsers(self): return [ (LEXER_INCLUDE, self.parse_include), - (LEXER_TEMPLATE_BEGIN, self.parse_template), - (LEXER_PACKAGE_BEGIN, self.parse_package), + (LEXER_PACKAGES_BEGIN, self.parse_packages), (LEXER_BUILD_BEGIN, self.parse_build), ] @@ -638,6 +666,46 @@ class RootLexer(DefaultLexer): if k and k in self.exports: self.exports.remove(k) + def parse_packages(self): + keys, lines = self.read_block( + pattern_start=LEXER_PACKAGES_BEGIN, + pattern_line=LEXER_PACKAGES_LINE, + pattern_end=LEXER_PACKAGES_END, + raw=True, + ) + + pkgs = PackagesLexer(lines, parent=self) + self.packages.inherit(pkgs) + + +class PackagesLexer(DefaultLexer): + def init(self, environ): + # A place to store all templates. + self.templates = {} + + # A place to store all packages. + self.packages = [] + + def inherit(self, other): + # Copy all templates and packages but make sure + # to update the parent lexer (for accessing each other). + for name, template in other.templates.items(): + template.parent = self + self.templates[name] = template + + for pkg in other.packages: + pkg.parent = self + self.packages.append(pkg) + + def __iter__(self): + return iter(self.packages) + + def get_parsers(self): + return [ + (LEXER_TEMPLATE_BEGIN, self.parse_template), + (LEXER_PACKAGE_BEGIN, self.parse_package), + ] + def parse_template(self): line = self.get_line(self._lineno) @@ -690,13 +758,15 @@ class RootLexer(DefaultLexer): if not m: raise LexerError, "Invalid package name: %s" % name - lines = ["name = %s" % name] + lines = ["_name = %s" % name] - while True: + opened = False + while len(self.lines) > self._lineno: line = self.get_line(self._lineno) m = re.match(LEXER_PACKAGE_END, line) if m: + opened = False self._lineno += 1 break @@ -704,6 +774,7 @@ class RootLexer(DefaultLexer): if m: self._lineno += 1 lines.append(m.group(1)) + opened = True continue # Accept empty lines. @@ -713,7 +784,16 @@ class RootLexer(DefaultLexer): lines.append(line) continue - raise Exception, "XXX unhandled line in package block: %s" % line + # If there is an unhandled line in a block, we raise an error. + if opened: + raise Exception, "XXX unhandled line in package block: %s" % line + + # If the block was never opened, we just go on. + else: + break + + if opened: + raise LexerError, "Unclosed package block '%s'." % name package = PackageLexer(lines, parent=self) self.packages.append(package) diff --git a/pakfire/packages/make.py b/pakfire/packages/make.py index d6196801a..e281209c2 100644 --- a/pakfire/packages/make.py +++ b/pakfire/packages/make.py @@ -212,7 +212,7 @@ class Makefile(MakefileBase): pkgs = [] for lexer in self.lexer.packages: - name = lexer.get_var("name") + name = lexer.get_var("_name") pkg = MakefilePackage(self.pakfire, name, lexer) pkgs.append(pkg) @@ -285,7 +285,7 @@ class Makefile(MakefileBase): @property def requires(self): - return self.lexer.get_var("build_requires").split() + return self.lexer.build.get_var("requires", "").split() @property def provides(self): diff --git a/po/pakfire.pot b/po/pakfire.pot index ac979b9d5..4784c8f3a 100644 --- a/po/pakfire.pot +++ b/po/pakfire.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-08-30 19:09+0200\n" +"POT-Creation-Date: 2011-09-10 22:15+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -334,7 +334,7 @@ msgstr "" msgid "Do not verify build dependencies." msgstr "" -#: ../pakfire/compress.py:133 ../pakfire/packages/packager.py:491 +#: ../pakfire/compress.py:133 ../pakfire/packages/packager.py:489 #, python-format msgid "Compressing %s" msgstr "" @@ -465,11 +465,11 @@ msgid "Package version is undefined." msgstr "" #. Load progressbar. -#: ../pakfire/packages/packager.py:317 +#: ../pakfire/packages/packager.py:315 msgid "Packaging" msgstr "" -#: ../pakfire/packages/packager.py:608 +#: ../pakfire/packages/packager.py:606 #, python-format msgid "Building source package %s:" msgstr "" -- 2.39.5