16 """A script to do source transformations to create a new LTS release. 
   18    Usage: ./create_lts.py YYYYMMDD 
   25   """Performs textual replacements in a file. 
   27   Rewrites filename with the keys in replacement_dict replaced with 
   28   their values. This function assumes the file can fit in memory. 
   31     filename: the filename to perform the replacement on 
   32     replacement_dict: a dictionary of key strings to be replaced with their 
   36     Exception: A failure occured 
   38   f = 
open(filename, 
'r')
 
   42   for key, value 
in replacement_dict.items():
 
   44     content = content.replace(key, value)
 
   45     if content == original:
 
   46       raise Exception(
'Failed to find {} in {}'.
format(key, filename))
 
   48   f = 
open(filename, 
'w')
 
   54   """Strip contents from a file. 
   56   Rewrites filename with by removing all content between 
   57   strip_begin_tag and strip_end_tag, including the tags themselves. 
   60     filename: the filename to perform the replacement on 
   61     strip_begin_tag: the start of the content to be removed 
   62     strip_end_tag: the end of the content to be removed 
   65     Exception: A failure occured 
   67   f = 
open(filename, 
'r')
 
   72     begin = content.find(strip_begin_tag)
 
   75     end = content.find(strip_end_tag, begin + 
len(strip_begin_tag))
 
   77       raise Exception(
'{}: imbalanced strip begin ({}) and ' 
   78                       'end ({}) tags'.
format(filename, strip_begin_tag,
 
   80     content = content.replace(content[begin:end + 
len(strip_end_tag)], 
'')
 
   82   f = 
open(filename, 
'w')
 
   89     print(
'Usage: {} YYYYMMDD'.
format(sys.argv[0], file=sys.stderr))
 
   92   datestamp = sys.argv[1]
 
   93   if len(datestamp) != 8 
or not datestamp.isdigit():
 
   95         'datestamp={} is not in the YYYYMMDD format'.
format(datestamp))
 
   99       'absl/base/config.h', {
 
  100           '#undef ABSL_LTS_RELEASE_VERSION':
 
  101               '#define ABSL_LTS_RELEASE_VERSION {}'.
format(datestamp),
 
  102           '#undef ABSL_LTS_RELEASE_PATCH_LEVEL':
 
  103               '#define ABSL_LTS_RELEASE_PATCH_LEVEL 0' 
  106       'absl/base/options.h', {
 
  107           '#define ABSL_OPTION_USE_INLINE_NAMESPACE 0':
 
  108               '#define ABSL_OPTION_USE_INLINE_NAMESPACE 1',
 
  109           '#define ABSL_OPTION_INLINE_NAMESPACE_NAME head':
 
  110               '#define ABSL_OPTION_INLINE_NAMESPACE_NAME lts_{}'.
format(
 
  115           'project(absl LANGUAGES CXX)':
 
  116               'project(absl LANGUAGES CXX VERSION {})'.
format(datestamp)
 
  126       'CMake/AbseilHelpers.cmake',
 
  127       {
'SOVERSION 0': 
'SOVERSION "{}.0.0"'.
format(datestamp[2:6])})
 
  129                           '# absl:lts-remove-end')
 
  132 if __name__ == 
'__main__':