From b6c950b38df64ef35b95357a17831b695ecf74ed Mon Sep 17 00:00:00 2001 From: dianjixz Date: Fri, 28 Jun 2024 18:19:19 +0800 Subject: [PATCH] [add] sqlite3 components --- components/sqlite3_component/Kconfig | 10 ++++ components/sqlite3_component/SConstruct | 75 +++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 components/sqlite3_component/Kconfig create mode 100644 components/sqlite3_component/SConstruct diff --git a/components/sqlite3_component/Kconfig b/components/sqlite3_component/Kconfig new file mode 100644 index 0000000..e94018f --- /dev/null +++ b/components/sqlite3_component/Kconfig @@ -0,0 +1,10 @@ + +menuconfig SQLITE3_COMPOENENT_ENABLED + bool "Enable sqlite3 lib" + default n + + config SQLITE3_COMPOENENT_DYNAMIC + bool "compile component as dynamic(shared) lib" + default n + depends on SQLITE3_COMPOENENT_ENABLED + diff --git a/components/sqlite3_component/SConstruct b/components/sqlite3_component/SConstruct new file mode 100644 index 0000000..e0b0240 --- /dev/null +++ b/components/sqlite3_component/SConstruct @@ -0,0 +1,75 @@ +# component/SConscript +Import('env') +import os +with open(env['PROJECT_TOOL_S']) as f: + exec(f.read()) + +def get_sqlite3_lib(): + sqlite3_path = str(ADir('../../github_source/sqlite3')) + if not os.path.exists(sqlite3_path): + zip_file = str(AFile('../../github_source/sqlite-amalgamation-3460000.zip')) + zip_file_extrpath = sqlite3_path + '_tmp' + down_url = "https://sqlite.org/2024/sqlite-amalgamation-3460000.zip" + + if 'CONFIG_REPO_AUTOMATION' in os.environ: + down = 'y' + else: + down = input('{} does not exist. Please choose whether to download it automatically? Y/N :'.format('sqlite-amalgamation-3460000.zip')) + down = down.lower() + if down == 'y': + # from git import Repo + import requests + import parse + import zipfile + import shutil + try: + # Downloading via HTTP (more common) + if not os.path.exists(zip_file): + response = requests.get(down_url) + if response.status_code == 200: + with open(zip_file, 'wb') as file: + file.write(response.content) + else: + env.Fatal("{} down failed".format(down_url)) + with zipfile.ZipFile(zip_file, 'r') as zip_ref: + zip_ref.extractall(zip_file_extrpath) + shutil.move(os.path.join(zip_file_extrpath, 'sqlite-amalgamation-3460000'), sqlite3_path) + shutil.rmtree(zip_file_extrpath) + print("The {} download successful.".format(down_url)) + except Exception as e: + print('Please manually download {} to {} .'.format(down_url, zip_file)) + env.Fatal("Cloning failed.: {}".format(e)) + else: + env.Fatal('Please manually download {} to {} .'.format(down_url, zip_file)) + INCLUDE = [sqlite3_path] + SRCS = [AFile('../../github_source/sqlite3/sqlite3.c')] + return INCLUDE, SRCS + +if 'CONFIG_SQLITE3_COMPOENENT_ENABLED' in os.environ: + SRCS=[] + INCLUDE=[] + PRIVATE_INCLUDE=[] + REQUIREMENTS=[] + STATIC_LIB=[] + DYNAMIC_LIB=[] + DEFINITIONS=[] + DEFINITIONS_PRIVATE=[] + LDFLAGS=[] + LINK_SEARCH_PATH=[] + _INCLUDE, _SRCS = get_sqlite3_lib() + INCLUDE += _INCLUDE + SRCS += _SRCS + + env['COMPONENTS'].append({'target':os.path.basename(env['component_dir']), + 'SRCS':SRCS, + 'INCLUDE':INCLUDE, + 'PRIVATE_INCLUDE':PRIVATE_INCLUDE, + 'REQUIREMENTS':REQUIREMENTS, + 'STATIC_LIB':STATIC_LIB, + 'DYNAMIC_LIB':DYNAMIC_LIB, + 'DEFINITIONS':DEFINITIONS, + 'DEFINITIONS_PRIVATE':DEFINITIONS_PRIVATE, + 'LDFLAGS':LDFLAGS, + 'LINK_SEARCH_PATH':LINK_SEARCH_PATH, + 'REGISTER':'static' + })