diff options
author | Miguel Costa <miguel.costa@qt.io> | 2019-10-02 16:39:00 +0200 |
---|---|---|
committer | Miguel Costa <miguel.costa@qt.io> | 2019-10-10 11:44:52 +0000 |
commit | fb068260f363a372d627c7991c9eb70d671e0f11 (patch) | |
tree | d57147ef8f442c82d136961dd341d080d5b48f2a | |
parent | 9a6e098cb810aa9f821beba07fae5b42c6f96729 (diff) |
Add sanity-check to project format conversion
When converting to the latest version of the Qt VS Tools project format,
some additional checks will now be carried out, namely if a filters file
is present and if ItemDefinitionGroup are properly formatted.
Task-number: QTVSADDINBUG-663
Change-Id: I1017959e7ede486b2697253b179e9f99107fd028
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
-rw-r--r-- | src/qtprojectlib/MsBuildProject.cs | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/src/qtprojectlib/MsBuildProject.cs b/src/qtprojectlib/MsBuildProject.cs index 5bbf3e3f..f4916a56 100644 --- a/src/qtprojectlib/MsBuildProject.cs +++ b/src/qtprojectlib/MsBuildProject.cs @@ -134,7 +134,7 @@ namespace QtProjectLib { foreach (var file in files) { if (file.isDirty) { - file.xml.Save(file.filePath, SaveOptions.None); + file.xml?.Save(file.filePath, SaveOptions.None); file.isCommittedDirty = file.isDirty = false; } } @@ -488,7 +488,8 @@ namespace QtProjectLib var propsCl = this[Files.Project].xml .Elements(ns + "Project") .Elements(ns + "ItemDefinitionGroup") - .Where(x => ((string)x.Attribute("Condition")).StartsWith(conditionPrefix)) + .Where(x => x.Attribute("Condition") != null + && ((string)x.Attribute("Condition")).StartsWith(conditionPrefix)) .Elements(ns + "ClCompile") .Select(x => new { @@ -521,7 +522,8 @@ namespace QtProjectLib var propsLink = this[Files.Project].xml .Elements(ns + "Project") .Elements(ns + "ItemDefinitionGroup") - .Where(x => ((string)x.Attribute("Condition")).StartsWith(conditionPrefix)) + .Where(x => x.Attribute("Condition") != null + && ((string)x.Attribute("Condition")).StartsWith(conditionPrefix)) .Elements(ns + "Link") .Select(x => new { @@ -909,7 +911,7 @@ namespace QtProjectLib customBuilds.ForEach(customBuild => { - var filterCustomBuild = this[Files.Filters].xml + var filterCustomBuild = this[Files.Filters]?.xml .Elements(ns + "Project") .Elements(ns + "ItemGroup") .Elements(ns + "CustomBuild") @@ -1021,16 +1023,18 @@ namespace QtProjectLib StringComparer.InvariantCultureIgnoreCase) .ToDictionary(x => x.Key, x => new List<XElement>(x)); - var filterItemsByPath = this[Files.Filters].xml - .Elements(ns + "Project") - .Elements(ns + "ItemGroup") - .Elements() - .Where(x => ((string)x.Attribute("Include")) - .IndexOfAny(Path.GetInvalidPathChars()) == -1) - .GroupBy(x => HelperFunctions.CanonicalPath( - Path.Combine(projDir, (string)x.Attribute("Include"))), - StringComparer.InvariantCultureIgnoreCase) - .ToDictionary(x => x.Key, x => new List<XElement>(x)); + var filterItemsByPath = (this[Files.Filters].xml != null) + ? this[Files.Filters].xml + .Elements(ns + "Project") + .Elements(ns + "ItemGroup") + .Elements() + .Where(x => ((string)x.Attribute("Include")) + .IndexOfAny(Path.GetInvalidPathChars()) == -1) + .GroupBy(x => HelperFunctions.CanonicalPath( + Path.Combine(projDir, (string)x.Attribute("Include"))), + StringComparer.InvariantCultureIgnoreCase) + .ToDictionary(x => x.Key, x => new List<XElement>(x)) + : new Dictionary<string, List<XElement>>(); var cppIncludePaths = this[Files.Project].xml .Elements(ns + "Project") @@ -1091,7 +1095,7 @@ namespace QtProjectLib cppMocItem.Remove(); //change type of item in filter - cppMocItems = this[Files.Filters].xml + cppMocItems = this[Files.Filters]?.xml .Elements(ns + "Project") .Elements(ns + "ItemGroup") .Elements(ns + "ClCompile") |