[genproj] Handle resources properly, add helper scripts to bootstrap
[mono.git] / msvc / scripts / genproj.cs
index 4f7343b9fe8e1a3fb213d56329e2f1b364f49cfd..ccaa3b3149c9059691926e96e6a17433c2ee84b8 100644 (file)
@@ -654,7 +654,7 @@ class MsbuildGenerator {
 
        public VsCsproj Csproj;
 
-       public VsCsproj Generate (Dictionary<string,MsbuildGenerator> projects, bool showWarnings = false)
+       public VsCsproj Generate (string library_output, Dictionary<string,MsbuildGenerator> projects, bool showWarnings = false)
        {
                var generatedProjFile = NativeName (Csproj.csProjFilename);
                //Console.WriteLine ("Generating: {0}", generatedProjFile);
@@ -696,7 +696,6 @@ class MsbuildGenerator {
                }
                //
                // Prebuild code, might be in inputs, check:
-               //  inputs/LIBRARY-PROFILE.pre
                //  inputs/LIBRARY.pre
                //
                string prebuild = Load (library + ".pre");
@@ -705,7 +704,7 @@ class MsbuildGenerator {
                int q = library.IndexOf ("-");
                if (q != -1)
                        prebuild = prebuild + Load (library.Substring (0, q) + ".pre");
-
+               
                if (prebuild.IndexOf ("@MONO@") != -1){
                        prebuild_unix = prebuild.Replace ("@MONO@", "mono").Replace ("@CAT@", "cat");
                        prebuild_windows = prebuild.Replace ("@MONO@", "").Replace ("@CAT@", "type");
@@ -713,11 +712,10 @@ class MsbuildGenerator {
                        prebuild_unix = prebuild.Replace ("jay.exe", "jay");
                        prebuild_windows = prebuild;
                }
-               
                const string condition_unix    = "Condition=\" '$(OS)' != 'Windows_NT' \"";
                const string condition_windows = "Condition=\" '$(OS)' == 'Windows_NT' \"";
                prebuild =
-                       "    <PreBuildEvent " + condition_unix + ">" + NewLine + prebuild_unix + NewLine + "    </PreBuildEvent>" + NewLine +
+                       "    <PreBuildEvent " + condition_unix + ">\n" + prebuild_unix + "\n    </PreBuildEvent>" + NewLine +
                        "    <PreBuildEvent " + condition_windows + ">" + NewLine + prebuild_windows + NewLine + "    </PreBuildEvent>" + NewLine;
 
                var all_args = new Queue<string []> ();
@@ -736,7 +734,7 @@ class MsbuildGenerator {
                                        var resp_file_full = Path.Combine (base_dir, response_file);
                                        extra_args = LoadArgs (resp_file_full);
                                        if (extra_args == null) {
-                                               Console.WriteLine ("Unable to open response file: " + resp_file_full);
+                                               Console.WriteLine ($"{library_output}: Unable to open response file: {resp_file_full}");
                                                Environment.Exit (1);
                                        }
 
@@ -746,13 +744,12 @@ class MsbuildGenerator {
 
                                if (CSCParseOption (f [i], ref f))
                                        continue;
-                               Console.WriteLine ("Failure with {0}", f [i]);
+                               Console.WriteLine ("{library_output}: Failure with {0}", f [i]);
                                Environment.Exit (1);
                        }
                }
 
                string [] source_files;
-               //Console.WriteLine ("Base: {0} res: {1}", base_dir, response);
                using (var reader = new StreamReader (NativeName (base_dir + "\\" + response))) {
                        source_files = reader.ReadToEnd ().Split ();
                }
@@ -812,7 +809,11 @@ class MsbuildGenerator {
                if (embedded_resources.Count > 0) {
                        resources.AppendFormat ("  <ItemGroup>" + NewLine);
                        foreach (var dk in embedded_resources) {
-                               resources.AppendFormat ("    <EmbeddedResource Include=\"{0}\">" + NewLine, dk.Key);
+                               var source = dk.Key;
+                               if (source.EndsWith (".resources"))
+                                       source = source.Replace (".resources", ".resx");
+                               Console.WriteLine ("Got {0} -> {1}", dk.Key, source);
+                               resources.AppendFormat ("    <EmbeddedResource Include=\"{0}\">" + NewLine, source);
                                resources.AppendFormat ("      <LogicalName>{0}</LogicalName>" + NewLine, dk.Value);
                                resources.AppendFormat ("    </EmbeddedResource>" + NewLine);
                        }
@@ -833,7 +834,7 @@ class MsbuildGenerator {
                        var refdistinct = references.Distinct ();
                        foreach (string reference in refdistinct) {
                                
-                               var match = GetMatchingCsproj (reference, projects);
+                               var match = GetMatchingCsproj (library_output, reference, projects);
                                if (match != null) {
                                        AddProjectReference (refs, Csproj, match, reference, null);
                                } else {
@@ -853,7 +854,7 @@ class MsbuildGenerator {
                                int index = r.IndexOf ('=');
                                string alias = r.Substring (0, index);
                                string assembly = r.Substring (index + 1);
-                               var match = GetMatchingCsproj (assembly, projects, explicitPath: true);
+                               var match = GetMatchingCsproj (library_output, assembly, projects, explicitPath: true);
                                if (match != null) {
                                        AddProjectReference (refs, Csproj, match, r, alias);
                                } else {
@@ -962,7 +963,7 @@ class MsbuildGenerator {
                return ret;
        }
 
-       MsbuildGenerator GetMatchingCsproj (string dllReferenceName, Dictionary<string,MsbuildGenerator> projects, bool explicitPath = false)
+       MsbuildGenerator GetMatchingCsproj (string library_output, string dllReferenceName, Dictionary<string,MsbuildGenerator> projects, bool explicitPath = false)
        {
                // libDir would be "./../../class/lib/net_4_x for example
                // project 
@@ -993,9 +994,10 @@ class MsbuildGenerator {
                                return project.Value;
 
                }
-               Console.WriteLine ("Did not find referenced {0} with libs={1}", dllReferenceName, String.Join (", ", libs));
+               var ljoined = String.Join (", ", libs);
+               Console.WriteLine ($"{library_output}: did not find referenced {dllReferenceName} with libs={ljoined}");
                foreach (var p in projects) {
-               //      Console.WriteLine ("{0}", p.Value.AbsoluteLibraryOutput);
+                       Console.WriteLine ("{0}", p.Value.AbsoluteLibraryOutput);
                }
                return null;
        }
@@ -1012,7 +1014,7 @@ public class Driver {
                        string library = project.Attribute ("library").Value;
                        var profile = project.Element ("profile").Value;
 
-#if true
+#if false
                        // Skip facades for now, the tool doesn't know how to deal with them yet.
                        if (dir.Contains ("Facades"))
                                continue;
@@ -1043,8 +1045,14 @@ public class Driver {
                        // The next ones are to make debugging easier for now
                        if (profile == "basic")
                                continue;
+
+                       // For now -- problem is, our resolver currently only considers the assembly name, and we ahve
+                       // conflicing 2.0 and 2.4 versions so for now, we just skip the nunit20 versions
+                       if (dir.Contains ("nunit20"))
+                               continue;
+                       
 #if true
-                       if (profile != "net_4_x" || library.Contains ("tests"))
+                       if (profile != "net_4_x" || library.Contains ("tests")) 
                                continue;
 #endif
                        //Console.WriteLine ("Going to handle {0}", library);
@@ -1089,10 +1097,10 @@ public class Driver {
                }
                foreach (var project in GetProjects (makefileDeps)){
                        var library_output = project.Element ("library_output").Value;
-                       Console.WriteLine ("=== {0} ===", library_output);
+                       //Console.WriteLine ("=== {0} ===", library_output);
                        var gen = projects [library_output];
                        try {
-                               var csproj = gen.Generate (projects);
+                               var csproj = gen.Generate (library_output, projects);
                                var csprojFilename = csproj.csProjFilename;
                                if (!sln_gen.ContainsProjectIdentifier (csproj.library)) {
                                        sln_gen.Add (csproj);