From d7a7d67d1bb875d3463a0fef9c0bdf6e48d3511d Mon Sep 17 00:00:00 2001 From: akwizgran <michael@briarproject.org> Date: Thu, 10 Mar 2022 17:09:16 +0000 Subject: [PATCH] Use a different output dir for each platform. --- build_tor_android.py | 34 ++++++++++++++++++---------------- build_tor_linux.py | 19 +++++++++---------- build_tor_windows.py | 15 +++++++-------- utils.py | 17 ++++++++++------- 4 files changed, 44 insertions(+), 41 deletions(-) diff --git a/build_tor_android.py b/build_tor_android.py index bb5eb57..44659fc 100755 --- a/build_tor_android.py +++ b/build_tor_android.py @@ -4,20 +4,20 @@ from shutil import rmtree, move, copy from subprocess import check_call import utils -from utils import get_sha256, fail, BUILD_DIR, OUTPUT_DIR, reset_time +from utils import get_sha256, fail, BUILD_DIR, get_output_dir, reset_time NDK_DIR = 'android-ndk' PLATFORM = "android" def build(): - versions, _ = utils.setup(PLATFORM) + versions, jar_name = utils.setup(PLATFORM) setup_android_ndk(versions) build_android(versions) - package_android(versions) + package_android(versions, jar_name) def setup_android_ndk(versions): @@ -91,16 +91,17 @@ def build_android(versions): def build_android_arch(name, env, versions): print("Building %s" % name) + output_dir = get_output_dir(PLATFORM) # TODO add extra flags to configure? # '--enable-static-tor', # '--enable-static-zlib', check_call(['make', 'clean', 'tor'], cwd=BUILD_DIR, env=env) - tor_path = os.path.join(OUTPUT_DIR, 'tor') + tor_path = os.path.join(output_dir, 'tor') # note: stripping happens in makefile for now copy(os.path.join(BUILD_DIR, 'tor', 'src', 'app', 'tor'), tor_path) reset_time(tor_path, versions) print("Sha256 hash of tor before zipping %s: %s" % (name, get_sha256(tor_path))) - check_call(['zip', '--no-dir-entries', '--junk-paths', '-X', name, 'tor'], cwd=OUTPUT_DIR) + check_call(['zip', '--no-dir-entries', '--junk-paths', '-X', name, 'tor'], cwd=output_dir) def apply_tor_patch(commit): @@ -110,18 +111,19 @@ def apply_tor_patch(commit): check_call(['git', 'apply', commit + '.patch'], cwd=tor_path) -def package_android(versions): - # zip Android binaries together - file_list_android = [ - os.path.join(OUTPUT_DIR, 'tor_arm_pie.zip'), - os.path.join(OUTPUT_DIR, 'tor_arm64_pie.zip'), - os.path.join(OUTPUT_DIR, 'tor_x86_pie.zip'), - os.path.join(OUTPUT_DIR, 'tor_x86_64_pie.zip'), +def package_android(versions, jar_name): + # zip binaries together + output_dir = get_output_dir(PLATFORM) + file_list = [ + os.path.join(output_dir, 'tor_arm_pie.zip'), + os.path.join(output_dir, 'tor_arm64_pie.zip'), + os.path.join(output_dir, 'tor_x86_pie.zip'), + os.path.join(output_dir, 'tor_x86_64_pie.zip'), ] - zip_name_android = utils.pack(versions, file_list_android, PLATFORM) - pom_name_android = utils.create_pom_file(versions, PLATFORM) - print("Android:") - for file in file_list_android + [zip_name_android, pom_name_android]: + zip_name = utils.pack(versions, file_list, PLATFORM) + pom_name = utils.create_pom_file(versions, PLATFORM) + print("%s:" % PLATFORM) + for file in file_list + [zip_name, jar_name, pom_name]: sha256hash = get_sha256(file) print("%s: %s" % (file, sha256hash)) diff --git a/build_tor_linux.py b/build_tor_linux.py index 78ab799..2db28c8 100755 --- a/build_tor_linux.py +++ b/build_tor_linux.py @@ -4,7 +4,7 @@ from shutil import rmtree, copy from subprocess import check_call import utils -from utils import BUILD_DIR, OUTPUT_DIR, TOR_CONFIGURE_FLAGS, OPENSSL_CONFIGURE_FLAGS, REPRODUCIBLE_GCC_CFLAGS, \ +from utils import BUILD_DIR, get_output_dir, TOR_CONFIGURE_FLAGS, OPENSSL_CONFIGURE_FLAGS, REPRODUCIBLE_GCC_CFLAGS, \ XZ_CONFIGURE_FLAGS, reset_time, get_sha256, pack, create_pom_file PLATFORM = "linux" @@ -114,27 +114,26 @@ def build_linux_arch(arch, gcc_arch, cc_env, openssl_target, autogen_host, versi check_call(['make', '-j', str(os.cpu_count()), 'install'], cwd=tor_dir, env=env) # copy and zip built Tor binary - tor_path = os.path.join(OUTPUT_DIR, 'tor') + output_dir = get_output_dir(PLATFORM) + tor_path = os.path.join(output_dir, 'tor') copy(os.path.join(BUILD_DIR, 'tor', 'src', 'app', 'tor'), tor_path) check_call(['strip', '-D', '--strip-unneeded', '--strip-debug', '-R', '.note*', '-R', '.comment', tor_path]) reset_time(tor_path, versions) print("Sha256 hash of tor before zipping %s: %s" % (name, get_sha256(tor_path))) - check_call(['zip', '--no-dir-entries', '--junk-paths', '-X', name, 'tor'], cwd=OUTPUT_DIR) + check_call(['zip', '--no-dir-entries', '--junk-paths', '-X', name, 'tor'], cwd=output_dir) def package_linux(versions, jar_name): # zip binaries together + output_dir = get_output_dir(PLATFORM) file_list = [ - os.path.join(OUTPUT_DIR, 'tor_linux-aarch64.zip'), - os.path.join(OUTPUT_DIR, 'tor_linux-armhf.zip'), - os.path.join(OUTPUT_DIR, 'tor_linux-x86_64.zip'), + os.path.join(output_dir, 'tor_linux-aarch64.zip'), + os.path.join(output_dir, 'tor_linux-armhf.zip'), + os.path.join(output_dir, 'tor_linux-x86_64.zip'), ] zip_name = pack(versions, file_list, PLATFORM) - - # create POM file from template pom_name = create_pom_file(versions, PLATFORM) - - # print hashes for debug purposes + print("%s:" % PLATFORM) for file in file_list + [zip_name, jar_name, pom_name]: sha256hash = get_sha256(file) print("%s: %s" % (file, sha256hash)) diff --git a/build_tor_windows.py b/build_tor_windows.py index e05b607..94ea91f 100755 --- a/build_tor_windows.py +++ b/build_tor_windows.py @@ -4,7 +4,7 @@ from shutil import rmtree, copy from subprocess import check_call import utils -from utils import BUILD_DIR, OUTPUT_DIR, TOR_CONFIGURE_FLAGS, OPENSSL_CONFIGURE_FLAGS, REPRODUCIBLE_GCC_CFLAGS, \ +from utils import BUILD_DIR, get_output_dir, TOR_CONFIGURE_FLAGS, OPENSSL_CONFIGURE_FLAGS, REPRODUCIBLE_GCC_CFLAGS, \ XZ_CONFIGURE_FLAGS, reset_time, get_sha256 PLATFORM = "windows" @@ -115,25 +115,24 @@ def build_windows_arch(arch, host, versions): check_call(['make', 'install'], cwd=tor_dir, env=env) # copy and zip built Tor binary - tor_path = os.path.join(OUTPUT_DIR, 'tor') + output_dir = get_output_dir(PLATFORM) + tor_path = os.path.join(output_dir, 'tor') copy(os.path.join(prefix_dir, 'bin', 'tor.exe'), tor_path) check_call(['strip', '-D', '--strip-unneeded', '--strip-debug', '-R', '.note*', '-R', '.comment', tor_path]) reset_time(tor_path, versions) print("Sha256 hash of tor before zipping %s: %s" % (name, get_sha256(tor_path))) - check_call(['zip', '--no-dir-entries', '--junk-paths', '-X', name, 'tor'], cwd=OUTPUT_DIR) + check_call(['zip', '--no-dir-entries', '--junk-paths', '-X', name, 'tor'], cwd=output_dir) def package_windows(versions, jar_name): # zip binaries together + output_dir = get_output_dir(PLATFORM) file_list = [ - os.path.join(OUTPUT_DIR, 'tor_windows-x86_64.zip'), + os.path.join(output_dir, 'tor_windows-x86_64.zip'), ] zip_name = utils.pack(versions, file_list, PLATFORM) - - # create POM file from template pom_name = utils.create_pom_file(versions, PLATFORM) - - # print hashes for debug purposes + print("%s:" % PLATFORM) for file in file_list + [zip_name, jar_name, pom_name]: sha256hash = utils.get_sha256(file) print("%s: %s" % (file, sha256hash)) diff --git a/utils.py b/utils.py index ee2b82d..ce725f9 100644 --- a/utils.py +++ b/utils.py @@ -9,7 +9,6 @@ from shutil import copy, rmtree from subprocess import check_call BUILD_DIR = 'tor-build' -OUTPUT_DIR = os.path.abspath(os.path.join(BUILD_DIR, 'output')) TOR_CONFIGURE_FLAGS = [ '--disable-asciidoc', '--disable-systemd', @@ -54,6 +53,8 @@ OPENSSL_CONFIGURE_FLAGS = [ ] REPRODUCIBLE_GCC_CFLAGS = '-fno-guess-branch-probability -frandom-seed="0"' +def get_output_dir(platform): + return os.path.abspath(os.path.join(BUILD_DIR, 'output', platform)) def setup(platform): # get Tor version from command or show usage information @@ -64,9 +65,10 @@ def setup(platform): print("Building Tor %s" % versions['tor']['commit']) # remove output from previous build - if os.path.isdir(OUTPUT_DIR): - rmtree(OUTPUT_DIR) - os.makedirs(OUTPUT_DIR) + output_dir = get_output_dir(platform) + if os.path.isdir(output_dir): + rmtree(output_dir) + os.makedirs(output_dir) # clone and checkout repos based on tor-versions.json prepare_repos(versions) @@ -176,6 +178,7 @@ def reset_time(filename, versions): def create_sources_jar(versions, platform): + output_dir = get_output_dir(platform) jar_files = [] for root, dir_names, filenames in os.walk(BUILD_DIR): for f in filenames: @@ -186,13 +189,13 @@ def create_sources_jar(versions, platform): reset_time(file, versions) jar_name = get_sources_file_name(versions, platform) jar_path = os.path.abspath(jar_name) - rel_paths = [os.path.relpath(f, OUTPUT_DIR) for f in sorted(jar_files)] + rel_paths = [os.path.relpath(f, output_dir) for f in sorted(jar_files)] # create jar archive with first files jar_step = 5000 - check_call(['jar', 'cf', jar_path] + rel_paths[0:jar_step], cwd=OUTPUT_DIR) + check_call(['jar', 'cf', jar_path] + rel_paths[0:jar_step], cwd=output_dir) # add subsequent files in steps, because the command line can't handle all at once for i in range(jar_step, len(rel_paths), jar_step): - check_call(['jar', 'uf', jar_path] + rel_paths[i:i + jar_step], cwd=OUTPUT_DIR) + check_call(['jar', 'uf', jar_path] + rel_paths[i:i + jar_step], cwd=output_dir) return jar_name -- GitLab