mirror of
https://github.com/react/react-native.git
synced 2026-09-28 13:23:09 +08:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55648 Changelog: [Internal] Updates the repository root resolution of the C++ api generation script. Reviewed By: cortinico Differential Revision: D93857297 fbshipit-source-id: 4c40ec2178807ddc5cae724c4233e2d029541031
53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
#
|
|
# This source code is licensed under the MIT license found in the
|
|
# LICENSE file in the root directory of this source tree.
|
|
|
|
import os
|
|
import subprocess
|
|
|
|
|
|
def get_repo_root() -> str:
|
|
"""Get the repository root directory.
|
|
|
|
Tries sl (Meta) first, then git (OSS).
|
|
"""
|
|
for cmd in [["sl", "root"], ["git", "rev-parse", "--show-toplevel"]]:
|
|
try:
|
|
result = subprocess.run(
|
|
cmd,
|
|
capture_output=True,
|
|
text=True,
|
|
)
|
|
if result.returncode == 0:
|
|
return result.stdout.strip()
|
|
except FileNotFoundError:
|
|
continue
|
|
raise RuntimeError("Could not determine repo root via 'sl root' or 'git rev-parse'")
|
|
|
|
|
|
def get_react_native_dir() -> str:
|
|
"""
|
|
Get the path to the react-native package directory.
|
|
|
|
This function handles two execution contexts:
|
|
1. Buck execution: Uses REACT_NATIVE_DIR env var + git repo root
|
|
2. Direct Python invocation: Uses __file__ relative path
|
|
"""
|
|
react_native_dir = os.environ.get("REACT_NATIVE_DIR")
|
|
if react_native_dir:
|
|
return os.path.join(get_repo_root(), react_native_dir)
|
|
|
|
# Use realpath to resolve symlinks — in Buck's link-tree, __file__
|
|
# is a symlink back to the source tree, so this gives the correct
|
|
# source location for relative path resolution.
|
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
|
return os.path.normpath(
|
|
os.path.join(
|
|
script_dir, # scripts/cxx-api/parser/
|
|
"..", # scripts/cxx-api/
|
|
"..", # scripts/
|
|
"..", # react-native-github/
|
|
)
|
|
)
|