1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-23 08:16:54 +00:00

reduce amount of setup_*.py files in toplevel dir

This commit is contained in:
Thomas Waldmann 2019-03-14 00:15:17 +01:00
parent 1579d58b3e
commit b516cf3c3f
5 changed files with 91 additions and 101 deletions

View file

@ -22,9 +22,7 @@
except ImportError:
cythonize = None
import setup_lz4
import setup_zstd
import setup_b2
import setup_compress
import setup_crypto
import setup_docs
@ -161,13 +159,13 @@ def members_appended(*ds):
crypto_ext_kwargs = members_appended(
dict(sources=[crypto_ll_source, crypto_helpers]),
setup_crypto.crypto_ext_kwargs(pc),
setup_b2.b2_ext_kwargs(pc, prefer_system_libb2),
setup_crypto.b2_ext_kwargs(pc, prefer_system_libb2),
)
compress_ext_kwargs = members_appended(
dict(sources=[compress_source]),
setup_lz4.lz4_ext_kwargs(pc, prefer_system_liblz4),
setup_zstd.zstd_ext_kwargs(pc, prefer_system_libzstd, multithreaded=False, legacy=False),
setup_compress.lz4_ext_kwargs(pc, prefer_system_liblz4),
setup_compress.zstd_ext_kwargs(pc, prefer_system_libzstd, multithreaded=False, legacy=False),
)
ext_modules += [

View file

@ -1,41 +0,0 @@
# Support code for building a C extension with blake2
import os
# b2 files, structure as seen in BLAKE2 (reference implementation) project repository:
# bundled_path: relative (to this file) path to the bundled library source code files
bundled_path = 'src/borg/algorithms/blake2'
b2_sources = [
'ref/blake2b-ref.c',
]
b2_includes = [
'ref',
]
def multi_join(paths, *path_segments):
"""apply os.path.join on a list of paths"""
return [os.path.join(*(path_segments + (path,))) for path in paths]
def b2_ext_kwargs(pc, prefer_system):
if prefer_system:
system_prefix = os.environ.get('BORG_LIBB2_PREFIX')
if system_prefix:
print('Detected and preferring libb2 [via BORG_LIBB2_PREFIX]')
return dict(include_dirs=[os.path.join(system_prefix, 'include')],
library_dirs=[os.path.join(system_prefix, 'lib')],
libraries=['b2'])
if pc and pc.installed('libb2', '>= 0.98.1'):
print('Detected and preferring libb2 [via pkg-config]')
return pc.parse('libb2')
print('Using bundled BLAKE2')
sources = multi_join(b2_sources, bundled_path)
include_dirs = multi_join(b2_includes, bundled_path)
define_macros = [('BORG_USE_BUNDLED_B2', 'YES')]
return dict(sources=sources, include_dirs=include_dirs, define_macros=define_macros)

View file

@ -1,11 +1,17 @@
# Support code for building a C extension with zstd
# Support code for building a C extension with compression code
import os
def multi_join(paths, *path_segments):
"""apply os.path.join on a list of paths"""
return [os.path.join(*(path_segments + (path,))) for path in paths]
# zstd files, structure as seen in zstd project repository:
# bundled_path: relative (to this file) path to the bundled library source code files
bundled_path = 'src/borg/algorithms/zstd'
# path relative (to this file) to the bundled library source code files
zstd_bundled_path = 'src/borg/algorithms/zstd'
zstd_sources = [
'lib/common/debug.c',
@ -63,11 +69,6 @@
]
def multi_join(paths, *path_segments):
"""apply os.path.join on a list of paths"""
return [os.path.join(*(path_segments + (path,))) for path in paths]
def zstd_ext_kwargs(pc, prefer_system, multithreaded=False, legacy=False):
if prefer_system:
system_prefix = os.environ.get('BORG_LIBZSTD_PREFIX')
@ -82,12 +83,12 @@ def zstd_ext_kwargs(pc, prefer_system, multithreaded=False, legacy=False):
return pc.parse('libzstd')
print('Using bundled ZSTD')
sources = multi_join(zstd_sources, bundled_path)
sources = multi_join(zstd_sources, zstd_bundled_path)
if legacy:
sources += multi_join(zstd_sources_legacy, bundled_path)
include_dirs = multi_join(zstd_includes, bundled_path)
sources += multi_join(zstd_sources_legacy, zstd_bundled_path)
include_dirs = multi_join(zstd_includes, zstd_bundled_path)
if legacy:
include_dirs += multi_join(zstd_includes_legacy, bundled_path)
include_dirs += multi_join(zstd_includes_legacy, zstd_bundled_path)
extra_compile_args = ['-DZSTDLIB_VISIBILITY=', '-DZDICTLIB_VISIBILITY=', '-DZSTDERRORLIB_VISIBILITY=', ]
# '-fvisibility=hidden' does not work, doesn't find PyInit_compress then
if legacy:
@ -97,3 +98,37 @@ def zstd_ext_kwargs(pc, prefer_system, multithreaded=False, legacy=False):
define_macros = [('BORG_USE_BUNDLED_ZSTD', 'YES')]
return dict(sources=sources, include_dirs=include_dirs,
extra_compile_args=extra_compile_args, define_macros=define_macros)
# lz4 files, structure as seen in lz4 project repository:
# path relative (to this file) to the bundled library source code files
lz4_bundled_path = 'src/borg/algorithms/lz4'
lz4_sources = [
'lib/lz4.c',
]
lz4_includes = [
'lib',
]
def lz4_ext_kwargs(pc, prefer_system):
if prefer_system:
system_prefix = os.environ.get('BORG_LIBLZ4_PREFIX')
if system_prefix:
print('Detected and preferring liblz4 [via BORG_LIBLZ4_PREFIX]')
return dict(include_dirs=[os.path.join(system_prefix, 'include')],
library_dirs=[os.path.join(system_prefix, 'lib')],
libraries=['lz4'])
if pc and pc.installed('liblz4', '>= 1.7.0'):
print('Detected and preferring liblz4 [via pkg-config]')
return pc.parse('liblz4')
print('Using bundled LZ4')
sources = multi_join(lz4_sources, lz4_bundled_path)
include_dirs = multi_join(lz4_includes, lz4_bundled_path)
define_macros = [('BORG_USE_BUNDLED_LZ4', 'YES')]
return dict(sources=sources, include_dirs=include_dirs, define_macros=define_macros)

View file

@ -1,8 +1,13 @@
# Support code for building a C extension with crypto from OpenSSL / LibreSSL
# Support code for building a C extension with crypto code
import os
def multi_join(paths, *path_segments):
"""apply os.path.join on a list of paths"""
return [os.path.join(*(path_segments + (path,))) for path in paths]
def crypto_ext_kwargs(pc):
system_prefix = os.environ.get('BORG_OPENSSL_PREFIX')
if system_prefix:
@ -16,3 +21,37 @@ def crypto_ext_kwargs(pc):
return pc.parse('libcrypto')
raise Exception('Could not find OpenSSL lib/headers, please set BORG_OPENSSL_PREFIX')
# b2 files, structure as seen in BLAKE2 (reference implementation) project repository:
# path relative (to this file) to the bundled library source code files
b2_bundled_path = 'src/borg/algorithms/blake2'
b2_sources = [
'ref/blake2b-ref.c',
]
b2_includes = [
'ref',
]
def b2_ext_kwargs(pc, prefer_system):
if prefer_system:
system_prefix = os.environ.get('BORG_LIBB2_PREFIX')
if system_prefix:
print('Detected and preferring libb2 [via BORG_LIBB2_PREFIX]')
return dict(include_dirs=[os.path.join(system_prefix, 'include')],
library_dirs=[os.path.join(system_prefix, 'lib')],
libraries=['b2'])
if pc and pc.installed('libb2', '>= 0.98.1'):
print('Detected and preferring libb2 [via pkg-config]')
return pc.parse('libb2')
print('Using bundled BLAKE2')
sources = multi_join(b2_sources, b2_bundled_path)
include_dirs = multi_join(b2_includes, b2_bundled_path)
define_macros = [('BORG_USE_BUNDLED_B2', 'YES')]
return dict(sources=sources, include_dirs=include_dirs, define_macros=define_macros)

View file

@ -1,41 +0,0 @@
# Support code for building a C extension with lz4 files
import os
# lz4 files, structure as seen in lz4 project repository:
# bundled_path: relative (to this file) path to the bundled library source code files
bundled_path = 'src/borg/algorithms/lz4'
lz4_sources = [
'lib/lz4.c',
]
lz4_includes = [
'lib',
]
def multi_join(paths, *path_segments):
"""apply os.path.join on a list of paths"""
return [os.path.join(*(path_segments + (path,))) for path in paths]
def lz4_ext_kwargs(pc, prefer_system):
if prefer_system:
system_prefix = os.environ.get('BORG_LIBLZ4_PREFIX')
if system_prefix:
print('Detected and preferring liblz4 [via BORG_LIBLZ4_PREFIX]')
return dict(include_dirs=[os.path.join(system_prefix, 'include')],
library_dirs=[os.path.join(system_prefix, 'lib')],
libraries=['lz4'])
if pc and pc.installed('liblz4', '>= 1.7.0'):
print('Detected and preferring liblz4 [via pkg-config]')
return pc.parse('liblz4')
print('Using bundled LZ4')
sources = multi_join(lz4_sources, bundled_path)
include_dirs = multi_join(lz4_includes, bundled_path)
define_macros = [('BORG_USE_BUNDLED_LZ4', 'YES')]
return dict(sources=sources, include_dirs=include_dirs, define_macros=define_macros)