mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-04 22:40:12 +01:00
Merge branch 'gradle-clean' into 'master'
* gradle-clean: add test for things `fdroid build` cleans build: clean buildSrc/build build: fix directories removal See merge request fdroid/fdroidserver!750
This commit is contained in:
commit
dec6b9deed
@ -475,8 +475,7 @@ def build_local(app, build, vcs, build_dir, output_dir, log_dir, srclib_dir, ext
|
||||
|
||||
def del_dirs(dl):
|
||||
for d in dl:
|
||||
if d in dirs:
|
||||
shutil.rmtree(os.path.join(root, d))
|
||||
shutil.rmtree(os.path.join(root, d), ignore_errors=True)
|
||||
|
||||
def del_files(fl):
|
||||
for f in fl:
|
||||
@ -494,6 +493,7 @@ def build_local(app, build, vcs, build_dir, output_dir, log_dir, srclib_dir, ext
|
||||
os.path.join('build', 'outputs'),
|
||||
os.path.join('build', 'reports'),
|
||||
os.path.join('build', 'tmp'),
|
||||
os.path.join('buildSrc', 'build'),
|
||||
'.gradle'])
|
||||
del_files(['gradlew', 'gradlew.bat'])
|
||||
|
||||
|
@ -10,7 +10,9 @@ import re
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
import textwrap
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
localmodule = os.path.realpath(
|
||||
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
|
||||
@ -121,6 +123,79 @@ class BuildTest(unittest.TestCase):
|
||||
self.assertEqual(versionCode, vc)
|
||||
self.assertEqual(versionName, vn)
|
||||
|
||||
def test_build_local_clean(self):
|
||||
"""Test if `fdroid build` cleans ant and gradle build products"""
|
||||
testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
|
||||
os.chdir(testdir)
|
||||
|
||||
config = dict()
|
||||
fdroidserver.common.fill_config_defaults(config)
|
||||
fdroidserver.common.config = config
|
||||
fdroidserver.build.options = mock.Mock()
|
||||
fdroidserver.build.options.json = False
|
||||
fdroidserver.build.options.notarball = True
|
||||
fdroidserver.build.options.skipscan = False
|
||||
|
||||
app = fdroidserver.metadata.App()
|
||||
app.id = 'mocked.app.id'
|
||||
build = fdroidserver.metadata.Build()
|
||||
build.commit = '1.0'
|
||||
build.output = app.id + '.apk'
|
||||
build.scanignore = ['baz.so']
|
||||
build.versionCode = '1'
|
||||
build.versionName = '1.0'
|
||||
vcs = mock.Mock()
|
||||
|
||||
os.mkdir('reports')
|
||||
os.mkdir('target')
|
||||
|
||||
for f in ('baz.so', 'foo.aar', 'gradle-wrapper.jar'):
|
||||
with open(f, 'w') as fp:
|
||||
fp.write('placeholder')
|
||||
self.assertTrue(os.path.exists(f))
|
||||
|
||||
os.mkdir('build')
|
||||
os.mkdir('build/reports')
|
||||
with open('build.gradle', 'w') as fp:
|
||||
fp.write('// placeholder')
|
||||
|
||||
os.mkdir('bin')
|
||||
os.mkdir('gen')
|
||||
with open('build.xml', 'w') as fp:
|
||||
fp.write(textwrap.dedent(
|
||||
"""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<project basedir="." default="clean" name="mockapp">
|
||||
<target name="release"/>
|
||||
<target name="clean"/>
|
||||
</project>"""))
|
||||
|
||||
def make_fake_apk(output, build):
|
||||
with open(build.output, 'w') as fp:
|
||||
fp.write('APK PLACEHOLDER')
|
||||
return output
|
||||
|
||||
with mock.patch('fdroidserver.common.replace_build_vars', wraps=make_fake_apk):
|
||||
with mock.patch('fdroidserver.common.get_native_code', return_value='x86'):
|
||||
with mock.patch('fdroidserver.common.get_apk_id',
|
||||
return_value=(app.id, build.versionCode, build.versionName)):
|
||||
with mock.patch('fdroidserver.common.is_apk_and_debuggable', return_value=False):
|
||||
fdroidserver.build.build_local(
|
||||
app, build, vcs,
|
||||
build_dir=testdir, output_dir=testdir,
|
||||
log_dir=None, srclib_dir=None, extlib_dir=None, tmp_dir=None,
|
||||
force=False, onserver=False, refresh=False
|
||||
)
|
||||
|
||||
self.assertTrue(os.path.exists('baz.so'))
|
||||
self.assertTrue(os.path.exists('foo.aar'))
|
||||
self.assertTrue(os.path.isdir('build'))
|
||||
self.assertTrue(os.path.isdir('reports'))
|
||||
self.assertTrue(os.path.isdir('target'))
|
||||
self.assertFalse(os.path.exists('bin'))
|
||||
self.assertFalse(os.path.exists('build/reports'))
|
||||
self.assertFalse(os.path.exists('gen'))
|
||||
self.assertFalse(os.path.exists('gradle-wrapper.jar'))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.chdir(os.path.dirname(__file__))
|
||||
|
Loading…
Reference in New Issue
Block a user