Skip to content

Commit

Permalink
add platform/version detection script
Browse files Browse the repository at this point in the history
  • Loading branch information
samansmink committed Nov 7, 2024
1 parent bb3809d commit 795955c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
25 changes: 22 additions & 3 deletions scripts/append_extension_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def main():

arg_parser.add_argument('-dv', '--duckdb-version', type=str, help='The DuckDB version to encode, depending on the ABI type '
'this encodes the duckdb version or the C API version', required=True)
arg_parser.add_argument('-ev', '--extension-version', type=str, help='The Extension version to encode', required=True)
arg_parser.add_argument('-ev', '--extension-version', type=str, help='The Extension version to encode')
arg_parser.add_argument('-evf', '--extension-version-file', type=str, help='The file containing the Extension version to encode')

arg_parser.add_argument('--abi-type', type=str, help='The ABI type to encode, set to C_STRUCT by default', default='C_STRUCT')

args = arg_parser.parse_args()
Expand Down Expand Up @@ -70,6 +72,23 @@ def main():
else:
raise Exception(f"Neither --duckdb-platform nor --duckdb-platform-file found, please specify the platform using either")

EXTENSION_VERSION = ""
if args.extension_version:
EXTENSION_VERSION = args.extension_version
elif args.extension_version_file:
try:
with open(args.extension_version_file, 'r') as file:
EXTENSION_VERSION = file.read().strip()
except Exception as e:
print(f"Failed to read extension version from file {args.extension_version_file}")
raise
if not EXTENSION_VERSION:
raise Exception(f"Extension version file passed to script is empty: {args.extension_version_file}")
else:
raise Exception(f"Neither --extension-version nor --extension-version-file found, please specify the extension version using either")



# Then append the metadata to the tmp file
print(f" - Metadata:")
with open(OUTPUT_FILE_TMP, 'ab') as file:
Expand All @@ -82,8 +101,8 @@ def main():
file.write(padded_byte_string(""))
print(f" - FIELD5 (abi_type) = {args.abi_type}")
file.write(padded_byte_string(args.abi_type))
print(f" - FIELD4 (extension_version) = {args.extension_version}")
file.write(padded_byte_string(args.extension_version))
print(f" - FIELD4 (extension_version) = {EXTENSION_VERSION}")
file.write(padded_byte_string(EXTENSION_VERSION))
print(f" - FIELD3 (duckdb_version) = {args.duckdb_version}")
file.write(padded_byte_string(args.duckdb_version))
print(f" - FIELD2 (duckdb_platform) = {PLATFORM}")
Expand Down
45 changes: 45 additions & 0 deletions scripts/configure_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import subprocess
import argparse
from pathlib import Path
import os

def main():
arg_parser = argparse.ArgumentParser(description='Script to aid in running the configure step of the extension build process')


arg_parser.add_argument('-o', '--output-directory', type=str, help='Specify the output directory', default='configure')

arg_parser.add_argument('-ev', '--extension-version', help='Write the autodetected extension version', action='store_true')
arg_parser.add_argument('-p', '--duckdb-platform', help='Write the auto-detected duckdb platform', action='store_true')

args = arg_parser.parse_args()

OUTPUT_DIR = args.output_directory

Path(OUTPUT_DIR).mkdir(parents=True, exist_ok=True)

# Write version
if args.extension_version:
git_tag = subprocess.getoutput("git tag --points-at HEAD")
if git_tag:
EXTENSION_VERSION = git_tag
else:
EXTENSION_VERSION = subprocess.getoutput("git --no-pager log -1 --format=%h")

version_file = Path(os.path.join(OUTPUT_DIR, "extension_version.txt"))
with open(version_file, 'w') as f:
print(f"Writing version {EXTENSION_VERSION} to {version_file}")
f.write(EXTENSION_VERSION)

# Write duck
if args.duckdb_platform:
import duckdb
platform_file = Path(os.path.join(OUTPUT_DIR, "platform.txt"))
duckdb_platform = duckdb.execute('pragma platform').fetchone()[0]
with open(platform_file, 'w') as f:
print(f"Writing platform {duckdb_platform} to {platform_file}")
f.write(duckdb_platform)


if __name__ == '__main__':
main()

0 comments on commit 795955c

Please sign in to comment.