Skip to content

Commit 5329d95

Browse files
andy31415restyled-commits
authored andcommitted
Avoid always re-generating output file in clang coverage driver (project-chip#37590)
* 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>
1 parent 92109c8 commit 5329d95

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

scripts/build/clang_coverage_wrapper.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
import logging
17+
import os
18+
import sys
1719

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

85+
expected_output = jinja2.Template(_CPP_TEMPLATE).render(raw_profile_filename=raw_profile_filename)
86+
if os.path.exists(output):
87+
with open(output, 'rt') as f:
88+
if f.read() == expected_output:
89+
logging.info("File %s is already as expected. Will not re-write", output)
90+
sys.exit(0)
91+
8392
logging.info("Writing output to %s (profile name: %s)", output, raw_profile_filename)
8493
with open(output, "wt") as f:
85-
f.write(jinja2.Template(_CPP_TEMPLATE).render(raw_profile_filename=raw_profile_filename))
94+
f.write(expected_output)
8695

8796
logging.debug("Writing completed")
8897

0 commit comments

Comments
 (0)