Skip to content

Commit

Permalink
Avoid always re-generating output file in clang coverage driver (#37590)
Browse files Browse the repository at this point in the history
* Do not always overwrite the clang coverage driver.

Ninja seems to look at timestamps, so attempt to not change
timestamps, so that compiles are not re-run.

* Restyled by autopep8

---------

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
andy31415 and restyled-commits authored Feb 25, 2025
1 parent ba98125 commit 2f5ee86
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion scripts/build/clang_coverage_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import os
import sys

import click
import coloredlogs
Expand Down Expand Up @@ -80,9 +82,16 @@ def main(log_level, no_log_timestamps, output, raw_profile_filename):
log_fmt = "%(levelname)-7s %(message)s"
coloredlogs.install(level=__LOG_LEVELS__[log_level], fmt=log_fmt)

expected_output = jinja2.Template(_CPP_TEMPLATE).render(raw_profile_filename=raw_profile_filename)
if os.path.exists(output):
with open(output, 'rt') as f:
if f.read() == expected_output:
logging.info("File %s is already as expected. Will not re-write", output)
sys.exit(0)

logging.info("Writing output to %s (profile name: %s)", output, raw_profile_filename)
with open(output, "wt") as f:
f.write(jinja2.Template(_CPP_TEMPLATE).render(raw_profile_filename=raw_profile_filename))
f.write(expected_output)

logging.debug("Writing completed")

Expand Down

0 comments on commit 2f5ee86

Please sign in to comment.