Skip to content

Commit

Permalink
Bug 1944955 - Have action.zip dump dependencies if asked to r=glandium
Browse files Browse the repository at this point in the history
This avoids unnecessary command execution upon nop build

Differential Revision: https://phabricator.services.mozilla.com/D237269
  • Loading branch information
serge-sans-paille committed Feb 25, 2025
1 parent 9c5505d commit 8807117
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
8 changes: 6 additions & 2 deletions config/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -890,9 +890,13 @@ endif
# When you move this out of the tools tier, please remove the corresponding
# hacks in recursivemake.py that check if Makefile.in sets the variable.
ifneq ($(XPI_PKGNAME),)
tools realchrome::
tools realchrome::$(FINAL_TARGET)/../$(XPI_PKGNAME).xpi

XPI_PKGNAME_DEPS=$(MDDEPDIR)/$(XPI_PKGNAME).d
EXTRA_MDDEPEND_FILES += $(XPI_PKGNAME_DEPS)
$(FINAL_TARGET)/../$(XPI_PKGNAME).xpi:
@echo 'Packaging $(XPI_PKGNAME).xpi...'
$(call py_action,zip $(XPI_PKGNAME).xpi,-C $(FINAL_TARGET) ../$(XPI_PKGNAME).xpi '*')
$(call py_action,zip $(XPI_PKGNAME).xpi,-C $(FINAL_TARGET) ../$(XPI_PKGNAME).xpi '*' --dep-target $(FINAL_TARGET)/../$(XPI_PKGNAME).xpi --dep-file $(XPI_PKGNAME_DEPS))
endif

#############################################################################
Expand Down
23 changes: 23 additions & 0 deletions python/mozbuild/mozbuild/action/zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# it finds before adding them to the zip.

import argparse
import os
import sys

import mozpack.path as mozpath
Expand All @@ -14,6 +15,9 @@
from mozpack.files import FileFinder
from mozpack.path import match

from mozbuild.makeutil import Makefile
from mozbuild.util import FileAvoidWrite


def main(args):
parser = argparse.ArgumentParser()
Expand All @@ -33,18 +37,37 @@ def main(args):
)
parser.add_argument("zip", help="Path to zip file to write")
parser.add_argument("input", nargs="+", help="Path to files to add to zip")
parser.add_argument(
"--dep-file",
help="File to write any additional make dependencies to",
)
parser.add_argument(
"--dep-target",
help="Make target to use in the dependencies file",
)
args = parser.parse_args(args)

jarrer = Jarrer()

deps = []
with errors.accumulate():
finder = FileFinder(args.C, find_executables=args.strip)
for path in args.input:
for p, f in finder.find(path):
if not any([match(p, exclude) for exclude in args.x]):
jarrer.add(p, f)
deps.append(f.path)
jarrer.copy(mozpath.join(args.C, args.zip))

if args.dep_target and args.dep_file:
mk = Makefile()
mk.create_rule([args.dep_target]).add_dependencies(deps)
mk.create_rule(deps) # empty rule to avoid error if a file gets removed

os.makedirs(mozpath.dirname(args.dep_file), exist_ok=True)
with FileAvoidWrite(args.dep_file) as dep_file:
mk.dump(dep_file)


if __name__ == "__main__":
main(sys.argv[1:])

0 comments on commit 8807117

Please sign in to comment.