From 24df262f6b93e5fe7d0c8d94c0dd11a0fd48a257 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Mon, 20 Feb 2023 22:38:30 +0100 Subject: [PATCH 1/2] handle str and pathlib.Path in getvcs() --- fdroidserver/common.py | 14 ++++++++++++-- tests/common.TestCase | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 275cfa40..b90c9bad 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -962,6 +962,11 @@ def setup_vcs(app): def getvcs(vcstype, remote, local): + """Return a vcs instance based on the arguments. + + remote and local can be either a string or a pathlib.Path + + """ if vcstype == 'git': return vcs_git(remote, local) if vcstype == 'git-svn': @@ -971,7 +976,7 @@ def getvcs(vcstype, remote, local): if vcstype == 'bzr': return vcs_bzr(remote, local) if vcstype == 'srclib': - if local != Path('build', 'srclib', remote): + if str(local) != os.path.join('build', 'srclib', str(remote)): raise VCSException("Error: srclib paths are hard-coded!") return getsrclib(remote, os.path.join('build', 'srclib'), raw=True) if vcstype == 'svn': @@ -1989,13 +1994,18 @@ def getsrclib(spec, srclib_dir, basepath=False, build=None): """Get the specified source library. - Returns the path to it. Normally this is the path to be used when + Return the path to it. Normally this is the path to be used when referencing it, which may be a subdirectory of the actual project. If you want the base directory of the project, pass 'basepath=True'. + spec and srclib_dir are both strings, not pathlib.Path. """ number = None subdir = None + if not isinstance(spec, str): + spec = str(spec) + if not isinstance(srclib_dir, str): + spec = str(srclib_dir) if raw: name = spec ref = None diff --git a/tests/common.TestCase b/tests/common.TestCase index c6697ed3..fe4df7fe 100755 --- a/tests/common.TestCase +++ b/tests/common.TestCase @@ -58,6 +58,7 @@ class CommonTest(unittest.TestCase): fdroidserver.common.config = None fdroidserver.common.options = mock.Mock() fdroidserver.common.options.verbose = False + fdroidserver.metadata.srclibs = None self._td = mkdtemp() self.testdir = self._td.name @@ -412,6 +413,47 @@ class CommonTest(unittest.TestCase): vcs1 = fdroidserver.common.getvcs('git', git_url, gitrepo) vcs1.gotorevision('0.3', refresh=False) + def test_setup_vcs_srclib(self): + app = fdroidserver.metadata.App( + { + 'RepoType': 'srclib', + 'Repo': 'TransportsRennes', + } + ) + srclib = { + 'RepoType': 'git', + 'Repo': 'https://github.com/ybonnel/TransportsRennes', + } + fdroidserver.metadata.srclibs = {'TransportsRennes': srclib} + vcs, build_dir = fdroidserver.common.setup_vcs(app) + self.assertIsNotNone(vcs) + self.assertEqual(build_dir, Path('build/srclib/TransportsRennes')) + + def test_getvcs_srclib(self): + vcstype = 'srclib' + remote = 'TransportsRennes' + local = 'build/srclib/' + remote + fdroidserver.metadata.srclibs = { + remote: { + 'RepoType': 'git', + 'Repo': 'https://github.com/ybonnel/TransportsRennes', + } + } + self.assertIsNotNone(fdroidserver.common.getvcs(vcstype, remote, local)) + self.assertIsNotNone(fdroidserver.common.getvcs(vcstype, Path(remote), local)) + self.assertIsNotNone(fdroidserver.common.getvcs(vcstype, remote, Path(local))) + self.assertIsNotNone(fdroidserver.common.getvcs( + vcstype, Path(remote), Path(local) + )) + with self.assertRaises(VCSException): + fdroidserver.common.getvcs(vcstype, remote, 'bad') + with self.assertRaises(VCSException): + fdroidserver.common.getvcs(vcstype, remote, Path('bad')) + with self.assertRaises(VCSException): + fdroidserver.common.getvcs(vcstype, Path(remote), 'bad') + with self.assertRaises(VCSException): + fdroidserver.common.getvcs(vcstype, Path(remote), Path('bad')) + def test_fdroid_popen_stderr_redirect(self): config = dict() fdroidserver.common.fill_config_defaults(config) From 5af5ed2759bf6a88a7a763a5f330a1688c50f791 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 21 Feb 2023 11:16:56 +0100 Subject: [PATCH 2/2] fix test_fill_config_defaults_java for non-amd64 arches --- tests/common.TestCase | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/common.TestCase b/tests/common.TestCase index fe4df7fe..29b9bdc2 100755 --- a/tests/common.TestCase +++ b/tests/common.TestCase @@ -2357,7 +2357,7 @@ class CommonTest(unittest.TestCase): fdroidserver.common.fill_config_defaults(config) java_paths = [] # use presence of javac to make sure its JDK not just JRE - for f in glob.glob('/usr/lib/jvm/java-*-openjdk-amd64/bin/javac'): + for f in glob.glob('/usr/lib/jvm/java-*-openjdk-*/bin/javac'): jdk = os.path.dirname(os.path.dirname(f)) if not os.path.islink(jdk): java_paths.append(jdk)