Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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"]);
        }
Ejemplo n.º 3
0
        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..]);
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
            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));
            }
Ejemplo n.º 8
0
        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) });
            }
Ejemplo n.º 11
0
        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);
            }
Ejemplo n.º 13
0
        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)));
        }
Ejemplo n.º 14
0
 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[] { };
 }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        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));
                }
            }
        }
Ejemplo n.º 17
0
 private string GetDocumentFilePath(MSB.Framework.ITaskItem documentItem) =>
 GetAbsolutePathRelativeToProject(documentItem.ItemSpec);
Ejemplo n.º 18
0
 protected static bool IsNotTemporaryGeneratedFile(MSB.Framework.ITaskItem item) =>
 !Path.GetFileName(item.ItemSpec)
 .StartsWith("TemporaryGeneratedFile_", StringComparison.Ordinal);
Ejemplo n.º 19
0
 public void AppendSwitchIfNotNull(string switchName, Microsoft.Build.Framework.ITaskItem parameter)
 {
 }
Ejemplo n.º 20
0
 public void AppendFileNameIfNotNull(Microsoft.Build.Framework.ITaskItem fileItem)
 {
 }
Ejemplo n.º 21
0
 public void CopyMetadataTo(Microsoft.Build.Framework.ITaskItem destinationItem)
 {
 }
Ejemplo n.º 22
0
 public TaskItem(Microsoft.Build.Framework.ITaskItem sourceItem)
 {
 }
Ejemplo n.º 23
0
 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[] { };
 }
Ejemplo n.º 24
0
 public BuildItem(string itemName, Microsoft.Build.Framework.ITaskItem taskItem)
 {
 }
Ejemplo n.º 25
0
 public static ExpectedAppConfig FromTaskItem(Microsoft.Build.Framework.ITaskItem item) =>
 new ExpectedAppConfig
 {
     OutputPath = item.ItemSpec,
     SourceFile = item.GetMetadata(BuildTools.Configuration.MetaData.SourceFile)
 };
Ejemplo n.º 26
0
 public static bool HasReferenceOutputAssemblyMetadataEqualToTrue(this MSB.Framework.ITaskItem item)
 => string.Equals(item.GetMetadata(MetadataNames.ReferenceOutputAssembly), bool.TrueString, StringComparison.OrdinalIgnoreCase);
Ejemplo n.º 27
0
 protected static bool IsDocumentLinked(MSB.Framework.ITaskItem documentItem)
 {
     return(!string.IsNullOrEmpty(documentItem.GetMetadata("Link")));
 }
Ejemplo n.º 28
0
 protected string GetDocumentFilePath(MSB.Framework.ITaskItem documentItem)
 {
     return(GetAbsolutePath(documentItem.ItemSpec));
 }
Ejemplo n.º 29
0
 private static bool IsDocumentLinked(MSB.Framework.ITaskItem documentItem) =>
 !RoslynString.IsNullOrEmpty(documentItem.GetMetadata(MetadataNames.Link));
Ejemplo n.º 30
0
            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"]);
        }
Ejemplo n.º 32
0
 protected bool IsProjectReferenceOutputAssembly(MSB.Framework.ITaskItem item)
 {
     return(item.GetMetadata("ReferenceOutputAssembly") == "true");
 }