From fdcafc6d1b5a37734e85319ca81b44453b83e2f2 Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Thu, 13 Sep 2018 09:57:31 +0200 Subject: [PATCH] Update syncthing to v0.14.51-rc.2 (#43) * Update syncthing to v0.14.51-rc.1 * Update syncthing to v0.14.51-rc.2 * Update fdroid metadata * Update python build script Use prebuilt go binaries from google and check SHA-256 after downloading requires files from google. --- .gitignore | 4 + app/build.gradle | 4 +- ...com.github.catfriend1.syncthingandroid.yml | 22 ++--- syncthing/build-syncthing.py | 81 +++++++++++++++++-- syncthing/build.gradle | 1 + syncthing/src/github.com/syncthing/syncthing | 2 +- 6 files changed, 92 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index ead45993..78da3d92 100644 --- a/.gitignore +++ b/.gitignore @@ -29,5 +29,9 @@ project.properties gradle/wrapper/gradle/ gradle/wrapper/gradlew* +# Prebuilt-go +syncthing/go +syncthing/go.tgz + # External build artifacts ext/ diff --git a/app/build.gradle b/app/build.gradle index 5d0230e4..f6d160e0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -35,8 +35,8 @@ android { applicationId "com.github.catfriend1.syncthingandroid" minSdkVersion 16 targetSdkVersion 26 - versionCode 4154 - versionName "0.14.50.rc2.6" + versionCode 4156 + versionName "0.14.51.rc2.1" testApplicationId 'com.github.catfriend1.syncthingandroid.test' testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' playAccountConfig = playAccountConfigs.defaultAccountConfig diff --git a/fdroiddata/metadata/com.github.catfriend1.syncthingandroid.yml b/fdroiddata/metadata/com.github.catfriend1.syncthingandroid.yml index fce6390d..191e22e5 100644 --- a/fdroiddata/metadata/com.github.catfriend1.syncthingandroid.yml +++ b/fdroiddata/metadata/com.github.catfriend1.syncthingandroid.yml @@ -6,7 +6,7 @@ SourceCode: https://github.com/Catfriend1/syncthing-android IssueTracker: https://github.com/Catfriend1/syncthing-android/issues Changelog: https://github.com/Catfriend1/syncthing-android/releases -AutoName: Syncthing-Fork (Catfriend1) +AutoName: Syncthing-Fork Summary: File synchronization Description: |- This is a fork of [[com.nutomic.syncthingandroid]] that brings major @@ -27,24 +27,24 @@ RepoType: git Repo: https://github.com/Catfriend1/syncthing-android.git Builds: - - versionName: 0.14.50.rc2.5 - versionCode: 4153 - commit: v0.14.50.rc2.5 + - versionName: 0.14.50.rc2.6 + versionCode: 4154 + commit: v0.14.50.rc2.6 submodules: true - sudo: |- - apt-get install -y golang-1.9-go/testing - ln -s /usr/lib/go-1.9/bin/go /usr/bin/go gradle: - yes output: app/build/outputs/apk/release/app-release-unsigned.apk rm: - syncthing/src/github.com/syncthing/syncthing/lib/model/testdata prebuild: sed -i -e '/signingConfig/d' app/build.gradle + build: |- + wget -O go.tgz https://dl.google.com/go/go1.9.7.linux-amd64.tar.gz && \ + echo '88573008f4f6233b81f81d8ccf92234b4f67238df0f0ab173d75a302a1f3d6ee go.tgz' | shasum -c - && \ + tar xf go.tgz && \ + PATH="$PWD/go/bin:$PATH" gradle buildNative ndk: r15c - preassemble: - - buildNative AutoUpdateMode: Version v%v UpdateCheckMode: Tags ^v[a-z0-9.]*$ -CurrentVersion: 0.14.50.rc2.5 -CurrentVersionCode: 4153 +CurrentVersion: 0.14.50.rc2.6 +CurrentVersionCode: 4154 diff --git a/syncthing/build-syncthing.py b/syncthing/build-syncthing.py index f2a0501d..5f90aeb5 100644 --- a/syncthing/build-syncthing.py +++ b/syncthing/build-syncthing.py @@ -47,9 +47,66 @@ def get_min_sdk(project_dir): def get_ndk_home(): if not os.environ.get('ANDROID_NDK_HOME', ''): - fail('ANDROID_NDK_HOME environment variable not defined') + fail('Error: ANDROID_NDK_HOME environment variable not defined') return os.environ['ANDROID_NDK_HOME'] +def which(program): + import os + def is_exe(fpath): + return os.path.isfile(fpath) and os.access(fpath, os.X_OK) + + fpath, fname = os.path.split(program) + if fpath: + if is_exe(program): + return program + else: + for path in os.environ["PATH"].split(os.pathsep): + exe_file = os.path.join(path, program) + if is_exe(exe_file): + return exe_file + + return None + +def install_go(): + import os + import tarfile + import urllib + import hashlib + + # Consts. + pwd_path = os.path.dirname(os.path.realpath(__file__)) + url = 'https://dl.google.com/go/go1.9.7.linux-amd64.tar.gz' + expected_shasum = '88573008f4f6233b81f81d8ccf92234b4f67238df0f0ab173d75a302a1f3d6ee' + + # Download prebuilt-go. + url_base_name = os.path.basename(url) + tar_gz_fullfn = pwd_path + os.path.sep + 'go.tgz'; + if not os.path.isfile(tar_gz_fullfn): + print('Downloading prebuilt-go tar to:', tar_gz_fullfn) + tar_gz_fullfn = urllib.urlretrieve(url, tar_gz_fullfn)[0] + print('Downloaded prebuilt-go tar to:', tar_gz_fullfn) + + # Verfiy SHA-1 checksum of downloaded files. + with open(tar_gz_fullfn, 'rb') as f: + contents = f.read() + found_shasum = hashlib.sha256(contents).hexdigest() + print("SHA-256:", tar_gz_fullfn, "%s" % found_shasum) + if found_shasum != expected_shasum: + fail('Error: SHA-256 checksum', found_shasum, 'of downloaded file does not match expected checksum', expected_shasum) + print("[ok] Checksum of", tar_gz_fullfn, "matches expected value.") + + # Proceed with extraction of the prebuilt go. + # This will go to a subfolder "go" in the current path. + print("Extracting prebuilt-go ...") + file_name, file_extension = os.path.splitext(url_base_name) + tar = tarfile.open(tar_gz_fullfn) + tar.extractall(pwd_path) + + # Add (...).tar/go/bin" to the PATH. + go_bin_path = pwd_path + os.path.sep + 'go' + os.path.sep + 'bin' + print('Adding to PATH:', go_bin_path) + os.environ["PATH"] += os.pathsep + go_bin_path + if platform.system() not in SUPPORTED_PYTHON_PLATFORMS: fail('Unsupported python platform %s. Supported platforms: %s', platform.system(), @@ -63,6 +120,18 @@ go_build_dir = os.path.join(build_dir, 'go-packages') syncthing_dir = os.path.join(module_dir, 'src', 'github.com', 'syncthing', 'syncthing') min_sdk = get_min_sdk(project_dir) +# Check if go is available. +go_bin = which("go"); +if not go_bin: + print('Warning: go is not available on the PATH.') + install_go(); + +# Retry: Check if go is available. +go_bin = which("go"); +if not go_bin: + fail('Error: go is not available on the PATH.') +print ('go_bin [', go_bin, ']') + # Make sure all tags are available for git describe # https://github.com/syncthing/syncthing-android/issues/872 subprocess.check_call([ @@ -79,16 +148,12 @@ for target in BUILD_TARGETS: if os.environ.get('SYNCTHING_ANDROID_PREBUILT', ''): # The environment variable indicates the SDK and stdlib was prebuilt, set a custom paths. - standalone_ndk_dir = '%s/standalone-ndk/android-%s-%s' % ( - get_ndk_home(), target_min_sdk, target['goarch'] - ) + standalone_ndk_dir = get_ndk_home() + os.path.sep + 'standalone-ndk' + os.path.sep + 'android-' + target_min_sdk + '-' + target['goarch'] pkg_argument = [] else: # Build standalone NDK toolchain if it doesn't exist. # https://developer.android.com/ndk/guides/standalone_toolchain.html - standalone_ndk_dir = '%s/standalone-ndk/android-%s-%s' % ( - build_dir, target_min_sdk, target['goarch'] - ) + standalone_ndk_dir = build_dir + os.path.sep + 'standalone-ndk' + os.path.sep + 'android-' + target_min_sdk + '-' + target['goarch'] pkg_argument = ['-pkgdir', os.path.join(go_build_dir, target['goarch'])] if not os.path.isdir(standalone_ndk_dir): @@ -122,7 +187,7 @@ for target in BUILD_TARGETS: syncthingVersion = syncthingVersion.replace("rc", "preview"); print('Building syncthing version', syncthingVersion); subprocess.check_call([ - 'go', 'run', 'build.go', '-goos', 'android', '-goarch', target['goarch'], + go_bin, 'run', 'build.go', '-goos', 'android', '-goarch', target['goarch'], '-version', syncthingVersion ] + pkg_argument + ['-no-upgrade', 'build'], env=environ, cwd=syncthing_dir) diff --git a/syncthing/build.gradle b/syncthing/build.gradle index 7816eb00..437af669 100644 --- a/syncthing/build.gradle +++ b/syncthing/build.gradle @@ -11,4 +11,5 @@ task buildNative(type: Exec) { task cleanNative(type: Delete) { delete "$projectDir/../app/src/main/jniLibs/" delete "gobuild" + delete "go" } diff --git a/syncthing/src/github.com/syncthing/syncthing b/syncthing/src/github.com/syncthing/syncthing index 7c0798b6..49d5eae6 160000 --- a/syncthing/src/github.com/syncthing/syncthing +++ b/syncthing/src/github.com/syncthing/syncthing @@ -1 +1 @@ -Subproject commit 7c0798b6224e6407e3b0872b204b6fc224d70325 +Subproject commit 49d5eae66a979596a229ce1ac95cfc7da11e4bf8