protected static string GetDocumentLogicalPath(MSB.Framework.ITaskItem documentItem, string projectDirectory) { var link = documentItem.GetMetadata("Link"); if (!string.IsNullOrEmpty(link)) { // if a specific link is specified in the project file then use it to form the logical path. return(link); } else { var result = documentItem.ItemSpec; if (Path.IsPathRooted(result)) { // If we have an absolute path, there are two possibilities: result = Path.GetFullPath(result); // If the document is within the current project directory (or subdirectory), then the logical path is the relative path // from the project's directory. if (result.StartsWith(projectDirectory, StringComparison.OrdinalIgnoreCase)) { result = result.Substring(projectDirectory.Length); } else { // if the document lies outside the project's directory (or subdirectory) then place it logically at the root of the project. // if more than one document ends up with the same logical name then so be it (the workspace will survive.) return(Path.GetFileName(result)); } } return(result); } }
public void Execute() { // Get a mock compiler ICompiler compiler = CreateMockCompiler(); IronPythonCompilerTask task = new IronPythonCompilerTask(compiler); // Create a fake engine as the logger will call into it Type engineType = GenericMockFactory.CreateType("MockBuildEngine", new Type[] { typeof(Microsoft.Build.Framework.IBuildEngine) }); BaseMock mockEngine = (BaseMock)Activator.CreateInstance(engineType); task.BuildEngine = (Microsoft.Build.Framework.IBuildEngine)mockEngine; // Set parameters task.SourceFiles = new string[] { "Foo.py", "bar.py" }; task.TargetKind = "exe"; task.MainFile = "Foo.py"; task.ResourceFiles = null; Microsoft.Build.Framework.ITaskItem[] resources = new Microsoft.Build.Framework.ITaskItem[1]; resources[0] = new Microsoft.Build.Utilities.TaskItem(@"obj\i386\form1.resources"); task.ResourceFiles = resources; // Execute bool result = task.Execute(); // Validation Assert.IsTrue(result); BaseMock mock = (BaseMock)compiler; Assert.AreEqual(PEFileKinds.ConsoleApplication, mock["TargetKind"]); Assert.AreEqual(task.MainFile, mock["MainFile"]); }
protected static string GetDocumentLogicalPath( MSB.Framework.ITaskItem documentItem, string projectDirectory ) { var link = documentItem.GetMetadata(MetadataNames.Link); if (!RoslynString.IsNullOrEmpty(link)) { // if a specific link is specified in the project file then use it to form the logical path. return(link); } else { var filePath = documentItem.ItemSpec; if (!PathUtilities.IsAbsolute(filePath)) { return(filePath); } var normalizedPath = FileUtilities.TryNormalizeAbsolutePath(filePath); if (normalizedPath == null) { return(filePath); } // If the document is within the current project directory (or subdirectory), then the logical path is the relative path // from the project's directory. if (normalizedPath.StartsWith(projectDirectory, StringComparison.OrdinalIgnoreCase)) { return(normalizedPath[projectDirectory.Length..]);
public static bool ReferenceOutputAssemblyIsTrue(this MSB.Framework.ITaskItem item) { var referenceOutputAssemblyText = item.GetMetadata(MetadataNames.ReferenceOutputAssembly); return(!string.IsNullOrWhiteSpace(referenceOutputAssemblyText) ? !string.Equals(referenceOutputAssemblyText, bool.FalseString, StringComparison.OrdinalIgnoreCase) : true); }
public static ImmutableArray <string> GetAliases(this MSB.Framework.ITaskItem item) { var aliasesText = item.GetMetadata(MetadataNames.Aliases); return(!string.IsNullOrWhiteSpace(aliasesText) ? ImmutableArray.CreateRange(aliasesText.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(a => a.Trim())) : ImmutableArray <string> .Empty); }
private IEnumerable <MetadataInfo> MakeMetadataInfo(MSB.Framework.ITaskItem item) { var filePath = GetDocumentFilePath(item); var aliases = GetAliases(item); return(new MetadataInfo[] { new MetadataInfo(filePath, new MetadataReferenceProperties(aliases: aliases)) }); }
private DocumentFileInfo MakeDocumentFileInfo(string projectDirectory, MSB.Framework.ITaskItem item) { var filePath = GetDocumentFilePath(item); var logicalPath = GetDocumentLogicalPath(item, projectDirectory); var isLinked = IsDocumentLinked(item); var isGenerated = IsDocumentGenerated(item); return(new DocumentFileInfo(filePath, logicalPath, isLinked, isGenerated)); }
private DocumentFileInfo MakeNonSourceFileDocumentFileInfo(MSB.Framework.ITaskItem documentItem) { var filePath = GetDocumentFilePath(documentItem); var logicalPath = GetDocumentLogicalPath(documentItem, _projectDirectory); var isLinked = IsDocumentLinked(documentItem); var isGenerated = IsDocumentGenerated(documentItem); return(new DocumentFileInfo(filePath, logicalPath, isLinked, isGenerated, SourceCodeKind.Regular)); }
private ImmutableArray <string> GetAliases(MSB.Framework.ITaskItem item) { var aliasesText = item.GetMetadata("Aliases"); if (string.IsNullOrEmpty(aliasesText)) { return(ImmutableArray <string> .Empty); } return(ImmutableArray.CreateRange(aliasesText.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries))); }
private IEnumerable <MetadataInfo> MakeMetadataInfo(MSB.Framework.ITaskItem item) { var filePath = GetDocumentFilePath(item); string[] aliases; if (TryGetAliases(item, out aliases)) { return(aliases.Select(alias => new MetadataInfo(filePath, new MetadataReferenceProperties(alias: alias)))); } return(new MetadataInfo[] { new MetadataInfo(filePath) }); }
protected bool IsDocumentGenerated(MSB.Framework.ITaskItem documentItem) { if (_documents == null) { _documents = new Dictionary <string, MSB.Evaluation.ProjectItem>(); foreach (var item in _loadedProject.GetItems(ItemNames.Compile)) { _documents[GetAbsolutePathRelativeToProject(item.EvaluatedInclude)] = item; } } return(!_documents.ContainsKey(GetAbsolutePathRelativeToProject(documentItem.ItemSpec))); }
private bool TryGetAliases(MSB.Framework.ITaskItem item, out string[] aliases) { var aliasesText = item.GetMetadata("Aliases"); if (!string.IsNullOrEmpty(aliasesText)) { aliases = aliasesText.Split(new char[] { ' ', ',', ';' }, StringSplitOptions.RemoveEmptyEntries); return(aliases.Length >= 1); } aliases = null; return(false); }
protected bool IsDocumentGenerated(MSB.Framework.ITaskItem documentItem) { if (this.documents == null) { this.documents = new Dictionary <string, MSB.Evaluation.ProjectItem>(); foreach (var item in this.loadedProject.GetItems("compile")) { this.documents[GetAbsolutePath(item.EvaluatedInclude)] = item; } } return(!this.documents.ContainsKey(GetAbsolutePath(documentItem.ItemSpec))); }
public CustomMTouchTask() { Architectures = "Default"; Debug = false; ExtraArgs = null; FastDev = false; I18n = null; LinkMode = "SdkOnly"; Profiling = false; SdkIsSimulator = true; UseLlvm = false; UseThumb = false; AppExtensionReferences = new Microsoft.Build.Framework.ITaskItem[] { }; }
public static bool Execute( #region Parameters Microsoft.Build.Framework.ITaskItem Item, System.String[] Keys, out System.String Hash) #endregion { #region Code var data = Encoding.UTF8.GetBytes(string.Concat(Keys.OrderBy(x => x) .Select(x => string.Format("[{0}={1}]", x, Item.GetMetadata(x)))) .ToUpper()); using (var dataZipped = new MemoryStream()) { using (var zip = new DeflateStream(dataZipped, CompressionLevel.Fastest)) zip.Write(data, 0, data.Length); Hash = Convert.ToBase64String(dataZipped.ToArray()); } #endregion return(true); }
protected static string GetDocumentLogicalPath(MSB.Framework.ITaskItem documentItem, string projectDirectory) { var link = documentItem.GetMetadata(MetadataNames.Link); if (!string.IsNullOrEmpty(link)) { // if a specific link is specified in the project file then use it to form the logical path. return(link); } else { var filePath = documentItem.ItemSpec; if (!PathUtilities.IsAbsolute(filePath)) { return(filePath); } var normalizedPath = FileUtilities.TryNormalizeAbsolutePath(filePath); if (normalizedPath == null) { return(filePath); } // If the document is within the current project directory (or subdirectory), then the logical path is the relative path // from the project's directory. if (normalizedPath.StartsWith(projectDirectory, StringComparison.OrdinalIgnoreCase)) { return(normalizedPath.Substring(projectDirectory.Length)); } else { // if the document lies outside the project's directory (or subdirectory) then place it logically at the root of the project. // if more than one document ends up with the same logical name then so be it (the workspace will survive.) return(PathUtilities.GetFileName(normalizedPath)); } } }
private string GetDocumentFilePath(MSB.Framework.ITaskItem documentItem) => GetAbsolutePathRelativeToProject(documentItem.ItemSpec);
protected static bool IsNotTemporaryGeneratedFile(MSB.Framework.ITaskItem item) => !Path.GetFileName(item.ItemSpec) .StartsWith("TemporaryGeneratedFile_", StringComparison.Ordinal);
public void AppendSwitchIfNotNull(string switchName, Microsoft.Build.Framework.ITaskItem parameter) { }
public void AppendFileNameIfNotNull(Microsoft.Build.Framework.ITaskItem fileItem) { }
public void CopyMetadataTo(Microsoft.Build.Framework.ITaskItem destinationItem) { }
public TaskItem(Microsoft.Build.Framework.ITaskItem sourceItem) { }
public CustomMTouchTask() { Architectures = "Default"; Debug = false; EnableGenericValueTypeSharing = true; ExtraArgs = null; FastDev = false; I18n = null; LinkMode = "SdkOnly"; Profiling = false; SdkIsSimulator = true; UseLlvm = false; UseThumb = false; AppExtensionReferences = new Microsoft.Build.Framework.ITaskItem[] { }; }
public BuildItem(string itemName, Microsoft.Build.Framework.ITaskItem taskItem) { }
public static ExpectedAppConfig FromTaskItem(Microsoft.Build.Framework.ITaskItem item) => new ExpectedAppConfig { OutputPath = item.ItemSpec, SourceFile = item.GetMetadata(BuildTools.Configuration.MetaData.SourceFile) };
public static bool HasReferenceOutputAssemblyMetadataEqualToTrue(this MSB.Framework.ITaskItem item) => string.Equals(item.GetMetadata(MetadataNames.ReferenceOutputAssembly), bool.TrueString, StringComparison.OrdinalIgnoreCase);
protected static bool IsDocumentLinked(MSB.Framework.ITaskItem documentItem) { return(!string.IsNullOrEmpty(documentItem.GetMetadata("Link"))); }
protected string GetDocumentFilePath(MSB.Framework.ITaskItem documentItem) { return(GetAbsolutePath(documentItem.ItemSpec)); }
private static bool IsDocumentLinked(MSB.Framework.ITaskItem documentItem) => !RoslynString.IsNullOrEmpty(documentItem.GetMetadata(MetadataNames.Link));
static string ReadImportItem(MSB.Framework.ITaskItem item) { var trimmed = item.ItemSpec.Trim(); return(trimmed.Contains(' ') ? $"\"{trimmed}\"" : trimmed); }
public void Execute() { // Get a mock compiler ICompiler compiler = CreateMockCompiler(); IronPythonCompilerTask task = new IronPythonCompilerTask(compiler); // Create a fake engine as the logger will call into it Type engineType = GenericMockFactory.CreateType("MockBuildEngine", new Type[] { typeof(Microsoft.Build.Framework.IBuildEngine) }); BaseMock mockEngine = (BaseMock)Activator.CreateInstance(engineType); task.BuildEngine = (Microsoft.Build.Framework.IBuildEngine)mockEngine; // Set parameters task.SourceFiles = new string[] { "Foo.py", "bar.py" }; task.TargetKind = "exe"; task.MainFile = "Foo.py"; task.ResourceFiles = null; Microsoft.Build.Framework.ITaskItem[] resources = new Microsoft.Build.Framework.ITaskItem[1]; resources[0] = new Microsoft.Build.Utilities.TaskItem(@"obj\i386\form1.resources"); task.ResourceFiles = resources; // Execute bool result = task.Execute(); // Validation Assert.IsTrue(result); BaseMock mock = (BaseMock)compiler; Assert.AreEqual(PEFileKinds.ConsoleApplication, mock["TargetKind"]); Assert.AreEqual(task.MainFile, mock["MainFile"]); }
protected bool IsProjectReferenceOutputAssembly(MSB.Framework.ITaskItem item) { return(item.GetMetadata("ReferenceOutputAssembly") == "true"); }