Skip to content

Commit 9a46522

Browse files
committed
Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios
2 parents 8d44e4d + bae29f3 commit 9a46522

32 files changed

+581
-138
lines changed

build-system/Make/BazelLocation.py

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
11
import os
22
import stat
33
import sys
4+
from urllib.parse import urlparse, urlunparse
5+
import tempfile
6+
import hashlib
7+
import shutil
48

5-
from BuildEnvironment import is_apple_silicon, resolve_executable, call_executable, BuildEnvironmentVersions
9+
from BuildEnvironment import is_apple_silicon, resolve_executable, call_executable, run_executable_with_status, BuildEnvironmentVersions
610

7-
def locate_bazel(base_path):
11+
def transform_cache_host_into_http(grpc_url):
12+
parsed_url = urlparse(grpc_url)
13+
14+
new_scheme = "http"
15+
new_port = 8080
16+
17+
transformed_url = urlunparse((
18+
new_scheme,
19+
f"{parsed_url.hostname}:{new_port}",
20+
parsed_url.path,
21+
parsed_url.params,
22+
parsed_url.query,
23+
parsed_url.fragment
24+
))
25+
26+
return transformed_url
27+
28+
29+
def calculate_sha256(file_path):
30+
sha256_hash = hashlib.sha256()
31+
with open(file_path, "rb") as file:
32+
# Read the file in chunks to avoid using too much memory
33+
for byte_block in iter(lambda: file.read(4096), b""):
34+
sha256_hash.update(byte_block)
35+
return sha256_hash.hexdigest()
36+
37+
38+
def locate_bazel(base_path, cache_host):
839
build_input_dir = '{}/build-input'.format(base_path)
940
if not os.path.isdir(build_input_dir):
1041
os.mkdir(build_input_dir)
@@ -17,6 +48,33 @@ def locate_bazel(base_path):
1748
bazel_name = 'bazel-{version}-{arch}'.format(version=versions.bazel_version, arch=arch)
1849
bazel_path = '{}/build-input/{}'.format(base_path, bazel_name)
1950

51+
if not os.path.isfile(bazel_path):
52+
if cache_host is not None and versions.bazel_version_sha256 is not None:
53+
http_cache_host = transform_cache_host_into_http(cache_host)
54+
55+
with tempfile.NamedTemporaryFile(delete=True) as temp_output_file:
56+
call_executable([
57+
'curl',
58+
'-L',
59+
'{cache_host}/cache/cas/{hash}'.format(
60+
cache_host=http_cache_host,
61+
hash=versions.bazel_version_sha256
62+
),
63+
'--output',
64+
temp_output_file.name
65+
], check_result=False)
66+
test_sha256 = calculate_sha256(temp_output_file.name)
67+
if test_sha256 == versions.bazel_version_sha256:
68+
shutil.copyfile(temp_output_file.name, bazel_path)
69+
70+
71+
if os.path.isfile(bazel_path) and versions.bazel_version_sha256 is not None:
72+
test_sha256 = calculate_sha256(bazel_path)
73+
if test_sha256 != versions.bazel_version_sha256:
74+
print(f"Bazel at {bazel_path} does not match SHA256 {versions.bazel_version_sha256}, removing")
75+
os.remove(bazel_path)
76+
77+
2078
if not os.path.isfile(bazel_path):
2179
call_executable([
2280
'curl',
@@ -29,6 +87,27 @@ def locate_bazel(base_path):
2987
bazel_path
3088
])
3189

90+
if os.path.isfile(bazel_path) and versions.bazel_version_sha256 is not None:
91+
test_sha256 = calculate_sha256(bazel_path)
92+
if test_sha256 != versions.bazel_version_sha256:
93+
print(f"Bazel at {bazel_path} does not match SHA256 {versions.bazel_version_sha256}, removing")
94+
os.remove(bazel_path)
95+
96+
if cache_host is not None and versions.bazel_version_sha256 is not None:
97+
http_cache_host = transform_cache_host_into_http(cache_host)
98+
print(f"Uploading bazel@{versions.bazel_version_sha256} to bazel-remote")
99+
call_executable([
100+
'curl',
101+
'-X',
102+
'PUT',
103+
'-T',
104+
bazel_path,
105+
'{cache_host}/cache/cas/{hash}'.format(
106+
cache_host=http_cache_host,
107+
hash=versions.bazel_version_sha256
108+
)
109+
], check_result=False)
110+
32111
if not os.access(bazel_path, os.X_OK):
33112
st = os.stat(bazel_path)
34113
os.chmod(bazel_path, st.st_mode | stat.S_IEXEC)

build-system/Make/BuildConfiguration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def write_to_variables_file(self, bazel_path, use_xcode_managed_codesigning, aps
6262

6363
def build_configuration_from_json(path):
6464
if not os.path.exists(path):
65-
print('Could not load build configuration from {}'.format(path))
65+
print('Could not load build configuration from non-existing path {}'.format(path))
6666
sys.exit(1)
6767
with open(path) as file:
6868
configuration_dict = json.load(file)

build-system/Make/BuildEnvironment.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,28 @@ def run_executable_with_output(path, arguments, decode=True, input=None, stderr_
6565
return output_data
6666

6767

68+
def run_executable_with_status(arguments, use_clean_environment=True):
69+
executable_path = resolve_executable(arguments[0])
70+
if executable_path is None:
71+
raise Exception(f'Could not resolve {arguments[0]} to a valid executable file')
72+
73+
if use_clean_environment:
74+
resolved_env = get_clean_env()
75+
else:
76+
resolved_env = os.environ
77+
78+
resolved_arguments = [executable_path] + arguments[1:]
79+
80+
result = subprocess.run(
81+
resolved_arguments,
82+
env=resolved_env,
83+
stdout=subprocess.PIPE,
84+
stderr=subprocess.PIPE
85+
)
86+
87+
return result.returncode
88+
89+
6890
def call_executable(arguments, use_clean_environment=True, check_result=True):
6991
executable_path = resolve_executable(arguments[0])
7092
if executable_path is None:
@@ -135,7 +157,9 @@ def __init__(
135157
if configuration_dict['bazel'] is None:
136158
raise Exception('Missing bazel version in {}'.format(configuration_path))
137159
else:
138-
self.bazel_version = configuration_dict['bazel']
160+
bazel_version, bazel_version_sha256 = configuration_dict['bazel'].split(':')
161+
self.bazel_version = bazel_version
162+
self.bazel_version_sha256 = bazel_version_sha256
139163
if configuration_dict['xcode'] is None:
140164
raise Exception('Missing xcode version in {}'.format(configuration_path))
141165
else:

build-system/Make/Make.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ def add_project_and_build_common_arguments(current_parser: argparse.ArgumentPars
985985

986986
bazel_path = None
987987
if args.bazel is None:
988-
bazel_path = locate_bazel(base_path=os.getcwd())
988+
bazel_path = locate_bazel(base_path=os.getcwd(), cache_host=args.cacheHost)
989989
else:
990990
bazel_path = args.bazel
991991

build-system/Make/RemoteBuild.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def handle_ssh_credentials(credentials):
161161
sys.exit(1)
162162

163163
DarwinContainers.run_remote_ssh(credentials=credentials, command='')
164-
sys.exit(0)
164+
#sys.exit(0)
165165

166166
def handle_stopped():
167167
pass
7.22 KB
Binary file not shown.
Binary file not shown.
2.38 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)