#!/usr/bin/env python import sys import importlib import os import platform # Nuclex SCons libraries sys.path.append('../../BuildSystem/scons') nuclex = importlib.import_module('nuclex') archive = importlib.import_module('archive') # ----------------------------------------------------------------------------------------------- # universal_trantor_target_name = 'trantor' environment = nuclex.create_cplusplus_environment() #environment['ENV'] = os.environ #environment['CXX'] = 'clang++' # ----------------------------------------------------------------------------------------------- # # Step 0: preparatory work # Fetch the list of headers used when compiling trantor_headers_file = environment.File('trantor-headers') trantor_header_files = archive.split_lines(trantor_headers_file.get_text_contents()) # Fetch the list of sources to compile trantor trantor_sources_file = environment.File('trantor-sources') trantor_source_files = archive.split_lines(trantor_sources_file.get_text_contents()) if platform.system() == 'Windows': trantor_source_files.append('build/third_party/wepoll/Wepoll.c') trantor_source_files.append('build/trantor/utils/WindowsSupport.cc') # ----------------------------------------------------------------------------------------------- # # Step 1: Download the current release # Fetch the available download URLs from a file download_url_file = environment.File('trantor-download-urls') download_urls = archive.split_lines(download_url_file.get_text_contents()) # Determine the target filename for the download (below 'downloads' folder) archive_filename = os.path.basename(download_urls[0]) archive_file = environment.File(os.path.join('downloads', archive_filename)) # Tell SCons how to "produce" the downloaded archive (by calling wget) if not archive_file.exists(): download_archive = environment.Command( source = download_url_file, #action = 'wget ' + download_urls[0] + ' --output-document=$TARGET', action = archive.download_url_in_urlfile, target = archive_file ) # ----------------------------------------------------------------------------------------------- # # Step 2: Extract the release into the build directory def extract_compressed_tarball(target, source, env): """Extracts the distribution .tar.gz archive and applies a patch that ensures the same headers will work on Windows and average Linux distributions. @param target Output files, not used by the function but passed along so SCons can look at them and knows its dependency tree @param source Source files, expected to be an array containing the .tar.gz path and the unified diff path @param env SCons build environment""" print(str(source[0])) build_directory = env.Dir('build') print(str(build_directory)) archive.extract_compressed_tarball(str(source[0]), str(build_directory), 1) archive.apply_patch(str(source[1])) # Tell SCons how to "produce" the sources & headers (by calling tar) extract_archive = environment.Command( source = [ archive_file, 'visual-studio-2017-and-later.patch' ], #action = 'tar --extract --gzip --strip-components=1 --file=$SOURCE --directory=build', action = extract_compressed_tarball, target = trantor_source_files + trantor_header_files ) # ----------------------------------------------------------------------------------------------- # # Step 3: Compile the trantor library trantor_environment = environment.Clone() del trantor_environment['SOURCE_DIRECTORY'] # We define the sources ourselves trantor_environment['HEADER_DIRECTORY'] = 'build' trantor_environment.add_preprocessor_constant('HAVE_CONFIG_H') trantor_environment.add_preprocessor_constant('CARES_STATICLIB') trantor_environment.add_source_directory( 'build', trantor_source_files, scons_issue_2908_workaround_needed = True ) trantor_environment.add_project('../c-ares') trantor_environment.add_include_directory('build/trantor/utils') trantor_environment.add_include_directory('build/trantor/net') trantor_environment.add_include_directory('build/trantor/net/inner') if platform.system() == 'Windows': trantor_environment.add_include_directory('build/third_party/wepoll') compile_trantor_library = trantor_environment.build_library( universal_trantor_target_name, static = True ) # ----------------------------------------------------------------------------------------------- # # Step 4: Put the header in the main package directory for header in trantor_header_files: if header.startswith('build/'): install_path = os.path.join('Include', header[6:]) environment.InstallAs(install_path, header) # ----------------------------------------------------------------------------------------------- #