blob: 8f046ea5344afabc429936c07661b08ee21c0de9 [file] [log] [blame]
Ben Murdoch097c5b22016-05-18 11:27:45 +01001#!/usr/bin/env python
2# Copyright (c) 2012 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Wipes out a directory recursively and then touches a stamp file.
7
8This odd pairing of operations is used to support build scripts which
9slurp up entire directories (e.g. build/android/javac.py when handling
10generated sources) as inputs.
11
12The general pattern of use is:
13
14 - Add a target which generates |gen_sources| into |out_path| from |inputs|.
15 - Include |stamp_file| as an input for that target or any of its rules which
16 generate files in |out_path|.
17 - Add an action which depends on |inputs| and which outputs |stamp_file|;
18 the action should run this script and pass |out_path| and |stamp_file| as
19 its arguments.
20
21The net result is that you will force |out_path| to be wiped and all
22|gen_sources| to be regenerated any time any file in |inputs| changes.
23
24See //mojo/mojom_bindings_generator.gypi for an example use case.
25
26"""
27
28import errno
29import os
30import shutil
31import sys
32
33
34def Main(dst_dir, stamp_file):
35 try:
36 shutil.rmtree(os.path.normpath(dst_dir))
37 except OSError as e:
38 # Ignore only "not found" errors.
39 if e.errno != errno.ENOENT:
40 raise e
41 with open(stamp_file, 'a'):
42 os.utime(stamp_file, None)
43
44if __name__ == '__main__':
45 sys.exit(Main(sys.argv[1], sys.argv[2]))