New upstream version 0.0.15

This commit is contained in:
Tianyu Chen 2022-11-22 11:19:55 +08:00
parent 3e1f11dd79
commit c286789e37
55 changed files with 3578 additions and 1371 deletions

35
tests/__init__.py Normal file
View file

@ -0,0 +1,35 @@
# ognibuild
# Copyright (C) 2020 Jelmer Vernooij <jelmer@jelmer.uk>
#
# 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; version 2
# of the License or (at your option) any later version of
# the License.
#
# 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.
import os
import unittest
def test_suite():
names = [
'buildlog',
'logs',
]
if os.path.exists("/usr/bin/dpkg-architecture"):
names.append("debian_build")
names.append("debian_fix_build")
names.append("resolver_apt")
module_names = ["tests.test_" + name for name in names]
loader = unittest.TestLoader()
return loader.loadTestsFromNames(module_names)

47
tests/test_buildlog.py Normal file
View file

@ -0,0 +1,47 @@
#!/usr/bin/python
# Copyright (C) 2022 Jelmer Vernooij <jelmer@jelmer.uk>
#
# 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 ognibuild.buildlog import PROBLEM_CONVERTERS
from buildlog_consultant import (
problem_clses,
__version__ as buildlog_consultant_version,
)
from unittest import TestCase
class TestProblemsExists(TestCase):
def test_exist(self):
for entry in PROBLEM_CONVERTERS:
if len(entry) == 2:
problem_kind, fn = entry
min_version = None
elif len(entry) == 3:
problem_kind, fn, min_version = entry
else:
raise TypeError(entry)
if min_version is not None:
min_version_tuple = tuple(
[int(x) for x in min_version.split('.')])
if buildlog_consultant_version < min_version_tuple:
continue
self.assertTrue(
problem_kind in problem_clses,
f"{problem_kind} does not exist in known "
"buildlog-consultant problem kinds")

201
tests/test_debian_build.py Normal file
View file

@ -0,0 +1,201 @@
#!/usr/bin/python
# Copyright (C) 2020 Jelmer Vernooij <jelmer@jelmer.uk>
#
# 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
import datetime
import os
import sys
from debian.changelog import Version
from ognibuild.debian.build import (
add_dummy_changelog_entry,
get_build_architecture,
version_add_suffix,
_builddeb_command,
DEFAULT_BUILDER,
)
from breezy.tests import TestCaseWithTransport, TestCase
class AddDummyChangelogEntryTests(TestCaseWithTransport):
def test_simple(self):
tree = self.make_branch_and_tree(".")
self.build_tree_contents(
[
("debian/",),
(
"debian/changelog",
"""\
janitor (0.1-1) UNRELEASED; urgency=medium
* Initial release. (Closes: #XXXXXX)
-- Jelmer Vernooij <jelmer@debian.org> Sat, 04 Apr 2020 14:12:13 +0000
""",
),
]
)
tree.add(["debian", "debian/changelog"])
add_dummy_changelog_entry(
tree,
"",
"jan+some",
"some-fixes",
"Dummy build.",
timestamp=datetime.datetime(2020, 9, 5, 12, 35, 4, 899654),
maintainer=("Jelmer Vernooij", "jelmer@debian.org"),
)
self.assertFileEqual(
"""\
janitor (0.1-1jan+some1) some-fixes; urgency=medium
* Initial release. (Closes: #XXXXXX)
* Dummy build.
-- Jelmer Vernooij <jelmer@debian.org> Sat, 05 Sep 2020 12:35:04 -0000
""",
"debian/changelog",
)
def test_native(self):
tree = self.make_branch_and_tree(".")
self.build_tree_contents(
[
("debian/",),
(
"debian/changelog",
"""\
janitor (0.1) UNRELEASED; urgency=medium
* Initial release. (Closes: #XXXXXX)
-- Jelmer Vernooij <jelmer@debian.org> Sat, 04 Apr 2020 14:12:13 +0000
""",
),
]
)
tree.add(["debian", "debian/changelog"])
add_dummy_changelog_entry(
tree,
"",
"jan+some",
"some-fixes",
"Dummy build.",
timestamp=datetime.datetime(2020, 9, 5, 12, 35, 4, 899654),
maintainer=("Jelmer Vernooij", "jelmer@debian.org"),
)
self.assertFileEqual(
"""\
janitor (0.1jan+some1) some-fixes; urgency=medium
* Initial release. (Closes: #XXXXXX)
* Dummy build.
-- Jelmer Vernooij <jelmer@debian.org> Sat, 05 Sep 2020 12:35:04 -0000
""",
"debian/changelog",
)
def test_exists(self):
tree = self.make_branch_and_tree(".")
self.build_tree_contents(
[
("debian/",),
(
"debian/changelog",
"""\
janitor (0.1-1jan+some1) UNRELEASED; urgency=medium
* Initial release. (Closes: #XXXXXX)
-- Jelmer Vernooij <jelmer@debian.org> Sat, 04 Apr 2020 14:12:13 +0000
""",
),
]
)
tree.add(["debian", "debian/changelog"])
add_dummy_changelog_entry(
tree,
"",
"jan+some",
"some-fixes",
"Dummy build.",
timestamp=datetime.datetime(2020, 9, 5, 12, 35, 4, 899654),
maintainer=("Jelmer Vernooij", "jelmer@debian.org"),
)
self.assertFileEqual(
"""\
janitor (0.1-1jan+some2) some-fixes; urgency=medium
* Initial release. (Closes: #XXXXXX)
* Dummy build.
-- Jelmer Vernooij <jelmer@debian.org> Sat, 05 Sep 2020 12:35:04 -0000
""",
"debian/changelog",
)
class BuildArchitectureTests(TestCase):
def setUp(self):
super(BuildArchitectureTests, self).setUp()
if not os.path.exists("/usr/bin/dpkg-architecture"):
self.skipTest("not a debian system")
def test_is_str(self):
self.assertIsInstance(get_build_architecture(), str)
class VersionAddSuffixTests(TestCase):
def test_native(self):
self.assertEqual(
Version('1.0~jan+lint4'),
version_add_suffix(Version('1.0~jan+lint3'), '~jan+lint'))
self.assertEqual(
Version('1.0~jan+lint1'),
version_add_suffix(Version('1.0'), '~jan+lint'))
def test_normal(self):
self.assertEqual(
Version('1.0-1~jan+lint4'),
version_add_suffix(Version('1.0-1~jan+lint3'), '~jan+lint'))
self.assertEqual(
Version('1.0-1~jan+lint1'),
version_add_suffix(Version('1.0-1'), '~jan+lint'))
self.assertEqual(
Version('0.0.12-1~jan+lint1'),
version_add_suffix(Version('0.0.12-1'), '~jan+lint'))
self.assertEqual(
Version('0.0.12-1~jan+unchanged1~jan+lint1'),
version_add_suffix(
Version('0.0.12-1~jan+unchanged1'), '~jan+lint'))
class BuilddebCommandTests(TestCase):
def test_simple(self):
self.assertEqual(
[sys.executable, "-m", "breezy", "builddeb",
"--guess-upstream-branch-url", "--builder=" + DEFAULT_BUILDER],
_builddeb_command())
self.assertEqual(
[sys.executable, "-m", "breezy", "builddeb",
"--guess-upstream-branch-url", "--builder=" + DEFAULT_BUILDER,
"--result-dir=/tmp/blah"],
_builddeb_command(result_dir="/tmp/blah"))

View file

@ -0,0 +1,308 @@
#!/usr/bin/python
# Copyright (C) 2020 Jelmer Vernooij <jelmer@jelmer.uk>
#
# 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
import re
from debian.deb822 import Deb822
from buildlog_consultant.common import (
MissingCommand,
MissingGoPackage,
MissingPerlModule,
MissingPkgConfig,
MissingPythonModule,
MissingRubyFile,
MissingRubyGem,
MissingValaPackage,
)
from ognibuild.debian.apt import AptManager, FileSearcher
from ognibuild.debian.fix_build import (
resolve_error,
versioned_package_fixers,
apt_fixers,
DebianPackagingContext,
add_build_dependency,
)
from ognibuild.resolver.apt import AptRequirement
from breezy.commit import NullCommitReporter
from breezy.tests import TestCaseWithTransport
class DummyAptSearcher(FileSearcher):
def __init__(self, files):
self._apt_files = files
async def search_files(self, path, regex=False, case_insensitive=False):
for p, pkg in sorted(self._apt_files.items()):
if case_insensitive:
flags = re.I
else:
flags = 0
if regex:
if re.match(path, p, flags):
yield pkg
elif case_insensitive:
if path.lower() == p.lower():
yield pkg
else:
if path == p:
yield pkg
class ResolveErrorTests(TestCaseWithTransport):
def setUp(self):
super(ResolveErrorTests, self).setUp()
self.tree = self.make_branch_and_tree(".")
self.build_tree_contents(
[
("debian/",),
(
"debian/control",
"""\
Source: blah
Build-Depends: libc6
Package: python-blah
Depends: ${python3:Depends}
Description: A python package
Foo
""",
),
(
"debian/changelog",
"""\
blah (0.1) UNRELEASED; urgency=medium
* Initial release. (Closes: #XXXXXX)
-- Jelmer Vernooij <jelmer@debian.org> Sat, 04 Apr 2020 14:12:13 +0000
""",
),
]
)
self.tree.add(["debian", "debian/control", "debian/changelog"])
self.tree.commit("Initial commit")
self._apt_files = {}
def resolve(self, error, context=("build",)):
from ognibuild.session.plain import PlainSession
session = PlainSession()
apt = AptManager(session)
apt._searchers = [DummyAptSearcher(self._apt_files)]
context = DebianPackagingContext(
self.tree,
subpath="",
committer="ognibuild <ognibuild@jelmer.uk>",
update_changelog=True,
commit_reporter=NullCommitReporter(),
)
fixers = versioned_package_fixers(
session, context, apt) + apt_fixers(apt, context)
return resolve_error(error, ("build",), fixers)
def get_build_deps(self):
with open(self.tree.abspath("debian/control"), "r") as f:
return next(Deb822.iter_paragraphs(f)).get("Build-Depends", "")
def test_missing_command_unknown(self):
self._apt_files = {}
self.assertFalse(self.resolve(
MissingCommand("acommandthatdoesnotexist")))
def test_missing_command_brz(self):
self._apt_files = {
"/usr/bin/b": "bash",
"/usr/bin/brz": "brz",
"/usr/bin/brzier": "bash",
}
self.overrideEnv("DEBEMAIL", "jelmer@debian.org")
self.overrideEnv("DEBFULLNAME", "Jelmer Vernooij")
self.assertTrue(self.resolve(MissingCommand("brz")))
self.assertEqual("libc6, brz", self.get_build_deps())
rev = self.tree.branch.repository.get_revision(
self.tree.branch.last_revision())
self.assertEqual("Add missing build dependency on brz.\n", rev.message)
self.assertFalse(self.resolve(MissingCommand("brz")))
self.assertEqual("libc6, brz", self.get_build_deps())
def test_missing_command_ps(self):
self._apt_files = {
"/bin/ps": "procps",
"/usr/bin/pscal": "xcal",
}
self.assertTrue(self.resolve(MissingCommand("ps")))
self.assertEqual("libc6, procps", self.get_build_deps())
def test_missing_ruby_file(self):
self._apt_files = {
"/usr/lib/ruby/vendor_ruby/rake/testtask.rb": "rake",
}
self.assertTrue(self.resolve(MissingRubyFile("rake/testtask")))
self.assertEqual("libc6, rake", self.get_build_deps())
def test_missing_ruby_file_from_gem(self):
self._apt_files = {
"/usr/share/rubygems-integration/all/gems/activesupport-"
"5.2.3/lib/active_support/core_ext/string/strip.rb":
"ruby-activesupport"
}
self.assertTrue(
self.resolve(MissingRubyFile(
"active_support/core_ext/string/strip"))
)
self.assertEqual("libc6, ruby-activesupport", self.get_build_deps())
def test_missing_ruby_gem(self):
self._apt_files = {
"/usr/share/rubygems-integration/all/specifications/"
"bio-1.5.2.gemspec": "ruby-bio",
"/usr/share/rubygems-integration/all/specifications/"
"bio-2.0.2.gemspec": "ruby-bio",
}
self.assertTrue(self.resolve(MissingRubyGem("bio", None)))
self.assertEqual("libc6, ruby-bio", self.get_build_deps())
self.assertTrue(self.resolve(MissingRubyGem("bio", "2.0.3")))
self.assertEqual("libc6, ruby-bio (>= 2.0.3)", self.get_build_deps())
def test_missing_perl_module(self):
self._apt_files = {
"/usr/share/perl5/App/cpanminus/fatscript.pm": "cpanminus"}
self.assertTrue(
self.resolve(
MissingPerlModule(
"App/cpanminus/fatscript.pm",
"App::cpanminus::fatscript",
[
"/<<PKGBUILDDIR>>/blib/lib",
"/<<PKGBUILDDIR>>/blib/arch",
"/etc/perl",
"/usr/local/lib/x86_64-linux-gnu/perl/5.30.0",
"/usr/local/share/perl/5.30.0",
"/usr/lib/x86_64-linux-gnu/perl5/5.30",
"/usr/share/perl5",
"/usr/lib/x86_64-linux-gnu/perl/5.30",
"/usr/share/perl/5.30",
"/usr/local/lib/site_perl",
"/usr/lib/x86_64-linux-gnu/perl-base",
".",
],
)
)
)
self.assertEqual("libc6, cpanminus", self.get_build_deps())
def test_missing_pkg_config(self):
self._apt_files = {
"/usr/lib/x86_64-linux-gnu/pkgconfig/xcb-xfixes.pc":
"libxcb-xfixes0-dev"
}
self.assertTrue(self.resolve(MissingPkgConfig("xcb-xfixes")))
self.assertEqual("libc6, libxcb-xfixes0-dev", self.get_build_deps())
def test_missing_pkg_config_versioned(self):
self._apt_files = {
"/usr/lib/x86_64-linux-gnu/pkgconfig/xcb-xfixes.pc":
"libxcb-xfixes0-dev"
}
self.assertTrue(self.resolve(MissingPkgConfig("xcb-xfixes", "1.0")))
self.assertEqual(
"libc6, libxcb-xfixes0-dev (>= 1.0)", self.get_build_deps())
def test_missing_python_module(self):
self._apt_files = {
"/usr/lib/python3/dist-packages/m2r.py": "python3-m2r"}
self.assertTrue(self.resolve(MissingPythonModule("m2r")))
self.assertEqual("libc6, python3-m2r", self.get_build_deps())
def test_missing_go_package(self):
self._apt_files = {
"/usr/share/gocode/src/github.com/chzyer/readline/utils_test.go":
"golang-github-chzyer-readline-dev",
}
self.assertTrue(self.resolve(
MissingGoPackage("github.com/chzyer/readline")))
self.assertEqual(
"libc6, golang-github-chzyer-readline-dev", self.get_build_deps()
)
def test_missing_vala_package(self):
self._apt_files = {
"/usr/share/vala-0.48/vapi/posix.vapi": "valac-0.48-vapi",
}
self.assertTrue(self.resolve(MissingValaPackage("posix")))
self.assertEqual("libc6, valac-0.48-vapi", self.get_build_deps())
class AddBuildDependencyTests(TestCaseWithTransport):
def setUp(self):
super(AddBuildDependencyTests, self).setUp()
self.tree = self.make_branch_and_tree(".")
self.build_tree_contents(
[
("debian/",),
(
"debian/control",
"""\
Source: blah
Build-Depends: libc6
Package: python-blah
Depends: ${python3:Depends}
Description: A python package
Foo
""",
),
(
"debian/changelog",
"""\
blah (0.1) UNRELEASED; urgency=medium
* Initial release. (Closes: #XXXXXX)
-- Jelmer Vernooij <jelmer@debian.org> Sat, 04 Apr 2020 14:12:13 +0000
""",
),
]
)
self.tree.add(["debian", "debian/control", "debian/changelog"])
self.tree.commit("Initial commit")
self.context = DebianPackagingContext(
self.tree,
subpath="",
committer="ognibuild <ognibuild@jelmer.uk>",
update_changelog=True,
commit_reporter=NullCommitReporter(),
)
def test_already_present(self):
requirement = AptRequirement.simple('libc6')
self.assertFalse(add_build_dependency(self.context, requirement))
def test_basic(self):
requirement = AptRequirement.simple('foo')
self.assertTrue(add_build_dependency(self.context, requirement))
self.assertFileEqual("""\
Source: blah
Build-Depends: libc6, foo
Package: python-blah
Depends: ${python3:Depends}
Description: A python package
Foo
""", 'debian/control')

95
tests/test_logs.py Normal file
View file

@ -0,0 +1,95 @@
#!/usr/bin/python
# Copyright (C) 2022 Jelmer Vernooij <jelmer@jelmer.uk>
#
# 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
import os
import sys
import tempfile
from unittest import TestCase
from ognibuild.logs import (
copy_output,
redirect_output,
rotate_logfile,
DirectoryLogManager,
)
class TestCopyOutput(TestCase):
def test_no_tee(self):
with tempfile.TemporaryDirectory() as td:
p = os.path.join(td, 'foo.log')
with copy_output(p, tee=False):
sys.stdout.write('lala\n')
sys.stdout.flush()
with open(p, 'r') as f:
self.assertEqual('lala\n', f.read())
def test_tee(self):
with tempfile.TemporaryDirectory() as td:
p = os.path.join(td, 'foo.log')
with copy_output(p, tee=True):
sys.stdout.write('lala\n')
sys.stdout.flush()
with open(p, 'r') as f:
self.assertEqual('lala\n', f.read())
class TestRedirectOutput(TestCase):
def test_simple(self):
with tempfile.TemporaryDirectory() as td:
p = os.path.join(td, 'foo.log')
with open(p, 'w') as f:
with redirect_output(f):
sys.stdout.write('lala\n')
sys.stdout.flush()
with open(p, 'r') as f:
self.assertEqual('lala\n', f.read())
class TestRotateLogfile(TestCase):
def test_does_not_exist(self):
with tempfile.TemporaryDirectory() as td:
p = os.path.join(td, 'foo.log')
rotate_logfile(p)
self.assertEqual([], os.listdir(td))
def test_simple(self):
with tempfile.TemporaryDirectory() as td:
p = os.path.join(td, 'foo.log')
with open(p, 'w') as f:
f.write('contents\n')
rotate_logfile(p)
self.assertEqual(['foo.log.1'], os.listdir(td))
class TestLogManager(TestCase):
def test_simple(self):
with tempfile.TemporaryDirectory() as td:
p = os.path.join(td, 'foo.log')
lm = DirectoryLogManager(p, mode='redirect')
def writesomething():
sys.stdout.write('foo\n')
sys.stdout.flush()
fn = lm.wrap(writesomething)
fn()
with open(p, 'r') as f:
self.assertEqual('foo\n', f.read())

View file

@ -0,0 +1,47 @@
#!/usr/bin/python
# Copyright (C) 2022 Jelmer Vernooij <jelmer@jelmer.uk>
#
# 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 unittest import TestCase
from ognibuild.resolver.apt import get_possible_python3_paths_for_python_object
class TestPython3Paths(TestCase):
def test_paths(self):
self.assertEqual([
'/usr/lib/python3/dist\\-packages/dulwich/__init__\\.py',
'/usr/lib/python3/dist\\-packages/dulwich\\.py',
'/usr/lib/python3\\.[0-9]+/'
'lib\\-dynload/dulwich.cpython\\-.*\\.so',
'/usr/lib/python3\\.[0-9]+/dulwich\\.py',
'/usr/lib/python3\\.[0-9]+/dulwich/__init__\\.py'],
get_possible_python3_paths_for_python_object('dulwich'))
self.assertEqual([
'/usr/lib/python3/dist\\-packages/cleo/foo/__init__\\.py',
'/usr/lib/python3/dist\\-packages/cleo/foo\\.py',
'/usr/lib/python3\\.[0-9]+/'
'lib\\-dynload/cleo/foo.cpython\\-.*\\.so',
'/usr/lib/python3\\.[0-9]+/cleo/foo\\.py',
'/usr/lib/python3\\.[0-9]+/cleo/foo/__init__\\.py',
'/usr/lib/python3/dist\\-packages/cleo/__init__\\.py',
'/usr/lib/python3/dist\\-packages/cleo\\.py',
'/usr/lib/python3\\.[0-9]+/lib\\-dynload/cleo.cpython\\-.*\\.so',
'/usr/lib/python3\\.[0-9]+/cleo\\.py',
'/usr/lib/python3\\.[0-9]+/cleo/__init__\\.py'],
get_possible_python3_paths_for_python_object('cleo.foo'))