import json
import os
import shutil
import subprocess
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
DUCKDB_SCRIPTS_DIR = os.path.join(SCRIPT_DIR, "duckdb-sources", "scripts")
TARGET_DIR = os.path.join(SCRIPT_DIR, "duckdb")
SRC_DIR = os.path.join(SCRIPT_DIR, "src")
EXTENSIONS = ["parquet", "json", "httpfs"]
try:
shutil.rmtree(os.path.join(TARGET_DIR))
os.remove(os.path.join(SCRIPT_DIR, "duckdb.tar.gz"))
except FileNotFoundError:
pass
os.mkdir(TARGET_DIR)
import sys
sys.path.append(DUCKDB_SCRIPTS_DIR)
import package_build
def get_sources(extensions):
(source_list, include_list, _) = package_build.build_package(
TARGET_DIR, extensions, False
)
source_list = [
x[len(SCRIPT_DIR) + 1 :] if x.startswith(SCRIPT_DIR) else x for x in source_list
]
return set(source_list), set(include_list)
base_source_list, base_include_list = get_sources([])
extension_sources = {}
for e in EXTENSIONS:
source_list, include_list = get_sources([e])
extension_sources[e] = {
"cpp_files": list(source_list - base_source_list),
"include_dirs": list(include_list - base_include_list),
}
manifest = {
"base": {
"cpp_files": list(base_source_list),
"include_dirs": list(base_include_list),
},
"extensions": extension_sources,
}
with open(os.path.join(TARGET_DIR, "manifest.json"), "w") as f:
json.dump(manifest, f, indent=2)
subprocess.check_call(
"tar -czf duckdb.tar.gz duckdb",
shell=True,
cwd=SCRIPT_DIR,
)
subprocess.check_call(
'find "' + SCRIPT_DIR + '/../target" -type f -name bindgen.rs -exec rm {} \;',
shell=True,
)
subprocess.check_call(
'env LIBDUCKDB_SYS_BUNDLING=1 cargo test --features "bundled buildtime_bindgen"',
shell=True,
)
print(
'find "'
+ SCRIPT_DIR
+ '/../target" -type f -name "bindgen.rs" -exec cp {} "'
+ SRC_DIR
+ '/bindgen_bundled_version.rs" \;'
)
subprocess.check_call(
'find "'
+ SCRIPT_DIR
+ '/../target" -type f -name "bindgen.rs" -exec cp {} "'
+ SRC_DIR
+ '/bindgen_bundled_version.rs" \;',
shell=True,
)