From b821dbd9b86e1ccb545d4d9e3a16ef16dbf9fba7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 12 Feb 2014 12:08:29 +0530 Subject: [PATCH] Only recompile coffescript if the source has actually changed since the last time it was compiled, rather than relying on mtimes. --- resources/compiled_coffeescript.zip | Bin 79026 -> 79792 bytes setup/resources.py | 28 ++++++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/resources/compiled_coffeescript.zip b/resources/compiled_coffeescript.zip index b1312cffc9b5a85941f6f5553223fa8006d25318..249e8bb4905840c6cfb359a84052516c6bd16461 100644 GIT binary patch delta 1059 zcmY*XO=wj|6u$HFtVTm38ecGp<>es=BF~vQ=gv=XBe>Iri!Lle$^6==@S=%7AR-8& z;KD_MR}c{wUHj95TZOujLJaPD`%@0|0UJ1_ohK3i{& zpFBR&oGkKLS~zj+$KJy+)9mH!=WG9r_Ota1?*`e^(??p(ns?*B-^Uugh38|BPxpaW zx8iv7Q5GItJGylwkzTI1$(x<4U$1Se887W9xj8jM8j~ac_dD>*zHfh9D2g0=t6v$} zU;PARS36HIedyGO*P}&|V_zO{cy^lVF_1mgM^0Kb_4fM5*Y^`G$J~&Xld*Gs>K#s| zYd6)7lr{cX>BC1jnX0F&-a>-s?)Kq-fwYpl>J=lijpl6Jtqk-YV}uBrmKHby)lxVsg$EzCWFm^d ztO~vy>eZ!{#q-MpwM)Gy=Ms=nN;O!6+$Nouik8xQN>MQjnANNEYcsWBrAy@$@>p7n zsgYKUGUc7{)H>~ibY3G3YNO@eTBViLTu{S=V$QLc-hwQRDKX8jg98fDmE3Hoc30^- zZNE|foHBC8qAiW`C<2rcBSV`K}{T2n70m7wIHRy8t5X1jR^lR68^1O^1740WXt-1rE> P7;O}1K9sA05%k>ev{@?qA}53;m-vH| zW#_U|=gpfxr}41}0cE$#GBG-`gP9xocoM;k&HCN4$|Nm6L6=`E&xj5f*|pN$EsfISAAM!m=ou zwpD|Tw=!ZBQvmt$)RX%`hI|YRAS{ida#Jf%rR?-Q#*92*A5TAH%qYbqGi7=KC!@%8 zdnQIs6l*~NrG7>>@@4`90|-l^7?wC2Z0%=5Mj?n{?~QDi|}034((1;~ zA>s@SAS^Ro$%Ikate_~hEHkxSFRK{YkHCO-NeRpAm@L4+0K)PpmOWCKZV1#X!pa5` Q<^sZ3ObiU03>kqu0MdtqiU0rr diff --git a/setup/resources.py b/setup/resources.py index 051677ba17..1bcc288ca0 100644 --- a/setup/resources.py +++ b/setup/resources.py @@ -6,8 +6,9 @@ __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import os, cPickle, re, shutil, marshal, zipfile, glob, time, subprocess, sys +import os, cPickle, re, shutil, marshal, zipfile, glob, time, subprocess, sys, hashlib, json from zlib import compress +from itertools import chain from setup import Command, basenames, __appname__ @@ -62,18 +63,20 @@ class Coffee(Command): # {{{ '*.coffee')): bn = os.path.basename(f).rpartition('.')[0] arcname = src.replace('/', '.') + '.' + bn + '.js' - src_files[arcname] = (f, os.stat(f).st_mtime) + with open(f, 'rb') as fs: + src_files[arcname] = (f, hashlib.sha1(fs.read()).hexdigest()) existing = {} dest = self.j(self.RESOURCES, 'compiled_coffeescript.zip') if os.path.exists(dest): with zipfile.ZipFile(dest, 'r') as zf: + existing_hashes = {} + raw = zf.comment + if raw: + existing_hashes = json.loads(raw) for info in zf.infolist(): - mtime = time.mktime(info.date_time + (0, 0, -1)) - arcname = info.filename - if (arcname in src_files and src_files[arcname][1] < - mtime): - existing[arcname] = (zf.read(info), info) + if info.filename in existing_hashes and src_files.get(info.filename, (None, None))[1] == existing_hashes[info.filename]: + existing[info.filename] = (zf.read(info), info, existing_hashes[info.filename]) todo = set(src_files) - set(existing) updated = {} @@ -81,7 +84,7 @@ class Coffee(Command): # {{{ name = arcname.rpartition('.')[0] print ('\t%sCompiling %s'%(time.strftime('[%H:%M:%S] ') if timestamp else '', name)) - src = src_files[arcname][0] + src, sig = src_files[arcname] try: js = subprocess.check_output(self.compiler + [src]).decode('utf-8') @@ -100,13 +103,14 @@ class Coffee(Command): # {{{ zi = zipfile.ZipInfo() zi.filename = arcname zi.date_time = time.localtime()[:6] - updated[arcname] = (js.encode('utf-8'), zi) + updated[arcname] = (js.encode('utf-8'), zi, sig) if updated: + hashes = {} with zipfile.ZipFile(dest, 'w', zipfile.ZIP_STORED) as zf: - for raw, zi in updated.itervalues(): - zf.writestr(zi, raw) - for raw, zi in existing.itervalues(): + for raw, zi, sig in sorted(chain(updated.itervalues(), existing.itervalues()), key=lambda x: x[1].filename): zf.writestr(zi, raw) + hashes[zi.filename] = sig + zf.comment = json.dumps(hashes) def clean(self): x = self.j(self.RESOURCES, 'compiled_coffeescript.zip')