Skip to content

Commit 657d6d1

Browse files
committed
refactor: new directory structure to separate multi-platform code from database-specific implementations
Refactor the codebase to separate multi-platform code from database-specific implementations, preparing for PostgreSQL extension development. vtab.c/h has been renamed to sqlite/cloudsync_changes_sqlite.c/h
1 parent 023622d commit 657d6d1

File tree

8 files changed

+36
-28
lines changed

8 files changed

+36
-28
lines changed

Makefile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ MAKEFLAGS += -j$(CPUS)
2929

3030
# Compiler and flags
3131
CC = gcc
32-
CFLAGS = -Wall -Wextra -Wno-unused-parameter -I$(SRC_DIR) -I$(SQLITE_DIR) -I$(CURL_DIR)/include
32+
CFLAGS = -Wall -Wextra -Wno-unused-parameter -I$(SRC_DIR) -I$(SRC_DIR)/sqlite -I$(SRC_DIR)/postgresql -I$(SQLITE_DIR) -I$(CURL_DIR)/include
3333
T_CFLAGS = $(CFLAGS) -DSQLITE_CORE -DCLOUDSYNC_UNITTEST -DCLOUDSYNC_OMIT_NETWORK -DCLOUDSYNC_OMIT_PRINT_RESULT
3434
COVERAGE = false
3535
ifndef NATIVE_NETWORK
@@ -38,10 +38,12 @@ endif
3838

3939
# Directories
4040
SRC_DIR = src
41+
SQLITE_IMPL_DIR = $(SRC_DIR)/sqlite
42+
POSTGRES_IMPL_DIR = $(SRC_DIR)/postgresql
4143
DIST_DIR = dist
4244
TEST_DIR = test
4345
SQLITE_DIR = sqlite
44-
VPATH = $(SRC_DIR):$(SQLITE_DIR):$(TEST_DIR)
46+
VPATH = $(SRC_DIR):$(SQLITE_IMPL_DIR):$(POSTGRES_IMPL_DIR):$(SQLITE_DIR):$(TEST_DIR)
4547
BUILD_RELEASE = build/release
4648
BUILD_TEST = build/test
4749
BUILD_DIRS = $(BUILD_TEST) $(BUILD_RELEASE)
@@ -50,12 +52,18 @@ CURL_SRC = $(CURL_DIR)/src/curl-$(CURL_VERSION)
5052
COV_DIR = coverage
5153
CUSTOM_CSS = $(TEST_DIR)/sqliteai.css
5254

53-
SRC_FILES = $(wildcard $(SRC_DIR)/*.c)
55+
# Multi-platform source files (at src/ root) - exclude database_*.c as they're in subdirs
56+
CORE_SRC = $(filter-out $(SRC_DIR)/database_%.c, $(wildcard $(SRC_DIR)/*.c))
57+
# SQLite-specific files
58+
SQLITE_SRC = $(wildcard $(SQLITE_IMPL_DIR)/*.c)
59+
# Combined for SQLite extension build
60+
SRC_FILES = $(CORE_SRC) $(SQLITE_SRC)
61+
5462
TEST_SRC = $(wildcard $(TEST_DIR)/*.c)
5563
TEST_FILES = $(SRC_FILES) $(TEST_SRC) $(wildcard $(SQLITE_DIR)/*.c)
5664
RELEASE_OBJ = $(patsubst %.c, $(BUILD_RELEASE)/%.o, $(notdir $(SRC_FILES)))
5765
TEST_OBJ = $(patsubst %.c, $(BUILD_TEST)/%.o, $(notdir $(TEST_FILES)))
58-
COV_FILES = $(filter-out $(SRC_DIR)/lz4.c $(SRC_DIR)/network.c $(SRC_DIR)/sql_sqlite.c $(SRC_DIR)/database_postgresql.c, $(SRC_FILES))
66+
COV_FILES = $(filter-out $(SRC_DIR)/lz4.c $(SRC_DIR)/network.c $(SQLITE_IMPL_DIR)/sql_sqlite.c $(POSTGRES_IMPL_DIR)/database_postgresql.c, $(SRC_FILES))
5967
CURL_LIB = $(CURL_DIR)/$(PLATFORM)/libcurl.a
6068
TEST_TARGET = $(patsubst %.c,$(DIST_DIR)/%$(EXE), $(notdir $(TEST_SRC)))
6169

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by Marco Bambini on 03/12/25.
66
//
77

8-
#include "database.h"
9-
#include "cloudsync.h"
8+
#include "../database.h"
9+
#include "../cloudsync.h"
1010

1111

src/vtab.c renamed to src/sqlite/cloudsync_changes_sqlite.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// vtab.c
2+
// cloudsync_changes_sqlite.c
33
// cloudsync
44
//
55
// Created by Marco Bambini on 23/09/24.
@@ -8,10 +8,10 @@
88
#include <stdio.h>
99
#include <string.h>
1010

11-
#include "vtab.h"
12-
#include "utils.h"
13-
#include "dbutils.h"
14-
#include "cloudsync_private.h"
11+
#include "cloudsync_changes_sqlite.h"
12+
#include "../utils.h"
13+
#include "../dbutils.h"
14+
#include "../cloudsync_private.h"
1515

1616
#ifndef SQLITE_CORE
1717
SQLITE_EXTENSION_INIT3

src/vtab.h renamed to src/sqlite/cloudsync_changes_sqlite.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//
2-
// vtab.h
2+
// cloudsync_changes_sqlite.h
33
// cloudsync
44
//
55
// Created by Marco Bambini on 23/09/24.
66
//
77

8-
#ifndef __CLOUDSYNC_VTAB__
9-
#define __CLOUDSYNC_VTAB__
8+
#ifndef __CLOUDSYNC_CHANGES_SQLITE__
9+
#define __CLOUDSYNC_CHANGES_SQLITE__
1010

11-
#include "cloudsync.h"
11+
#include "../cloudsync.h"
1212

1313
#ifndef SQLITE_CORE
1414
#include "sqlite3ext.h"
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
// Created by Marco Bambini on 05/12/25.
66
//
77

8-
#include "cloudsync.h"
8+
#include "../cloudsync.h"
99
#include "cloudsync_sqlite.h"
10-
#include "cloudsync_private.h"
11-
#include "database.h"
12-
#include "dbutils.h"
13-
#include "vtab.h"
14-
#include "pk.h"
10+
#include "../cloudsync_private.h"
11+
#include "../database.h"
12+
#include "../dbutils.h"
13+
#include "cloudsync_changes_sqlite.h"
14+
#include "../pk.h"
1515

1616
#ifndef CLOUDSYNC_OMIT_NETWORK
17-
#include "network.h"
17+
#include "../network.h"
1818
#endif
1919

2020
#ifndef SQLITE_CORE
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
// Created by Marco Bambini on 03/12/25.
66
//
77

8-
#include "cloudsync.h"
9-
#include "database.h"
10-
#include "dbutils.h"
11-
#include "utils.h"
12-
#include "sql.h"
8+
#include "../cloudsync.h"
9+
#include "../database.h"
10+
#include "../dbutils.h"
11+
#include "../utils.h"
12+
#include "../sql.h"
1313

1414
#include <inttypes.h>
1515
#include <string.h>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by Marco Bambini on 17/12/25.
66
//
77

8-
#include "sql.h"
8+
#include "../sql.h"
99

1010
// MARK: Settings
1111

0 commit comments

Comments
 (0)