1#!/usr/bin/env python3
2
3# Copyright 2018 the V8 project authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6# vim:fenc=utf-8:shiftwidth=2:tabstop=2:softtabstop=2:extandtab
7
8"""
9Generate object-macros-undef.h from object-macros.h.
10"""
11
12import os.path
13import re
14import sys
15
16INPUT = 'src/objects/object-macros.h'
17OUTPUT = 'src/objects/object-macros-undef.h'
18HEADER = """// Copyright 2016 the V8 project authors. All rights reserved.
19// Use of this source code is governed by a BSD-style license that can be
20// found in the LICENSE file.
21
22// Generate this file using the {} script.
23
24// PRESUBMIT_INTENTIONALLY_MISSING_INCLUDE_GUARD
25
26""".format(os.path.basename(__file__))
27
28
29def main():
30  if not os.path.isfile(INPUT):
31    sys.exit("Input file {} does not exist; run this script in a v8 checkout."
32             .format(INPUT))
33  if not os.path.isfile(OUTPUT):
34    sys.exit("Output file {} does not exist; run this script in a v8 checkout."
35             .format(OUTPUT))
36  regexp = re.compile('^#define (\w+)')
37  seen = set()
38  with open(INPUT, 'r') as infile, open(OUTPUT, 'w') as outfile:
39    outfile.write(HEADER)
40    for line in infile:
41      match = regexp.match(line)
42      if match and match.group(1) not in seen:
43        seen.add(match.group(1))
44        outfile.write('#undef {}\n'.format(match.group(1)))
45
46if __name__ == "__main__":
47  main()
48