Skip to content

Commit b19b73a

Browse files
committed
feat(migration): add automated split option using #line directives
1 parent d0cc550 commit b19b73a

File tree

2 files changed

+86
-5
lines changed

2 files changed

+86
-5
lines changed

.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"Bash(grep:*)",
66
"Bash(ls:*)",
77
"Bash(find:*)",
8-
"Bash(lzz:*)"
8+
"Bash(lzz:*)",
9+
"Bash(cp:*)"
910
]
1011
},
1112
"enableAllProjectMcpServers": false

lzz-migration.md

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,89 @@ cp src/better_sqlite3.cpp src/better_sqlite3.cpp.backup
175175
- Requires careful testing
176176
- Could improve code quality significantly
177177

178+
## Migration Options (continued)
179+
180+
### Option C: Automated Split Using #line Directives
181+
**Approach**: Use lzz's #line directives as metadata to automate file splitting
182+
183+
**Steps**:
184+
1. Generate files WITH #line directives to use as splitting guides
185+
2. Parse #line directives to automatically split into correct files
186+
3. Clean up the split files and remove #line directives
187+
4. Maintain single compilation unit or modularize as needed
188+
189+
**Advantages**:
190+
- Automated and accurate file splitting
191+
- No manual boundary detection needed
192+
- Preserves exact lzz file organization
193+
- Less error-prone than manual splitting
194+
- Can be scripted for repeatability
195+
196+
**Disadvantages**:
197+
- Requires writing a parsing script
198+
- Still need to clean up #line directives
199+
- Temporary use of "dirty" files with #line
200+
201+
**Detailed Instructions**:
202+
```bash
203+
# 1. Generate with #line directives (intentionally keeping them)
204+
lzz -hx hpp -sx cpp -k BETTER_SQLITE3 -d -hl -sl -e ./src/better_sqlite3.lzz
205+
206+
# 2. Backup the #line-annotated files
207+
cp src/better_sqlite3.hpp src/better_sqlite3.hpp.withlines
208+
cp src/better_sqlite3.cpp src/better_sqlite3.cpp.withlines
209+
210+
# 3. Parse #line directives to understand file boundaries
211+
# Example #line format: #line 1 "util/macros.lzz"
212+
# This indicates the following content originated from util/macros.lzz
213+
214+
# 4. Write a script to:
215+
# a. Read the generated .hpp file
216+
# b. Split content based on #line directives
217+
# c. Create individual .hpp files for each original .lzz file
218+
# d. Remove all #line directives from the split files
219+
220+
# 5. For the .cpp file:
221+
# - Keep as single compilation unit (Option C-A), OR
222+
# - Split into modules using same #line parsing (Option C-B)
223+
224+
# 6. Create new src/better_sqlite3.hpp that includes all split headers:
225+
#include "util/macros.hpp"
226+
#include "util/query-macros.hpp"
227+
// ... in original #insert order
228+
229+
# 7. Test the build and remove .lzz files
230+
```
231+
232+
**Sample Splitting Script Logic**:
233+
```python
234+
# Pseudocode for splitting based on #line
235+
current_file = None
236+
current_content = []
237+
238+
for line in generated_file:
239+
if line.startswith('#line'):
240+
# Parse: #line 123 "path/to/file.lzz"
241+
if current_file:
242+
write_content_to_file(current_file, current_content)
243+
current_file = extract_path_from_line_directive(line)
244+
current_content = []
245+
elif not line.startswith('#line'):
246+
current_content.append(line)
247+
248+
# Write final file
249+
if current_file:
250+
write_content_to_file(current_file, current_content)
251+
```
252+
178253
## Recommendation
179254

180-
Start with **Option A** as a safe intermediate step, then consider moving to Option B in a separate phase. This allows:
181-
1. Immediate removal of lzz dependency
182-
2. Working codebase to test against
183-
3. Future improvement opportunity
255+
**Option C** is likely the best approach because it:
256+
1. Automates the most error-prone part (identifying file boundaries)
257+
2. Guarantees correct file organization matching original .lzz structure
258+
3. Can be validated by comparing against original .lzz files
259+
4. Provides a clear migration path with less manual work
260+
261+
After using Option C to split files, you can then decide whether to:
262+
- Keep single compilation unit (simpler, like Option A)
263+
- Move to modular compilation (cleaner, like Option B)

0 commit comments

Comments
 (0)