internal ProjectTargetInstance (ProjectTargetElement xml) { FullPath = xml.ContainingProject.FullPath; Children = xml.Children.Select<ProjectElement,ProjectTargetInstanceChild> (c => { if (c is ProjectOnErrorElement) return new ProjectOnErrorInstance ((ProjectOnErrorElement) c); if (c is ProjectItemGroupElement) return new ProjectItemGroupTaskInstance ((ProjectItemGroupElement) c); if (c is ProjectPropertyGroupElement) return new ProjectPropertyGroupTaskInstance ((ProjectPropertyGroupElement) c); if (c is ProjectTaskElement) return new ProjectTaskInstance ((ProjectTaskElement) c); throw new NotSupportedException (); }).ToArray (); Condition = xml.Condition; DependsOnTargets = xml.DependsOnTargets; //FullPath = fullPath; Inputs = xml.Inputs; KeepDuplicateOutputs = xml.KeepDuplicateOutputs; Name = xml.Name; OnErrorChildren = xml.OnErrors.Select (c => new ProjectOnErrorInstance (c)).ToArray (); Outputs = xml.Outputs; Returns = xml.Returns; Tasks = xml.Tasks.Select (t => new ProjectTaskInstance (t)).ToArray (); AfterTargetsLocation = xml.AfterTargetsLocation; BeforeTargetsLocation = xml.BeforeTargetsLocation; ConditionLocation = xml.ConditionLocation; DependsOnTargetsLocation = xml.DependsOnTargetsLocation; InputsLocation = xml.InputsLocation; KeepDuplicateOutputsLocation = xml.KeepDuplicateOutputsLocation; Location = xml.Location; OutputsLocation = xml.OutputsLocation; ReturnsLocation = xml.ReturnsLocation; }
private static void AssertTargetOutput(string expected, ProjectTargetElement projectTargetElement) { var stringLogger = new StringLogger(); var success = BuildTarget(projectTargetElement, stringLogger); Assert.IsTrue(success, stringLogger.Error); Assert.AreEqual(expected, stringLogger.HighImportance); }
/// <summary> /// Parse a ProjectTaskElement /// </summary> private ProjectTaskElement ParseProjectTaskElement(XmlElementWithLocation element, ProjectTargetElement parent) { foreach (XmlAttributeWithLocation attribute in element.Attributes) { ProjectErrorUtilities.VerifyThrowInvalidProject ( !XMakeAttributes.IsBadlyCasedSpecialTaskAttribute(attribute.Name), attribute.Location, "BadlyCasedSpecialTaskAttribute", attribute.Name, element.Name, element.Name ); } ProjectTaskElement task = new ProjectTaskElement(element, parent, _project); foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element)) { ProjectErrorUtilities.VerifyThrowInvalidProject(childElement.Name == XMakeElements.output, childElement.Location, "UnrecognizedChildElement", childElement.Name, task.Name); ProjectOutputElement output = ParseProjectOutputElement(childElement, task); task.AppendParentedChildNoChecks(output); } return(task); }
/// <summary> /// Parse a ProjectTargetElement /// </summary> private ProjectTargetElement ParseProjectTargetElement(XmlElementWithLocation element) { ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnTarget); ProjectXmlUtilities.VerifyThrowProjectRequiredAttribute(element, XMakeAttributes.name); string targetName = ProjectXmlUtilities.GetAttributeValue(element, XMakeAttributes.name); // Orcas compat: all target names are automatically unescaped targetName = EscapingUtilities.UnescapeAll(targetName); int indexOfSpecialCharacter = targetName.IndexOfAny(XMakeElements.illegalTargetNameCharacters); if (indexOfSpecialCharacter >= 0) { ProjectErrorUtilities.ThrowInvalidProject(element.GetAttributeLocation(XMakeAttributes.name), "NameInvalid", targetName, targetName[indexOfSpecialCharacter]); } ProjectTargetElement target = new ProjectTargetElement(element, _project, _project); ProjectOnErrorElement onError = null; foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element)) { ProjectElement child = null; switch (childElement.Name) { case XMakeElements.propertyGroup: if (onError != null) { ProjectErrorUtilities.ThrowInvalidProject(onError.Location, "NodeMustBeLastUnderElement", XMakeElements.onError, XMakeElements.target, childElement.Name); } child = ParseProjectPropertyGroupElement(childElement, target); break; case XMakeElements.itemGroup: if (onError != null) { ProjectErrorUtilities.ThrowInvalidProject(onError.Location, "NodeMustBeLastUnderElement", XMakeElements.onError, XMakeElements.target, childElement.Name); } child = ParseProjectItemGroupElement(childElement, target); break; case XMakeElements.onError: onError = ParseProjectOnErrorElement(childElement, target); child = onError; break; case XMakeElements.itemDefinitionGroup: ProjectErrorUtilities.ThrowInvalidProject(childElement.Location, "ItemDefinitionGroupNotLegalInsideTarget", childElement.Name); break; default: if (onError != null) { ProjectErrorUtilities.ThrowInvalidProject(onError.Location, "NodeMustBeLastUnderElement", XMakeElements.onError, XMakeElements.target, childElement.Name); } child = ParseProjectTaskElement(childElement, target); break; } target.AppendParentedChildNoChecks(child); } return(target); }
/// <summary> /// Parse a ProjectOnErrorElement /// </summary> private ProjectOnErrorElement ParseProjectOnErrorElement(XmlElementWithLocation element, ProjectTargetElement parent) { // Previous OM accidentally didn't verify ExecuteTargets on parse, // but we do, as it makes no sense ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnOnError); ProjectXmlUtilities.VerifyThrowProjectRequiredAttribute(element, XMakeAttributes.executeTargets); ProjectXmlUtilities.VerifyThrowProjectNoChildElements(element); return new ProjectOnErrorElement(element, parent, _project); }
/// <summary> /// Parse a ProjectTaskElement /// </summary> private ProjectTaskElement ParseProjectTaskElement(XmlElementWithLocation element, ProjectTargetElement parent) { foreach (XmlAttributeWithLocation attribute in element.Attributes) { ProjectErrorUtilities.VerifyThrowInvalidProject ( !XMakeAttributes.IsBadlyCasedSpecialTaskAttribute(attribute.Name), attribute.Location, "BadlyCasedSpecialTaskAttribute", attribute.Name, element.Name, element.Name ); } ProjectTaskElement task = new ProjectTaskElement(element, parent, _project); foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element)) { ProjectErrorUtilities.VerifyThrowInvalidProject(childElement.Name == XMakeElements.output, childElement.Location, "UnrecognizedChildElement", childElement.Name, task.Name); ProjectOutputElement output = ParseProjectOutputElement(childElement, task); task.AppendParentedChildNoChecks(output); } return task; }
/// <summary> /// Parse a ProjectTargetElement /// </summary> private ProjectTargetElement ParseProjectTargetElement(XmlElementWithLocation element) { ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnTarget); ProjectXmlUtilities.VerifyThrowProjectRequiredAttribute(element, XMakeAttributes.name); string targetName = ProjectXmlUtilities.GetAttributeValue(element, XMakeAttributes.name); // Orcas compat: all target names are automatically unescaped targetName = EscapingUtilities.UnescapeAll(targetName); int indexOfSpecialCharacter = targetName.IndexOfAny(XMakeElements.illegalTargetNameCharacters); if (indexOfSpecialCharacter >= 0) { ProjectErrorUtilities.ThrowInvalidProject(element.GetAttributeLocation(XMakeAttributes.name), "NameInvalid", targetName, targetName[indexOfSpecialCharacter]); } ProjectTargetElement target = new ProjectTargetElement(element, _project, _project); ProjectOnErrorElement onError = null; foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element)) { ProjectElement child = null; switch (childElement.Name) { case XMakeElements.propertyGroup: if (onError != null) { ProjectErrorUtilities.ThrowInvalidProject(onError.Location, "NodeMustBeLastUnderElement", XMakeElements.onError, XMakeElements.target, childElement.Name); } child = ParseProjectPropertyGroupElement(childElement, target); break; case XMakeElements.itemGroup: if (onError != null) { ProjectErrorUtilities.ThrowInvalidProject(onError.Location, "NodeMustBeLastUnderElement", XMakeElements.onError, XMakeElements.target, childElement.Name); } child = ParseProjectItemGroupElement(childElement, target); break; case XMakeElements.onError: onError = ParseProjectOnErrorElement(childElement, target); child = onError; break; case XMakeElements.itemDefinitionGroup: ProjectErrorUtilities.ThrowInvalidProject(childElement.Location, "ItemDefinitionGroupNotLegalInsideTarget", childElement.Name); break; default: if (onError != null) { ProjectErrorUtilities.ThrowInvalidProject(onError.Location, "NodeMustBeLastUnderElement", XMakeElements.onError, XMakeElements.target, childElement.Name); } child = ParseProjectTaskElement(childElement, target); break; } target.AppendParentedChildNoChecks(child); } return target; }
private void LoadTargetTasks(ProjectTargetElement target, List<EnvVar> vars, BuildToolDefine tool, ToolOptions toolOptions, params List<ToolFlag>[] commonFlags) { foreach (ProjectTaskElement task in target.Tasks) { BuildScript script = new BuildScript(); string exeCmdEnv = ToEnvVar(tool.Description.ToLower()).Trim(); string exeCmd = tool.Description.ToLower(); int idx = -1; script.Conditional = task.Condition; script.Script = task.GetParameter(TaskScriptAttributeName); if (!string.IsNullOrEmpty(script.Script)) { if ((idx = script.Script.ToLower().IndexOf(exeCmdEnv)) >= 0) { // remove exe command and script.Script = script.Script.Remove(idx, exeCmdEnv.Length); script.Script = RemoveFlagsAndWrapper(script.Script, toolOptions, commonFlags); toolOptions.BuildToolParameters.Parameters.Add(script); } else if ((idx = script.Script.ToLower().IndexOf(exeCmd)) >= 0) { // remove exe command and script.Script = script.Script.Remove(idx, exeCmd.Length); script.Script = RemoveFlagsAndWrapper(script.Script, toolOptions, commonFlags); toolOptions.BuildToolParameters.Parameters.Add(script); } else if (toolOptions.BuildToolParameters.Parameters.Count > 0) { toolOptions.BuildToolParameters.PostBuild.Add(script); } else { toolOptions.BuildToolParameters.PreBuild.Add(script); } } else if(string.Compare(task.Name, SetEnvScriptTag) == 0) { EnvVar var = new EnvVar(); var.Name = task.GetParameter("Name"); var.Conditional = task.Condition; var.Value = task.GetParameter("Value"); vars.Add(var); } } }
static void addCreateProperty(ProjectTargetElement targetElement, string taskValue, string taskCondition, string taskOutputValue) { var v0 = targetElement.AddTask("CreateProperty"); v0.SetParameter("Value", taskValue); if (!string.IsNullOrEmpty(taskCondition)) v0.Condition = taskCondition; v0.AddOutputProperty("Value", taskOutputValue); }
private void GenerateConfigurationPropertyInitializers(ProjectTargetElement initTarget) { var pivots = Pivots; ProjectPropertyGroupElement pg = null; foreach(var pivot in pivots.Values) { // dynamic cfg = configurationsView.GetProperty(pivot); IEnumerable<string> choices = pivot.Choices.Keys; if(!pivot.IsBuiltIn) { // add init steps for this. var finalPropName = "{0}-{1}".format(pivot.Name, SafeName); foreach(var choice in choices.Distinct()) { var choicePropName = "{0}-{1}".format(pivot.Name, choice); var tsk = initTarget.AddTask("StringContains"); tsk.SetParameter("Text", choicePropName); tsk.SetParameter("Library", SafeName); tsk.SetParameter("Value", choice); tsk.Condition = @"'$({0})'==''".format(finalPropName); tsk.AddOutputProperty("Result", finalPropName); } pg = pg ?? Xml.AddPropertyGroup(); pg.Label = "Default initializers for properties"; pg.AddProperty(finalPropName, choices.FirstOrDefault()).Condition = @"'$({0})' == ''".format(finalPropName); } } }
static void addCreateItem(ProjectTargetElement v0, string includeValue, string condition, string meta, string outItemName) { var v2 = v0.AddTask("CreateItem"); v2.SetParameter("Include", includeValue); if (!string.IsNullOrEmpty(meta)) v2.SetParameter("AdditionalMetadata", meta); if (!string.IsNullOrEmpty(condition)) v2.Condition = condition; v2.AddOutputItem("Include", outItemName); }
private static ProjectTaskElement GetNamedTask(ProjectTargetElement target, string taskName) { if (target != null) { foreach (ProjectTaskElement task in target.Tasks) { if (task.Name == taskName) { return task; } } } return null; }
/// <summary> /// Initialize a parented ProjectOnErrorElement /// </summary> internal ProjectOnErrorElement(XmlElementWithLocation xmlElement, ProjectTargetElement parent, ProjectRootElement project) : base(xmlElement, parent, project) { ErrorUtilities.VerifyThrowArgumentNull(parent, "parent"); }
private static bool BuildTarget(ProjectTargetElement projectTargetElement, StringLogger stringLogger) { var success = new ProjectInstance(projectTargetElement.ContainingProject).Build(new[] { stringLogger }); return success; }
/// <summary> /// Parse a ProjectOnErrorElement /// </summary> private ProjectOnErrorElement ParseProjectOnErrorElement(XmlElementWithLocation element, ProjectTargetElement parent) { // Previous OM accidentally didn't verify ExecuteTargets on parse, // but we do, as it makes no sense ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnOnError); ProjectXmlUtilities.VerifyThrowProjectRequiredAttribute(element, XMakeAttributes.executeTargets); ProjectXmlUtilities.VerifyThrowProjectNoChildElements(element); return(new ProjectOnErrorElement(element, parent, _project)); }
/// <summary> /// Add a new error/warning/message tag into the given target /// </summary> internal static ProjectTaskElement AddErrorWarningMessageElement ( ProjectTargetElement target, string elementType, bool treatAsLiteral, string textResourceName, params object[] args ) { string code = null; string helpKeyword = null; string text = ResourceUtilities.FormatResourceString(out code, out helpKeyword, textResourceName, args); if (treatAsLiteral) { text = EscapingUtilities.Escape(text); } ProjectTaskElement task = target.AddTask(elementType); task.SetParameter("Text", text); if ((elementType != XMakeElements.message) && (code != null)) { task.SetParameter("Code", EscapingUtilities.Escape(code)); } if ((elementType != XMakeElements.message) && (helpKeyword != null)) { task.SetParameter("HelpKeyword", EscapingUtilities.Escape(helpKeyword)); } return task; }
/// <summary> /// Creates an unparented ProjectTargetElement, wrapping an unparented XmlElement. /// Validates the name. /// Caller should then ensure the element is added to a parent. /// </summary> internal static ProjectTargetElement CreateDisconnected(string name, ProjectRootElement containingProject) { XmlElementWithLocation element = containingProject.CreateElement(XMakeElements.target); ProjectTargetElement target = new ProjectTargetElement(element, containingProject); target.Name = name; return target; }