-
Notifications
You must be signed in to change notification settings - Fork 4
fix(binding): drop node-PATH dependency in binding.gyp (#153) #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
032f971
fix(binding): drop node-PATH dependency in binding.gyp (closes #153)
oorabona e30935b
fix(binding): quote python/module_root paths + add legacy node-gyp fa…
oorabona 9140766
refactor(binding): drop ineffective legacy node-gyp fallback for python
oorabona 7ddc955
fix(binding): ship binding_config.py in tarball and drop dead py3 subcmd
oorabona File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| """Resolve binding.gyp variables without invoking node. | ||
|
|
||
| Replaces the previous `<!(node -p "process.env.X || default")` shell-outs | ||
| that fail on Windows under mise/pnpm/aube when node.exe is not in the | ||
| shell PATH inherited by node-gyp's child process (see issue #153). | ||
|
|
||
| Python is used because node-gyp already requires it to evaluate gyp files | ||
| (see `find Python` step in node-gyp output), so it is the most reliable | ||
| interpreter available at this point in the install lifecycle. | ||
|
|
||
| Subcommands: | ||
| use_global_liblzma env USE_GLOBAL or platform default ("true" on linux/darwin, "false" elsewhere) | ||
| runtime_link env RUNTIME_LINK or platform default ("shared" on linux/darwin, "static" elsewhere) | ||
| enable_thread_support env ENABLE_THREAD_SUPPORT or "yes" | ||
| node_addon_api_include absolute path to node-addon-api include dir (POSIX-style) | ||
|
oorabona marked this conversation as resolved.
|
||
| node_addon_api_gyp absolute path to node-addon-api node_api.gyp (POSIX-style) | ||
| """ | ||
|
|
||
| import json | ||
| import os | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| def is_unix(): | ||
| return sys.platform in ("linux", "darwin") | ||
|
|
||
|
|
||
| def env_or(name, default): | ||
| val = os.environ.get(name) | ||
| return val if val else default | ||
|
|
||
|
|
||
| def use_global_liblzma(): | ||
| return env_or("USE_GLOBAL", "true" if is_unix() else "false") | ||
|
|
||
|
|
||
| def runtime_link(): | ||
| return env_or("RUNTIME_LINK", "shared" if is_unix() else "static") | ||
|
|
||
|
|
||
| def enable_thread_support(): | ||
| return env_or("ENABLE_THREAD_SUPPORT", "yes") | ||
|
|
||
|
|
||
| def find_node_addon_api(): | ||
| """Locate node-addon-api package by walking up from the script dir. | ||
|
|
||
| pnpm/aube can hoist node-addon-api outside the local node_modules tree, | ||
| so we walk every parent's node_modules looking for the package. | ||
| """ | ||
| here = Path(__file__).resolve().parent | ||
| for ancestor in [here, *here.parents]: | ||
| nm = ancestor / "node_modules" / "node-addon-api" | ||
| if nm.is_dir(): | ||
| return nm | ||
| sys.exit("node-addon-api not found in any parent node_modules") | ||
|
|
||
|
|
||
| def node_addon_api_include(): | ||
| pkg = find_node_addon_api() | ||
| pkg_json = pkg / "package.json" | ||
| include_subpath = None | ||
| if pkg_json.is_file(): | ||
| try: | ||
| with pkg_json.open(encoding="utf-8") as f: | ||
| data = json.load(f) | ||
| include_subpath = data.get("include_dir") or data.get("include") | ||
| except (OSError, json.JSONDecodeError): | ||
| include_subpath = None | ||
| if include_subpath: | ||
| resolved = (pkg / include_subpath).resolve() | ||
| else: | ||
| resolved = pkg | ||
| return str(resolved).replace(os.sep, "/") | ||
|
|
||
|
|
||
| def node_addon_api_gyp(): | ||
| """Return the gyp dependency reference matching `require('node-addon-api').gyp`. | ||
|
|
||
| node-addon-api exposes `node_api.gyp:nothing` (single legacy target) as | ||
| its canonical gyp dependency string. The `:nothing` suffix tells gyp | ||
| which target to depend on; without it, gyp can't resolve the dependency | ||
| (target name defaults differ from file basename here). | ||
| """ | ||
| pkg = find_node_addon_api() | ||
| gyp_path = (pkg / "node_api.gyp").resolve() | ||
| if not gyp_path.is_file(): | ||
| sys.exit(f"node-addon-api node_api.gyp not found at {gyp_path}") | ||
| return f"{str(gyp_path).replace(os.sep, '/')}:nothing" | ||
|
|
||
|
|
||
| COMMANDS = { | ||
| "use_global_liblzma": use_global_liblzma, | ||
| "runtime_link": runtime_link, | ||
| "enable_thread_support": enable_thread_support, | ||
| "node_addon_api_include": node_addon_api_include, | ||
| "node_addon_api_gyp": node_addon_api_gyp, | ||
| } | ||
|
|
||
|
|
||
| def main(): | ||
| if len(sys.argv) != 2: | ||
| sys.exit(f"usage: {sys.argv[0]} <{'|'.join(COMMANDS)}>") | ||
| name = sys.argv[1] | ||
| handler = COMMANDS.get(name) | ||
| if handler is None: | ||
| sys.exit(f"unknown variable: {name}") | ||
| sys.stdout.write(handler()) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.