Example #1
0
            internal static void Build(
                string assemblyPath,
                int methodLimit,
                List <TypeInfo> typeInfoList,
                out ImmutableArray <PartitionInfo> partitionInfoList
                )
            {
                var list = new List <PartitionInfo>();
                var hasEventListenerGuard = typeInfoList.Any(
                    x => x.FullName == EventListenerGuardFullName
                    );
                var currentTypeInfoList       = new List <TypeInfo>();
                var currentClassNameLengthSum = -1;
                var currentId = 0;

                BeginPartition();

                foreach (var typeInfo in typeInfoList)
                {
                    currentTypeInfoList.Add(typeInfo);
                    currentClassNameLengthSum += typeInfo.FullName.Length;
                    CheckForPartitionLimit(done: false);
                }

                CheckForPartitionLimit(done: true);

                partitionInfoList = ImmutableArray.CreateRange(list);

                void BeginPartition()
                {
                    currentId++;
                    currentTypeInfoList.Clear();
                    currentClassNameLengthSum = 0;

                    // Ensure the EventListenerGuard is in every partition.
                    if (hasEventListenerGuard)
                    {
                        currentClassNameLengthSum += EventListenerGuardFullName.Length;
                    }
                }

                void CheckForPartitionLimit(bool done)
                {
                    if (done)
                    {
                        // The builder is done looking at types.  If there are any TypeInfo that have not
                        // been added to a partition then do it now.
                        if (currentTypeInfoList.Count > 0)
                        {
                            FinishPartition();
                        }

                        return;
                    }

                    // One item we have to consider here is the maximum command line length in
                    // Windows which is 32767 characters (XP is smaller but don't care).  Once
                    // we get close then create a partition and move on.
                    if (
                        currentTypeInfoList.Sum(x => x.MethodCount) >= methodLimit ||
                        currentClassNameLengthSum > 25000
                        )
                    {
                        FinishPartition();
                        BeginPartition();
                    }

                    void FinishPartition()
                    {
                        var partitionInfo = new PartitionInfo(
                            currentId,
                            assemblyPath,
                            $"{Path.GetFileName(assemblyPath)}.{currentId}",
                            ImmutableArray.CreateRange(currentTypeInfoList)
                            );

                        list.Add(partitionInfo);
                    }
                }
            }
Example #2
0
 internal AssemblyInfo(PartitionInfo partitionInfo, string targetFramework, string platform)
 {
     PartitionInfo   = partitionInfo;
     TargetFramework = targetFramework;
     Platform        = platform;
 }
Example #3
0
 internal AssemblyInfo(PartitionInfo partitionInfo, string targetFramework, string architecture)
 {
     PartitionInfo   = partitionInfo;
     TargetFramework = targetFramework;
     Architecture    = architecture;
 }