2 # Licensed to the .NET Foundation under one or more agreements.
3 # The .NET Foundation licenses this file to you under the MIT license.
4 # See the LICENSE file in the project root for more information.
7 # This script checks the consistency between compiler definitions
8 # of the native part of CoreCLR and managed part (mscorlib.dll) of
12 # $ ./check-definitions.py Definition_File String_of_Definitions [String_of_Ignored_Definitions]
14 # Definition_File: the filename of a file containing the list of
15 # compiler definitions of CMAKE, seperated by line.
17 # String_of_Definitions: the list of managed code compiler
18 # definitions, seperated by semicolon without spaces.
20 # String_of_Ignored_Definitions: the list of compiler definitions
21 # to be suppressed from emitting warnings, seperated by semicolon without spaces.
24 # (c) 2016 MyungJoo Ham <myungjoo.ham@samsung.com>
26 from __future__ import print_function
34 # For the native part, return the sorted definition array.
35 def loadDefinitionFile(filename):
39 with open(filename, 'r') as f:
45 # If cmake was not used, this script won't work, and that's ok
48 result = sorted(result)
52 # For the managed part, return the sorted definition array.
53 def loadDefinitionString(string):
54 splitted = string.split(';')
57 theLine = line.strip()
58 if (len(theLine) > 0):
59 result.append(theLine)
61 result = sorted(result)
65 def getDiff(arrNative, arrManaged):
67 iF = 0 # From file (native)
70 iS = 0 # From string (managed)
73 while (iS < nS) and (iF < nF):
74 if (arrNative[iF] == arrManaged[iS]):
76 print("Both have " + arrNative[iF])
79 elif (arrNative[iF] == (arrManaged[iS] + "=1")):
81 print("Both have " + arrNative[iF] + "(=1)")
84 elif (arrNative[iF] < arrManaged[iS]):
86 print("--- Managed Omitted " + arrNative[iF])
87 result[1].append(arrNative[iF])
89 elif (arrNative[iF] > arrManaged[iS]):
91 print("+++ Managed Added " + arrManaged[iS])
92 result[0].append(arrManaged[iS])
98 print("+++ Managed Added " + arrManaged[iS])
99 result[0].append(arrManaged[iS])
104 print("--- Managed Omitted " + arrNative[iF])
105 result[1].append(arrNative[iF])
110 def printPotentiallyCritical(arrDefinitions, referencedFilename, arrIgnore):
112 with open(referencedFilename, 'r') as f:
115 for keyword in arrDefinitions:
118 if (keyword[-2:] == "=1"):
123 if re.search("[^\\w]"+key+"[^\\w]", content):
124 for ign in arrIgnore:
132 if len(sys.argv) < 3:
134 print("$ check-definitions.py [ProjectDir] [Definition file] [String of definitions]")
135 print(" Definition file contains the list of cmake (native) compiler definitions")
136 print(" seperated by line.")
137 print(" String of definitions contains the list of csproj (managed) definitions")
138 print(" seperated by semicolons.")
141 projectDir = sys.argv[1]
142 filename = sys.argv[2]
145 arrayNative = loadDefinitionFile(filename)
146 arrayManaged = loadDefinitionString(string)
149 if len(sys.argv) > 4:
150 arrayIgnore = loadDefinitionString(sys.argv[4])
152 arrays = getDiff(arrayNative, arrayManaged)
153 # arrays[0] = array of added in managed
154 # arrays[1] = array of omitted in managed (added in native)
156 print("Potentially Dangerous Compiler Definitions in clrdefinitions.cmake (omitted in native build):")
157 printPotentiallyCritical(arrays[0], os.path.join(projectDir, "clrdefinitions.cmake"), arrayIgnore)
159 print("Potentially Dangerous Compiler Definitions in clr.featuredefines.props (omitted in managed build):")
160 printPotentiallyCritical(arrays[1], os.path.join(projectDir, "clr.featuredefines.props"), arrayIgnore)
162 print("Definition Check Completed.")