Skip to content

Commit

Permalink
support -r in mcs.rsp
Browse files Browse the repository at this point in the history
  • Loading branch information
van800 committed Nov 10, 2017
1 parent 338e32b commit b826f46
Showing 1 changed file with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private static void UpgradeProjectFile(string projectFile)
SetXCodeDllReference("UnityEditor.iOS.Extensions.Xcode.dll", xmlns, projectContentElement);
SetXCodeDllReference("UnityEditor.iOS.Extensions.Common.dll", xmlns, projectContentElement);
#endif
ApplyManualCompilingSettingsReferences(projectContentElement, xmlns);
doc.Save(projectFile);
}

Expand Down Expand Up @@ -114,12 +115,12 @@ private static void ChangeNunitReference(XElement projectContentElement, XNamesp
}
}

private static readonly string PROJECT_MANUAL_CONFIG_ABSOLUTE_FILE_PATH = Path.Combine(UnityEngine.Application.dataPath, "mcs.rsp");
#if !UNITY_2017_1_OR_NEWER // Unity 2017.1 and later has this features by itself
private const string UNITY_PLAYER_PROJECT_NAME = "Assembly-CSharp.csproj";
private const string UNITY_EDITOR_PROJECT_NAME = "Assembly-CSharp-Editor.csproj";
private const string UNITY_UNSAFE_KEYWORD = "-unsafe";
private const string UNITY_DEFINE_KEYWORD = "-define:";
private static readonly string PROJECT_MANUAL_CONFIG_ABSOLUTE_FILE_PATH = Path.Combine(UnityEngine.Application.dataPath, "mcs.rsp");
private static readonly string PLAYER_PROJECT_MANUAL_CONFIG_ABSOLUTE_FILE_PATH = Path.Combine(UnityEngine.Application.dataPath, "smcs.rsp");
private static readonly string EDITOR_PROJECT_MANUAL_CONFIG_ABSOLUTE_FILE_PATH = Path.Combine(UnityEngine.Application.dataPath, "gmcs.rsp");

Expand Down Expand Up @@ -239,6 +240,57 @@ private static void SetXCodeDllReference(string name, XNamespace xmlns, XElement
}
}
#endif
private const string UNITY_REFERENCE_KEYWORD = "-r:";
private static void ApplyManualCompilingSettingsReferences(XElement projectContentElement, XNamespace xmlns)
{
if (!File.Exists(PROJECT_MANUAL_CONFIG_ABSOLUTE_FILE_PATH))
return;

var configFilePath = PROJECT_MANUAL_CONFIG_ABSOLUTE_FILE_PATH;

if (File.Exists(configFilePath))
{
var configText = File.ReadAllText(configFilePath);
if (configText.Contains(UNITY_REFERENCE_KEYWORD))
{
var referenceList = new List<string>();
var compileFlags = configText.Split(' ', '\n');
foreach (var flag in compileFlags)
{
var f = flag.Trim();
if (f.Contains(UNITY_REFERENCE_KEYWORD))
{
var defineEndPos = f.IndexOf(UNITY_REFERENCE_KEYWORD) + UNITY_REFERENCE_KEYWORD.Length;
var definesSubString = f.Substring(defineEndPos,f.Length - defineEndPos);
definesSubString = definesSubString.Replace(";", ",");
referenceList.AddRange(definesSubString.Split(','));
}
}

foreach (var referenceName in referenceList)
{
ApplyCustomReference(referenceName, projectContentElement, xmlns);
}
}
}
}

private static void ApplyCustomReference(string name, XElement projectContentElement, XNamespace xmlns)
{
string unityAppBaseFolder = Path.GetDirectoryName(EditorApplication.applicationPath);

var dllPath = Path.Combine(unityAppBaseFolder, Path.Combine("MonoBleedingEdge/lib/mono/4.5/", name));
//if (File.Exists(dllPath))
{
var itemGroup = new XElement(xmlns + "ItemGroup");
var reference = new XElement(xmlns + "Reference");
reference.Add(new XAttribute("Include", Path.GetFileNameWithoutExtension(dllPath)));
reference.Add(new XElement(xmlns + "HintPath", dllPath));
itemGroup.Add(reference);
projectContentElement.Add(itemGroup);
}
}

// Helps resolve System.Linq under mono 4 - RIDER-573
private static void FixTargetFrameworkVersion(XElement projectElement, XNamespace xmlns)
{
Expand Down

0 comments on commit b826f46

Please sign in to comment.