Skip to content

Commit c3a990d

Browse files
authored
Support the exclusion of entire paths when creating package files. Rename create_xpi.py to create_zip.py (EFForg#14440)
1 parent 4a07684 commit c3a990d

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

.build_exclusions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ webextension/chrome-resources/update-from-chrome-svn.sh
1616
.eslintrc.json
1717
webextension/.eslintrc.json
1818
.eslintignore
19+
node_modules

make.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ trap 'rm -f "$pub" "$sig" "$zip"' EXIT
109109

110110
# zip up the crx dir
111111
cwd=$(pwd -P)
112-
(cd "$dir" && ../../utils/create_xpi.py -n "$cwd/$zip" -x "../../.build_exclusions" .)
112+
(cd "$dir" && ../../utils/create_zip.py -n "$cwd/$zip" -x "../../.build_exclusions" .)
113+
echo >&2 "CWS crx package has sha1sum: `sha1sum "$cwd/$zip"`"
113114

114115
# signature
115116
openssl sha1 -sha1 -binary -sign "$key" < "$zip" > "$sig"
@@ -147,7 +148,7 @@ dir=pkg/xpi-amo
147148
zip="$name.zip"
148149

149150
cwd=$(pwd -P)
150-
(cd "$dir" && ../../utils/create_xpi.py -n "$cwd/$zip" -x "../../.build_exclusions" .)
151+
(cd "$dir" && ../../utils/create_zip.py -n "$cwd/$zip" -x "../../.build_exclusions" .)
151152
echo >&2 "AMO xpi package has sha1sum: `sha1sum "$cwd/$zip"`"
152153

153154
cp $zip $xpi_amo
@@ -160,7 +161,7 @@ dir=pkg/xpi-eff
160161
zip="$name.zip"
161162

162163
cwd=$(pwd -P)
163-
(cd "$dir" && ../../utils/create_xpi.py -n "$cwd/$zip" -x "../../.build_exclusions" .)
164+
(cd "$dir" && ../../utils/create_zip.py -n "$cwd/$zip" -x "../../.build_exclusions" .)
164165
echo >&2 "EFF xpi package has sha1sum: `sha1sum "$cwd/$zip"`"
165166

166167
cp $zip $xpi_eff
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env python2.7
22

3-
# Uses the Python zip implementation to create deterministic XPI's
3+
# Uses the Python zip implementation to create deterministic zip's
44
# Author: Yan Zhu, yan@mit.edu
55

66
"""
7-
Usage: python create_xpi.py -x <exclusions> -n <name of zipped file> <directory>
7+
Usage: python create_zip.py -x <exclusions> -n <name of zipped file> <directory>
88
"""
99

1010
import argparse
@@ -13,20 +13,20 @@
1313
import zipfile_deterministic as zipfile
1414

1515
parser = argparse.ArgumentParser(
16-
description="Deterministic XPI file creator.")
16+
description="Deterministic zip file creator.")
1717
parser.add_argument("-x", type=str, nargs="?",
1818
dest="exclusions", metavar="File with file pattern exclusions",
1919
default=".build_exclusions", help="Excluded file patterns.")
2020
parser.add_argument("-n", type=str,
21-
dest="xpiname", help="Name of target XPI file.")
21+
dest="zipname", help="Name of target zip file.")
2222
parser.add_argument("directory", type=str,
2323
help="Directory to compress.")
2424

2525
args = parser.parse_args()
2626

2727
compress = zipfile.ZIP_DEFLATED
2828

29-
xpiFile = zipfile.ZipFile(args.xpiname, mode='w', compression=compress)
29+
createdZipFile = zipfile.ZipFile(args.zipname, mode='w', compression=compress)
3030

3131
f = open(args.exclusions)
3232

@@ -37,5 +37,5 @@
3737
exclusions.extend(glob.glob(line.strip()))
3838
exclusions = map(lambda x: './'+x, exclusions)
3939

40-
xpiFile.write_from_directory(".", exclusions, compress_type=compress)
41-
xpiFile.close()
40+
createdZipFile.write_from_directory(".", exclusions, compress_type=compress)
41+
createdZipFile.close()

utils/zipfile_deterministic.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,10 +1146,14 @@ def write_from_directory(self, directory, exclusions=None,
11461146
"""
11471147
file_dict = {}
11481148
for root,subfolders,files in os.walk(directory):
1149-
for fi in files:
1150-
filename = os.path.join(root, fi)
1151-
if filename not in exclusions:
1152-
file_dict.update({standardize_filename(filename): filename})
1149+
path_fragments = root.split(os.sep)
1150+
path_nested = [os.path.join(*path_fragments[:x + 1]) for x, _ in enumerate(path_fragments)]
1151+
1152+
if not set(path_nested) & set(exclusions):
1153+
for fi in files:
1154+
filename = os.path.join(root, fi)
1155+
if filename not in exclusions:
1156+
file_dict.update({standardize_filename(filename): filename})
11531157
for new_filename, old_filename in sorted(file_dict.items()):
11541158
self.write(old_filename, compress_type=compress_type, date_time=date_time)
11551159

0 commit comments

Comments
 (0)