node icon indicating copy to clipboard operation
node copied to clipboard

build,tools: make addons tests work with GN

Open zcbenz opened this issue 1 year ago • 16 comments

This PR refactors the install and build_addons scripts so they can be reused by node-ci and electron projects to build the addons tests.

In detail, this PR does following things:

  1. Minor modifications of the GN configurations to fix loading native modules.
  2. Add some flags to tools/install.py script to allow customize locations of config.gypi, v8, etc. With some refactoring to remove global variables.
  3. Rewrite the tools/build_addons.py script:
    1. Rewrite it from js to python, because implementing cmd args handling with vanilla Node.js would take much longer time than a simple rewrite.
    2. Add a few more flags to make it easier to use for embedders.
  4. Modify the Makefile to generate headers in out dir first, and then calls build_addons.py --headers-dir=out_dir/headers (which calls node-gyp --nodedir=out_dir/headers) to build addons. Previously the build system was just calling node-gyp --nodedir=., which relied on quirky behavior of node-gyp and did not really test whether the generated headers work.

Users that rely on make or vcbuild.bat to work on Node are not affected.

zcbenz avatar Nov 15 '23 08:11 zcbenz

Review requested:

  • [ ] @nodejs/tsc

nodejs-github-bot avatar Nov 15 '23 08:11 nodejs-github-bot

I have separated some changes out of this PR so review should be easier.

/cc @nodejs/gyp @joyeecheung @richardlau for reviewing changes on tools.

zcbenz avatar Nov 16 '23 07:11 zcbenz

CI: https://ci.nodejs.org/job/node-test-pull-request/55698/

nodejs-github-bot avatar Nov 17 '23 02:11 nodejs-github-bot

Ping @nodejs/gyp @joyeecheung @anonrig for review after the holiday.

zcbenz avatar Nov 28 '23 01:11 zcbenz

CI: https://ci.nodejs.org/job/node-test-pull-request/56066/

nodejs-github-bot avatar Dec 04 '23 07:12 nodejs-github-bot

I have tested following commands with and without this PR, and compared the file list of generated tarballs:

  • make tar tar-headers binary on linux/x64: The only difference is the tools/build-addons.mjs became tools/build_addons.py in node-v22.0.0.tar.gz.
  • make tar-headers binary on mac/x64: The tarballs contain the same files.
  • make tar-headers binary pkg on mac/arm64: The tarballs contain the same files. The pkg files contain the same files.
  • vcbuild.bat build-release on win/x64: The msi files contain the same files.

I have a high confidence that this change won't break Node's release process, @nodejs/build please let me know if there is anything that you want to verify.

zcbenz avatar Jan 04 '24 05:01 zcbenz

CI: https://ci.nodejs.org/job/node-test-pull-request/56676/

nodejs-github-bot avatar Jan 05 '24 01:01 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/56711/

nodejs-github-bot avatar Jan 08 '24 02:01 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/56823/

nodejs-github-bot avatar Jan 17 '24 13:01 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/56832/

nodejs-github-bot avatar Jan 18 '24 13:01 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/56877/

nodejs-github-bot avatar Jan 22 '24 14:01 nodejs-github-bot

From the CI this is failing on Windows:

21:27:57 > python "C:\workspace\node-test-binary-windows-native-suites\node\tools\build_addons.py" "C:\workspace\node-test-binary-windows-native-suites\node\test\addons" 
21:28:28 Generating headers
21:28:28 Traceback (most recent call last):
21:28:28   File "C:\workspace\node-test-binary-windows-native-suites\node\tools\build_addons.py", line 129, in <module>
21:28:28     main()
21:28:28   File "C:\workspace\node-test-binary-windows-native-suites\node\tools\build_addons.py", line 124, in main
21:28:28     rebuild_addons(args)
21:28:28   File "C:\workspace\node-test-binary-windows-native-suites\node\tools\build_addons.py", line 43, in rebuild_addons
21:28:28     shutil.copy2(os.path.join(args.out_dir, 'node.lib'),
21:28:28   File "C:\Python310\lib\shutil.py", line 434, in copy2
21:28:28     copyfile(src, dst, follow_symlinks=follow_symlinks)
21:28:28   File "C:\Python310\lib\shutil.py", line 254, in copyfile
21:28:28     with open(src, 'rb') as fsrc:
21:28:28 FileNotFoundError: [Errno 2] No such file or directory: 'out/Release\\node.lib'

joyeecheung avatar Jan 22 '24 14:01 joyeecheung

I have pushed a fix for the CI failure. The scripts in CI assume the out dir is Release instead of out/Release, which was an very old behavior that happens to work.

zcbenz avatar Jan 23 '24 01:01 zcbenz

CI: https://ci.nodejs.org/job/node-test-pull-request/56892/

nodejs-github-bot avatar Jan 23 '24 02:01 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/57006/

nodejs-github-bot avatar Feb 01 '24 12:02 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/57017/

nodejs-github-bot avatar Feb 02 '24 10:02 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/57270/

nodejs-github-bot avatar Feb 21 '24 21:02 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/57320/

nodejs-github-bot avatar Feb 23 '24 01:02 nodejs-github-bot

Commit Queue failed
- Loading data for nodejs/node/pull/50737
✔  Done loading data for nodejs/node/pull/50737
----------------------------------- PR info ------------------------------------
Title      build,tools: make addons tests work with GN (#50737)
   ⚠  Could not retrieve the email or name of the PR author's from user's GitHub profile!
Branch     zcbenz:build-addons-gn -> nodejs:main
Labels     windows, build, openssl, libuv, tools, python, needs-ci, dependencies, commit-queue-squash
Commits    3
 - build,tools: make addons tests work with GN
 - build,tools: generate node headers on request
 - build,tools: there are 2 out dirs on windows
Committers 1
 - Cheng Zhao 
PR-URL: https://github.com/nodejs/node/pull/50737
Reviewed-By: Joyee Cheung 
Reviewed-By: Benjamin Gruenbaum 
Reviewed-By: Yagiz Nizipli 
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/50737
Reviewed-By: Joyee Cheung 
Reviewed-By: Benjamin Gruenbaum 
Reviewed-By: Yagiz Nizipli 
--------------------------------------------------------------------------------
   ⚠  Commits were pushed since the last approving review:
   ⚠  - build,tools: make addons tests work with GN
   ⚠  - build,tools: generate node headers on request
   ⚠  - build,tools: there are 2 out dirs on windows
   ℹ  This PR was created on Wed, 15 Nov 2023 08:29:46 GMT
   ✔  Approvals: 3
   ✔  - Joyee Cheung (@joyeecheung) (TSC): https://github.com/nodejs/node/pull/50737#pullrequestreview-1810123695
   ✔  - Benjamin Gruenbaum (@benjamingr) (TSC): https://github.com/nodejs/node/pull/50737#pullrequestreview-1756204771
   ✔  - Yagiz Nizipli (@anonrig) (TSC): https://github.com/nodejs/node/pull/50737#pullrequestreview-1805222548
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2024-02-23T01:17:58Z: https://ci.nodejs.org/job/node-test-pull-request/57320/
- Querying data for job/node-test-pull-request/57320/
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/8015803850

nodejs-github-bot avatar Feb 23 '24 07:02 nodejs-github-bot

Landed in b1468d21eec30dc1f39666b802346913ef1609e8

zcbenz avatar Feb 23 '24 07:02 zcbenz

Sorry to report it, but this PR caused regression, build in --shared mode now fails:

11:02:41: stdout installing /some_dir/build/prototype/i386/some_bindir/node
11:02:41: stderr Traceback (most recent call last):
11:02:41: stderr   File "/some_dir/build/amd64/tools/install.py", line 419, in <module>
11:02:41: stderr     run(parse_options(sys.argv[1:]))
11:02:41: stderr   File "/some_dir/build/amd64/tools/install.py", line 372, in run
11:02:41: stderr     files(options, install)
11:02:41: stderr   File "/some_dir/build/amd64/tools/install.py", line 179, in files
11:02:41: stderr     action(options, [os.path.join(output_prefix, output_lib)],
11:02:41: stderr                                   ^^^^^^^^^^^^^
11:02:42: stderr UnboundLocalError: cannot access local variable 'output_prefix' where it is not associated with a value   

The problem in source code is obvious, the variable 'output_prefix' is only defined in some branches. Later in code the variable is used in a branch where it was not defined before.

batrla avatar Feb 28 '24 10:02 batrla

Sorry for breaking it! I'll create a fix soon.

zcbenz avatar Feb 28 '24 10:02 zcbenz