Skip to content

Commit f625b66

Browse files
build: improve logging in build_addons
1 parent 80677c9 commit f625b66

File tree

8 files changed

+29
-170
lines changed

8 files changed

+29
-170
lines changed

test/addons/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ Makefile
66
gyp-mac-tool
77
/*/build
88
/esm/node_modules/*/build
9+
/*/logs

test/js-native-api/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ Makefile
55
*.mk
66
gyp-mac-tool
77
/*/build
8+
/*/logs

test/js-native-api/test_warning/build_logs/build_clang.log

Lines changed: 0 additions & 72 deletions
This file was deleted.

test/js-native-api/test_warning/build_logs/build_gcc.log

Lines changed: 0 additions & 72 deletions
This file was deleted.

test/js-native-api/test_warning/test.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,12 @@ assert.strictEqual(binding2.hello(), 'world');
1414
{
1515
const warningMessage = '#warning "NAPI_EXPERIMENTAL is enabled. Experimental features may be unstable."';
1616

17-
const gccLogFilePath = path.resolve(__dirname, './build_logs/build_gcc.log');
18-
const gccLogContent = fs.readFileSync(gccLogFilePath, 'utf8');
17+
const logFilePath = path.resolve(__dirname, './logs/build.log');
18+
const logContent = fs.readFileSync(logFilePath, 'utf8');
1919

20-
const gccWarningCount = gccLogContent.split(warningMessage).length - 1;
21-
const gccHasWarning = gccLogContent.includes(warningMessage);
20+
const warningCount = logContent.split(warningMessage).length - 1;
21+
const hasWarning = logContent.includes(warningMessage);
2222

23-
assert.strictEqual(gccHasWarning, true, `Expected warning not found: "${warningMessage}"`);
24-
assert.strictEqual(gccWarningCount, 1, `Expected warning to appear exactly once, but found ${gccWarningCount} occurrences.`);
25-
26-
const clangLogFilePath = path.resolve(__dirname, './build_logs/build_clang.log');
27-
const clangLogContent = fs.readFileSync(clangLogFilePath, 'utf8');
28-
29-
const clangWarningCount = clangLogContent.split(warningMessage).length - 1;
30-
const clangHasWarning = clangLogContent.includes(warningMessage);
31-
32-
assert.strictEqual(clangHasWarning, true, `Expected warning not found: "${warningMessage}"`);
33-
assert.strictEqual(clangWarningCount, 1, `Expected warning to appear exactly once, but found ${gccWarningCount} occurrences.`);
23+
assert.strictEqual(hasWarning, true, `Expected warning not found: "${warningMessage}"`);
24+
assert.strictEqual(warningCount, 1, `Expected warning to appear exactly once, but found ${warningCount} occurrences.`);
3425
}

test/node-api/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
build
2+
/*/logs

test/sqlite/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
build
2+
/*/logs

tools/build_addons.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,33 @@ def node_gyp_rebuild(test_dir):
4747
print('Building addon in', test_dir)
4848
try:
4949
process = subprocess.Popen([
50-
node_bin,
51-
node_gyp,
52-
'rebuild',
53-
'--directory', test_dir,
54-
'--nodedir', headers_dir,
55-
'--python', sys.executable,
56-
'--loglevel', args.loglevel,
57-
], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
50+
node_bin,
51+
node_gyp,
52+
'rebuild',
53+
'--directory', test_dir,
54+
'--nodedir', headers_dir,
55+
'--python', sys.executable,
56+
'--loglevel', args.loglevel,
57+
], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
5858

5959
# We buffer the output and print it out once the process is done in order
6060
# to avoid interleaved output from multiple builds running at once.
6161
return_code = process.wait()
6262
stdout, stderr = process.communicate()
6363
if return_code != 0:
64-
print(f'Failed to build addon in {test_dir}:')
64+
print(f'Failed to build addon in {test_dir}. Check build.log for details.')
65+
66+
build_dir = os.path.join(test_dir, 'logs')
67+
os.makedirs(build_dir, exist_ok=True)
68+
log_file_path = os.path.join(build_dir, 'build.log')
69+
with open(log_file_path, 'w') as log_file:
6570
if stdout:
66-
print(stdout.decode())
71+
print(stdout)
72+
log_file.write(stdout)
6773
if stderr:
68-
print(stderr.decode())
74+
print(stderr)
75+
log_file.write(stderr)
76+
6977
return return_code
7078

7179
except Exception as e:

0 commit comments

Comments
 (0)