update-object-macros-undef.py 1.4 KB

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