Define and check out all dependency versions before building

parent 3fcfb81e
Pipeline #2561 passed with stages
in 5 minutes and 3 seconds
......@@ -9,8 +9,8 @@ from utils import get_build_versions, ex, get_sha256, fail, zip_files, get_final
NDK_DIR = 'android-ndk'
REPO_DIR = 'obfs4'
SOURCE = 'obfs4/obfs4proxy/*'
GO_FLAGS = ['-asmflags', '-trimpath', '-o', 'obfs4proxy']
GO_PATH = os.environ.get("GOPATH", os.path.expanduser('~/go'))
def main():
......@@ -24,17 +24,14 @@ def main():
# Setup Android NDK
setup_android_ndk(versions)
# Clone or reset the git repository
prepare_repo(versions)
# Install dependencies (of git HEAD)
ex(['go', 'get', '-d', versions['obfs4']['got-get']])
# Fetch and checkout dependencies at specific version
checkout_source_repos(versions)
# Build for various Android versions and create package
build_android()
build_android(versions)
# Build for 64-bit Linux and create package
build_linux()
build_linux(versions)
# Package both builds
package_android(versions)
......@@ -79,46 +76,59 @@ def setup_android_ndk(versions):
os.putenv('ANDROID_NDK_HOME', os.path.abspath(NDK_DIR))
def prepare_repo(versions):
if os.path.isdir(REPO_DIR):
# get latest commits and tags from remote
check_call(['git', 'fetch', 'origin'], cwd=REPO_DIR)
else:
# clone repo
url = versions['obfs4']['url']
check_call(['git', 'clone', url, REPO_DIR])
def checkout_source_repos(versions):
# download dependencies
ex(['go', 'get', '-d', versions['obfs4']['go-get']])
# find dependencies
go_src = os.path.join(GO_PATH, 'src')
dependencies = []
for root, dirs, files in os.walk(go_src):
if root.endswith("/.git"):
dependencies.append(os.path.split(root)[0])
# checkout specific versions
for dependency in dependencies:
# get version (commit or tag)
key = os.path.split(dependency)[1]
try:
version = versions['obfs4']['versions'][key]
except KeyError as e:
fail("Version for dependency '%s' missing." % key)
raise e
# checkout tag
check_call(['git', 'checkout', '-f', versions['obfs4']['tag']], cwd=REPO_DIR)
# checkout tag
print("Checking out %s in %s" % (version, dependency))
check_call(['git', 'checkout', '-f', version], cwd=dependency)
# undo all changes
check_call(['git', 'reset', '--hard'], cwd=REPO_DIR)
# undo all changes
check_call(['git', 'reset', '--hard'], cwd=dependency)
# clean all untracked files and directories (-d) from repo
check_call(['git', 'clean', '-dffx'], cwd=REPO_DIR)
# clean all untracked files and directories (-d) from repo
check_call(['git', 'clean', '-dffx'], cwd=dependency)
def build_android():
def build_android(versions):
env = os.environ.copy()
env['GOARCH'] = "arm"
env['GOARM'] = "7"
build_android_arch(env, "arm-linux-androideabi", ndk_arch="arm", pie=False)
build_android_arch(versions, env, "arm-linux-androideabi", ndk_arch="arm", pie=False)
env = os.environ.copy()
env['GOARCH'] = "arm"
env['GOARM'] = "7"
build_android_arch(env, "arm-linux-androideabi", ndk_arch="arm", pie=True)
build_android_arch(versions, env, "arm-linux-androideabi", ndk_arch="arm", pie=True)
env = os.environ.copy()
env['GOARCH'] = "386"
build_android_arch(env, "i686-linux-android", ndk_arch="x86", pie=False)
build_android_arch(versions, env, "i686-linux-android", ndk_arch="x86", pie=False)
env = os.environ.copy()
env['GOARCH'] = "386"
build_android_arch(env, "i686-linux-android", ndk_arch="x86", pie=True)
build_android_arch(versions, env, "i686-linux-android", ndk_arch="x86", pie=True)
def build_android_arch(env, tool, ndk_arch, pie):
def build_android_arch(versions, env, tool, ndk_arch, pie):
toolchain = os.path.join("toolchain", ndk_arch)
if not os.path.isdir(toolchain):
toolchain_maker = os.path.join(NDK_DIR, "build", "tools", "make-standalone-toolchain.sh")
......@@ -133,23 +143,19 @@ def build_android_arch(env, tool, ndk_arch, pie):
extldflags = " -extldflags=-pie" if pie else ""
ex(['go', 'build', '-buildmode=%s' % build_mode, '-ldflags',
'-w -s' + extldflags] + GO_FLAGS + get_sources(), env=env)
'-w -s' + extldflags] + GO_FLAGS + [versions['obfs4']['go-get']], env=env)
pie_suffix = '_pie' if pie else ''
zip_files(['obfs4proxy'], 'obfs4proxy_%s%s.zip' % (ndk_arch, pie_suffix))
os.remove('obfs4proxy')
def build_linux():
ex(['go', 'build', '-ldflags', '-w -s'] + GO_FLAGS + get_sources())
def build_linux(versions):
ex(['go', 'build', '-ldflags', '-w -s'] + GO_FLAGS + [versions['obfs4']['go-get']])
zip_files(['obfs4proxy'], 'obfs4proxy_linux-x86_64.zip')
os.remove('obfs4proxy')
def get_sources():
return sorted(glob(SOURCE))
def package_android(versions):
file_list = ['obfs4proxy_arm.zip', 'obfs4proxy_arm_pie.zip',
'obfs4proxy_x86.zip', 'obfs4proxy_x86_pie.zip']
......@@ -164,23 +170,25 @@ def package_linux(versions):
def package(versions, file_list, android):
zip_file = get_final_file_name(versions, android)
zip_files(file_list, zip_file)
jar_file = create_sources_jar(versions)
pom_file = create_pom_file(versions, android)
create_sources_jar(versions)
create_pom_file(versions, android)
# print hashes for debug purposes
for file in file_list + [zip_file]:
sha256hash = get_sha256(file)
print("%s: %s" % (file, sha256hash))
prefix = '->' if file == zip_file else ''
print("%s %s: %s" % (prefix, file, sha256hash))
def create_sources_jar(versions):
check_call(['git', 'clean', '-dfx'], cwd=REPO_DIR)
jar_files = glob(SOURCE)
for file in jar_files:
jar_files = []
go_src = os.path.join(GO_PATH, 'src')
for file in glob(os.path.join(go_src, '*')):
reset_time(file)
jar_files.append(os.path.relpath(file, go_src))
jar_file = get_sources_file_name(versions)
jar_path = os.path.abspath(jar_file)
check_call(['jar', 'cf', jar_path] + jar_files)
check_call(['jar', 'cf', jar_path] + jar_files, cwd=go_src)
return jar_file
......
......@@ -51,7 +51,10 @@ def zip_files(files, zip_name):
def get_obfs4_version(versions):
return versions['obfs4']['tag'].split('-')[1]
version = versions['obfs4']['versions']['obfs4.git']
if '-' in version:
return version.split('-')[1]
return version
def get_file_suffix(versions, android=False):
......
{
"0.0.7": {
"obfs4": {
"url": "https://git.torproject.org/pluggable-transports/obfs4.git",
"got-get": "git.torproject.org/pluggable-transports/obfs4.git/obfs4proxy",
"tag": "obfs4proxy-0.0.7"
"go-get": "git.torproject.org/pluggable-transports/obfs4.git/obfs4proxy",
"versions": {
"obfs4.git": "obfs4proxy-0.0.7",
"goptlib.git": "7d56ec4f381e",
"crypto": "0c41d7ab0a0e",
"net": "49bb7cea24b1",
"siphash": "v1.2.0",
"ed25519": "5312a6153412"
}
},
"go": {
"version": "go1.10.3"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment