Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,7 @@ def test_embed_file_dup(self, args):
self.do_runf('main.c', '|frist|\n|sacond|\n|thard|\n',
cflags=['--embed-file', 'tst'] + args)

def test_exclude_file(self):
def test_file_packager_exclude_file(self):
ensure_dir('tst/abc.exe')
ensure_dir('tst/abc.txt')

Expand All @@ -2083,6 +2083,52 @@ def test_exclude_file(self):
self.run_process([EMCC, 'main.c', '--embed-file', 'tst', '--exclude-file', '*.exe'])
self.assertEqual(self.run_js('a.out.js').strip(), '')

def test_file_packager_exclude_file_negative(self):
ensure_dir('tst/abc.exe')
ensure_dir('tst/abc.txt')

create_file('tst/hello.exe', 'hello')
create_file('tst/hello.txt', 'world')
create_file('tst/abc.exe/foo', 'emscripten')
create_file('tst/abc.txt/bar', '!!!')
create_file('main.c', r'''
#include <stdio.h>
int main() {
if(!fopen("tst/hello.exe", "rb")) printf("Failed\n");
if(!fopen("tst/hello.txt", "rb")) printf("Failed\n");
if(fopen("tst/abc.exe/foo", "rb")) printf("Failed\n");
if(!fopen("tst/abc.txt/bar", "rb")) printf("Failed\n");

return 0;
}
''')

self.run_process([EMCC, 'main.c', '--embed-file', 'tst', '--exclude-file', '*.exe', '--exclude-file', '!*hello.exe'])
self.assertEqual(self.run_js('a.out.js').strip(), '')

def test_file_packager_exclude_file_negative_order(self):
ensure_dir('tst/abc.exe')
ensure_dir('tst/abc.txt')

create_file('tst/hello.exe', 'hello')
create_file('tst/hello.txt', 'world')
create_file('tst/abc.exe/foo', 'emscripten')
create_file('tst/abc.txt/bar', '!!!')
create_file('main.c', r'''
#include <stdio.h>
int main() {
if(fopen("tst/hello.exe", "rb")) printf("Failed\n");
if(!fopen("tst/hello.txt", "rb")) printf("Failed\n");
if(fopen("tst/abc.exe/foo", "rb")) printf("Failed\n");
if(!fopen("tst/abc.txt/bar", "rb")) printf("Failed\n");

return 0;
}
''')

self.run_process([EMCC, 'main.c', '--embed-file', 'tst', '--exclude-file', '!*hello.exe', '--exclude-file', '*.exe'])
self.assertEqual(self.run_js('a.out.js').strip(), '')

def test_dylink_strict(self):
self.do_run_in_out_file_test('hello_world.c', cflags=['-sSTRICT', '-sMAIN_MODULE=1'])

Expand Down
12 changes: 10 additions & 2 deletions tools/file_packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

--exclude E [F..] Specifies filename pattern matches to use for excluding given files from being added to the package.
See https://docs.python.org/2/library/fnmatch.html for syntax.
Negative patterns are also supported using ! prefex.

--from-emcc Indicate that `file_packager` was called from `emcc` and will be further processed by it, so some code generation can be skipped here

Expand Down Expand Up @@ -156,8 +157,15 @@ def should_ignore(fullname):
is hidden (Win32) or it matches any pattern specified in --exclude"""
if has_hidden_attribute(fullname):
return True

return any(fnmatch.fnmatch(fullname, p) for p in excluded_patterns)
ignored = False
for pattern in excluded_patterns:
if pattern.startswith("!"):
if fnmatch.fnmatch(fullname, pattern[1:]):
ignored = False
else:
if fnmatch.fnmatch(fullname, pattern):
ignored = True
return ignored


def add(mode, rootpathsrc, rootpathdst):
Expand Down