support/scripts/pycompile: add --verbose option
authorRobin Jarry <robin.jarry@6wind.com>
Thu, 10 Sep 2020 08:32:52 +0000 (10:32 +0200)
committerYann E. MORIN <yann.morin.1998@free.fr>
Sun, 13 Sep 2020 08:28:36 +0000 (10:28 +0200)
Add a new option that prints the (runtime) path of compiled .py files
when VERBOSE=1 is set.

Signed-off-by: Robin Jarry <robin.jarry@6wind.com>
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
package/python/python.mk
package/python3/python3.mk
support/scripts/pycompile.py

index 1320770eaba6f5267dec8dfdd12037f957bb0263..1a3a60bbac7205933b529ac60c45a23b5260edde 100644 (file)
@@ -262,6 +262,7 @@ define PYTHON_CREATE_PYC_FILES
        PYTHONPATH="$(PYTHON_PATH)" \
        $(HOST_DIR)/bin/python$(PYTHON_VERSION_MAJOR) \
                $(TOPDIR)/support/scripts/pycompile.py \
+               $(if $(VERBOSE),--verbose) \
                --strip-root $(TARGET_DIR) \
                $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)
 endef
index 7daf893712989e90a9d3deefb229e13dca624f6c..d63a8bc080236fff53498ae9c12ffd9eac3e9819 100644 (file)
@@ -279,6 +279,7 @@ define PYTHON3_CREATE_PYC_FILES
        PYTHONPATH="$(PYTHON3_PATH)" \
        $(HOST_DIR)/bin/python$(PYTHON3_VERSION_MAJOR) \
                $(TOPDIR)/support/scripts/pycompile.py \
+               $(if $(VERBOSE),--verbose) \
                --strip-root $(TARGET_DIR) \
                $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)
 endef
index 8399d5793644e326dd42880596e6130b3bcb7d13..2b636e03cbe5b8a897bcc9860f566df21c0c5eaf 100644 (file)
@@ -15,7 +15,7 @@ import re
 import sys
 
 
-def compile_one(host_path, strip_root=None):
+def compile_one(host_path, strip_root=None, verbose=False):
     """
     Compile a .py file into a .pyc file located next to it.
 
@@ -24,6 +24,8 @@ def compile_one(host_path, strip_root=None):
     :arg strip_root:
         Prefix to remove from the original source paths encoded in compiled
         files.
+    :arg verbose:
+        Print compiled file paths.
     """
     if os.path.islink(host_path) or not os.path.isfile(host_path):
         return  # only compile real files
@@ -39,6 +41,9 @@ def compile_one(host_path, strip_root=None):
     else:
         runtime_path = host_path
 
+    if verbose:
+        print("  PYC  {}".format(runtime_path))
+
     # will raise an error if the file cannot be compiled
     py_compile.compile(host_path, cfile=host_path + "c",
                        dfile=runtime_path, doraise=True)
@@ -63,6 +68,8 @@ def main():
                         Prefix to remove from the original source paths encoded
                         in compiled files
                         """)
+    parser.add_argument("--verbose", action="store_true",
+                        help="Print compiled files")
 
     args = parser.parse_args()
 
@@ -72,7 +79,8 @@ def main():
                 parser.error("DIR: not inside ROOT dir: {!r}".format(d))
             for parent, _, files in os.walk(d):
                 for f in files:
-                    compile_one(os.path.join(parent, f), args.strip_root)
+                    compile_one(os.path.join(parent, f), args.strip_root,
+                                args.verbose)
 
     except Exception as e:
         print("error: {}".format(e))