Exemplo n.º 1
0
        private Dictionary <string, Type> LoadAssembly(string path, Reference mod)
        {
            Assembly asm;

            try
            {
                asm = Assembly.LoadFrom(path);
            }
            catch (Exception ex)
            {
                AddError(LinkerError.UnableLoadAssembly, mod.SourceFileName, mod.SourceLocation,
                         mod.DllName, ex.Message);
                return(null);
            }

            var dict = new Dictionary <string, Type>();

            foreach (var t in asm.GetTypes())
            {
                if (Attribute.GetCustomAttribute(t, typeof(DyUnitAttribute)) is DyUnitAttribute attr)
                {
                    if (dict.ContainsKey(attr.Name))
                    {
                        AddError(LinkerError.DuplicateModuleName, mod.SourceFileName, mod.SourceLocation,
                                 mod.DllName, attr.Name);
                    }
                    else
                    {
                        dict.Add(attr.Name, t);
                    }
                }
            }

            AssemblyMap.Add(path, dict);
            return(dict);
        }
Exemplo n.º 2
0
    private Dictionary <string, ForeignUnit>?LookupAssembly(Unit self, string dll, Reference? @ref = null)
    {
        if (!AssemblyMap.TryGetValue(dll, out var dict))
        {
            if (!Lookup.Find(Path.GetDirectoryName(self.FileName), dll, out var path))
            {
                return(null);
            }

            dict = LoadAssembly(path, @ref ?? Reference.Empty);

            if (dict is not null)
            {
                AssemblyMap.Add(dll, dict);
            }

            if (dll == DYALECTLIB)
            {
                dyalectLib = dict;
            }
        }

        return(dict);
    }
 private void GetOutputAssemblies(PublishInfo[] publishInfos, ref List<ITaskItem> assemblyList)
 {
     AssemblyMap map = new AssemblyMap();
     if (this.managedAssemblies != null)
     {
         foreach (ITaskItem item in this.managedAssemblies)
         {
             if (!IsFiltered(item))
             {
                 item.SetMetadata("AssemblyType", "Managed");
                 map.Add(item);
             }
         }
     }
     if (this.nativeAssemblies != null)
     {
         foreach (ITaskItem item2 in this.nativeAssemblies)
         {
             if (!IsFiltered(item2))
             {
                 item2.SetMetadata("AssemblyType", "Native");
                 map.Add(item2);
             }
         }
     }
     foreach (PublishInfo info in publishInfos)
     {
         MapEntry entry = map[info.key];
         if (entry != null)
         {
             entry.publishInfo = info;
         }
         else
         {
             base.Log.LogWarningWithCodeFromResources("ResolveManifestFiles.PublishFileNotFound", new object[] { info.key });
         }
     }
     foreach (MapEntry entry2 in (IEnumerable) map)
     {
         if (entry2.publishInfo == null)
         {
             entry2.publishInfo = new PublishInfo();
         }
         if (entry2.publishInfo.state == PublishState.Auto)
         {
             string metadata = entry2.item.GetMetadata("DependencyType");
             if (string.Equals(metadata, "Prerequisite", StringComparison.Ordinal))
             {
                 entry2.publishInfo.state = PublishState.Prerequisite;
             }
             else if (string.Equals(metadata, "Install", StringComparison.Ordinal))
             {
                 entry2.publishInfo.state = PublishState.Include;
             }
         }
         bool itemCopyLocal = GetItemCopyLocal(entry2.item);
         PublishFlags assemblyFlags = PublishFlags.GetAssemblyFlags(entry2.publishInfo.state, itemCopyLocal);
         if ((assemblyFlags.IsPublished && string.Equals(entry2.publishInfo.includeHash, "false", StringComparison.OrdinalIgnoreCase)) && this.SigningManifests)
         {
             this.canPublish = false;
         }
         if (assemblyFlags.IsPublished)
         {
             assemblyList.Add(CreateAssemblyItem(entry2.item, entry2.publishInfo.group, entry2.publishInfo.targetPath, entry2.publishInfo.includeHash));
         }
         else if (assemblyFlags.IsPrerequisite)
         {
             assemblyList.Add(CreatePrerequisiteItem(entry2.item));
         }
     }
 }
Exemplo n.º 4
0
        private void GetOutputAssemblies(PublishInfo[] publishInfos, ref List <ITaskItem> assemblyList)
        {
            AssemblyMap assemblyMap = new AssemblyMap();

            // Add all managed assemblies to the AssemblyMap, except assemblies that are part of the .NET Framework...
            if (_managedAssemblies != null)
            {
                foreach (ITaskItem item in _managedAssemblies)
                {
                    if (!IsFiltered(item))
                    {
                        item.SetMetadata("AssemblyType", "Managed");
                        assemblyMap.Add(item);
                    }
                }
            }

            if (_nativeAssemblies != null)
            {
                foreach (ITaskItem item in _nativeAssemblies)
                {
                    if (!IsFiltered(item))
                    {
                        item.SetMetadata("AssemblyType", "Native");
                        assemblyMap.Add(item);
                    }
                }
            }

            // Apply PublishInfo state from PublishFile items...
            foreach (PublishInfo publishInfo in publishInfos)
            {
                MapEntry entry = assemblyMap[publishInfo.key];
                if (entry != null)
                {
                    entry.publishInfo = publishInfo;
                }
                else
                {
                    Log.LogWarningWithCodeFromResources("ResolveManifestFiles.PublishFileNotFound", publishInfo.key);
                }
            }

            // Go through the AssemblyMap and determine which items get added to ouput AssemblyList based
            // on computed PublishFlags for each item...
            foreach (MapEntry entry in assemblyMap)
            {
                // If PublishInfo didn't come from a PublishFile item, then construct PublishInfo from the item
                if (entry.publishInfo == null)
                {
                    entry.publishInfo = new PublishInfo();
                }

                // If state is auto then also need to look on the item to see whether the dependency type
                // has alread been specified upstream (i.e. from ResolveNativeReference task)...
                if (entry.publishInfo.state == PublishState.Auto)
                {
                    string dependencyType = entry.item.GetMetadata("DependencyType");
                    if (String.Equals(dependencyType, "Prerequisite", StringComparison.Ordinal))
                    {
                        entry.publishInfo.state = PublishState.Prerequisite;
                    }
                    else if (String.Equals(dependencyType, "Install", StringComparison.Ordinal))
                    {
                        entry.publishInfo.state = PublishState.Include;
                    }
                }

                bool         copyLocal = GetItemCopyLocal(entry.item);
                PublishFlags flags     = PublishFlags.GetAssemblyFlags(entry.publishInfo.state, copyLocal);

                if (flags.IsPublished &&
                    string.Equals(entry.publishInfo.includeHash, "false", StringComparison.OrdinalIgnoreCase) &&
                    SigningManifests == true)
                {
                    _canPublish = false;
                }

                if (flags.IsPublished)
                {
                    assemblyList.Add(CreateAssemblyItem(entry.item, entry.publishInfo.group, entry.publishInfo.targetPath, entry.publishInfo.includeHash));
                }
                else if (flags.IsPrerequisite)
                {
                    assemblyList.Add(CreatePrerequisiteItem(entry.item));
                }
            }
        }
Exemplo n.º 5
0
        private void GetOutputAssemblies(PublishInfo[] publishInfos, ref List<ITaskItem> assemblyList)
        {
            AssemblyMap assemblyMap = new AssemblyMap();

            // Add all managed assemblies to the AssemblyMap, except assemblies that are part of the .NET Framework...
            if (_managedAssemblies != null)
                foreach (ITaskItem item in _managedAssemblies)
                    if (!IsFiltered(item))
                    {
                        item.SetMetadata("AssemblyType", "Managed");
                        assemblyMap.Add(item);
                    }

            if (_nativeAssemblies != null)
                foreach (ITaskItem item in _nativeAssemblies)
                    if (!IsFiltered(item))
                    {
                        item.SetMetadata("AssemblyType", "Native");
                        assemblyMap.Add(item);
                    }

            // Apply PublishInfo state from PublishFile items...
            foreach (PublishInfo publishInfo in publishInfos)
            {
                MapEntry entry = assemblyMap[publishInfo.key];
                if (entry != null)
                    entry.publishInfo = publishInfo;
                else
                    Log.LogWarningWithCodeFromResources("ResolveManifestFiles.PublishFileNotFound", publishInfo.key);
            }

            // Go through the AssemblyMap and determine which items get added to ouput AssemblyList based
            // on computed PublishFlags for each item...
            foreach (MapEntry entry in assemblyMap)
            {
                // If PublishInfo didn't come from a PublishFile item, then construct PublishInfo from the item
                if (entry.publishInfo == null)
                    entry.publishInfo = new PublishInfo();

                // If state is auto then also need to look on the item to see whether the dependency type
                // has alread been specified upstream (i.e. from ResolveNativeReference task)...
                if (entry.publishInfo.state == PublishState.Auto)
                {
                    string dependencyType = entry.item.GetMetadata("DependencyType");
                    if (String.Equals(dependencyType, "Prerequisite", StringComparison.Ordinal))
                        entry.publishInfo.state = PublishState.Prerequisite;
                    else if (String.Equals(dependencyType, "Install", StringComparison.Ordinal))
                        entry.publishInfo.state = PublishState.Include;
                }

                bool copyLocal = GetItemCopyLocal(entry.item);
                PublishFlags flags = PublishFlags.GetAssemblyFlags(entry.publishInfo.state, copyLocal);

                if (flags.IsPublished &&
                    string.Equals(entry.publishInfo.includeHash, "false", StringComparison.OrdinalIgnoreCase) &&
                    SigningManifests == true)
                    _canPublish = false;

                if (flags.IsPublished)
                    assemblyList.Add(CreateAssemblyItem(entry.item, entry.publishInfo.group, entry.publishInfo.targetPath, entry.publishInfo.includeHash));
                else if (flags.IsPrerequisite)
                    assemblyList.Add(CreatePrerequisiteItem(entry.item));
            }
        }
        private void GetOutputAssemblies(PublishInfo[] publishInfos, ref List <ITaskItem> assemblyList)
        {
            AssemblyMap map = new AssemblyMap();

            if (this.managedAssemblies != null)
            {
                foreach (ITaskItem item in this.managedAssemblies)
                {
                    if (!IsFiltered(item))
                    {
                        item.SetMetadata("AssemblyType", "Managed");
                        map.Add(item);
                    }
                }
            }
            if (this.nativeAssemblies != null)
            {
                foreach (ITaskItem item2 in this.nativeAssemblies)
                {
                    if (!IsFiltered(item2))
                    {
                        item2.SetMetadata("AssemblyType", "Native");
                        map.Add(item2);
                    }
                }
            }
            foreach (PublishInfo info in publishInfos)
            {
                MapEntry entry = map[info.key];
                if (entry != null)
                {
                    entry.publishInfo = info;
                }
                else
                {
                    base.Log.LogWarningWithCodeFromResources("ResolveManifestFiles.PublishFileNotFound", new object[] { info.key });
                }
            }
            foreach (MapEntry entry2 in (IEnumerable)map)
            {
                if (entry2.publishInfo == null)
                {
                    entry2.publishInfo = new PublishInfo();
                }
                if (entry2.publishInfo.state == PublishState.Auto)
                {
                    string metadata = entry2.item.GetMetadata("DependencyType");
                    if (string.Equals(metadata, "Prerequisite", StringComparison.Ordinal))
                    {
                        entry2.publishInfo.state = PublishState.Prerequisite;
                    }
                    else if (string.Equals(metadata, "Install", StringComparison.Ordinal))
                    {
                        entry2.publishInfo.state = PublishState.Include;
                    }
                }
                bool         itemCopyLocal = GetItemCopyLocal(entry2.item);
                PublishFlags assemblyFlags = PublishFlags.GetAssemblyFlags(entry2.publishInfo.state, itemCopyLocal);
                if ((assemblyFlags.IsPublished && string.Equals(entry2.publishInfo.includeHash, "false", StringComparison.OrdinalIgnoreCase)) && this.SigningManifests)
                {
                    this.canPublish = false;
                }
                if (assemblyFlags.IsPublished)
                {
                    assemblyList.Add(CreateAssemblyItem(entry2.item, entry2.publishInfo.group, entry2.publishInfo.targetPath, entry2.publishInfo.includeHash));
                }
                else if (assemblyFlags.IsPrerequisite)
                {
                    assemblyList.Add(CreatePrerequisiteItem(entry2.item));
                }
            }
        }