[libc++] Update the <version> header in-place from generate_feature_test_macro_components

This simplifies the workflow for adding new feature-test macros for
contributors. Previously, they would have to move the generated <version>
header from a temporary directory to libc++'s include directory by hand.
This makes the behavior for the <version> header consistent with what's
done for the tests and the documentation.

GitOrigin-RevId: 647fb6b37488080efd8dd5e5a40d21e926b6e726
diff --git a/docs/DesignDocs/FeatureTestMacros.rst b/docs/DesignDocs/FeatureTestMacros.rst
index 2fbba65..644eb4a 100644
--- a/docs/DesignDocs/FeatureTestMacros.rst
+++ b/docs/DesignDocs/FeatureTestMacros.rst
@@ -39,7 +39,5 @@
 update feature test macros in libc++.
 
 Whenever a feature test macro is added or changed, the table should be updated
-and the script should be re-ran. The script will clobber the existing test files
-and the documentation and it will generate a new `<version>` header as a
-temporary file. The generated `<version>` header should be merged with the
-existing one.
+and the script should be re-ran. The script will clobber the existing test files,
+the documentation and the `<version>` header.
diff --git a/utils/generate_feature_test_macro_components.py b/utils/generate_feature_test_macro_components.py
index 889eabf..edf6689 100755
--- a/utils/generate_feature_test_macro_components.py
+++ b/utils/generate_feature_test_macro_components.py
@@ -639,12 +639,18 @@
 
 #endif // _LIBCPP_VERSIONH
 """
-  return template.format(
+
+  version_str = template.format(
       synopsis=produce_version_synopsis().strip(),
       cxx14_macros=produce_macros_definition_for_std('c++14').strip(),
       cxx17_macros=produce_macros_definition_for_std('c++17').strip(),
       cxx2a_macros=produce_macros_definition_for_std('c++2a').strip())
 
+  version_header_path = os.path.join(include_path, 'version')
+  with open(version_header_path, 'w') as f:
+    f.write(version_str)
+
+
 """
     Functions to produce test files
 """
@@ -884,9 +890,7 @@
     f.write(doc_str)
 
 def main():
-  with tempfile.NamedTemporaryFile(mode='w', prefix='version.', delete=False) as tmp_file:
-    print("producing new <version> header as %s" % tmp_file.name)
-    tmp_file.write(produce_version_header())
+  produce_version_header()
   produce_tests()
   produce_docs()