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
|
import os
from .constants import (
NODE_MODULES_DIRNAME,
NODE_MODULES_WORKSPACE_BUNDLE_FILENAME,
PACKAGE_JSON_FILENAME,
PNPM_BUILD_BACKUP_LOCKFILE_FILENAME,
PNPM_PRE_LOCKFILE_FILENAME,
PNPM_LOCKFILE_FILENAME,
PNPM_WS_FILENAME,
)
# Base utility functions
def home_dir():
"""
Stolen from ya (in the root of arcadia)
"""
# Do not trust $HOME, as it is unreliable in certain environments
# Temporarily delete os.environ["HOME"] to force reading current home directory from /etc/passwd
home_from_env = os.environ.pop("HOME", None)
try:
home_from_passwd = os.path.expanduser("~")
if os.path.isabs(home_from_passwd):
# This home dir is valid, prefer it over $HOME
return home_from_passwd
else:
# When python is built with musl (this is quire weird though),
# only users from /etc/passwd will be properly resolved,
# as musl does not have nss module for LDAP integration.
return home_from_env
finally:
if home_from_env is not None:
os.environ["HOME"] = home_from_env
def s_rooted(p):
return os.path.join("$S", p)
def b_rooted(p):
return os.path.join("$B", p)
def build_pj_path(p):
return os.path.join(p, PACKAGE_JSON_FILENAME)
def build_tmp_pj_path(p):
return os.path.join(p, "tmp." + PACKAGE_JSON_FILENAME)
def build_nm_path(p):
return os.path.join(p, NODE_MODULES_DIRNAME)
def build_nm_bundle_path(p):
return os.path.join(p, NODE_MODULES_WORKSPACE_BUNDLE_FILENAME)
def build_nots_path(build_root: str) -> str:
home_nots = os.getenv("NOTS_STORE_PATH", os.path.join(home_dir(), ".nots"))
build_nots = os.path.join(build_root, ".nots")
if os.getenv("NOTS_BUILDER_ISOLATED_STORE", "no") == "yes":
# this simulates the behavior of the distbuild
os.makedirs(build_nots, exist_ok=True)
else:
try:
if not os.path.exists(home_nots):
os.makedirs(home_nots)
if not os.path.exists(build_nots):
os.symlink(home_nots, build_nots)
except (OSError, RuntimeError):
os.makedirs(build_nots, exist_ok=True)
return build_nots
def build_nm_store_path(build_root: str, moddir: str) -> str:
return os.path.join(build_nots_path(build_root), "nm_store", moddir)
def build_vs_store_path(build_root: str, moddir: str) -> str:
return os.path.join(build_nots_path(build_root), "vm_store", moddir)
def build_traces_store_path(build_root: str, moddir: str) -> str:
return os.path.join(build_nots_path(build_root), "traces", moddir)
def build_pnpm_store_path(build_root: str) -> str:
return os.path.join(build_nots_path(build_root), "pnpm_store")
def extract_package_name_from_path(p):
# if we have scope prefix then we are using the first two tokens, otherwise - only the first one
parts = p.split("/", 2)
return "/".join(parts[:2]) if p.startswith("@") else parts[0]
# PNPM-specific utility functions
def build_pre_lockfile_path(p):
return os.path.join(p, PNPM_PRE_LOCKFILE_FILENAME)
def build_build_backup_lockfile_path(p):
return os.path.join(p, PNPM_BUILD_BACKUP_LOCKFILE_FILENAME)
def build_lockfile_path(p):
return os.path.join(p, PNPM_LOCKFILE_FILENAME)
def build_ws_config_path(p):
return os.path.join(p, PNPM_WS_FILENAME)
|