From 21ed7c4a7d0100b1455eeedec5434e100fd60d73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelmer=20Vernoo=C4=B3?= Date: Sun, 7 Feb 2021 21:55:47 +0000 Subject: [PATCH] Implement basic subcommands. --- ognibuild/__main__.py | 8 ++++--- ognibuild/apt.py | 4 +++- ognibuild/build.py | 34 ++++++++++++++++++++++++++++ ognibuild/buildsystem.py | 48 +++++++++++++++++++++++++++++++++++++++- ognibuild/clean.py | 34 ++++++++++++++++++++++++++++ ognibuild/install.py | 31 ++++++++++++++++++++++++++ ognibuild/test.py | 34 ++++++++++++++++++++++++++++ 7 files changed, 188 insertions(+), 5 deletions(-) create mode 100644 ognibuild/build.py create mode 100644 ognibuild/clean.py create mode 100644 ognibuild/install.py create mode 100644 ognibuild/test.py diff --git a/ognibuild/__main__.py b/ognibuild/__main__.py index 3cb47ae..aef0c6f 100644 --- a/ognibuild/__main__.py +++ b/ognibuild/__main__.py @@ -17,11 +17,13 @@ import os import sys -from . import ( - run_build, run_clean, run_install, run_test, - note) +from . import note from .buildsystem import NoBuildToolsFound +from .build import run_build +from .clean import run_clean from .dist import run_dist +from .install import run_install +from .test import run_test def main(): diff --git a/ognibuild/apt.py b/ognibuild/apt.py index ad29696..00ca1a7 100644 --- a/ognibuild/apt.py +++ b/ognibuild/apt.py @@ -67,8 +67,10 @@ class AptManager(object): status_path = os.path.join(root, 'var/lib/dpkg/status') missing = set(packages) with apt_pkg.TagFile(status_path) as tagf: - while tagf and missing: + while missing: tagf.step() + if not tagf.section: + break if tagf.section['Package'] in missing: if tagf.section['Status'] == 'install ok installed': missing.remove(tagf.section['Package']) diff --git a/ognibuild/build.py b/ognibuild/build.py new file mode 100644 index 0000000..405a5b4 --- /dev/null +++ b/ognibuild/build.py @@ -0,0 +1,34 @@ +#!/usr/bin/python3 +# Copyright (C) 2020-2021 Jelmer Vernooij +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +from .apt import AptManager +from .buildsystem import detect_buildsystems, NoBuildToolsFound + + +def run_build(session): + apt = AptManager(session) + apt.install(['git']) + + # Some things want to write to the user's home directory, + # e.g. pip caches in ~/.cache + session.create_home() + + for buildsystem in detect_buildsystems(session): + buildsystem.build() + return + + raise NoBuildToolsFound() diff --git a/ognibuild/buildsystem.py b/ognibuild/buildsystem.py index a68a9a4..9ce72be 100644 --- a/ognibuild/buildsystem.py +++ b/ognibuild/buildsystem.py @@ -18,6 +18,10 @@ import logging +import os + +from .apt import AptManager +from .fix_build import run_with_build_fixer class NoBuildToolsFound(Exception): @@ -33,7 +37,49 @@ class BuildSystem(object): def dist(self): raise NotImplementedError(self.dist) + def test(self): + raise NotImplementedError(self.test) + + def build(self): + raise NotImplementedError(self.build) + + def clean(self): + raise NotImplementedError(self.clean) + + def install(self): + raise NotImplementedError(self.install) + + +class Pear(BuildSystem): + + def dist(self): + apt = AptManager(self.session) + apt.install(['php-pear']) + run_with_build_fixer(self.session, ['pear', 'package']) + + def test(self): + apt = AptManager(self.session) + apt.install(['php-pear']) + run_with_build_fixer(self.session, ['pear', 'run-tests']) + + def build(self): + apt = AptManager(self.session) + apt.install(['php-pear']) + run_with_build_fixer(self.session, ['pear', 'build']) + + def clean(self): + apt = AptManager(self.session) + apt.install(['php-pear']) + # TODO + + def install(self): + apt = AptManager(self.session) + apt.install(['php-pear']) + run_with_build_fixer(self.session, ['pear', 'install']) + def detect_buildsystems(session): """Detect build systems.""" - return [] + if os.path.exists('package.xml'): + logging.info('Found package.xml, assuming pear package.') + yield Pear(session) diff --git a/ognibuild/clean.py b/ognibuild/clean.py new file mode 100644 index 0000000..80bfaa0 --- /dev/null +++ b/ognibuild/clean.py @@ -0,0 +1,34 @@ +#!/usr/bin/python3 +# Copyright (C) 2020-2021 Jelmer Vernooij +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +from .apt import AptManager +from .buildsystem import detect_buildsystems, NoBuildToolsFound + + +def run_clean(session): + apt = AptManager(session) + apt.install(['git']) + + # Some things want to write to the user's home directory, + # e.g. pip caches in ~/.cache + session.create_home() + + for buildsystem in detect_buildsystems(session): + buildsystem.clean() + return + + raise NoBuildToolsFound() diff --git a/ognibuild/install.py b/ognibuild/install.py new file mode 100644 index 0000000..27ec180 --- /dev/null +++ b/ognibuild/install.py @@ -0,0 +1,31 @@ +#!/usr/bin/python3 +# Copyright (C) 2020-2021 Jelmer Vernooij +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +from .apt import AptManager +from .buildsystem import detect_buildsystems, NoBuildToolsFound + + +def run_install(session): + # Some things want to write to the user's home directory, + # e.g. pip caches in ~/.cache + session.create_home() + + for buildsystem in detect_buildsystems(session): + buildsystem.install() + return + + raise NoBuildToolsFound() diff --git a/ognibuild/test.py b/ognibuild/test.py new file mode 100644 index 0000000..10c90d7 --- /dev/null +++ b/ognibuild/test.py @@ -0,0 +1,34 @@ +#!/usr/bin/python3 +# Copyright (C) 2020-2021 Jelmer Vernooij +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +from .apt import AptManager +from .buildsystem import detect_buildsystems, NoBuildToolsFound + + +def run_test(session): + apt = AptManager(session) + apt.install(['git']) + + # Some things want to write to the user's home directory, + # e.g. pip caches in ~/.cache + session.create_home() + + for buildsystem in detect_buildsystems(session): + buildsystem.test() + return + + raise NoBuildToolsFound()