コード例 #1
0
        public void CanResolveDefaultAssemblyAssetPath()
        {
            var assembly     = CompilationPipeline.GetAssemblies(AssembliesType.Player).FirstOrDefault(a => a.name.Equals(Path.GetFileNameWithoutExtension(AssemblyInfo.DefaultAssemblyFileName)));
            var assemblyInfo = AssemblyInfoProvider.GetAssemblyInfoFromAssemblyPath(assembly.outputPath);

            var path = AssemblyInfoProvider.ResolveAssetPath(assemblyInfo, Path.Combine(Application.dataPath, "somefile"));

            Assert.True(path.Equals("Assets/somefile"));
        }
コード例 #2
0
        void AnalyzeMethodBody(AssemblyInfo assemblyInfo, MethodDefinition caller, Action <CallInfo> onCallFound, Action <ProjectIssue> onIssueFound)
        {
            if (!caller.DebugInformation.HasSequencePoints)
            {
                return;
            }

            Profiler.BeginSample("ScriptAuditor.AnalyzeMethodBody");

            var callerNode          = new CallTreeNode(caller);
            var perfCriticalContext = IsPerformanceCriticalContext(caller);

            foreach (var inst in caller.Body.Instructions.Where(i => m_OpCodes.Contains(i.OpCode)))
            {
                SequencePoint s = null;
                for (var i = inst; i != null; i = i.Previous)
                {
                    s = caller.DebugInformation.GetSequencePoint(i);
                    if (s != null)
                    {
                        break;
                    }
                }

                Location location = null;
                if (s != null && !s.IsHidden)
                {
                    location            = new Location(AssemblyInfoProvider.ResolveAssetPath(assemblyInfo, s.Document.Url), s.StartLine);
                    callerNode.location = location;
                }
                else
                {
                    // sequence point not found. Assuming caller.IsHideBySig == true
                }

                if (inst.OpCode == OpCodes.Call || inst.OpCode == OpCodes.Callvirt)
                {
                    onCallFound(new CallInfo
                    {
                        callee              = (MethodReference)inst.Operand,
                        caller              = caller,
                        location            = location,
                        perfCriticalContext = perfCriticalContext
                    });
                }

                foreach (var analyzer in m_Analyzers)
                {
                    if (analyzer.GetOpCodes().Contains(inst.OpCode))
                    {
                        var projectIssue = analyzer.Analyze(caller, inst);
                        if (projectIssue != null)
                        {
                            projectIssue.dependencies.perfCriticalContext = perfCriticalContext;
                            projectIssue.dependencies.AddChild(callerNode);
                            projectIssue.location = location;
                            projectIssue.SetCustomProperties(new[] { assemblyInfo.name });

                            onIssueFound(projectIssue);
                        }
                    }
                }
            }
            Profiler.EndSample();
        }