Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: visual_studio/NativeClientVSAddIn/NaCl.Build.CPPTasks/XamlParser.cs

Issue 11046011: fix processing of non-switch arguments (Closed) Base URL: http://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 using System; 1 using System;
2 using System.Collections.Generic; 2 using System.Collections.Generic;
3 using System.Linq; 3 using System.Linq;
4 using System.Text; 4 using System.Text;
5 5
6 using Microsoft.Build.Framework; 6 using Microsoft.Build.Framework;
7 using System.Xaml; 7 using System.Xaml;
8 using Microsoft.Build.Framework.XamlTypes; 8 using Microsoft.Build.Framework.XamlTypes;
9 using Microsoft.Build.Utilities; 9 using Microsoft.Build.Utilities;
10 10
11 namespace NaCl.Build.CPPTasks 11 namespace NaCl.Build.CPPTasks
12 { 12 {
13 class XamlParser 13 class XamlParser
14 { 14 {
15 public XamlParser(string path) 15 public XamlParser(string path)
16 { 16 {
17 // load and store properties from xaml file 17 // load and store properties from xaml file
18 m_parsedBuildRule = (Rule)XamlServices.Load(path); 18 m_parsedBuildRule = (Rule)XamlServices.Load(path);
19 19
20 // NOTE: 20 // NOTE:
21 // There are MSBuild classes which support command line building, 21 // There are MSBuild classes which support command line building,
22 // argument switch encapsulation and more. Code within VCToolTask, 22 // argument switch encapsulation and more. Code within VCToolTask,
23 // a hidden interface, uses some these classes to generate command l ine 23 // a hidden interface, uses some these classes to generate command l ine
24 // switches given project settings. As the VCToolTask class is a hid den 24 // switches given project settings. As the VCToolTask class is a hid den
25 // class and the MSBuild documentation is very sparse, we are going 25 // class and the MSBuild documentation is very sparse, we are going
26 // with a small custom solution. For reference see the 26 // with a small custom solution. For reference see the
27 // Microsoft.Build.Tasks.Xaml, Microsoft.Build.Framework.XamlTypes n amespaces. 27 // Microsoft.Build.Tasks.Xaml, Microsoft.Build.Framework.XamlTypes n amespaces.
28 28
29 // move the properties to a property name keyed dictionary for faste r lookup 29 // move the properties to a property name keyed dictionary for faste r lookup
30 ToolProperties = new Dictionary<string, PropertyWrapper>(); 30 ToolProperties = new Dictionary<string, PropertyWrapper>();
31 ToolProperties = m_parsedBuildRule.Properties.ToDictionary(x => x.Na me, x => (new PropertyWrapper(x.GetType(), x))); 31 ToolProperties = m_parsedBuildRule.Properties.ToDictionary(x => x.Na me, x => (new PropertyWrapper(x.GetType(), x)));
32 32
33 InitFunctionMap(); 33 InitFunctionMap();
34 } 34 }
35 35
36 private void InitFunctionMap() 36 private void InitFunctionMap()
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 builder.AppendSwitchUnquotedIfNotNull(m_parsedBuildRule.SwitchPr efix, result.Switch); 80 builder.AppendSwitchUnquotedIfNotNull(m_parsedBuildRule.SwitchPr efix, result.Switch);
81 } 81 }
82 } 82 }
83 83
84 // helper for string-based properties 84 // helper for string-based properties
85 private void AppendStringValue(CommandLineBuilder builder, BaseProperty property, string subtype, string value) 85 private void AppendStringValue(CommandLineBuilder builder, BaseProperty property, string subtype, string value)
86 { 86 {
87 value = value.Trim(); 87 value = value.Trim();
88 88
89 // could cache this SubType test off in property wrapper or somewher e if performance were an issue 89 // could cache this SubType test off in property wrapper or somewher e if performance were an issue
90 string switchName = m_parsedBuildRule.SwitchPrefix + property.Switch + property.Separator;
binji 2012/10/02 23:43:47 nit: wrap at 100
90 if (subtype == "file" || subtype == "folder") 91 if (subtype == "file" || subtype == "folder")
91 { 92 {
92 builder.AppendSwitchIfNotNull(m_parsedBuildRule.SwitchPrefix + p roperty.Switch + property.Separator, value); 93 // for switches that contains files or folders we need quoting
94 builder.AppendSwitchIfNotNull(switchName, value);
93 } 95 }
94 else 96 else if (!string.IsNullOrEmpty(property.Switch))
95 { 97 {
96 builder.AppendSwitchUnquotedIfNotNull(m_parsedBuildRule.SwitchPr efix + property.Switch + property.Separator, value); 98 builder.AppendSwitchUnquotedIfNotNull(switchName, value);
99 }
100 else if (!string.IsNullOrEmpty(value))
101 {
102 // for non-switchs such as AdditionalOpions we just append the v alue
binji 2012/10/02 23:43:47 nit: s/switchs/switches/ s/Opions/Options/
103 builder.AppendTextUnquoted(" " + value);
97 } 104 }
98 } 105 }
99 106
100 private void GenerateArgumentStringList(CommandLineBuilder builder, Base Property property, string value) 107 private void GenerateArgumentStringList(CommandLineBuilder builder, Base Property property, string value)
101 { 108 {
102 » » » string [] arguments = value.Split(';'); 109 string[] arguments = value.Split(';');
103 110
104 foreach (string argument in arguments) 111 foreach (string argument in arguments)
105 { 112 {
106 if (argument.Length > 0) 113 if (argument.Length > 0)
107 { 114 {
108 StringListProperty casted = (StringListProperty)property; 115 StringListProperty casted = (StringListProperty)property;
109 AppendStringValue(builder, property, casted.Subtype, argumen t); 116 AppendStringValue(builder, property, casted.Subtype, argumen t);
110 } 117 }
111 } 118 }
112 } 119 }
(...skipping 30 matching lines...) Expand all
143 } // class 150 } // class
144 151
145 private Rule m_parsedBuildRule; 152 private Rule m_parsedBuildRule;
146 private Dictionary<string, PropertyWrapper> ToolProperties { get; set; } 153 private Dictionary<string, PropertyWrapper> ToolProperties { get; set; }
147 154
148 // function mapping for easy property function calling 155 // function mapping for easy property function calling
149 private Dictionary<Type, Action<CommandLineBuilder, BaseProperty, string >> m_typeFunctionMap; 156 private Dictionary<Type, Action<CommandLineBuilder, BaseProperty, string >> m_typeFunctionMap;
150 } // XamlParser 157 } // XamlParser
151 } // namespace NaCl.Build.CPPTasks 158 } // namespace NaCl.Build.CPPTasks
152 159
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698