Remove License Header Futzing from bazel_to_cmake (#4918)
Generated files don't need license headers. This made more sense when
bazel_to_cmake was a tool to aid manually writing files, but in these
cases we're really just autogenerating the files. There's a silly
amount of logic fiddling around with this in a tool that has nothing to
do with license headers.
Note: We shouldn't drop these from manually-created files. More
motivation to make your CMake files work with bazel_to_cmake
:stuck_out_tongue:
diff --git a/build_tools/bazel_to_cmake/bazel_to_cmake.py b/build_tools/bazel_to_cmake/bazel_to_cmake.py
index cbac4bc..15dc6ba 100755
--- a/build_tools/bazel_to_cmake/bazel_to_cmake.py
+++ b/build_tools/bazel_to_cmake/bazel_to_cmake.py
@@ -163,27 +163,26 @@
if not os.path.isfile(build_file_path):
return Status.NO_BUILD_FILE
- copyright_line = f"# Copyright {datetime.date.today().year} Google LLC"
- write_allowed = write_files
if os.path.isfile(cmakelists_file_path):
with open(cmakelists_file_path) as f:
for i, line in enumerate(f):
- if line.startswith("# Copyright"):
- copyright_line = line.rstrip()
if EDIT_BLOCKING_PATTERN.search(line):
if verbosity >= 1:
log(f"Skipped. line {i + 1}: '{line.strip()}' prevents edits.",
indent=2)
return Status.SKIPPED
+ header = (f"# Autogenerated from {rel_build_file_path} by\n"
+ f"# {repo_relpath(os.path.abspath(__file__))}")
+
with open(build_file_path, "rt") as build_file:
build_file_code = compile(build_file.read(), build_file_path, "exec")
try:
converted_text = bazel_to_cmake_converter.convert_build_file(
build_file_code,
- copyright_line,
+ header,
allow_partial_conversion=allow_partial_conversion)
- if write_allowed:
+ if write_files:
with open(cmakelists_file_path, "wt") as cmakelists_file:
cmakelists_file.write(converted_text)
else: