Pārlūkot izejas kodu

[bcl] Build some assemblies with -warnaserror (#5295)

* [bcl] Build some assemblies with -warnaserror

This ensures that we keep the build warning free.

We'll only opt-in a few assemblies that already have zero warnings.
We also only apply this when using csc as mcs might raise different warnings.

For now just opt-in assemblies in the net_4_x profile.
Alexander Köplinger 8 gadi atpakaļ
vecāks
revīzija
5ef930b5f8

+ 8 - 0
mcs/build/library.make

@@ -67,6 +67,14 @@ IL_REPLACE_FILES += $(IL_REPLACE:%=--ilreplace:%)
 endif
 endif
 
+ifdef ENFORCE_LIBRARY_WARN_AS_ERROR
+ifeq ($(LIBRARY_WARN_AS_ERROR),yes)
+ifndef MCS_MODE
+LIB_MCS_FLAGS += -warnaserror
+endif
+endif
+endif
+
 #
 # The bare directory contains the plain versions of System and System.Xml
 #

+ 2 - 0
mcs/build/profiles/net_4_x.make

@@ -19,3 +19,5 @@ API_BIN_PROFILE = net_4_x
 FRAMEWORK_VERSION = 4.5
 XBUILD_VERSION = 4.0
 MONO_FEATURE_APPLETLS=1
+
+ENFORCE_LIBRARY_WARN_AS_ERROR = yes

+ 2 - 0
mcs/class/Mono.Profiler.Log/Makefile

@@ -8,6 +8,8 @@ LIB_REFS = System System.Core
 KEYFILE = $(LIBRARY_SNK)
 LIB_MCS_FLAGS = /unsafe /publicsign
 
+LIBRARY_WARN_AS_ERROR = yes
+
 NO_TEST = yes
 
 include ../../build/library.make

+ 1 - 0
mcs/class/Mono.Security/Makefile

@@ -8,6 +8,7 @@ LIB_REFS = bare/System
 KEYFILE = ../mono.pub
 LIB_MCS_FLAGS = -unsafe -nowarn:1030,3009
 TEST_MCS_FLAGS = $(LIB_MCS_FLAGS) -nowarn:169,219,618,672
+LIBRARY_WARN_AS_ERROR = yes
 
 CC_PROFILE := $(filter monotouch% xammac, $(PROFILE))
 ifdef CC_PROFILE

+ 1 - 0
mcs/class/System.Configuration/Makefile

@@ -12,6 +12,7 @@ LIB_MCS_FLAGS = -nowarn:618
 TEST_MCS_FLAGS =
 TEST_LIB_REFS = System.Xml System
 TEST_NUNITLITE_APP_CONFIG_GLOBAL=Test/test-config-file
+LIBRARY_WARN_AS_ERROR = yes
 
 include ../../build/library.make
 

+ 2 - 0
mcs/class/System.Core/Makefile

@@ -18,6 +18,8 @@ RESX_RESOURCE_STRING = \
 	../../../external/corefx/src/System.Linq.Parallel/src/Resources/Strings.resx \
 	../../../external/corefx/src/System.Linq.Queryable/src/Resources/Strings.resx
 
+LIBRARY_WARN_AS_ERROR = yes
+
 ifneq (2.1, $(FRAMEWORK_VERSION))
 LIB_MCS_FLAGS += -d:NET_3_5
 endif

+ 0 - 14
mcs/class/System.Core/Test/System.Linq.Expressions/ExpressionTest.cs

@@ -195,20 +195,6 @@ namespace MonoTests.System.Linq.Expressions {
 			Assert.IsNotNull (identity.Target);
 		}
 
-		class Foo {
-			public string gazonk;
-		}
-
-		struct Bar {
-			public int baz;
-
-			public override string ToString ()
-			{
-				return baz.ToString ();
-			}
-		}
-
-
 		[Test]
 		public void SimpleHoistedParameter ()
 		{

+ 1 - 0
mcs/class/System.IO.Compression.FileSystem/Makefile

@@ -8,6 +8,7 @@ KEYFILE = ../ecma.pub
 LIB_MCS_FLAGS = -unsafe
 TEST_MCS_FLAGS =
 TEST_LIB_REFS = System System.Core System.IO.Compression
+LIBRARY_WARN_AS_ERROR = yes
 
 RESX_RESOURCE_STRING = \
 	../../../external/corefx/src/System.IO.Compression.FileSystem/src/Resources/Strings.resx \

+ 1 - 0
mcs/class/System.IO.Compression/Makefile

@@ -8,6 +8,7 @@ KEYFILE = ../ecma.pub
 LIB_MCS_FLAGS =
 TEST_MCS_FLAGS =
 TEST_LIB_REFS = System System.Core
+LIBRARY_WARN_AS_ERROR = yes
 
 RESX_RESOURCE_STRING = \
 	../../../external/corefx/src/System.IO.Compression/src/Resources/Strings.resx

+ 2 - 0
mcs/class/System.Net.Http/Makefile

@@ -14,4 +14,6 @@ endif
 TEST_LIB_REFS = System System.Core
 TEST_MCS_FLAGS =
 
+LIBRARY_WARN_AS_ERROR = yes
+
 include ../../build/library.make

+ 1 - 0
mcs/class/System.Net/Makefile

@@ -5,6 +5,7 @@ include ../../build/rules.make
 LIBRARY = System.Net.dll
 LIB_REFS = System System.Core System.Xml
 LIB_MCS_FLAGS =  -unsafe
+LIBRARY_WARN_AS_ERROR = yes
 
 ifneq (2.1, $(FRAMEWORK_VERSION))
 LIB_MCS_FLAGS += -d:NET_3_5 -nowarn:1720

+ 1 - 0
mcs/class/System.Numerics.Vectors/Makefile

@@ -6,6 +6,7 @@ LIBRARY = System.Numerics.Vectors.dll
 LIB_REFS = System System.Numerics
 KEYFILE = ../msfinal.pub
 LIB_MCS_FLAGS = -unsafe
+LIBRARY_WARN_AS_ERROR = yes
 
 RESX_RESOURCE_STRING = ../../../external/corefx/src/System.Numerics.Vectors/src/Resources/Strings.resx
 

+ 1 - 0
mcs/class/System.Numerics/Makefile

@@ -9,6 +9,7 @@ LIB_MCS_FLAGS = /unsafe
 TEST_MCS_FLAGS = $(LIB_MCS_FLAGS)
 XTEST_LIB_REFS = System Facades/System.Threading.Tasks Facades/System.Runtime.InteropServices.RuntimeInformation System.Core System.Numerics.Vectors Microsoft.CSharp
 XTEST_LIB_FLAGS = -unsafe
+LIBRARY_WARN_AS_ERROR = yes
 
 RESX_RESOURCE_STRING = \
 	../../../external/corefx/src/System.Runtime.Numerics/src/Resources/Strings.resx \

+ 6 - 2
mcs/class/System.Numerics/Test/System.Numerics/BigIntegerTest.cs

@@ -560,7 +560,7 @@ namespace MonoTests.System.Numerics
 					Assert.AreEqual (val, (long)a, "#a_" + val);
 					Assert.AreEqual (val, (long)b, "#b_" + val);
 					Assert.AreEqual (a, b, "#a  == #b (" + val + ")");
-				} catch (Exception e) {
+				} catch (Exception) {
 					Assert.Fail ("could not roundtrip {0}", val);
 				}
 			}
@@ -1259,13 +1259,17 @@ namespace MonoTests.System.Numerics
 			Assert.AreEqual ("0", a.ToString (), "#4");
 
 			a = new BigInteger ();
+#pragma warning disable 1718
 			Assert.AreEqual (true, a == a, "#5");
+#pragma warning restore
 
 			a = new BigInteger ();
+#pragma warning disable 1718
 			Assert.AreEqual (false, a < a, "#6");
+#pragma warning restore
 
 			a = new BigInteger ();
-			Assert.AreEqual (true, a < 10l, "#7");
+			Assert.AreEqual (true, a < 10L, "#7");
 
 			a = new BigInteger ();
 			Assert.AreEqual (true, a.IsEven, "#8");

+ 2 - 0
mcs/class/System.XML/Makefile

@@ -26,6 +26,8 @@ endif
 TEST_LIB_REFS = System.Data System.Core
 TEST_MCS_FLAGS = $(LIB_MCS_FLAGS) -nowarn:0618 -nowarn:219 -nowarn:169
 
+LIBRARY_WARN_AS_ERROR = yes
+
 ifneq (bare/,$(intermediate))
 LIB_REFS += secxml/System 
 ifndef MOBILE_PROFILE

+ 1 - 1
mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaValidatorTests.cs

@@ -358,7 +358,7 @@ namespace MonoTests.System.Xml
 				XmlDocument document = new XmlDocument ();
 				document.Load (reader);
 				document.Validate (null);
-			} catch (Exception e) {
+			} catch (Exception) {
 				if (!shouldFail)
 					throw;
 				return;

+ 1 - 1
mcs/class/System.XML/Test/System.Xml.Serialization/XmlAttributesTests.cs

@@ -110,7 +110,7 @@ namespace MonoTests.System.XmlSerialization
 			try {
 				Serialize (10, ao);
 				Assert.Fail ("Should be invalid.");
-			} catch (InvalidOperationException ex) {
+			} catch (InvalidOperationException) {
 			}
 		}
 		

+ 2 - 2
mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializationReaderTests.cs

@@ -81,7 +81,7 @@ namespace MonoTests.System.XmlSerialization
 			try {
 				ToEnum ("One", values, "Some.Type.Name");
 				Assert.Fail ("#C1");
-			} catch (InvalidCastException ex) {
+			} catch (InvalidCastException) {
 			}
 
 			values.Clear ();
@@ -90,7 +90,7 @@ namespace MonoTests.System.XmlSerialization
 			try {
 				ToEnum ("One", values, "Some.Type.Name");
 				Assert.Fail ("#D1");
-			} catch (InvalidCastException ex) {
+			} catch (InvalidCastException) {
 			}
 
 			values.Clear ();

+ 0 - 1
mcs/class/System.XML/Test/System.Xml.XPath/XPathNavigatorReaderTests.cs

@@ -668,7 +668,6 @@ namespace MonoTests.System.Xml.XPath
 		[Test]
 		public void ReadSubtreeAttributesByIndex ()
 		{
-			XmlWriter xw;
 			XmlDocument doc = new XmlDocument ();
 			doc.LoadXml ("<u:Timestamp u:Id='ID1' xmlns:u='urn:foo'></u:Timestamp>");
 			XmlReader r = doc.CreateNavigator ().ReadSubtree ();

+ 1 - 1
mcs/class/System.XML/Test/System.Xml/XmlConvertTests.cs

@@ -929,7 +929,7 @@ namespace MonoTests.System.Xml
 				if (success)
 					return;
 				Assert.Fail (s + "should fail");
-			} catch (XmlException ex) {
+			} catch (XmlException) {
 				if (success)
 					Assert.Fail (s + "should not fail");
 			}

+ 0 - 15
mcs/class/System.XML/Test/System.Xml/XmlReaderCommonTests.cs

@@ -2304,21 +2304,6 @@ namespace MonoTests.System.Xml
 			r.ReadAsync ();
 		}
 
-		Exception RunAsync (Action action)
-		{
-			var task = Task<Exception>.Run (async () => {
-				try {
-					action ();
-					return null;
-				} catch (Exception ex) {
-					return ex;
-				}
-			});
-			task.Wait ();
-			Assert.That (task.IsCompleted);
-			return task.Result;
-		}
-
 		[Test]
 		public void SimpleAsync ()
 		{

+ 6 - 0
mcs/class/System.XML/Test/System.Xml/XmlSecureResolverTests.cs

@@ -71,7 +71,9 @@ namespace MonoTests.System.Xml
 		{
 			// "normal" path
 			Evidence e = XmlSecureResolver.CreateEvidenceForUrl (Assembly.GetExecutingAssembly ().Location);
+#pragma warning disable 612
 			Assert.AreEqual (2, e.Count, "Assembly.GetExecutingAssembly ().Location");
+#pragma warning restore
 			bool url = false;
 			bool zone = false;
 			IEnumerator en = e.GetHostEnumerator ();
@@ -86,7 +88,9 @@ namespace MonoTests.System.Xml
 
 			// file://
 			e = XmlSecureResolver.CreateEvidenceForUrl (Assembly.GetExecutingAssembly ().CodeBase);
+#pragma warning disable 612
 			Assert.AreEqual (2, e.Count, "Assembly.GetExecutingAssembly ().CodeBase");
+#pragma warning restore
 			url = false;
 			zone = false;
 			en = e.GetHostEnumerator ();
@@ -106,7 +110,9 @@ namespace MonoTests.System.Xml
 		{
 			// http://
 			Evidence e = XmlSecureResolver.CreateEvidenceForUrl ("http://www.go-mono.com");
+#pragma warning disable 612
 			Assert.AreEqual (3, e.Count, "http://www.go-mono.com");
+#pragma warning restore
 			bool url = false;
 			bool zone = false;
 			bool site = false;

+ 1 - 1
mcs/class/System.XML/Test/System.Xml/nist_dom/fundamental/Element/Element.cs

@@ -1764,7 +1764,7 @@ namespace nist_dom.fundamental
                 {
                     employeeIdElement.SetAttributeNode(newAttribute);//.node.
                 }
-                catch(System.InvalidOperationException ex) 
+                catch(System.InvalidOperationException) 
                 { 
                     computedValue = "InvalidOperationException"; 
                 }

+ 2 - 1
mcs/class/corlib/Makefile

@@ -8,6 +8,7 @@ LIBRARY_NAME = mscorlib.dll
 
 LIB_MCS_FLAGS = $(REFERENCE_SOURCES_FLAGS) $(RESOURCE_FILES:%=-resource:%)
 
+LIBRARY_WARN_AS_ERROR = yes
 #LIBRARY_USE_INTERMEDIATE_FILE = yes
 
 ifeq (2, $(FRAMEWORK_VERSION_MAJOR))
@@ -93,7 +94,7 @@ LIB_MCS_FLAGS += -d:MONO_FEATURE_APPLE_X509
 endif
 
 WARNING_ABOUT_DISABLED_WARNING=1635
-LOCAL_MCS_FLAGS = -unsafe -nostdlib -nowarn:612,618,$(WARNING_ABOUT_DISABLED_WARNING) -d:INSIDE_CORLIB,MONO_CULTURE_DATA -d:LIBC $(REFERENCE_SOURCES_FLAGS)
+LOCAL_MCS_FLAGS = -unsafe -nostdlib -nowarn:612,618,3001,3003,$(WARNING_ABOUT_DISABLED_WARNING) -d:INSIDE_CORLIB,MONO_CULTURE_DATA -d:LIBC $(REFERENCE_SOURCES_FLAGS)
 DEFAULT_REFERENCES =
 
 TEST_LIB_REFS = System.Core System