diff options
author | rockot <rockot@chromium.org> | 2015-02-25 21:20:30 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-26 05:20:56 +0000 |
commit | 99b81f3496f7e5f9badf9504904da20545823d30 (patch) | |
tree | 98a60842cb48b4f7ecb32327c2288bcb02952e01 /build/rmdir_and_stamp.py | |
parent | 5c1a294cd30d44560ce45980a809f86146584761 (diff) | |
download | chromium_src-99b81f3496f7e5f9badf9504904da20545823d30.zip chromium_src-99b81f3496f7e5f9badf9504904da20545823d30.tar.gz chromium_src-99b81f3496f7e5f9badf9504904da20545823d30.tar.bz2 |
Fix stale mojom-generated Java problems with gyp builds
This causes any gyp targets which use the mojom bindings generator
to regenerate all outputs when any of the input mojom files have
changed. In such cases, the Java output directory is first wiped
out.
This avoids problems with stale mojom-generated Java files hanging
around and being compiled by build/android/javac.py, which tries
to build everything in its generated sources location.
BUG=461622
Review URL: https://codereview.chromium.org/958773002
Cr-Commit-Position: refs/heads/master@{#318190}
Diffstat (limited to 'build/rmdir_and_stamp.py')
-rwxr-xr-x | build/rmdir_and_stamp.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/build/rmdir_and_stamp.py b/build/rmdir_and_stamp.py new file mode 100755 index 0000000..6aa11f8 --- /dev/null +++ b/build/rmdir_and_stamp.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""Wipes out a directory recursively and then touches a stamp file. + +This odd pairing of operations is used to support build scripts which +slurp up entire directories (e.g. build/android/javac.py when handling +generated sources) as inputs. + +The general pattern of use is: + + - Add a target which generates |gen_sources| into |out_path| from |inputs|. + - Include |stamp_file| as an input for that target or any of its rules which + generate files in |out_path|. + - Add an action which depends on |inputs| and which outputs |stamp_file|; + the action should run this script and pass |out_path| and |stamp_file| as + its arguments. + +The net result is that you will force |out_path| to be wiped and all +|gen_sources| to be regenerated any time any file in |inputs| changes. + +See //third_party/mojo/mojom_bindings_generator.gypi for an example use case. + +""" + +import errno +import os +import shutil +import sys + + +def Main(dst_dir, stamp_file): + try: + shutil.rmtree(os.path.normpath(dst_dir)) + except OSError as e: + # Ignore only "not found" errors. + if e.errno != errno.ENOENT: + raise e + with open(stamp_file, 'a'): + os.utime(stamp_file, None) + +if __name__ == '__main__': + sys.exit(Main(sys.argv[1], sys.argv[2])) |