tvl-depot/absl/copts/generate_copts.py
Abseil Team f197d7c72a Export of internal Abseil changes.
--
1a5fb4eb5bc6c0332962f659470a07908168aa5c by CJ Johnson <johnsoncj@google.com>:

Move InlinedVector's AbslHashValue(...) definition to out of line

PiperOrigin-RevId: 224389234

--
b7c5ccdfe17b9cb5f7124c8d591ce0989a15b9fb by Jon Cohen <cohenjon@google.com>:

Add a shebang line and chmod +x generate_copts.py.  Note that we use the "python" command as suggested in PEP 934 (https://www.python.org/dev/peps/pep-0394/) as this script should work in both Python 2 and Python 3.

Also adds a gitignore for __pycache__ for when using python3

PiperOrigin-RevId: 224375405

--
c57a148a1106b21dbcd750541f10b058bf55a2bf by CJ Johnson <johnsoncj@google.com>:

Adds comment to InlinedVector intended to help the g4 diffing algo to better identify the substantive change

PiperOrigin-RevId: 224362807

--
b635ab981a07dc2434be7b0d164030a42cc67923 by Greg Falcon <gfalcon@google.com>:

internal change

PiperOrigin-RevId: 224362442

--
217021f7dcec31141a89b91930c241af062c2133 by CJ Johnson <johnsoncj@google.com>:

Distinguishes the source of InlinedVector::at(...)'s bounds checking exception

PiperOrigin-RevId: 224341645

--
01a5943560ce9216a9d8ccb1279b5c5c2f6e1019 by CJ Johnson <johnsoncj@google.com>:

Relocates out of line member function definitions to their respective declarations in InlinedVector

PiperOrigin-RevId: 224320130

--
b3d57fcddcd737e91aab812d69b82fef2ca43d7e by Abseil Team <absl-team@google.com>:

On 32-bit systems, the alignment of int64 can be 4 bytes. Created a custom Int64 type (to go with the custom Int128 type) just for the purpose of testing layouts and alignments; it doesn't need to support actual arithmetic.

PiperOrigin-RevId: 224209785
GitOrigin-RevId: 1a5fb4eb5bc6c0332962f659470a07908168aa5c
Change-Id: I9d6b1c441cd712709ebd6c0a8911d0755cab506f
2018-12-07 14:40:28 -05:00

108 lines
2.4 KiB
Python
Executable file

#!/usr/bin/python
"""Generate Abseil compile compile option configs.
Usage: <path_to_absl>/copts/generate_copts.py
The configs are generated from copts.py.
"""
from os import path
import sys
from copts import COPT_VARS
# Helper functions
def file_header_lines():
return [
"GENERATED! DO NOT MANUALLY EDIT THIS FILE.", "",
"(1) Edit absl/copts/copts.py.",
"(2) Run `python <path_to_absl>/copts/generate_copts.py`."
]
def flatten(*lists):
return [item for sublist in lists for item in sublist]
def relative_filename(filename):
return path.join(path.dirname(__file__), filename)
# Style classes. These contain all the syntactic styling needed to generate a
# copt file for different build tools.
class CMakeStyle(object):
"""Style object for CMake copts file."""
def separator(self):
return ""
def list_introducer(self, name):
return "list(APPEND " + name
def list_closer(self):
return ")\n"
def docstring(self):
return "\n".join((("# " + line).strip() for line in file_header_lines()))
def filename(self):
return "GENERATED_AbseilCopts.cmake"
class StarlarkStyle(object):
"""Style object for Starlark copts file."""
def separator(self):
return ","
def list_introducer(self, name):
return name + " = ["
def list_closer(self):
return "]\n"
def docstring(self):
docstring_quotes = "\"\"\""
return docstring_quotes + "\n".join(
flatten(file_header_lines(), [docstring_quotes]))
def filename(self):
return "GENERATED_copts.bzl"
# Copt file generation
def copt_list(name, arg_list, style):
make_line = lambda s: " \"" + s + "\"" + style.separator()
external_str_list = [make_line(s) for s in arg_list]
return "\n".join(
flatten(
[style.list_introducer(name)],
external_str_list,
[style.list_closer()]))
def generate_copt_file(style):
"""Creates a generated copt file using the given style object.
Args:
style: either StarlarkStyle() or CMakeStyle()
"""
with open(relative_filename(style.filename()), "w") as f:
f.write(style.docstring())
f.write("\n")
for var_name, arg_list in sorted(COPT_VARS.items()):
f.write("\n")
f.write(copt_list(var_name, arg_list, style))
def main(argv):
if len(argv) > 1:
raise RuntimeError("generate_copts needs no command line args")
generate_copt_file(StarlarkStyle())
generate_copt_file(CMakeStyle())
if __name__ == "__main__":
main(sys.argv)