[genproj] Simplify strong name key handling
[mono.git] / msvc / scripts / genproj.cs
index d442697c3ce92389f3396c4cd502b66b0bc57126..c60bc5397ce28ad027f8856df3061ebfad69d4f6 100644 (file)
@@ -563,7 +563,13 @@ class MsbuildGenerator {
 
                case "/publicsign":
                        return true;
-                       
+
+               case "/deterministic":
+                       return true;
+
+               case "/runtimemetadataversion":
+                       return true;
+
                case "/-getresourcestrings":
                        return true;
                }
@@ -654,12 +660,19 @@ class MsbuildGenerator {
 
        public VsCsproj Csproj;
 
+       void AppendResource (StringBuilder resources, string source, string logical)
+       {
+               resources.AppendFormat ("    <EmbeddedResource Include=\"{0}\">" + NewLine, source);
+               resources.AppendFormat ("      <LogicalName>{0}</LogicalName>" + NewLine, logical);
+               resources.AppendFormat ("    </EmbeddedResource>" + NewLine);
+       }
+       
        public VsCsproj Generate (string library_output, Dictionary<string,MsbuildGenerator> projects, bool showWarnings = false)
        {
                var generatedProjFile = NativeName (Csproj.csProjFilename);
                //Console.WriteLine ("Generating: {0}", generatedProjFile);
 
-               string boot, flags, output_name, built_sources, response, profile;
+               string boot, flags, output_name, built_sources, response, profile, reskey;
 
                boot = xproject.Element ("boot").Value;
                flags = xproject.Element ("flags").Value;
@@ -668,6 +681,7 @@ class MsbuildGenerator {
                        Target = Target.Exe;
                built_sources = xproject.Element ("built_sources").Value;
                response = xproject.Element ("response").Value;
+               reskey = xproject.Element ("resources").Value;
 
                profile = xproject.Element ("profile").Value;
                if (string.IsNullOrEmpty (response)) {
@@ -788,14 +802,16 @@ class MsbuildGenerator {
                        refs.Append (string.Format ("    <Reference Include=\"{0}\" />" + NewLine, nunitLibPath));
                }
 
+               //
+               // Generate resource referenced from the command line
+               //
                var resources = new StringBuilder ();
                if (embedded_resources.Count > 0) {
-                       resources.AppendFormat ("  <ItemGroup>" + NewLine);
                        foreach (var dk in embedded_resources) {
                                var source = dk.Key;
                                if (source.EndsWith (".resources"))
                                        source = source.Replace (".resources", ".resx");
-
+                               
                                // try to find a pre-built resource, and use that instead of trying to build it
                                if (source.EndsWith (".resx")) {
                                        var probe_prebuilt = Path.Combine (base_dir, source.Replace (".resx", ".resources.prebuilt"));
@@ -804,13 +820,27 @@ class MsbuildGenerator {
                                                source = GetRelativePath (base_dir + "/", probe_prebuilt);
                                        }
                                }
-                               resources.AppendFormat ("    <EmbeddedResource Include=\"{0}\">" + NewLine, source);
-                               resources.AppendFormat ("      <LogicalName>{0}</LogicalName>" + NewLine, dk.Value);
-                               resources.AppendFormat ("    </EmbeddedResource>" + NewLine);
+                               AppendResource (resources, source, dk.Value);
                        }
+               }
+               //
+               // Generate resources that were part of the explicit <resource> node
+               //
+               if (reskey != null && reskey != ""){
+                       var pairs = reskey.Split (' ', '\n', '\t');
+                       foreach (var pair in pairs){
+                               var p = pair.IndexOf (",");
+                               if (p == -1){
+                                       Console.Error.WriteLine ($"Found a resource without a filename: {pairs} for {Csproj.csProjFilename}");
+                                       Environment.Exit (1);
+                               }
+                               AppendResource (resources, pair.Substring (p+1), pair.Substring (0, p) + ".resources");
+                       }
+               }
+               if (resources.Length > 0){
+                       resources.Insert (0, "  <ItemGroup>" + NewLine);
                        resources.AppendFormat ("  </ItemGroup>" + NewLine);
                }
-       
 
                if (references.Count > 0 || reference_aliases.Count > 0) {
                        // -r:mscorlib.dll -r:System.dll
@@ -870,6 +900,12 @@ class MsbuildGenerator {
                else
                        build_output_dir = "bin\\Debug\\" + library;
 
+               if (build_output_dir.Contains ("-linux") || build_output_dir.Contains ("-darwin") || build_output_dir.Contains ("-win32"))
+                       build_output_dir = build_output_dir
+                               .Replace ("-linux", "-$(HostPlatform)")
+                               .Replace ("-darwin", "-$(HostPlatform)")
+                               .Replace ("-win32", "-$(HostPlatform)");
+
                bool basic_or_build = (library.Contains ("-basic") || library.Contains ("-build"));
 
                //
@@ -879,13 +915,10 @@ class MsbuildGenerator {
                string strongNameSection = "";
                if (StrongNameKeyFile != null){
                        strongNameSection = String.Format (
-                               "  <PropertyGroup>" + NewLine +
                                "    <SignAssembly>true</SignAssembly>" + NewLine +
                                "{1}" +
-                               "  </PropertyGroup>" + NewLine +
-                               "  <PropertyGroup>" + NewLine +
-                               "    <AssemblyOriginatorKeyFile>{0}</AssemblyOriginatorKeyFile>" + NewLine +
-                               "  </PropertyGroup>", StrongNameKeyFile, StrongNameDelaySign ? "    <DelaySign>true</DelaySign>" + NewLine : "");
+                               "    <AssemblyOriginatorKeyFile>{0}</AssemblyOriginatorKeyFile>",
+                               StrongNameKeyFile, StrongNameDelaySign ? "    <DelaySign>true</DelaySign>" + NewLine : "");
                }
                Csproj.output = template.
                        Replace ("@OUTPUTTYPE@", Target == Target.Library ? "Library" : "Exe").