Alex Richardson has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/54525 )

Change subject: scons: avoid rebuilding sim/tags.cc when unchanged
......................................................................

scons: avoid rebuilding sim/tags.cc when unchanged

Previously a no-changes incremental build of build/RISCV/gem5.debug would
result in the following build steps being performed:
```
 [VER TAGS]  -> RISCV/sim/tags.cc
 [     CXX] RISCV/sim/tags.cc -> .do
 [     CXX] RISCV/mem/ruby/protocol/DMA_Controller.cc -> .do
 [     CXX] RISCV/mem/ruby/protocol/DMA_Wakeup.cc -> .do
 [     CXX] RISCV/mem/ruby/protocol/Directory_Controller.cc -> .do
 [     CXX] RISCV/mem/ruby/protocol/Directory_Wakeup.cc -> .do
 [     CXX] RISCV/mem/ruby/protocol/L1Cache_Controller.cc -> .do
 [     CXX] RISCV/mem/ruby/protocol/L1Cache_Wakeup.cc -> .do
 [     CXX] RISCV/base/date.cc -> .do
 [    LINK]  -> RISCV/gem5.debug
```

This commit adds a --output-file flag to cpt_updater.py that only updates
the output file if the contents has changed. With this change a no-changes
build only prints the following (and avoids the expensive LINK step):
```
 [VER TAGS]  -> RISCV/sim/tags.cc
scons: `build/RISCV/gem5.debug' is up to date.
```

Change-Id: If33cfd4ccb10dd4a55495c188a1c77845f340f69
---
M util/cpt_upgrader.py
M src/SConscript
2 files changed, 68 insertions(+), 13 deletions(-)



diff --git a/src/SConscript b/src/SConscript
index e40262a..127f28c 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -809,7 +809,7 @@
 # version tags
 tags = \
 env.Command('sim/tags.cc', None,
-            MakeAction('util/cpt_upgrader.py --get-cc-file > $TARGET',
+            MakeAction('util/cpt_upgrader.py --get-cc-file -o $TARGET',
                        Transform("VER TAGS")))
 env.AlwaysBuild(tags)

diff --git a/util/cpt_upgrader.py b/util/cpt_upgrader.py
index abbaba2..5f76e62 100755
--- a/util/cpt_upgrader.py
+++ b/util/cpt_upgrader.py
@@ -72,6 +72,7 @@
 import configparser
 import glob, types, sys, os
 import os.path as osp
+from pathlib import Path

 verbose_print = False

@@ -281,6 +282,10 @@
         "--get-cc-file", action="store_true",
         # used during build; generate src/sim/tags.cc and exit
         help=SUPPRESS)
+    parser.add_argument(
+        "-o", "--output-file", default="-",
+        help="The output file for --get-cc-file (default=stdout)."
+ "If specified this program will not update an unchanged file.")
     parser.add_argument("checkpoint", nargs='?')

     args = parser.parse_args()
@@ -289,19 +294,37 @@
     Upgrader.load_all()

     if args.get_cc_file:
-        print("// this file is auto-generated by util/cpt_upgrader.py")
-        print("#include <string>")
-        print("#include <set>")
-        print()
-        print("namespace gem5")
-        print("{")
-        print()
-        print("std::set<std::string> version_tags = {")
+ contents = """// this file is auto-generated by util/cpt_upgrader.py
+#include <set>
+#include <string>
+
+namespace gem5
+{
+
+std::set<std::string> version_tags = {
+"""
         for tag in sorted(Upgrader.tag_set):
-            print("  \"{}\",".format(tag))
-        print("};")
-        print()
-        print("} // namespace gem5")
+            contents += "  \"{}\",\n".format(tag)
+        contents += """};
+
+} // namespace gem5
+"""
+        if args.output_file == "-":
+            sys.stdout.write(contents)
+            exit(0)
+ # Otherwise, check if the file already exists and if so only overwrite + # it if the contents is different. This avoids unnecessary rebuilds.
+        output_file = Path(args.output_file)
+        if output_file.exists():
+            existing_contents = output_file.read_text(encoding="utf-8")
+            if existing_contents == contents:
+                verboseprint("Existing file", output_file,
+                             "matches generated contents.")
+                exit(0)
+            else:
+                verboseprint("Overwriting", output_file,
+                             "with new generated contents.")
+        output_file.write_text(contents, encoding="utf-8")
         exit(0)
     elif not args.checkpoint:
         parser.error("You must specify a checkpoint file to modify or a "

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/54525
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: If33cfd4ccb10dd4a55495c188a1c77845f340f69
Gerrit-Change-Number: 54525
Gerrit-PatchSet: 1
Gerrit-Owner: Alex Richardson <alexrichard...@google.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to