chiark / gitweb /
Merge branch 'some-compatibility-fixes' of https://gitlab.com/eighthave/fdroidserver
[fdroidserver.git] / fdroidserver / build.py
index 02faf38e19f8253e4d965e16d37653b7b8378d18..84af7f41c5b0497e422a36bf6aa7833771a59227 100644 (file)
@@ -348,8 +348,7 @@ def build_server(app, thisbuild, vcs, build_dir, output_dir, force):
         if thisbuild['srclibs']:
             for lib in thisbuild['srclibs']:
                 srclibpaths.append(
-                    common.getsrclib(lib, 'build/srclib', srclibpaths,
-                                     basepath=True, prepare=False))
+                    common.getsrclib(lib, 'build/srclib', basepath=True, prepare=False))
 
         # If one was used for the main source, add that too.
         basesrclib = vcs.getsrclib()
@@ -428,13 +427,18 @@ def build_server(app, thisbuild, vcs, build_dir, output_dir, force):
 
 
 def adapt_gradle(build_dir):
+    filename = 'build.gradle'
     for root, dirs, files in os.walk(build_dir):
-        if 'build.gradle' in files:
-            path = os.path.join(root, 'build.gradle')
-            logging.debug("Adapting build.gradle at %s" % path)
+        for filename in files:
+            if not filename.endswith('.gradle'):
+                continue
+            path = os.path.join(root, filename)
+            if not os.path.isfile(path):
+                continue
+            logging.debug("Adapting %s at %s" % (filename, path))
 
             FDroidPopen(['sed', '-i',
-                         r's@buildToolsVersion\([ =]*\)["\'][0-9\.]*["\']@buildToolsVersion\1"'
+                         r's@buildToolsVersion\([ =]\+\).*@buildToolsVersion\1"'
                          + config['build_tools'] + '"@g', path])
 
 
@@ -448,7 +452,7 @@ def capitalize_intact(string):
     return string[0].upper() + string[1:]
 
 
-def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_dir, tmp_dir, force, onserver):
+def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_dir, tmp_dir, force, onserver, refresh):
     """Do a build locally."""
 
     if thisbuild['buildjni'] and thisbuild['buildjni'] != ['no']:
@@ -475,7 +479,7 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
     # Prepare the source code...
     root_dir, srclibpaths = common.prepare_source(vcs, app, thisbuild,
                                                   build_dir, srclib_dir,
-                                                  extlib_dir, onserver)
+                                                  extlib_dir, onserver, refresh)
 
     # We need to clean via the build tool in case the binary dirs are
     # different from the default ones
@@ -513,7 +517,12 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
             adapt_gradle(libpath)
 
         cmd = [config['gradle']]
-        cmd += ['clean' + capitalize_intact(task) for task in gradletasks]
+        for task in gradletasks:
+            parts = task.split(':')
+            parts[-1] = 'clean' + capitalize_intact(parts[-1])
+            cmd += [':'.join(parts)]
+
+        cmd += ['clean']
 
         p = FDroidPopen(cmd, cwd=root_dir)
 
@@ -565,7 +574,7 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
     # Run a build command if one is required...
     if thisbuild['build']:
         logging.info("Running 'build' commands in %s" % root_dir)
-        cmd = common.replace_config_vars(thisbuild['build'])
+        cmd = common.replace_config_vars(thisbuild['build'], thisbuild)
 
         # Substitute source library paths into commands...
         for name, number, libpath in srclibpaths:
@@ -867,7 +876,7 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
 
 
 def trybuild(app, thisbuild, build_dir, output_dir, also_check_dir, srclib_dir, extlib_dir,
-             tmp_dir, repo_dir, vcs, test, server, force, onserver):
+             tmp_dir, repo_dir, vcs, test, server, force, onserver, refresh):
     """
     Build a particular version of an application, if it needs building.
 
@@ -912,7 +921,7 @@ def trybuild(app, thisbuild, build_dir, output_dir, also_check_dir, srclib_dir,
 
         build_server(app, thisbuild, vcs, build_dir, output_dir, force)
     else:
-        build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_dir, tmp_dir, force, onserver)
+        build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_dir, tmp_dir, force, onserver, refresh)
     return True
 
 
@@ -940,6 +949,8 @@ def parse_commandline():
                       help="Skip scanning the source code for binaries and other problems")
     parser.add_option("--no-tarball", dest="notarball", action="store_true", default=False,
                       help="Don't create a source tarball, useful when testing a build")
+    parser.add_option("--no-refresh", dest="refresh", action="store_false", default=True,
+                      help="Don't refresh the repository, useful when testing a build with no internet connection")
     parser.add_option("-f", "--force", action="store_true", default=False,
                       help="Force build of disabled apps, and carries on regardless of scan problems. Only allowed in test mode.")
     parser.add_option("-a", "--all", action="store_true", default=False,
@@ -1065,7 +1076,7 @@ def main():
                             also_check_dir, srclib_dir, extlib_dir,
                             tmp_dir, repo_dir, vcs, options.test,
                             options.server, options.force,
-                            options.onserver):
+                            options.onserver, options.refresh):
 
                     if app.get('Binaries', None):
                         # This is an app where we build from source, and
@@ -1079,9 +1090,7 @@ def main():
                         logging.info("...retrieving " + url)
                         of = "{0}_{1}.apk.binary".format(app['id'], thisbuild['vercode'])
                         of = os.path.join(output_dir, of)
-                        p = FDroidPopen(['wget', '-nv', '-O', of, url])
-                        if p.returncode != 0 or not os.path.exists(of):
-                            raise BuildException("...failed to retrieve " + url)
+                        common.download_file(url, local_filename=of)
 
                     build_succeeded.append(app)
                     wikilog = "Build succeeded"