]> granicus.if.org Git - graphviz/commitdiff
teach version script how to output CPP definitions
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 21 Feb 2021 05:15:33 +0000 (21:15 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 27 Feb 2021 18:12:09 +0000 (10:12 -0800)
gen_version.py

index 3cc56975b8adddc9f73e3f4debf70167b11ef294..4a8cf460a357daa89c3fe3075489a606ca050457 100644 (file)
@@ -67,6 +67,9 @@ parser.add_argument('--patch',
                     action='store_const',
                     const='patch',
                     help='Print patch version')
+parser.add_argument('--definition',
+                    action='store_true',
+                    help='Print a C-style preprocessor #define')
 
 args = parser.parse_args()
 
@@ -110,14 +113,33 @@ if not patch_version.isnumeric():
     patch_version += '.' + committer_date
 
 if args.date_format:
-    print(committer_date)
+    if args.definition:
+        print(f'#define BUILDDATE "{committer_date}"')
+    else:
+        print(committer_date)
 elif args.collection:
-    print(collection)
+    if args.definition:
+        print(f'#define COLLECTION "{collection}"')
+    else:
+        print(collection)
 elif args.component == 'major':
-    print(major_version)
+    if args.definition:
+        print(f'#define VERSION_MAJOR "{major_version}"')
+    else:
+        print(major_version)
 elif args.component == 'minor':
-    print(minor_version)
+    if args.definition:
+        print(f'#define VERSION_MINOR "{minor_version}"')
+    else:
+        print(minor_version)
 elif args.component == 'patch':
-    print(patch_version)
+    if args.definition:
+        print(f'#define VERSION_PATCH "{patch_version}"')
+    else:
+        print(patch_version)
 else:
-    print('{0}.{1}.{2}'.format(major_version, minor_version, patch_version))
+    if args.definition:
+        print(f'#define VERSION "{major_version}.{minor_version}.'
+              f'{patch_version}"')
+    else:
+        print(f'{major_version}.{minor_version}.{patch_version}')