summaryrefslogtreecommitdiff
path: root/src/scripts
diff options
context:
space:
mode:
authorMyungJoo Ham <myungjoo.ham@gmail.com>2016-06-23 20:13:46 +0900
committerJan Vorlicek <janvorli@microsoft.com>2016-06-23 13:13:46 +0200
commit9ae38ddd84ac77e52f76a04c1c87a17742ba06da (patch)
treef198e82e2e50d3e664a3f82b97edcf35535bd87e /src/scripts
parent70ac3533bfd4d4ebce6d834c3656b2d6c5bae941 (diff)
downloadcoreclr-9ae38ddd84ac77e52f76a04c1c87a17742ba06da.tar.gz
coreclr-9ae38ddd84ac77e52f76a04c1c87a17742ba06da.tar.bz2
coreclr-9ae38ddd84ac77e52f76a04c1c87a17742ba06da.zip
Scripts: verify compiler definitions of native and managed (#4675)
* Scripts: find out compiler definitions of CMake In order to find mismatch between native and managed, we need to know the list of definitions of native. The copmiler definitions are stored at cmake.definitions This addresses the complaints of #4674 Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com> * Scripts: add check-definitions.py scripts/check-definitions.py checks the consistency between the native-build (CMake) compiler definitions and the managed-build (MSBuild/mscorlib) compiler definitions at build-time and prints out potentially dangerous inconsistencies. In order to get the proper results, managed build should be executed after the native build (build.sh will do so if no options such as skipnative or skipmanaged are given.) Fix #4674 Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com> * Scripts: allow check-definitions py to ignore the harmless The third argument of check-definitions.py specifies harmless keywords to be suppressed from emitting warning messages. Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com> * Scripts: add ignored cdefine keywords for warning As an example of how to declare compiler definition keywords that are harmless to be inconsistent between the native and the managed, we have added FEATURE_IMPLICIT_TLS and FEATURE_HIJACK. Developers may add more keywords in System.Private.CoreLib.csproj if the keywords are verified to be harmless; i.e., although the keywords exist in both cmake and clr.coreclr.props, the keywords are NEVER used in either side of the sources or the keywords only happen to have the same name while they denote the completely different semantics and may be disjoint. Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Diffstat (limited to 'src/scripts')
-rw-r--r--src/scripts/check-definitions.py154
1 files changed, 154 insertions, 0 deletions
diff --git a/src/scripts/check-definitions.py b/src/scripts/check-definitions.py
new file mode 100644
index 0000000000..19d4739afd
--- /dev/null
+++ b/src/scripts/check-definitions.py
@@ -0,0 +1,154 @@
+#!/usr/bin/env python
+# Licensed to the .NET Foundation under one or more agreements.
+# The .NET Foundation licenses this file to you under the MIT license.
+# See the LICENSE file in the project root for more information.
+#
+# check-definitions.py
+# This script checks the consistency between compiler definitions
+# of the native part of CoreCLR and managed part (mscorlib.dll) of
+# CoreCLR
+#
+# Usage:
+# $ ./check-definitions.py Definition_File String_of_Definitions [String_of_Ignored_Definitions]
+#
+# Definition_File: the filename of a file containing the list of
+# compiler definitions of CMAKE, seperated by line.
+# (Mandatory)
+# String_of_Definitions: the list of managed code compiler
+# definitions, seperated by semicolon without spaces.
+# (Mandatory)
+# String_of_Ignored_Definitions: the list of compiler definitions
+# to be suppressed from emitting warnings, seperated by semicolon without spaces.
+# (Optional)
+#
+# (c) 2016 MyungJoo Ham <myungjoo.ham@samsung.com>
+
+import sys
+import re
+
+debug = 0
+
+# For the native part, return the sorted definition array.
+def loadDefinitionFile(filename):
+ result = []
+ f = open(filename, 'r')
+ for line in f:
+ theLine = line.rstrip("\r\n").strip()
+ if (len(theLine) > 0):
+ result.append(theLine)
+
+ f.close()
+ result = sorted(result)
+ return result
+
+
+# For the managed part, return the sorted definition array.
+def loadDefinitionString(string):
+ splitted = string.split(';')
+ result = []
+ for line in splitted:
+ theLine = line.strip()
+ if (len(theLine) > 0):
+ result.append(theLine)
+
+ result = sorted(result)
+ return result
+
+
+def getDiff(arrNative, arrManaged):
+ result = [[], []]
+ iF = 0 # From file (native)
+ nF = len(arrNative)
+
+ iS = 0 # From string (managed)
+ nS = len(arrManaged)
+
+ while (iS < nS) and (iF < nF):
+ if (arrNative[iF] == arrManaged[iS]):
+ if (debug == 1):
+ print("Both have " + arrNative[iF])
+ iF = iF + 1
+ iS = iS + 1
+ elif (arrNative[iF] == (arrManaged[iS] + "=1")):
+ if (debug == 1):
+ print("Both have " + arrNative[iF] + "(=1)")
+ iF = iF + 1
+ iS = iS + 1
+ elif (arrNative[iF] < arrManaged[iS]):
+ if (debug == 1):
+ print("--- Managed Omitted " + arrNative[iF])
+ result[1].append(arrNative[iF])
+ iF = iF + 1
+ elif (arrNative[iF] > arrManaged[iS]):
+ if (debug == 1):
+ print("+++ Managed Added " + arrManaged[iS])
+ result[0].append(arrManaged[iS])
+ iS = iS + 1
+
+ if (iS < nS):
+ while iS < nS:
+ if (debug == 1):
+ print("+++ Managed Added " + arrManaged[iS])
+ result[0].append(arrManaged[iS])
+ iS = iS + 1
+ elif (iF < nF):
+ while iF < nF:
+ if (debug == 1):
+ print("--- Managed Omitted " + arrNative[iF])
+ result[1].append(arrNative[iF])
+ iF = iF + 1
+ return result
+
+
+def printPotentiallyCritical(arrDefinitions, referencedFilename, arrIgnore):
+ f = open(referencedFilename, 'r')
+ content = f.read()
+ f.close()
+ for keyword in arrDefinitions:
+ skip = 0
+
+ if (keyword[-2:] == "=1"):
+ key = keyword[:-2]
+ else:
+ key = keyword
+
+ if re.search("[^\\w]"+key+"[^\\w]", content):
+ for ign in arrIgnore:
+ if key == ign:
+ skip = 1
+ break
+ if skip == 0:
+ print(keyword)
+
+# MAIN SCRIPT
+if len(sys.argv) < 3:
+ print "\nUsage:"
+ print "$ check-definitions.py [Definition file] [String of definitions]"
+ print " Definition file contains the list of cmake (native) compiler definitions"
+ print " seperated by line."
+ print " String of definitions contains the list of csproj (managed) definitions"
+ print " seperated by semicolons."
+ sys.exit(-1)
+
+filename = sys.argv[1]
+string = sys.argv[2]
+
+arrayNative = loadDefinitionFile(filename)
+arrayManaged = loadDefinitionString(string)
+arrayIgnore = []
+
+if len(sys.argv) > 3:
+ arrayIgnore = loadDefinitionString(sys.argv[3])
+
+arrays = getDiff(arrayNative, arrayManaged)
+# arrays[0] = array of added in managed
+# arrays[1] = array of omitted in managed (added in native)
+
+print "Potentially Dangerous Compiler Definitions in clrdefinitions.cmake (omitted in native build):"
+printPotentiallyCritical(arrays[0], "../../clrdefinitions.cmake", arrayIgnore)
+
+print "Potentially Dangerous Compiler Definitions in clr.defines.targets (omitted in managed build):"
+printPotentiallyCritical(arrays[1], "../../clr.defines.targets", arrayIgnore)
+
+print "Definition Check Completed."
+