From d0f426e076bf1507919586c2652699390ef7382f Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 24 Jun 2020 20:50:21 +0200 Subject: [PATCH 1/2] replace $$srclib$$ with an absolute path closes #725 --- fdroidserver/build.py | 3 +-- fdroidserver/common.py | 5 ++-- tests/common.TestCase | 52 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/fdroidserver/build.py b/fdroidserver/build.py index 2799dc1b..e8880c02 100644 --- a/fdroidserver/build.py +++ b/fdroidserver/build.py @@ -541,8 +541,7 @@ def build_local(app, build, vcs, build_dir, output_dir, log_dir, srclib_dir, ext # Substitute source library paths into commands... for name, number, libpath in srclibpaths: - libpath = os.path.relpath(libpath, root_dir) - cmd = cmd.replace('$$' + name + '$$', libpath) + cmd = cmd.replace('$$' + name + '$$', os.path.join(os.getcwd(), libpath)) p = FDroidPopen(['bash', '-x', '-c', cmd], cwd=root_dir) diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 04a17fd3..39c87aec 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -2116,8 +2116,7 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver= # Substitute source library paths into prebuild commands for name, number, libpath in srclibpaths: - libpath = os.path.relpath(libpath, root_dir) - cmd = cmd.replace('$$' + name + '$$', libpath) + cmd = cmd.replace('$$' + name + '$$', os.path.join(os.getcwd(), libpath)) p = FDroidPopen(['bash', '-x', '-c', '--', cmd], cwd=root_dir) if p.returncode != 0: @@ -2744,7 +2743,7 @@ def set_FDroidPopen_env(build=None): def replace_build_vars(cmd, build): cmd = cmd.replace('$$COMMIT$$', build.commit) cmd = cmd.replace('$$VERSION$$', build.versionName) - cmd = cmd.replace('$$VERCODE$$', build.versionCode) + cmd = cmd.replace('$$VERCODE$$', str(build.versionCode)) return cmd diff --git a/tests/common.TestCase b/tests/common.TestCase index 4dc51e5c..49e46af7 100755 --- a/tests/common.TestCase +++ b/tests/common.TestCase @@ -288,6 +288,58 @@ class CommonTest(unittest.TestCase): self.assertIsNotNone(re.search('android:versionName="%s"' % build.versionName, filedata)) self.assertIsNotNone(re.search('android:versionCode="%s"' % build.versionCode, filedata)) + def test_prepare_sources_with_prebuild_subdir(self): + testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir) + app_build_dir = os.path.join(testdir, 'build', 'com.example') + shutil.copytree(os.path.join(self.basedir, 'source-files', 'fdroid', 'fdroidclient'), + app_build_dir) + + subdir = 'baz/bar' + subdir_path = os.path.join(app_build_dir, subdir) + os.makedirs(subdir_path) + with open(os.path.join(subdir_path, 'build.gradle'), 'w') as fp: + fp.write('// just a test placeholder') + + config = dict() + fdroidserver.common.fill_config_defaults(config) + fdroidserver.common.config = config + + srclibname = 'FakeSrcLib' + srclib_testdir = os.path.join(testdir, 'build', 'srclib') + os.makedirs(os.path.join(srclib_testdir, srclibname, 'testdirshouldexist')) + fdroidserver.metadata.srclibs = { + srclibname: { + 'RepoType': 'git', + 'Repo': 'https://example.com/foo/fakesrclib', + 'Subdir': None, + 'Prepare': None, + } + } + + app = fdroidserver.metadata.App() + app.id = 'app.has.srclibs' + build = fdroidserver.metadata.Build() + build.commit = 'master' + build.gradle = ['yes'] + build.prebuild = 'test -d $$FakeSrcLib$$/testdirshouldexist' # actual test condition + build.srclibs = [srclibname + '@1.2.3'] + build.subdir = subdir + build.versionCode = 0xcafe + build.versionName = 'vCAFE' + + class FakeVcs(): + # no need to change to the correct commit here + def gotorevision(self, rev, refresh=True): + pass + + # no srclib info needed, but it could be added... + def getsrclib(self): + return None + + fdroidserver.common.prepare_source(FakeVcs(), app, build, + app_build_dir, srclib_testdir, app_build_dir, + onserver=True, refresh=False) # do not clone in this test + def test_prepare_sources_refresh(self): packageName = 'org.fdroid.ci.test.app' testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir) From 5fce16c8477752bc6d3233f829e3288ef90a4a69 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 24 Jun 2020 21:33:31 +0200 Subject: [PATCH 2/2] remove unused, confusing arg to common.getsrclib() --- fdroidserver/common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 39c87aec..374789b0 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -1841,7 +1841,7 @@ def parse_srclib_spec(spec): return (name, ref, number, subdir) -def getsrclib(spec, srclib_dir, subdir=None, basepath=False, +def getsrclib(spec, srclib_dir, basepath=False, raw=False, prepare=True, preponly=False, refresh=True, build=None): """Get the specified source library. @@ -1976,7 +1976,7 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver= if build.srclibs: logging.info("Collecting source libraries") for lib in build.srclibs: - srclibpaths.append(getsrclib(lib, srclib_dir, build, preponly=onserver, + srclibpaths.append(getsrclib(lib, srclib_dir, preponly=onserver, refresh=refresh, build=build)) for name, number, libpath in srclibpaths: