diff options
author | JF Bastien <jfb@chromium.org> | 2016-01-06 19:32:56 -0800 |
---|---|---|
committer | JF Bastien <jfb@chromium.org> | 2016-01-06 19:32:56 -0800 |
commit | d73b0be51bc1d64c0fcb6a992927ace75876abde (patch) | |
tree | 9bb0bc4c0fd67b1468a1407ee44072ca8fbbf3c9 /update.py | |
parent | d8c94b6ad4094b580f4a788de3733b5433ca4c2a (diff) | |
download | binaryen-d73b0be51bc1d64c0fcb6a992927ace75876abde.tar.gz binaryen-d73b0be51bc1d64c0fcb6a992927ace75876abde.tar.bz2 binaryen-d73b0be51bc1d64c0fcb6a992927ace75876abde.zip |
update.py: update only if needed
@kripken asked if test/lkgr could be updated only if the downloaded content is different. This patch does just that.
Diffstat (limited to 'update.py')
-rwxr-xr-x | update.py | 58 |
1 files changed, 40 insertions, 18 deletions
@@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import filecmp import glob import os import shutil @@ -24,17 +25,19 @@ import urllib2 STORAGE_BASE = 'https://storage.googleapis.com/wasm-llvm/builds/git/' -BASE_DIR = 'test' +BASE_DIR = os.path.abspath('test') LKGR_PATH = os.path.join(BASE_DIR, 'lkgr') TORTURE_TAR = 'wasm-torture-s-%s.tbz2' -TORTURE_FOLDER = os.path.join(BASE_DIR, 'torture-s') +TORTURE_DIR = os.path.join(BASE_DIR, 'torture-s') def download_last_known_good_revision(): - with open(LKGR_PATH, 'w+') as f: - lkgr = urllib2.urlopen(STORAGE_BASE + 'lkgr').read().strip() + return urllib2.urlopen(STORAGE_BASE + 'lkgr').read().strip() + + +def write_lkgr(lkgr): + with open(LKGR_PATH, 'w') as f: f.write(lkgr) - return lkgr def download_tar_at_lkgr(tar_pattern, lkgr): @@ -50,18 +53,32 @@ def download_tar_at_lkgr(tar_pattern, lkgr): return lkgr_tar_path -def untar(tarfile, outfolder): - if os.path.exists(outfolder): - shutil.rmtree(outfolder) - with tempfile.TemporaryFile(mode='w+') as f: - try: - base = os.path.basename(tarfile) - subprocess.check_call(['tar', '-xvf', base], cwd=BASE_DIR, stdout=f) - except: - f.seek(0) - sys.stderr.write(f.read()) - raise - assert os.path.isdir(outfolder), 'Expected to untar into %s' % outfolder +def untar(tarfile, outdir): + """Returns True if the untar dir differs from a pre-existing dir.""" + tmp_dir = tempfile.mkdtemp() + try: + with tempfile.TemporaryFile(mode='w+') as f: + try: + subprocess.check_call(['tar', '-xvf', tarfile], cwd=tmp_dir, stdout=f) + except: + f.seek(0) + sys.stderr.write(f.read()) + raise + untar_outdir = os.path.join(tmp_dir, os.path.basename(outdir)) + if os.path.exists(outdir): + diff = filecmp.dircmp(untar_outdir, outdir) + if not (diff.left_only + diff.right_only + diff.diff_files + + diff.common_funny + diff.funny_files): + # outdir already existed with exactly the same content. + return False + shutil.rmtree(outdir) + # The untar files are different, or there was no previous outdir. + print 'Updating', outdir + shutil.move(untar_outdir, outdir) + return True + finally: + if os.path.isdir(tmp_dir): + shutil.rmtree(tmp_dir) def main(): @@ -70,8 +87,13 @@ def main(): subprocess.check_call(['git', 'submodule', 'update', '--quiet']) subprocess.check_call(['git', 'submodule', 'foreach', 'git', 'pull', 'origin', 'master', '--quiet']) + updates = 0 lkgr = download_last_known_good_revision() - untar(download_tar_at_lkgr(TORTURE_TAR, lkgr), TORTURE_FOLDER) + updates += untar(download_tar_at_lkgr(TORTURE_TAR, lkgr), TORTURE_DIR) + if updates: + # Only update lkgr if the files it downloaded are different. + print 'Updating lkgr to', lkgr + write_lkgr(lkgr) if __name__ == '__main__': |