Skip to content

Commit b92a45a

Browse files
committed
Bug 1882852 - remove vendored createprecomplete in iscript and signingscript
This needed to be kept in sync with the code in mozilla-central, or bad things happen, which bit us in https://bugzilla.mozilla.org/show_bug.cgi?id=1882322 Instead, directly add remove instructions for the extra signature files we're adding, leaving the rest of the file unchanged.
1 parent aa4b9cf commit b92a45a

File tree

8 files changed

+61
-197
lines changed

8 files changed

+61
-197
lines changed

iscript/src/iscript/autograph.py

+22-12
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from mozpack import mozjar
1616
from requests_hawk import HawkAuth
1717

18-
from iscript.createprecomplete import generate_precomplete
1918
from iscript.exceptions import IScriptError
2019
from scriptworker_client.aio import raise_future_exceptions, retry_async
2120
from scriptworker_client.utils import makedirs, rm
@@ -85,6 +84,7 @@ async def sign_widevine_dir(config, sign_config, app_dir):
8584
"""
8685
log.info(f"Signing widevine in {app_dir}...")
8786
all_files = []
87+
signed_files = {}
8888
for top_dir, dirs, files in os.walk(app_dir):
8989
for file_ in files:
9090
all_files.append(os.path.join(top_dir, file_))
@@ -98,11 +98,12 @@ async def sign_widevine_dir(config, sign_config, app_dir):
9898
makedirs(os.path.dirname(to))
9999
tasks.append(asyncio.ensure_future(sign_widevine_with_autograph(sign_config, from_, "blessed" in fmt, to=to)))
100100
all_files.append(to)
101+
signed_files[from_] = to
101102
await raise_future_exceptions(tasks)
102103
remove_extra_files(app_dir, all_files)
103-
# Regenerate the `precomplete` file, which is used for cleanup before
104+
# Update the `precomplete` file, which is used for cleanup before
104105
# applying a complete mar.
105-
_run_generate_precomplete(config, app_dir)
106+
_update_precomplete(config, app_dir, signed_files)
106107
return app_dir
107108

108109

@@ -142,16 +143,25 @@ def _get_widevine_signing_files(file_list):
142143
return files
143144

144145

145-
# _run_generate_precomplete {{{1
146-
def _run_generate_precomplete(config, app_dir):
146+
# _update_precomplete {{{1
147+
def _update_precomplete(config, app_dir, signed_files):
147148
"""Regenerate `precomplete` file with widevine sig paths for complete mar."""
148149
log.info("Generating `precomplete` file...")
149-
path = _ensure_one_precomplete(app_dir, "before")
150-
with open(path, "r") as fh:
150+
precomplete = _ensure_one_precomplete(app_dir)
151+
with open(precomplete, "r") as fh:
151152
before = fh.readlines()
152-
generate_precomplete(os.path.dirname(path))
153-
path = _ensure_one_precomplete(app_dir, "after")
154-
with open(path, "r") as fh:
153+
with open(precomplete, "w") as fh:
154+
for line in before:
155+
fh.write(line)
156+
instr, path = line.strip().split(None, 1)
157+
if instr != "remove":
158+
continue
159+
if not path or path[0] != '"' or path[-1] != '"':
160+
continue
161+
if path[1:-1] not in signed_files:
162+
continue
163+
fh.write('remove "{}"\n'.format(signed_files[path[1:-1]]))
164+
with open(precomplete, "r") as fh:
155165
after = fh.readlines()
156166
# Create diff file
157167
makedirs(os.path.join(config["artifact_dir"], "public", "logs"))
@@ -162,13 +172,13 @@ def _run_generate_precomplete(config, app_dir):
162172

163173

164174
# _ensure_one_precomplete {{{1
165-
def _ensure_one_precomplete(tmp_dir, adj):
175+
def _ensure_one_precomplete(tmp_dir):
166176
"""Ensure we only have one `precomplete` file in `tmp_dir`."""
167177
precompletes = glob.glob(os.path.join(tmp_dir, "**", "precomplete"), recursive=True)
168178
if len(precompletes) < 1:
169179
raise IScriptError('No `precomplete` file found in "%s"', tmp_dir)
170180
if len(precompletes) > 1:
171-
raise IScriptError('More than one `precomplete` file %s in "%s"', adj, tmp_dir)
181+
raise IScriptError('More than one `precomplete` file in "%s"', tmp_dir)
172182
return precompletes[0]
173183

174184

iscript/src/iscript/createprecomplete.py

-76
This file was deleted.

iscript/tests/test_autograph.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ def fake_isfile(path):
135135

136136
mocker.patch.object(autograph, "sign_widevine_with_autograph", new=noop_async)
137137
mocker.patch.object(autograph, "makedirs", new=noop_sync)
138-
mocker.patch.object(autograph, "generate_precomplete", new=noop_sync)
139-
mocker.patch.object(autograph, "_run_generate_precomplete", new=noop_sync)
138+
mocker.patch.object(autograph, "_update_precomplete", new=noop_sync)
140139
mocker.patch.object(os.path, "isfile", new=fake_isfile)
141140
mocker.patch.object(os, "walk", new=fake_walk)
142141

@@ -172,22 +171,21 @@ def test_get_widevine_signing_files(filenames, expected):
172171
assert autograph._get_widevine_signing_files(filenames) == expected
173172

174173

175-
# _run_generate_precomplete {{{1
174+
# _update_precomplete {{{1
176175
@pytest.mark.parametrize("num_precomplete,raises", ((1, False), (0, True), (2, True)))
177-
def test_run_generate_precomplete(tmp_path, num_precomplete, raises, mocker):
178-
mocker.patch.object(autograph, "generate_precomplete", new=noop_sync)
176+
def test_update_precomplete(tmp_path, num_precomplete, raises, mocker):
179177
work_dir = tmp_path / "work"
180178
config = {"artifact_dir": tmp_path / "artifacts"}
181179
for i in range(0, num_precomplete):
182180
path = os.path.join(work_dir, "foo", str(i))
183181
makedirs(path)
184182
with open(os.path.join(path, "precomplete"), "w") as fh:
185-
fh.write("blah")
183+
fh.write('remove "blah"\n')
186184
if raises:
187185
with pytest.raises(IScriptError):
188-
autograph._run_generate_precomplete(config, work_dir)
186+
autograph._update_precomplete(config, work_dir, {})
189187
else:
190-
autograph._run_generate_precomplete(config, work_dir)
188+
autograph._update_precomplete(config, work_dir, {})
191189

192190

193191
# remove_extra_files {{{1

iscript/tox.ini

-2
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,3 @@ addopts = -vv -s --color=yes
5858

5959
[coverage:run]
6060
branch = true
61-
omit =
62-
src/iscript/createprecomplete.py

signingscript/src/signingscript/createprecomplete.py

-76
This file was deleted.

signingscript/src/signingscript/sign.py

+26-14
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
from winsign.crypto import load_pem_certs
3131

3232
from signingscript import task, utils
33-
from signingscript.createprecomplete import generate_precomplete
3433
from signingscript.exceptions import SigningScriptError
3534
from signingscript.rcodesign import RCodesignError, rcodesign_notarize, rcodesign_notary_wait, rcodesign_staple
3635

@@ -307,18 +306,20 @@ async def sign_widevine_zip(context, orig_path, fmt):
307306
# Extract all files so we can create `precomplete` with the full
308307
# file list
309308
all_files = await _extract_zipfile(context, orig_path, tmp_dir=tmp_dir)
309+
signed_files = {}
310310
tasks = []
311311
# Sign the appropriate inner files
312312
for from_, fmt in files_to_sign.items():
313313
from_ = os.path.join(tmp_dir, from_)
314314
to = f"{from_}.sig"
315315
tasks.append(asyncio.ensure_future(sign_widevine_with_autograph(context, from_, "blessed" in fmt, to=to)))
316316
all_files.append(to)
317+
signed_files[from_] = to
317318
await raise_future_exceptions(tasks)
318319
remove_extra_files(tmp_dir, all_files)
319-
# Regenerate the `precomplete` file, which is used for cleanup before
320+
# Update the `precomplete` file, which is used for cleanup before
320321
# applying a complete mar.
321-
_run_generate_precomplete(context, tmp_dir)
322+
_update_precomplete(context, tmp_dir, signed_files)
322323
await _create_zipfile(context, orig_path, all_files, mode="w", tmp_dir=tmp_dir)
323324
return orig_path
324325

@@ -358,6 +359,7 @@ async def sign_widevine_tar(context, orig_path, fmt):
358359
# Extract all files so we can create `precomplete` with the full
359360
# file list
360361
all_files = await _extract_tarfile(context, orig_path, compression, tmp_dir=tmp_dir)
362+
signed_files = {}
361363
tasks = []
362364
# Sign the appropriate inner files
363365
for from_, fmt in files_to_sign.items():
@@ -371,11 +373,12 @@ async def sign_widevine_tar(context, orig_path, fmt):
371373
makedirs(os.path.dirname(to))
372374
tasks.append(asyncio.ensure_future(sign_widevine_with_autograph(context, from_, "blessed" in fmt, to=to)))
373375
all_files.append(to)
376+
signed_files[from_] = to
374377
await raise_future_exceptions(tasks)
375378
remove_extra_files(tmp_dir, all_files)
376-
# Regenerate the `precomplete` file, which is used for cleanup before
379+
# Update the `precomplete` file, which is used for cleanup before
377380
# applying a complete mar.
378-
_run_generate_precomplete(context, tmp_dir)
381+
_update_precomplete(context, tmp_dir, signed_files)
379382
await _create_tarfile(context, orig_path, all_files, compression, tmp_dir=tmp_dir)
380383
return orig_path
381384

@@ -577,16 +580,25 @@ def _get_omnija_signing_files(file_list):
577580
return files
578581

579582

580-
# _run_generate_precomplete {{{1
581-
def _run_generate_precomplete(context, tmp_dir):
583+
# _update_precomplete {{{1
584+
def _update_precomplete(context, tmp_dir, signed_files):
582585
"""Regenerate `precomplete` file with widevine sig paths for complete mar."""
583586
log.info("Generating `precomplete` file...")
584-
path = _ensure_one_precomplete(tmp_dir, "before")
585-
with open(path, "r") as fh:
587+
precomplete = _ensure_one_precomplete(tmp_dir)
588+
with open(precomplete, "r") as fh:
586589
before = fh.readlines()
587-
generate_precomplete(os.path.dirname(path))
588-
path = _ensure_one_precomplete(tmp_dir, "after")
589-
with open(path, "r") as fh:
590+
with open(precomplete, "w") as fh:
591+
for line in before:
592+
fh.write(line)
593+
instr, path = line.strip().split(None, 1)
594+
if instr != "remove":
595+
continue
596+
if not path or path[0] != '"' or path[-1] != '"':
597+
continue
598+
if path[1:-1] not in signed_files:
599+
continue
600+
fh.write('remove "{}"\n'.format(signed_files[path[1:-1]]))
601+
with open(precomplete, "r") as fh:
590602
after = fh.readlines()
591603
# Create diff file
592604
diff_path = os.path.join(context.config["work_dir"], "precomplete.diff")
@@ -597,14 +609,14 @@ def _run_generate_precomplete(context, tmp_dir):
597609

598610

599611
# _ensure_one_precomplete {{{1
600-
def _ensure_one_precomplete(tmp_dir, adj):
612+
def _ensure_one_precomplete(tmp_dir):
601613
"""Ensure we only have one `precomplete` file in `tmp_dir`."""
602614
return get_single_item_from_sequence(
603615
glob.glob(os.path.join(tmp_dir, "**", "precomplete"), recursive=True),
604616
condition=lambda _: True,
605617
ErrorClass=SigningScriptError,
606618
no_item_error_message='No `precomplete` file found in "{}"'.format(tmp_dir),
607-
too_many_item_error_message='More than one `precomplete` file {} in "{}"'.format(adj, tmp_dir),
619+
too_many_item_error_message='More than one `precomplete` file in "{}"'.format(tmp_dir),
608620
)
609621

610622

0 commit comments

Comments
 (0)