summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChun-wei Fan <fanc999@yahoo.com.tw>2020-04-06 06:53:49 +0000
committerChun-wei Fan <fanc999@yahoo.com.tw>2020-04-06 06:53:49 +0000
commit13677bd24a4bb5bd6afd57917c05a50ec77b9494 (patch)
tree7b80f96512069961a6d47ec7e028c83db50bde14
parentd9533d4e5fde228b985ac15764241fb76d231713 (diff)
parent51eeca6abdd3e8b2e2b1d503b8182c28675cc8d8 (diff)
downloadmm-common-13677bd24a4bb5bd6afd57917c05a50ec77b9494.tar.gz
Merge branch 'check-dllexport-usage' into 'master'
util: Add script to check gmmproc version See merge request GNOME/mm-common!5
-rw-r--r--Makefile.am1
-rw-r--r--README5
-rw-r--r--meson.build1
-rw-r--r--skeletonmm/meson.build1
-rw-r--r--skeletonmm/untracked/README3
-rw-r--r--util/build_scripts/check-dllexport-usage.py87
-rwxr-xr-xutil/build_scripts/dist-build-scripts.py1
-rw-r--r--util/mm-common-get.1.in2
-rw-r--r--util/mm-common-get.in2
9 files changed, 101 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am
index cbb7451..68019a7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -30,6 +30,7 @@ dist_build_support_DATA = \
am_include/dist-changelog.am \
am_include/doc-reference.am \
am_include/generate-binding.am \
+ util/build_scripts/check-dllexport-usage.py \
util/build_scripts/dist-build-scripts.py \
util/build_scripts/dist-changelog.py \
util/build_scripts/doc-reference.py \
diff --git a/README b/README
index d4bea2a..0cf0f24 100644
--- a/README
+++ b/README
@@ -221,6 +221,11 @@ util/build_scripts/dist-build-scripts.py:
not checked into the git repository. All .gitignore files and an empty build/
directory are removed
+util/build_scripts/check-dllexport-usage.py:
+ Command that checks on the gmmproc version that is to be used or been used
+ to generate the sources, to check whether to use compiler directives to
+ export symbols. Only used for Visual Studio or clang-cl builds.
+
Documentation utilities (Meson and Autotools)
---------------------------------------------
diff --git a/meson.build b/meson.build
index fbc7e5e..92c639a 100644
--- a/meson.build
+++ b/meson.build
@@ -73,6 +73,7 @@ endforeach
# These are installed so that mm-common-get can copy them
# into projects at Meson setup or configure time.
meson_build_support_basefiles = [
+ 'check-dllexport-usage.py',
'dist-build-scripts.py',
'dist-changelog.py',
'doc-reference.py',
diff --git a/skeletonmm/meson.build b/skeletonmm/meson.build
index 2274d32..0c885c6 100644
--- a/skeletonmm/meson.build
+++ b/skeletonmm/meson.build
@@ -102,6 +102,7 @@ generate_binding = script_dir / 'generate-binding.py'
doc_reference = script_dir / 'doc-reference.py'
dist_changelog = script_dir / 'dist-changelog.py'
dist_build_scripts = script_dir / 'dist-build-scripts.py'
+check_dllexport_usage = script_dir / 'check-dllexport-usage.py'
dist_cmd = project_source_root / 'tools' / 'dist-cmd.py' # Must be committed to git.
if maintainer_mode and mm_common_get.found()
diff --git a/skeletonmm/untracked/README b/skeletonmm/untracked/README
index 8082503..b51c2cb 100644
--- a/skeletonmm/untracked/README
+++ b/skeletonmm/untracked/README
@@ -19,7 +19,8 @@ untracked/doc/doc-install.pl
doc-postprocess.pl
doxygen-extra.css
tagfile-to-devhelp2.xsl
-untracked/build_scripts/dist-build-scripts.py
+untracked/build_scripts/check-dllexport-usage.py
+ dist-build-scripts.py
dist-changelog.py
doc-reference.py
generate-binding.py
diff --git a/util/build_scripts/check-dllexport-usage.py b/util/build_scripts/check-dllexport-usage.py
new file mode 100644
index 0000000..09875ad
--- /dev/null
+++ b/util/build_scripts/check-dllexport-usage.py
@@ -0,0 +1,87 @@
+#!/usr/bin/env python3
+#
+# Check for the first line in a file generated with gmmproc,
+# to see which gmmproc version was used, to see whether
+# to enable __declspec(dllexport to export symbols). This
+# is *not* intended for source files that are not generated
+# with gmmproc.
+#
+# Author: Chun-wei Fan April 2, 2020
+
+import argparse
+import os
+import sys
+
+min_required_gmmproc_ver = '2.64.3'
+
+parser = argparse.ArgumentParser(description='Check gmmproc version used.')
+parser.add_argument('--file',
+ dest='file',
+ help='Generated .cc/.h file to check gmmproc version')
+parser.add_argument('--gmmprocdir',
+ dest='gmmprocdir',
+ help='Directory where gmmproc is located')
+args = parser.parse_args()
+
+if args.file is None and args.gmmprocdir is None:
+ raise ValueError('Either --file or --gmmprocdir must be specified')
+
+if args.gmmprocdir is not None:
+ # gmmprocdir is specified: Check version string in gmmproc
+ gmmproc_path = os.path.join(args.gmmprocdir, 'gmmproc')
+ if not os.path.exists(gmmproc_path):
+ raise ValueError('A valid directory to locate gmmproc must be ' \
+ 'specified with --gmmprocdir=<directory>')
+
+ gmmproc_ver_str = None
+ with open(gmmproc_path, 'r') as f:
+ for line in f:
+ if line.startswith(' $main::glibmm_version = '):
+ gmmproc_ver_str = line[line.find('\"') + 1:line.rfind('\"')]
+
+ if gmmproc_ver_str is None:
+ raise ValueError('The gmmproc at %s is invalid' % gmmproc_path)
+
+ gmmproc_ver = gmmproc_ver_str.split('.')
+else:
+ # A pre-generated file is specified via --file
+ if not os.path.exists(args.file):
+ raise FileNotFoundError('File specified with --file does not exist')
+
+ # We only allow .h/.cc files to run this check
+ if not args.file.endswith('.cc') and \
+ not args.file.endswith('.h'):
+ raise ValueError('Only .cc/.h files are accepted here')
+
+ # Now grab the first line of the file we are checking for
+ f = open(args.file)
+ firstline = f.readline()
+ f.close()
+
+ # Check for gmmproc signature...
+ if not firstline.startswith('// Generated by gmmproc '):
+ raise ValueError('Specified file is not generated by gmmproc')
+
+ tokens = firstline.split()
+ gmmproc_ver = tokens[tokens.index('gmmproc') + 1].split('.')
+
+# Now compare the gmmproc version against the one we want
+# (2.64.3 or later)
+gmmproc_major = int(gmmproc_ver[0])
+gmmproc_minor = int(gmmproc_ver[1])
+gmmproc_micro = int(gmmproc_ver[2])
+
+min_required_ver = min_required_gmmproc_ver.split('.')
+min_major_ver = int(min_required_ver[0])
+min_minor_ver = int(min_required_ver[1])
+min_micro_ver = int(min_required_ver[2])
+
+if gmmproc_major > min_major_ver or \
+ (gmmproc_major == min_major_ver and \
+ gmmproc_minor > min_minor_ver) or \
+ (gmmproc_major == min_major_ver and \
+ gmmproc_minor == min_minor_ver and \
+ gmmproc_micro >= min_micro_ver):
+ sys.exit(0)
+else:
+ sys.exit(1)
diff --git a/util/build_scripts/dist-build-scripts.py b/util/build_scripts/dist-build-scripts.py
index 7318bc7..bdcda10 100755
--- a/util/build_scripts/dist-build-scripts.py
+++ b/util/build_scripts/dist-build-scripts.py
@@ -19,6 +19,7 @@ os.makedirs(dist_script_dir, exist_ok=True)
# Distribute files that mm-common-get has copied to src_script_dir.
files = [
+ 'check-dllexport-usage.py',
'dist-build-scripts.py',
'dist-changelog.py',
'doc-reference.py',
diff --git a/util/mm-common-get.1.in b/util/mm-common-get.1.in
index ff8996c..951f7ea 100644
--- a/util/mm-common-get.1.in
+++ b/util/mm-common-get.1.in
@@ -30,6 +30,8 @@ are listed below.
.BI "Meson build scripts copied to " BUILDSCRIPT-DIR :
.PD 0
.IP
+.I check-dllexport-usage.py
+.IP
.I dist-build-scripts.py
.IP
.I dist-changelog.py
diff --git a/util/mm-common-get.in b/util/mm-common-get.in
index e0b28f0..8a21f02 100644
--- a/util/mm-common-get.in
+++ b/util/mm-common-get.in
@@ -41,7 +41,7 @@ doctooldir = args.doctool_dir
print(progname + ': putting Meson build scripts in ' + buildscriptdir)
# Create the destination directory, if it does not exist.
os.makedirs(buildscriptdir, exist_ok=True)
-for file in ['dist-build-scripts.py', 'dist-changelog.py', 'doc-reference.py', 'generate-binding.py']:
+for file in ['check-dllexport-usage.py', 'dist-build-scripts.py', 'dist-changelog.py', 'doc-reference.py', 'generate-binding.py']:
src_file = os.path.join(pkgdatadir, 'build', file)
dest_file = os.path.join(buildscriptdir, file)
# Don't update the timestamp of dest_file, if it's equal to src_file.