using System.Text;
using System.Globalization;
using System.Xml.Linq;
+using System.Xml.XPath;
using System.Linq;
+using System.Xml;
public enum Target {
Library, Exe, Module, WinExe
const string project_start = "Project(\"{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}\") = \"{0}\", \"{1}\", \"{2}\""; // Note: No need to double up on {} around {2}
const string project_end = "EndProject";
- List<MsbuildGenerator.VsCsproj> libraries = new List<MsbuildGenerator.VsCsproj> ();
+ public List<MsbuildGenerator.VsCsproj> libraries = new List<MsbuildGenerator.VsCsproj> ();
string header;
string MakeHeader (string formatVersion, string yearTag)
sln.WriteLine ();
sln.WriteLine (header);
foreach (var proj in libraries) {
- sln.WriteLine (project_start, proj.library, proj.csprojFileName, proj.projectGuid);
+ sln.WriteLine (project_start, proj.library, proj.csProjFilename, proj.projectGuid);
sln.WriteLine (project_end);
}
sln.WriteLine ("Global");
class MsbuildGenerator {
static readonly string NewLine = SlnGenerator.NewLine;
+ static XmlNamespaceManager xmlns;
public const string profile_2_0 = "_2_0";
public const string profile_3_5 = "_3_5";
using (var input = new StreamReader ("csproj.tmpl")) {
template = input.ReadToEnd ();
}
+
+ xmlns = new XmlNamespaceManager (new NameTable ());
+ xmlns.AddNamespace ("x", "http://schemas.microsoft.com/developer/msbuild/2003");
}
// The directory as specified in order.xml
- string dir;
+ public string dir;
+ string library;
+ string projectGuid;
+ string fx_version;
+
+ XElement xproject;
+ public string CsprojFilename;
//
// Our base directory, this is relative to our exectution point mono/msvc/scripts
string base_dir;
string mcs_topdir;
- public MsbuildGenerator (string dir)
+ public string LibraryOutput, AbsoluteLibraryOutput;
+
+ public MsbuildGenerator (XElement xproject)
{
- this.dir = dir;
+ this.xproject = xproject;
+ dir = xproject.Attribute ("dir").Value;
+ library = xproject.Attribute ("library").Value;
+ CsprojFilename = "..\\..\\mcs\\" + dir + "\\" + library + ".csproj";
+ LibraryOutput = xproject.Element ("library_output").Value;
+
+ projectGuid = LookupOrGenerateGuid ();
+ fx_version = xproject.Element ("fx_version").Value;
+ Csproj = new VsCsproj () {
+ csProjFilename = this.CsprojFilename,
+ projectGuid = this.projectGuid,
+ library_output = this.LibraryOutput,
+ fx_version = double.Parse (fx_version),
+ library = this.library,
+ MsbuildGenerator = this
+ };
if (dir == "mcs") {
- mcs_topdir = "..\\";
- class_dir = "..\\class\\";
- base_dir = "..\\..\\mcs\\mcs";
+ mcs_topdir = "../";
+ class_dir = "../class/";
+ base_dir = "../../mcs/mcs";
} else {
- mcs_topdir = "..\\";
+ mcs_topdir = "../";
foreach (char c in dir) {
if (c == '/')
base_dir = Path.Combine ("..", "..", "mcs", dir);
}
+ AbsoluteLibraryOutput = Path.GetFullPath (Path.Combine (base_dir, LibraryOutput));
+ }
+
+ string LookupOrGenerateGuid ()
+ {
+ var projectFile = NativeName (CsprojFilename);
+ if (File.Exists (projectFile)){
+ var doc = XDocument.Load (projectFile);
+ return doc.XPathSelectElement ("x:Project/x:PropertyGroup/x:ProjectGuid", xmlns).Value;
+ }
+ return "{" + Guid.NewGuid ().ToString ().ToUpper () + "}";
}
// Currently used
public class VsCsproj {
public string projectGuid;
public string output;
- public string csprojFileName;
public string library_output;
+ public string csProjFilename;
public double fx_version;
public List<VsCsproj> projReferences = new List<VsCsproj> ();
public string library;
+ public MsbuildGenerator MsbuildGenerator;
}
- public VsCsproj Generate (XElement xproject, List<MsbuildGenerator.VsCsproj> projects, bool showWarnings = false)
+ public VsCsproj Csproj;
+
+ public VsCsproj Generate (Dictionary<string,MsbuildGenerator> projects, bool showWarnings = false)
{
+ var generatedProjFile = NativeName (Csproj.csProjFilename);
+ //Console.WriteLine ("Generating: {0}", generatedProjFile);
- var result = new VsCsproj ();
- string library = xproject.Attribute ("library").Value;
- string boot, flags, output_name, built_sources, library_output, response, fx_version, profile;
+ string boot, flags, output_name, built_sources, response, profile;
boot = xproject.Element ("boot").Value;
flags = xproject.Element ("flags").Value;
output_name = xproject.Element ("output").Value;
built_sources = xproject.Element ("built_sources").Value;
- library_output = xproject.Element ("library_output").Value;
response = xproject.Element ("response").Value;
- fx_version = xproject.Element ("fx_version").Value;
//if (library.EndsWith("-build")) fx_version = "2.0"; // otherwise problem if .NET4.5 is installed, seems. (https://github.com/nikhilk/scriptsharp/issues/156)
profile = xproject.Element ("profile").Value;
if (string.IsNullOrEmpty (response)) {
prebuild_unix = prebuild.Replace ("@MONO@", "mono").Replace ("@CAT@", "cat");
prebuild_windows = prebuild.Replace ("@MONO@", "").Replace ("@CAT@", "type");
} else {
- prebuild_unix = prebuild;
+ prebuild_unix = prebuild.Replace ("jay.exe", "jay");
prebuild_windows = prebuild;
}
string [] f = all_args.Dequeue ();
for (int i = 0; i < f.Length; i++) {
- if (f [i] [0] == '-')
+ if (f [i].Length > 0 && f [i][0] == '-')
f [i] = "/" + f [i].Substring (1);
-
+
if (f [i] [0] == '@') {
string [] extra_args;
string response_file = f [i].Substring (1);
// this.ignore_warning.Add(0436);
//}
- result.library = library;
- result.csprojFileName = "..\\..\\mcs\\" + dir + "\\" + library + ".csproj";
-
var refs = new StringBuilder ();
bool is_test = response.Contains ("_test_");
}
resources.AppendFormat (" </ItemGroup>" + NewLine);
}
+
+
if (references.Count > 0 || reference_aliases.Count > 0) {
// -r:mscorlib.dll -r:System.dll
//<ProjectReference Include="..\corlib\corlib-basic.csproj">
//</ProjectReference>
var refdistinct = references.Distinct ();
foreach (string r in refdistinct) {
- VsCsproj lastMatching = GetMatchingCsproj (Path.GetFileName (r), projects);
- if (lastMatching != null) {
- AddProjectReference (refs, result, lastMatching, r, null);
+ var match = GetMatchingCsproj (Path.GetFileName (r), projects);
+ if (match != null) {
+ AddProjectReference (refs, Csproj, match, r, null);
} else {
if (showWarnings){
Console.WriteLine ("{0}: Could not find a matching project reference for {1}", library, Path.GetFileName (r));
int index = r.IndexOf ('=');
string alias = r.Substring (0, index);
string assembly = r.Substring (index + 1);
- VsCsproj lastMatching = GetMatchingCsproj (Path.GetFileName (assembly), projects);
- if (lastMatching != null) {
- AddProjectReference (refs, result, lastMatching, r, alias);
+ var match = GetMatchingCsproj (assembly, projects, explicitPath: true);
+ if (match != null) {
+ AddProjectReference (refs, Csproj, match, r, alias);
} else {
throw new NotSupportedException (string.Format ("From {0}, could not find a matching project reference for {1}", library, r));
refs.Append (" <Reference Include=\"" + assembly + "\">" + NewLine);
// /class/lib/basic/System.Core.dll
// <library_output>mcs.exe</library_output>
string build_output_dir;
- if (library_output.Contains ("/"))
- build_output_dir = Path.GetDirectoryName (library_output);
+ if (LibraryOutput.Contains ("/"))
+ build_output_dir = Path.GetDirectoryName (LibraryOutput);
else
build_output_dir = "bin\\Debug\\" + library;
//
// Replace the template values
//
- result.projectGuid = "{" + Guid.NewGuid ().ToString ().ToUpper () + "}";
- result.library_output = library_output;
- result.fx_version = double.Parse (fx_version);
- result.output = template.
- Replace ("@PROJECTGUID@", result.projectGuid).
+
+ string strongNameSection = "";
+ if (StrongNameKeyFile != null){
+ strongNameSection = String.Format (
+ " <PropertyGroup>\n" +
+ " <SignAssembly>true</SignAssembly>\n" +
+ "{1}" +
+ " </PropertyGroup>\n" +
+ " <PropertyGroup>\n" +
+ " <AssemblyOriginatorKeyFile>{0}</AssemblyOriginatorKeyFile>\n" +
+ " </PropertyGroup>", StrongNameKeyFile, StrongNameDelaySign ? " <DelaySign>true</DelaySign>\n" : "");
+ }
+ Csproj.output = template.
+ Replace ("@SIGNATURE@", strongNameSection).
+ Replace ("@PROJECTGUID@", Csproj.projectGuid).
Replace ("@DEFINES@", defines.ToString ()).
Replace ("@DISABLEDWARNINGS@", string.Join (",", (from i in ignore_warning select i.ToString ()).ToArray ())).
//Replace("@NOSTDLIB@", (basic_or_build || (!StdLib)) ? "<NoStdLib>true</NoStdLib>" : string.Empty).
Replace ("@SOURCES@", sources.ToString ());
//Console.WriteLine ("Generated {0}", ofile.Replace ("\\", "/"));
- var generatedProjFile = NativeName (result.csprojFileName);
- Console.WriteLine ("Generating: {0}", generatedProjFile);
using (var o = new StreamWriter (generatedProjFile)) {
- o.WriteLine (result.output);
+ o.WriteLine (Csproj.output);
}
- return result;
+ return Csproj;
}
- void AddProjectReference (StringBuilder refs, VsCsproj result, VsCsproj lastMatching, string r, string alias)
+ void AddProjectReference (StringBuilder refs, VsCsproj result, MsbuildGenerator match, string r, string alias)
{
- refs.AppendFormat (" <ProjectReference Include=\"{0}\">{1}", GetRelativePath (result.csprojFileName, lastMatching.csprojFileName), NewLine);
- refs.Append (" <Project>" + lastMatching.projectGuid + "</Project>" + NewLine);
- refs.Append (" <Name>" + Path.GetFileNameWithoutExtension (lastMatching.csprojFileName) + "</Name>" + NewLine);
+ refs.AppendFormat (" <ProjectReference Include=\"{0}\">{1}", GetRelativePath (result.csProjFilename, match.CsprojFilename), NewLine);
+ refs.Append (" <Project>" + match.projectGuid + "</Project>" + NewLine);
+ refs.Append (" <Name>" + Path.GetFileNameWithoutExtension (match.CsprojFilename.Replace ('\\', Path.DirectorySeparatorChar)) + "</Name>" + NewLine);
if (alias != null)
refs.Append (" <Aliases>" + alias + "</Aliases>");
refs.Append (" </ProjectReference>" + NewLine);
- if (!result.projReferences.Contains (lastMatching))
- result.projReferences.Add (lastMatching);
+ if (!result.projReferences.Contains (match.Csproj))
+ result.projReferences.Add (match.Csproj);
}
- static string GetRelativePath (string from, string to)
+ public static string GetRelativePath (string from, string to)
{
from = from.Replace ("\\", "/");
to = to.Replace ("\\", "/");
return ret;
}
- static VsCsproj GetMatchingCsproj (string dllReferenceName, List<VsCsproj> projects)
+ MsbuildGenerator GetMatchingCsproj (string dllReferenceName, Dictionary<string,MsbuildGenerator> projects, bool explicitPath = false)
{
- return projects.LastOrDefault (x => Path.GetFileName (x.library_output).Replace (".dll", "") == dllReferenceName.Replace (".dll", ""));
+ // libDir would be "./../../class/lib/net_4_5 for example
+ // project
+ if (!dllReferenceName.EndsWith (".dll"))
+ dllReferenceName += ".dll";
+
+ if (explicitPath){
+ var probe = Path.GetFullPath (Path.Combine (base_dir, dllReferenceName));
+ foreach (var project in projects){
+ if (probe == project.Value.AbsoluteLibraryOutput)
+ return project.Value;
+ }
+ }
+
+ // not explicit, search for the library in the lib path order specified
+
+ foreach (var libDir in libs) {
+ var abs = Path.GetFullPath (Path.Combine (base_dir, libDir));
+ foreach (var project in projects){
+ var probe = Path.Combine (abs, dllReferenceName);
+
+ if (probe == project.Value.AbsoluteLibraryOutput)
+ return project.Value;
+ }
+ }
+ Console.WriteLine ("Did not find referenced {0} with libs={1}", dllReferenceName, String.Join (", ", libs));
+ foreach (var p in projects) {
+ Console.WriteLine (" => {0}", p.Value.AbsoluteLibraryOutput);
+ }
+ return null;
}
}
public class Driver {
+ static IEnumerable<XElement> GetProjects (bool full = false)
+ {
+ XDocument doc = XDocument.Load ("order.xml");
+ foreach (XElement project in doc.Root.Elements ()) {
+ string dir = project.Attribute ("dir").Value;
+ string library = project.Attribute ("library").Value;
+ var profile = project.Element ("profile").Value;
+
+ //
+ // Do only class libraries for now
+ //
+ if (!(dir.StartsWith ("class") || dir.StartsWith ("mcs") || dir.StartsWith ("basic")))
+ continue;
+
+ if (full){
+ if (!library.Contains ("tests"))
+ yield return project;
+ continue;
+ }
+
+ //
+ // Do not do 2.1, it is not working yet
+ // Do not do basic, as there is no point (requires a system mcs to be installed).
+ //
+ if (library.Contains ("moonlight") || library.Contains ("-basic") || library.EndsWith ("bootstrap") || library.Contains ("build"))
+ continue;
+
+ // The next ones are to make debugging easier for now
+ if (profile == "basic")
+ continue;
+ if (profile != "net_4_5" || library.Contains ("tests"))
+ continue;
+
+ yield return project;
+ }
+ }
+
static void Main (string [] args)
{
if (!File.Exists ("genproj.cs")) {
Console.WriteLine (" assemblies (and dependencies) is included in the solution.");
Console.WriteLine ("Example:");
Console.WriteLine ("genproj.exe 2012 false");
- Console.WriteLine ("genproj.exe with no arguments is equivalent to 'genproj.exe 2012 true'");
+ Console.WriteLine ("genproj.exe with no arguments is equivalent to 'genproj.exe 2012 true'\n\n");
+ Console.WriteLine ("genproj.exe deps");
+ Console.WriteLine ("Generates a Makefile dependency file from the projects input");
Environment.Exit (0);
}
+
var slnVersion = (args.Length > 0) ? args [0] : "2012";
bool fullSolutions = (args.Length > 1) ? bool.Parse (args [1]) : true;
+ // To generate makefile depenedencies
+ var makefileDeps = (args.Length > 0 && args [0] == "deps");
+
var sln_gen = new SlnGenerator (slnVersion);
var two_sln_gen = new SlnGenerator (slnVersion);
var four_sln_gen = new SlnGenerator (slnVersion);
var three_five_sln_gen = new SlnGenerator (slnVersion);
var four_five_sln_gen = new SlnGenerator (slnVersion);
- var projects = new List<MsbuildGenerator.VsCsproj> ();
+ var projects = new Dictionary<string,MsbuildGenerator> ();
- XDocument doc = XDocument.Load ("order.xml");
var duplicates = new List<string> ();
- foreach (XElement project in doc.Root.Elements ()) {
- string dir = project.Attribute ("dir").Value;
- string library = project.Attribute ("library").Value;
-
- //
- // Do only class libraries for now
- //
- if (!(dir.StartsWith ("class") || dir.StartsWith ("mcs") || dir.StartsWith ("basic")))
- continue;
-
- //
- // Do not do 2.1, it is not working yet
- // Do not do basic, as there is no point (requires a system mcs to be installed).
- //
- //if (library.Contains ("moonlight") || library.Contains ("-basic") || library.EndsWith ("bootstrap"))
- if (library.Contains ("moonlight") || library.EndsWith ("bootstrap"))
- continue;
-
- var gen = new MsbuildGenerator (dir);
+ foreach (var project in GetProjects (makefileDeps)) {
+ var library_output = project.Element ("library_output").Value;
+ projects [library_output] = new MsbuildGenerator (project);
+ }
+ foreach (var project in GetProjects (makefileDeps)){
+ var library_output = project.Element ("library_output").Value;
+ var gen = projects [library_output];
try {
- var csproj = gen.Generate (project, projects);
- var csprojFilename = csproj.csprojFileName;
+ var csproj = gen.Generate (projects);
+ var csprojFilename = csproj.csProjFilename;
if (!sln_gen.ContainsProjectIdentifier (csproj.library)) {
- projects.Add (csproj);
sln_gen.Add (csproj);
} else {
duplicates.Add (csprojFilename);
}
-
+
} catch (Exception e) {
- Console.WriteLine ("Error in {0}\n{1}", dir, e);
+ Console.WriteLine ("Error in {0}\n{1}", project, e);
}
}
Func<MsbuildGenerator.VsCsproj, bool> additionalFilter;
additionalFilter = fullSolutions ? (Func<MsbuildGenerator.VsCsproj, bool>)null : IsCommonLibrary;
- FillSolution (two_sln_gen, MsbuildGenerator.profile_2_0, projects, additionalFilter);
- FillSolution (four_five_sln_gen, MsbuildGenerator.profile_4_5, projects, additionalFilter);
- FillSolution (four_sln_gen, MsbuildGenerator.profile_4_0, projects, additionalFilter);
- FillSolution (three_five_sln_gen, MsbuildGenerator.profile_3_5, projects, additionalFilter);
+ FillSolution (two_sln_gen, MsbuildGenerator.profile_2_0, projects.Values, additionalFilter);
+ FillSolution (four_five_sln_gen, MsbuildGenerator.profile_4_5, projects.Values, additionalFilter);
+ FillSolution (four_sln_gen, MsbuildGenerator.profile_4_0, projects.Values, additionalFilter);
+ FillSolution (three_five_sln_gen, MsbuildGenerator.profile_3_5, projects.Values, additionalFilter);
var sb = new StringBuilder ();
sb.AppendLine ("WARNING: Skipped some project references, apparent duplicates in order.xml:");
WriteSolution (three_five_sln_gen, MakeSolutionName (MsbuildGenerator.profile_3_5));
WriteSolution (four_sln_gen, MakeSolutionName (MsbuildGenerator.profile_4_0));
WriteSolution (four_five_sln_gen, MakeSolutionName (MsbuildGenerator.profile_4_5));
+
+ if (makefileDeps){
+ const string classDirPrefix = "./../../";
+ Console.WriteLine ("here {0}", sln_gen.libraries.Count);
+ foreach (var p in sln_gen.libraries){
+ string rebasedOutput = RebaseToClassDirectory (MsbuildGenerator.GetRelativePath ("../../mcs/class", p.library_output));
+
+ Console.Write ("{0}: ", rebasedOutput);
+ foreach (var r in p.projReferences){
+ var lo = r.library_output;
+ if (lo.StartsWith (classDirPrefix))
+ lo = lo.Substring (classDirPrefix.Length);
+ else
+ lo = "<<ERROR-dependency is not a class library>>";
+ Console.Write ("{0} ", lo);
+ }
+ Console.Write ("\n\t(cd {0}; make {1})", p.MsbuildGenerator.dir, p.library_output);
+ Console.WriteLine ("\n");
+ }
+ }
// A few other optional solutions
// Solutions with 'everything' and the most common libraries used in development may be of interest
//WriteSolution (build_sln_gen, "mcs_build.sln");
}
+ // Rebases a path, assuming that execution is taking place in the "class" subdirectory,
+ // so it strips ../class/ from a path, which is a no-op
+ static string RebaseToClassDirectory (string path)
+ {
+ const string prefix = "../class/";
+ int p = path.IndexOf (prefix);
+ if (p == -1)
+ return path;
+ return path.Substring (0, p) + path.Substring (p+prefix.Length);
+ return path;
+ }
+
static string MakeSolutionName (string profileTag)
{
return "net" + profileTag + ".sln";
}
- static void FillSolution (SlnGenerator solution, string profileString, List<MsbuildGenerator.VsCsproj> projects, Func<MsbuildGenerator.VsCsproj, bool> additionalFilter = null)
+ static void FillSolution (SlnGenerator solution, string profileString, IEnumerable<MsbuildGenerator> projects, Func<MsbuildGenerator.VsCsproj, bool> additionalFilter = null)
{
- foreach (var vsCsproj in projects) {
+ foreach (var generator in projects) {
+ var vsCsproj = generator.Csproj;
if (!vsCsproj.library.Contains (profileString))
continue;
if (additionalFilter != null && !additionalFilter (vsCsproj))
continue;
- var csprojFilename = vsCsproj.csprojFileName;
+ var csprojFilename = vsCsproj.csProjFilename;
if (!solution.ContainsProjectIdentifier (vsCsproj.library)) {
solution.Add (vsCsproj);
RecursiveAddProj (solution, vsCsproj);