-
-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathcopy_cpp_sources.js
More file actions
206 lines (175 loc) Β· 6.19 KB
/
Copy pathcopy_cpp_sources.js
File metadata and controls
206 lines (175 loc) Β· 6.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/usr/bin/env node
/**
* Standalone script to copy C/C++ source files from bridge/ to webf/src for non-macOS platforms
*
* Usage:
* node scripts/copy_cpp_sources.js [webf-directory]
*
* If no directory is specified, defaults to 'webf' relative to the project root.
*/
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const os = require('os');
/**
* Copy a file from source to destination
* @param {string} source - Source file path
* @param {string} destination - Destination file path
*/
function copyFile(source, destination) {
console.log(`Copying file: ${path.basename(source)} -> ${destination}`);
// Ensure the destination directory exists
const destDir = path.dirname(destination);
if (!fs.existsSync(destDir)) {
fs.mkdirSync(destDir, { recursive: true });
}
// Delete the destination file if it exists
if (fs.existsSync(destination)) {
fs.unlinkSync(destination);
}
// Read and write the file
const buffer = fs.readFileSync(source);
fs.writeFileSync(destination, buffer);
}
/**
* Copy C/C++ source files from bridge/ to webf/src
* @param {string} rootDir - Path to the project root directory
* @param {string} webfDir - Path to the WebF package directory
*/
function copyCppSourceFiles(rootDir, webfDir) {
console.log('π Copying C/C++ source files...');
try {
const bridgeDir = path.join(rootDir, 'bridge');
const srcDir = path.join(webfDir, 'src');
console.log(`π Source: ${bridgeDir}`);
console.log(`π Target: ${srcDir}`);
// Check if source directory exists
if (!fs.existsSync(bridgeDir)) {
console.error(`β Bridge directory not found: ${bridgeDir}`);
process.exit(1);
}
// Ensure the src directory exists
if (!fs.existsSync(srcDir)) {
fs.mkdirSync(srcDir, { recursive: true });
console.log(`β
Created directory: ${srcDir}`);
} else {
// Clean the src directory if it exists
console.log('π§Ή Cleaning existing src directory...');
if (os.platform() === 'win32') {
execSync(`rd /s /q "${srcDir}"`);
fs.mkdirSync(srcDir, { recursive: true });
} else {
execSync(`rm -rf "${srcDir}"`);
fs.mkdirSync(srcDir, { recursive: true });
}
}
// Directories to copy (based on iOS structure)
const directoriesToCopy = [
'bindings',
'core',
'foundation',
'include',
'code_gen',
'bridge_sources.json5',
'scripts/get_app_ver.js',
'scripts/read_bridge_sources.js',
'scripts/read_quickjs_sources.js',
'multiple_threading',
'third_party/dart',
'third_party/gumbo-parser',
'third_party/modp_b64',
'third_party/quickjs',
'third_party/cityhash',
'third_party/double_conversion'
];
let successCount = 0;
let warningCount = 0;
// Copy all directories and files
for (const item of directoriesToCopy) {
const sourcePath = path.join(bridgeDir, item);
const destPath = path.join(srcDir, item);
if (fs.existsSync(sourcePath)) {
const stats = fs.statSync(sourcePath);
if (stats.isDirectory()) {
// It's a directory - copy recursively
// Create the destination directory if it doesn't exist
if (!fs.existsSync(destPath)) {
fs.mkdirSync(destPath, { recursive: true });
}
// Use rsync or recursive copy depending on the platform
if (os.platform() === 'win32') {
// For Windows, use xcopy or robocopy
execSync(`xcopy "${sourcePath}" "${destPath}" /E /I /Y`, { stdio: 'ignore' });
} else {
// For Unix-like systems, use rsync or cp
execSync(`rsync -a "${sourcePath}/" "${destPath}/"`, { stdio: 'ignore' });
}
console.log(`β
Copied directory: ${item}`);
successCount++;
} else if (stats.isFile()) {
// It's a file - copy it directly
copyFile(sourcePath, destPath);
console.log(`β
Copied file: ${item}`);
successCount++;
}
} else {
console.warn(`β οΈ Warning: Source path ${sourcePath} does not exist.`);
warningCount++;
}
}
// Also copy specific files at the root level
const rootFilesToCopy = [
'CMakeLists.txt',
'webf_bridge.cc',
'webf_bridge.h'
];
for (const file of rootFilesToCopy) {
const sourceFile = path.join(bridgeDir, file);
const destFile = path.join(srcDir, file);
if (fs.existsSync(sourceFile)) {
copyFile(sourceFile, destFile);
console.log(`β
Copied root file: ${file}`);
successCount++;
} else {
console.warn(`β οΈ Warning: Source file ${sourceFile} does not exist.`);
warningCount++;
}
}
// Summary
console.log('\nπ Copy Summary:');
console.log(` β
Successfully copied: ${successCount} items`);
if (warningCount > 0) {
console.log(` β οΈ Warnings: ${warningCount} items not found`);
}
console.log('\nπ C/C++ source files copied successfully!');
console.log(` Files are now available in: ${srcDir}`);
} catch (error) {
console.error('β Error copying C/C++ source files:', error.message);
process.exit(1);
}
}
// Main execution
function main() {
// Parse command line arguments
const args = process.argv.slice(2);
// Default to 'webf' directory if no argument provided
const webfDir = args[0] || path.join(__dirname, '../webf');
// Convert to absolute path
const absoluteWebfDir = path.resolve(webfDir);
const rootDir = path.join(__dirname, '..');
console.log(`Using WebF directory: ${absoluteWebfDir}`);
console.log(`Using root directory: ${rootDir}`);
// Check if the directory exists
if (!fs.existsSync(absoluteWebfDir)) {
console.error(`Error: WebF directory does not exist: ${absoluteWebfDir}`);
process.exit(1);
}
// Copy the C/C++ source files
copyCppSourceFiles(rootDir, absoluteWebfDir);
}
// Run the script if called directly
if (require.main === module) {
main();
}
// Export for use as a module
module.exports = { copyCppSourceFiles };