[gtk/msvc-project-improvements: 3/4] Visual Studio: Make gen-gdkversionmacros-h.py generic




commit 8ce1321439b7c6a725588aaeb4cb4560369b0245
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon Jan 3 16:27:59 2022 +0800

    Visual Studio: Make gen-gdkversionmacros-h.py generic
    
    Rename the script as gen-version-items.py, and so make things more generic and
    usable by other items in the build.  We want to eventually to be able to
    generate the .rc files and the *version*.h files from their *.in counterparts
    using this script.

 win32/Makefile.am               |  2 +-
 win32/gen-gdkversionmacros-h.py | 35 -------------------------------
 win32/gen-version-items.py      | 46 +++++++++++++++++++++++++++++++++++++++++
 win32/generate-msvc.mak         |  2 +-
 4 files changed, 48 insertions(+), 37 deletions(-)
---
diff --git a/win32/Makefile.am b/win32/Makefile.am
index e5f9a3ff73..0e70d0d665 100644
--- a/win32/Makefile.am
+++ b/win32/Makefile.am
@@ -42,7 +42,7 @@ EXTRA_DIST += \
        create-lists.bat        \
        create-lists-msvc.mak           \
        detectenv-msvc.mak              \
-       gen-gdkversionmacros-h.py       \
+       gen-version-items.py    \
        generate-msvc.mak       \
        gtk-introspection-msvc.mak      \
        introspection-msvc.mak          \
diff --git a/win32/gen-version-items.py b/win32/gen-version-items.py
new file mode 100644
index 0000000000..a2f450cfe1
--- /dev/null
+++ b/win32/gen-version-items.py
@@ -0,0 +1,46 @@
+#!/usr/bin/python3
+
+# Generate various items with version info
+
+# Author: Fan, Chun-wei
+# Date: July 25, 2019
+
+import os
+import sys
+import argparse
+
+from replace import replace_multi, replace
+
+def main(argv):
+    srcdir = os.path.dirname(__file__)
+    top_srcdir = os.path.join(srcdir, os.pardir)
+    parser = argparse.ArgumentParser(description='Generate various items with version info')
+    parser.add_argument('--version', help='Version of the package',
+                        required=True)
+    parser.add_argument('--interface-age', help='Interface age of the package',
+                        required=True)
+    parser.add_argument('--source', help='Source file template to process',
+                        required=True)
+    parser.add_argument('--output', '-o', help='Output generated file location',
+                        required=True)
+    args = parser.parse_args()
+    gdk_sourcedir = os.path.join(top_srcdir, 'gdk')
+    version_parts = args.version.split('.')
+    # (100 * gtk_minor_version + gtk_micro_version - gtk_interface_age)
+    binary_age = (int(version_parts[1]) * 100) + int(version_parts[2])
+    lt_current = (int(version_parts[1]) * 100) + int(version_parts[2]) - int(args.interface_age)
+    lt_age = binary_age - int(args.interface_age)
+
+    version_info_replace_items = {'@GTK_MAJOR_VERSION@':    version_parts[0],
+                                  '@GTK_MINOR_VERSION@':    version_parts[1],
+                                  '@GTK_MICRO_VERSION@':    version_parts[2],
+                                  '@GTK_API_VERSION@':      '3.0',
+                                  '@GTK_VERSION@':          args.version,
+                                  '@GTK_BINARY_AGE@':       str(binary_age),
+                                  '@GTK_INTERFACE_AGE@':    args.interface_age,
+                                  '@LT_CURRENT_MINUS_AGE@': str(lt_current - lt_age)}
+
+    replace_multi(args.source, args.output, version_info_replace_items)
+
+if __name__ == '__main__':
+    sys.exit(main(sys.argv))
diff --git a/win32/generate-msvc.mak b/win32/generate-msvc.mak
index e15d648a4f..f017db11dc 100644
--- a/win32/generate-msvc.mak
+++ b/win32/generate-msvc.mak
@@ -121,7 +121,7 @@ generate-base-sources:      \
 .\vs$(VSVER)\$(CFG)\$(PLAT)\obj\gdk-3\gdk\gdkversionmacros.h: ..\gdk\gdkversionmacros.h.in
        @echo Generating $@...
        @if not exist $(@D)\ md $(@D)
-       @$(PYTHON) gen-gdkversionmacros-h.py --version=$(GTK_VERSION) 
--outdir=.\vs$(VSVER)\$(CFG)\$(PLAT)\obj\gdk-3\gdk
+       @$(PYTHON) gen-version-items.py --version=$(GTK_VERSION) --interface-age=$(GTK_INTERFACE_AGE) 
--source=$** --output=$@
 
 .\vs$(VSVER)\$(CFG)\$(PLAT)\obj\gdk-3\gdk\gdkmarshalers.h: ..\gdk\gdkmarshalers.list
        @echo Generating $@...


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]