Skip to content

Commit

Permalink
do not recrunch if dds is unchanged
Browse files Browse the repository at this point in the history
  • Loading branch information
kripken committed Jun 18, 2012
1 parent b72e2aa commit 0b2ef82
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
19 changes: 19 additions & 0 deletions tests/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7183,6 +7183,25 @@ def test_link_s(self):
code = open('a.out.js').read()
assert 'SAFE_HEAP' in code, 'valid -s option had an effect'

def test_crunch(self):
# crunch should not be run if a .crn exists that is more recent than the .dds
shutil.copyfile(path_from_root('tests', 'ship.dds'), 'ship.dds')
time.sleep(0.1)
Popen(['python', FILE_PACKAGER, 'test.data', '--pre-run', '--crunch=32', '--preload', 'ship.dds'], stdout=open('pre.js', 'w')).communicate()
assert os.stat('test.data').st_size < 0.25*os.stat('ship.dds').st_size, 'Compressed should be much smaller than dds'
crunch_time = os.stat('ship.crn').st_mtime
dds_time = os.stat('ship.dds').st_mtime
assert crunch_time > dds_time, 'Crunch is more recent'
# run again, should not recrunch!
time.sleep(0.1)
Popen(['python', FILE_PACKAGER, 'test.data', '--pre-run', '--crunch=32', '--preload', 'ship.dds'], stdout=open('pre.js', 'w')).communicate()
assert crunch_time == os.stat('ship.crn').st_mtime, 'Crunch is unchanged'
# update dds, so should recrunch
time.sleep(0.1)
os.utime('ship.dds', None)
Popen(['python', FILE_PACKAGER, 'test.data', '--pre-run', '--crunch=32', '--preload', 'ship.dds'], stdout=open('pre.js', 'w')).communicate()
assert crunch_time < os.stat('ship.crn').st_mtime, 'Crunch was changed'

elif 'browser' in str(sys.argv):
# Browser tests.

Expand Down
10 changes: 8 additions & 2 deletions tools/file_packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
be added to convert the crn to dds in the browser.
crunch-worker.js will be generated in the current directory. You should include that file when
packaging your site.
DDS files will not be crunched if the .crn is more recent than the .dds. This prevents a lot of
unneeded computation.
TODO: You can also provide .crn files yourself, pre-crunched. With this option, they will be decompressed
to dds files in the browser, exactly the same as if this tool compressed them.
Expand Down Expand Up @@ -156,9 +158,13 @@ def was_seen(name):

for file_ in data_files:
if file_['name'].endswith(CRUNCH_INPUT_SUFFIX):
# TODO: do not crunch if crunched version exists and is more recent than dds source
Popen([CRUNCH, '-file', file_['name'], '-quality', crunch], stdout=sys.stderr).communicate()
# Do not crunch if crunched version exists and is more recent than dds source
crunch_name = unsuffixed(file_['name']) + CRUNCH_OUTPUT_SUFFIX
crunch_time = os.stat(crunch_name).st_mtime
dds_time = os.stat(file_['name']).st_mtime
if dds_time < crunch_time: continue

Popen([CRUNCH, '-file', file_['name'], '-quality', crunch], stdout=sys.stderr).communicate()
shutil.move(os.path.basename(crunch_name), crunch_name) # crunch places files in the current dir
# prepend the dds header
crunched = open(crunch_name, 'rb').read()
Expand Down

0 comments on commit 0b2ef82

Please sign in to comment.