コード例 #1
0
ファイル: Call.cs プロジェクト: dbremner/smokey
		/// <summary>Returns true if we're calling an instance method with caller's this
		/// pointer, or if we're calling a static method in caller's declaring
		/// type with caller's this pointer as an argument.</summary>
		public bool IsThisCall(AssemblyCache cache, MethodInfo caller, int callIndex)
		{
			DBC.Pre(cache != null, "cache is null");				
			DBC.Pre(caller != null, "caller is null");
				
			if (!m_isThisCall.HasValue)
			{
				m_isThisCall = false;

				MethodInfo target = cache.FindMethod(Target);
				if (target != null && !target.Method.IsConstructor)
				{
					if (target.Method.HasThis)
					{
						int nth = target.Method.Parameters.Count;
						int j = caller.Tracker.GetStackIndex(callIndex, nth);
						
						if (j >= 0)
							m_isThisCall = caller.Instructions.LoadsThisArg(j);
					}
					else if (target.Method.IsStatic)
					{
						for (int i = 0; i < target.Method.Parameters.Count && !m_isThisCall.Value; ++i)
						{
							int j = caller.Tracker.GetStackIndex(callIndex, i);				

							if (j >= 0)
								m_isThisCall = caller.Instructions.LoadsThisArg(j);
						}
					}
				}
			}
			return m_isThisCall.Value;
		}
コード例 #2
0
 private AssemblyCache GetAssemblyCache(Type classType, IConfiguration config)
 {
     if (_assemblyCache == null)
     {
         _assemblyCache = new Dictionary<Assembly, AssemblyCache>();
     }
     AssemblyCache cache = null;
     if (!_assemblyCache.TryGetValue(classType.Assembly, out cache))
     {
         cache = new AssemblyCache(classType.Assembly);
         foreach (JsonExDefaultValuesAttribute attr in classType.Assembly.GetCustomAttributes(typeof(JsonExDefaultValuesAttribute), false))
         {
             if (attr.DefaultValueSetting != DefaultValueOption.InheritParentSetting)
                 cache.defaultOption = attr.DefaultValueSetting;
             if (attr.Type != null)
             {
                 if (cache.defaultValues == null)
                     cache.defaultValues = new DefaultValueCollection(config.DefaultValues);
                 cache.defaultValues[attr.Type] = attr.DefaultValue;
             }
         }
         if (cache.defaultOption == DefaultValueOption.InheritParentSetting && cache.defaultValues != null)
             cache.defaultOption = DefaultValueOption.SuppressDefaultValues;
         _assemblyCache[classType.Assembly] = cache;
     }
     return cache;
 }
コード例 #3
0
		private int DoCallsVirtual(AssemblyCache cache, MethodInfo info)
		{
			int offset = -1;
			if (m_tested.IndexOf(info.Method.ToString()) >= 0)
				return offset;
				
			m_tested.Add(info.Method.ToString());

			Log.DebugLine(this, "checking:");
			Log.Indent();
			
			// If the class isn't sealed then,
			if (info.Method.Body != null && info.Instructions != null)
			{
				Log.DebugLine(this, "{0:F}", info.Instructions);

				// loop through every instruction,
				for (int i = 0; i < info.Instructions.Length && offset < 0; ++i)
				{
					// if it's a call,
					Call call = info.Instructions[i] as Call;
					if (call != null)
					{	
						// then we have a problem if we're calling a virtual method
						// on our instance,
						MethodInfo targetInfo = cache.FindMethod(call.Target);
						if (targetInfo != null)
						{
							if (call.IsThisCall(Cache, info, i))
							{
								if (targetInfo.Method.IsVirtual && !targetInfo.Method.IsFinal)
								{
									Log.DebugLine(this, "{0} is virtual", call.Target);
									{
										m_details = call.Target.ToString();			
										offset = call.Untyped.Offset;
										Log.DebugLine(this, "found virtual call at {0:X2}", offset);
									}
								}
								else
								{
									// or we're calling one of our methods which calls a virtual method
									// on our instance.
									offset = DoCallsVirtual(cache, targetInfo);
								}
							}
						}
					}
				}
			}
			Log.Unindent();
			
			if (offset >= 0)
				m_details = info.Method + " -> " + Environment.NewLine + "       " + m_details;			
			
			return offset;
		}
コード例 #4
0
ファイル: LargeStructRule.cs プロジェクト: dbremner/smokey
		// There doesn't seem to be a way to get this via Cecil: all of the obvious
		// candidates like TypeDefinition::PackingSize, TypeDefinition::ClassSize,
		// and FieldDefinition::Offset return zero.
		private int DoGetStructSize(AssemblyCache cache, TypeDefinition type, int level)
		{
			int size = 0;
			DBC.Assert(level < 100, "LargeStructRule didn't terminate for type {0}", type.FullName);
//			Console.WriteLine(prefix + type.FullName);
			
			// For each field,
			foreach (FieldDefinition field in type.Fields)
			{
				Log.WarningLine(this, "checking field of type {0}{1}", new string(' ', 3*level), field.FieldType.FullName);
				
				// if it isn't static,
				if (!field.IsStatic)
				{
					// if it's a value type,
					if (field.FieldType.IsValueType)
					{
						// if it's a standard system struct then we know the size,
						int temp = DoGetSystemTypeSize(field.FieldType.FullName);
						if (temp > 0)
							size += temp;
						else 
						{
							// otherwise if it's one of our types we can figure the
							// size out,
							TypeDefinition t = cache.FindType(field.FieldType);
							if (t != null && t.FullName != type.FullName)	// TODO: shouldn't need the name check (but mscorlib.dll infinitely recurses w/o it)
							{
								if (t.IsEnum || !t.IsValueType)
									size += 4;
								else
									size += DoGetStructSize(cache, t, level + 1);
							}
							
							// if it's not one of our types then we appear to be hosed
							// (this should rarely happen now that we load dependant
							// assemblies).
							else
							{
								Log.TraceLine(this, "couldn't find the size for {0}", field.FieldType.FullName);
								size += 1;		
							}
						}
					}
					
					// if it's not a value type then for our purposes its size is 4 
					// (pointers may be 8 bytes on a 64-bit platform but we don't want
					// to report errors just because they happen to be running on a 
					// 64-bit system).
					else
						size += 4;
				}
			}
						
			return size;
		}
コード例 #5
0
		public UseFlagsAttributeRule(AssemblyCache cache, IReportViolations reporter) 
			: base(cache, reporter, "D1019")
		{
			long mask = 1;
			for (int i = 0; i < 63; ++i)
			{
				m_powers.Add(mask);
				mask = mask << 1;
			}
			m_powers.Add(mask);
		}
コード例 #6
0
ファイル: GenericTestFixture.cs プロジェクト: cbsistem/JSIL
 protected ComparisonTest MakeTest (
     string filename, string[] stubbedAssemblies = null,
     TypeInfoProvider typeInfo = null,
     AssemblyCache assemblyCache = null
 ) {
     return new ComparisonTest(
         EvaluatorPool,
         Portability.NormalizeDirectorySeparators(filename), stubbedAssemblies,
         typeInfo, assemblyCache
     );
 }
コード例 #7
0
ファイル: Rule.cs プロジェクト: dbremner/smokey
		protected Rule(AssemblyCache cache, IReportViolations reporter, string checkID)
		{
			DBC.Pre(cache != null, "cache is null");
			DBC.Pre(reporter != null, "reporter is null");
			DBC.Pre(!string.IsNullOrEmpty(checkID), "checkID is null or empty");

			Cache = cache;
			Reporter = reporter;
			CheckID = checkID;
			Runtime = TargetRuntime.NET_1_0;
		}
コード例 #8
0
ファイル: TestUtil.cs プロジェクト: xen2/JSIL
        public ComparisonTest(
            EvaluatorPool pool,
            IEnumerable<string> filenames, string outputPath, 
            string[] stubbedAssemblies = null, TypeInfoProvider typeInfo = null,
            AssemblyCache assemblyCache = null
        )
        {
            var started = DateTime.UtcNow.Ticks;
            OutputPath = outputPath;
            EvaluatorPool = pool;

            var extensions = (from f in filenames select Path.GetExtension(f).ToLower()).Distinct().ToArray();
            var absoluteFilenames = (from f in filenames select Path.Combine(TestSourceFolder, f));

            if (extensions.Length != 1)
                throw new InvalidOperationException("Mixture of different source languages provided.");

            var assemblyNamePrefix = Path.GetDirectoryName(outputPath).Split(new char[] { '\\', '/' }).Last();
            var assemblyName = Path.Combine(
                assemblyNamePrefix,
                Path.GetFileName(outputPath).Replace(".js", "")
            );

            switch (extensions[0]) {
                case ".cs":
                    Assembly = CompilerUtil.CompileCS(absoluteFilenames, assemblyName);
                    break;
                case ".vb":
                    Assembly = CompilerUtil.CompileVB(absoluteFilenames, assemblyName);
                    break;
                case ".exe":
                case ".dll":
                    var fns = absoluteFilenames.ToArray();
                    if (fns.Length > 1)
                        throw new InvalidOperationException("Multiple binary assemblies provided.");

                    Assembly = Assembly.LoadFile(fns[0]);
                    break;
                default:
                    throw new ArgumentException("Unsupported source file type for test");
            }

            if (typeInfo != null)
                typeInfo.ClearCaches();

            StubbedAssemblies = stubbedAssemblies;
            TypeInfo = typeInfo;
            AssemblyCache = assemblyCache;

            var ended = DateTime.UtcNow.Ticks;
            CompilationElapsed = TimeSpan.FromTicks(ended - started);
        }
コード例 #9
0
		public NonLocalizedGuiRule(AssemblyCache cache, IReportViolations reporter) 
			: base(cache, reporter, "G1002")
		{
			m_enabled = Settings.Get("*localized*", "true") == "true";
			Log.TraceLine(this, "enabled: {0}", m_enabled);
			
			string custom = Settings.Get("localize", string.Empty);
			foreach (string name in custom.Split(';'))
			{
				Log.TraceLine(this, "using custom: {0}", name);
				m_custom.Add(" " + name + "(");		// add some goo so we match only what we should
			}
		}
コード例 #10
0
ファイル: TestUtil.cs プロジェクト: xen2/JSIL
 public ComparisonTest(
     EvaluatorPool pool, 
     string filename, string[] stubbedAssemblies = null, 
     TypeInfoProvider typeInfo = null, AssemblyCache assemblyCache = null
 )
     : this(pool,
         new[] { filename }, 
         Path.Combine(
             TestSourceFolder,
             MapSourceFileToTestFile(filename)
         ), 
         stubbedAssemblies, typeInfo, assemblyCache)
 {
 }
コード例 #11
0
		public OperatorAlternativeRule(AssemblyCache cache, IReportViolations reporter) 
			: base(cache, reporter, "D1033")
		{
			m_table.Add("op_Addition", "Add");
			m_table.Add("op_Subtraction", "Subtract");
			m_table.Add("op_Multiply", "Multiply");
			m_table.Add("op_Division", "Divide");
			m_table.Add("op_Modulus", "Mod");
			m_table.Add("op_GreaterThan", "Compare");
			m_table.Add("op_GreaterThanOrEqual", "Compare");
			m_table.Add("op_LessThan", "Compare");
			m_table.Add("op_LessThanOrEqual", "Compare");
			m_table.Add("op_Inequality", "Equals");
			m_table.Add("op_Equality", "Equals");
		}
コード例 #12
0
ファイル: Program.cs プロジェクト: simon-heinen/JSIL
        static AssemblyTranslator CreateTranslator(
            Configuration configuration, AssemblyManifest manifest, AssemblyCache assemblyCache
        )
        {
            TypeInfoProvider typeInfoProvider = null;

            if (
                configuration.ReuseTypeInfoAcrossAssemblies.GetValueOrDefault(true) &&
                (CachedTypeInfoProvider != null)
            ) {
                if (CachedTypeInfoProviderConfiguration.Assemblies.Equals(configuration.Assemblies))
                    typeInfoProvider = CachedTypeInfoProvider;
            }

            var translator = new AssemblyTranslator(
                configuration, typeInfoProvider, manifest, assemblyCache,
                onProxyAssemblyLoaded: (name) => {
                    Console.Error.WriteLine("// Loaded proxies from '{0}'", ShortenPath(name));
                }
            );

            translator.Decompiling += MakeProgressHandler       ("Decompiling ");
            translator.RunningTransforms += MakeProgressHandler ("Translating ");
            translator.Writing += MakeProgressHandler           ("Writing JS  ");

            translator.AssemblyLoaded += (fn) => {
                Console.Error.WriteLine("// Loaded {0}", ShortenPath(fn));
            };
            translator.CouldNotLoadSymbols += (fn, ex) => {
            };
            translator.CouldNotResolveAssembly += (fn, ex) => {
                Console.Error.WriteLine("// Could not load module {0}: {1}", fn, ex.Message);
            };
            translator.CouldNotDecompileMethod += (fn, ex) => {
                Console.Error.WriteLine("// Could not decompile method {0}: {1}", fn, ex.Message);
            };

            if (typeInfoProvider == null) {
                if (CachedTypeInfoProvider != null)
                    CachedTypeInfoProvider.Dispose();

                CachedTypeInfoProvider = translator.GetTypeInfoProvider();
                CachedTypeInfoProviderConfiguration = configuration;
            }

            return translator;
        }
コード例 #13
0
ファイル: SpecialFolderRule.cs プロジェクト: dbremner/smokey
		public SpecialFolderRule(AssemblyCache cache, IReportViolations reporter) 
			: base(cache, reporter, "PO1003")
		{
			string user = Environment.UserName;
			
			Array values = Enum.GetValues(typeof(Environment.SpecialFolder));			
			foreach (object o in values)
			{
				Environment.SpecialFolder name = (Environment.SpecialFolder) o;
				string path = Environment.GetFolderPath(name);
				if (path.Length > 0)
				{
					path = path.Replace(user, "*");
					if (!m_globs.ContainsKey(name))
						m_globs.Add(name, path.Split(Path.DirectorySeparatorChar));
				}
			}
		}
コード例 #14
0
ファイル: GenericTestFixture.cs プロジェクト: Ocelloid/JSIL
        protected IEnumerable<TestCaseData> FilenameTestSource(string[] filenames, TypeInfoProvider typeInfo = null, AssemblyCache asmCache = null)
        {
            var testNames = filenames.OrderBy((s) => s).ToArray();

            for (int i = 0, l = testNames.Length; i < l; i++) {
                var testName = testNames[i];

                bool isIgnored = testName.StartsWith("ignored:", StringComparison.OrdinalIgnoreCase);
                var actualTestName = testName;

                if (isIgnored)
                    actualTestName = actualTestName.Substring(actualTestName.IndexOf(":") + 1);

                var item = (new TestCaseData(new object[] { new object[] { actualTestName, typeInfo, asmCache, null, i == (l - 1) } }))
                    .SetName(Path.GetFileName(actualTestName));

                if (isIgnored)
                    item.Ignore();

                yield return item;
            }
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: c444b774/JSIL
        static AssemblyTranslator CreateTranslator(Configuration configuration, AssemblyManifest manifest, AssemblyCache assemblyCache)
        {
            var translator = new AssemblyTranslator(configuration, null, manifest, assemblyCache);

            translator.Decompiling += MakeProgressHandler("Decompiling   ");
            translator.Optimizing += MakeProgressHandler ("Optimizing    ");
            translator.Writing += MakeProgressHandler    ("Generating JS ");

            translator.AssemblyLoaded += (fn) => {
                Console.Error.WriteLine("// Loaded {0}", ShortenPath(fn));
            };
            translator.CouldNotLoadSymbols += (fn, ex) => {
            };
            translator.CouldNotResolveAssembly += (fn, ex) => {
                Console.Error.WriteLine("// Could not load module {0}: {1}", fn, ex.Message);
            };
            translator.CouldNotDecompileMethod += (fn, ex) => {
                Console.Error.WriteLine("// Could not decompile method {0}: {1}", fn, ex.Message);
            };

            return translator;
        }
コード例 #16
0
ファイル: NoStaticRemoveRule.cs プロジェクト: dbremner/smokey
		public NoStaticRemoveRule(AssemblyCache cache, IReportViolations reporter) 
			: base(cache, reporter, "C1026")
		{
			// Collections.Generic
			m_adders.Add  ("System.Collections.Generic.Dictionary`", new List<string>{"Add", "set_Item"});
			m_removers.Add("System.Collections.Generic.Dictionary`", new List<string>{"Clear", "Remove"});
			
			m_adders.Add  ("System.Collections.Generic.HashSet`", new List<string>{"Add", "UnionWith"});
			m_removers.Add("System.Collections.Generic.HashSet`", new List<string>{"Clear", "ExceptWith", "IntersectWith", "Remove", "RemoveWhere", "SymmetricExceptWith"});
			
			m_adders.Add  ("System.Collections.Generic.List`", new List<string>{"Add", "AddRange", "Insert", "InsertRange"});
			m_removers.Add("System.Collections.Generic.List`", new List<string>{"Clear", "Remove", "RemoveAll", "RemoveAt", "RemoveRange"});
			
			m_adders.Add  ("System.Collections.Generic.Queue`", new List<string>{"Enqueue"});
			m_removers.Add("System.Collections.Generic.Queue`", new List<string>{"Clear", "Dequeue"});
			
			m_adders.Add  ("System.Collections.Generic.SortedDictionary`", new List<string>{"Add", "set_Item"});
			m_removers.Add("System.Collections.Generic.SortedDictionary`", new List<string>{"Clear", "Remove"});
			
			m_adders.Add  ("System.Collections.Generic.Stack`", new List<string>{"Push"});
			m_removers.Add("System.Collections.Generic.Stack`", new List<string>{"Clear", "Pop"});
			
			// Collections
			m_adders.Add  ("System.Collections.ArrayList", new List<string>{"Add", "AddRange", "Insert", "InsertRange"});
			m_removers.Add("System.Collections.ArrayList", new List<string>{"Clear", "Remove", "RemoveAt", "RemoveRange"});
			
			m_adders.Add  ("System.Collections.Hashtable", new List<string>{"Add", "set_Item"});
			m_removers.Add("System.Collections.Hashtable", new List<string>{"Clear", "Remove"});
			
			m_adders.Add  ("System.Collections.Queue", new List<string>{"Enqueue"});
			m_removers.Add("System.Collections.Queue", new List<string>{"Clear", "Dequeue"});
			
			m_adders.Add  ("System.Collections.SortedList", new List<string>{"Add", "set_Item"});
			m_removers.Add("System.Collections.SortedList", new List<string>{"Clear", "Remove", "RemoveAt"});
			
		}
コード例 #17
0
ファイル: HungarianRule.cs プロジェクト: dbremner/smokey
		[DisableRule("C1000", "StringSpelling")]	// ignore the weird hungarian strings
		public HungarianRule(AssemblyCache cache, IReportViolations reporter) 
			: base(cache, reporter, "MS1030")
		{
		}
コード例 #18
0
        public void Smoke()
        {
            using (var context = new TemporalMongoUnitTestContext(this))
            {
                // Root of the C# source code of the DataCentric module
                string srcRootFolder = Path.Combine(context.TestFolderPath, "..\\..\\..");
                string libFolder     = Path.Combine(srcRootFolder, "DataCentric.Test\\bin\\Debug\\netcoreapp2.1"); // TODO - support Linux and release modes
                var    options       = new ExtractCommand
                {
                    Assemblies   = Directory.GetFiles(libFolder, "*.dll"),
                    OutputFolder = context.TestFolderPath,
                    Types        = new List <string>(),
                    ProjectPath  = srcRootFolder
                };

                AssemblyCache assemblies = new AssemblyCache();

                // Create list of assemblies (enrolling masks when needed)
                foreach (string assemblyPath in options.Assemblies)
                {
                    string assemblyName = Path.GetFileName(assemblyPath);
                    if (!string.IsNullOrEmpty(assemblyName))
                    {
                        string assemblyDirectory =
                            string.IsNullOrEmpty(assemblyDirectory = Path.GetDirectoryName(assemblyPath))
                                ? Environment.CurrentDirectory
                                : Path.GetFullPath(assemblyDirectory);
                        assemblies.AddFiles(Directory.EnumerateFiles(assemblyDirectory, assemblyName));
                    }
                }

                List <IDecl> declarations = new List <IDecl>();

                foreach (Assembly assembly in assemblies)
                {
                    CommentNavigator.TryCreate(assembly, out CommentNavigator docNavigator);
                    ProjectNavigator.TryCreate(options.ProjectPath, assembly, out ProjectNavigator projNavigator);

                    List <Type> types = TypesExtractor.GetTypes(assembly, options.Types);
                    List <Type> enums = TypesExtractor.GetEnums(assembly, options.Types);
                    declarations.AddRange(types.Concat(enums)
                                          .Select(type => DeclarationConvertor.ToDecl(type, docNavigator, projNavigator)));
                }

                var converted = DeclarationToPythonConverter.ConvertSet(declarations);

                var result = new Dictionary <string, string>();
                foreach (var file in converted)
                {
                    if (file.FolderName == null)
                    {
                        result[$"{file.FileName}"] = file.Content;
                    }
                    else
                    {
                        result[$"{file.FolderName}/{file.FileName}"] = file.Content;
                    }
                }

                // Record the contents of a selected list of generated files
                // for the purposes of approval testing
                var approvalTestFiles = new List <string>
                {
                    "job_status",
                    "job",
                    "job_key",
                    "zone",
                    "zone_key"
                };

                // Record approval test output
                foreach (var file in result.OrderBy(f => f.Key))
                {
                    string[] tokens   = file.Key.Split('/');
                    string   fileName = tokens[tokens.Length - 1].Split('.')[0];

                    if (approvalTestFiles.Contains(fileName))
                    {
                        context.Log.Verify(file.Key, file.Value);
                    }
                }

                // Enable to generate files on disk
                if (false)
                {
                    foreach (var file in result)
                    {
                        var fullPath  = Path.Combine(options.OutputFolder, file.Key);
                        var directory = Path.GetDirectoryName(fullPath);
                        Directory.CreateDirectory(directory);

                        File.WriteAllText(fullPath, file.Value);
                    }
                }
            }
        }
コード例 #19
0
 public CollectionToStringRule(AssemblyCache cache, IReportViolations reporter)
     : base(cache, reporter, "D1040")
 {
 }
コード例 #20
0
ファイル: Program.cs プロジェクト: yongweisun/JSIL
        static Configuration ParseCommandLine(
            IEnumerable <string> arguments, List <BuildGroup> buildGroups,
            Dictionary <string, IProfile> profiles, Dictionary <string, IAnalyzer> analyzers,
            Dictionary <string, IEmitterFactory> emitterFactories,
            AssemblyCache assemblyCache
            )
        {
            var      baseConfig         = new Configuration();
            var      commandLineConfig  = new Configuration();
            IProfile defaultProfile     = new Profiles.Default();
            var      profileAssemblies  = new List <string>();
            var      analyzerAssemblies = new List <string>();
            var      emitterAssemblies  = new List <string>();

            bool[]        autoloadProfiles  = new bool[] { true };
            bool[]        autoloadAnalyzers = new bool[] { true };
            bool[]        autoloadEmitters  = new bool[] { true };
            List <string> filenames;

            {
                var os = new Mono.Options.OptionSet {
                    { "o=|out=",
                      "Specifies the output directory for generated javascript and manifests.",
                      (path) => commandLineConfig.OutputDirectory = Path.GetFullPath(path) },
                    { "outputFile=",
                      "Specifies the exact location and name of the output file for the main assembly.",
                      (path) => commandLineConfig.OutputFileName = Path.GetFullPath(path) },
                    { "q|quiet",
                      "Suppresses non-error/non-warning stderr messages.",
                      (_) => commandLineConfig.Quiet = Quiet = true },
                    { "nac|noautoconfig",
                      "Suppresses automatic loading of same-named .jsilconfig files located next to solutions and/or assemblies.",
                      (b) => commandLineConfig.AutoLoadConfigFiles = b == null },
                    { "nt|nothreads",
                      "Suppresses use of multiple threads to speed up the translation process.",
                      (b) => commandLineConfig.UseThreads = b == null },
                    { "sbc|suppressbugcheck",
                      "Suppresses JSIL bug checks that detect bugs in .NET runtimes and standard libraries.",
                      (b) => commandLineConfig.RunBugChecks = b == null },

                    "Solution Builder options",
                    { "configuration=",
                      "When building one or more solution files, specifies the build configuration to use (like 'Debug').",
                      (v) => commandLineConfig.SolutionBuilder.Configuration = v },
                    { "platform=",
                      "When building one or more solution files, specifies the build platform to use (like 'x86').",
                      (v) => commandLineConfig.SolutionBuilder.Platform = v },
                    { "target=",
                      "When building one or more solution files, specifies the build target to use (like 'Build'). The default is 'Build'.",
                      (v) => commandLineConfig.SolutionBuilder.Target = v },
                    { "logVerbosity=",
                      "When building one or more solution files, specifies the level of log verbosity. Valid options are 'Quiet', 'Minimal', 'Normal', 'Detailed', and 'Diagnostic'.",
                      (v) => commandLineConfig.SolutionBuilder.LogVerbosity = v },

                    "Assembly options",
                    { "p=|proxy=",
                      "Loads a type proxy assembly to provide type information for the translator.",
                      (name) => commandLineConfig.Assemblies.Proxies.Add(Path.GetFullPath(name)) },
                    { "i=|ignore=",
                      "Specifies a regular expression pattern for assembly names that should be ignored during the translation process.",
                      (regex) => commandLineConfig.Assemblies.Ignored.Add(regex) },
                    { "s=|stub=",
                      "Specifies a regular expression pattern for assembly names that should be stubbed during the translation process. " +
                      "Stubbing forces all methods to be externals.",
                      (regex) => commandLineConfig.Assemblies.Stubbed.Add(regex) },
                    { "nd|nodeps",
                      "Suppresses the automatic loading and translation of assembly dependencies.",
                      (b) => commandLineConfig.IncludeDependencies = b == null },
                    { "nodefaults",
                      "Suppresses the default list of stubbed assemblies.",
                      (b) => commandLineConfig.ApplyDefaults = b == null },
                    { "nolocal",
                      "Disables using local proxy types from translated assemblies.",
                      (b) => commandLineConfig.UseLocalProxies = b == null },
                    { "fv=|frameworkVersion=",
                      "Specifies the version of the .NET framework proxies to use. " +
                      "This ensures that correct type information is provided (as different versions of the framework use different standard libraries). " +
                      "The only accepted value is currently '4.0'. Default: '4.0'",
                      (fv) => commandLineConfig.FrameworkVersion = double.Parse(fv) },

                    "Profile options",
                    { "nap|noautoloadprofiles",
                      "Disables automatic loading of profile assemblies from the compiler directory.",
                      (b) => autoloadProfiles[0] = (b == null) },
                    { "pa=|profileAssembly=",
                      "Loads one or more project profiles from the specified profile assembly. Note that this does not force the profiles to be used.",
                      profileAssemblies.Add },

                    "CodeGenerator options",
                    { "os",
                      "Suppresses struct copy elimination.",
                      (b) => commandLineConfig.CodeGenerator.EliminateStructCopies = b == null },
                    { "ot",
                      "Suppresses temporary local variable elimination.",
                      (b) => commandLineConfig.CodeGenerator.EliminateTemporaries = b == null },
                    { "oo",
                      "Suppresses simplification of operator expressions and special method calls.",
                      (b) => commandLineConfig.CodeGenerator.SimplifyOperators = b == null },
                    { "ol",
                      "Suppresses simplification of loop blocks.",
                      (b) => commandLineConfig.CodeGenerator.SimplifyLoops = b == null },

                    "Emitter options",
                    { "nae|noautoloademitters",
                      "Disables automatic loading of emitter assemblies from the compiler directory.",
                      (b) => autoloadEmitters[0] = (b == null) },
                    { "ea=|emitterAssembly=",
                      "Specifies an assembly to load emitters from.",
                      emitterAssemblies.Add },
                    { "e=|emitter=",
                      "Specifies an emitter factory to use instead of the default.",
                      (emitterName) => commandLineConfig.EmitterFactoryName = emitterName }
                };

                filenames = os.Parse(arguments);

                if (filenames.Count == 0)
                {
                    var asmName = Assembly.GetExecutingAssembly().GetName();
                    Console.WriteLine("==== JSILc v{0}.{1}.{2} ====", asmName.Version.Major, asmName.Version.Minor, asmName.Version.Revision);
                    Console.WriteLine("Specify one or more compiled assemblies (dll/exe) to translate them. Symbols will be loaded if they exist in the same directory.");
                    Console.WriteLine("You can also specify Visual Studio solution files (sln) to build them and automatically translate their output(s).");
                    Console.WriteLine("Specify the path of a .jsilconfig file to load settings from it.");

                    os.WriteOptionDescriptions(Console.Out);

                    return(null);
                }
            }

            {
                if (autoloadProfiles[0])
                {
                    profileAssemblies.AddRange(Directory.GetFiles(
                                                   GetJSILDirectory(),
                                                   "JSIL.Profiles.*.dll"
                                                   ));
                }

                if (autoloadAnalyzers[0])
                {
                    analyzerAssemblies.AddRange(Directory.GetFiles(
                                                    GetJSILDirectory(),
                                                    "JSIL.Analysis.*.dll"
                                                    ));
                }

                if (autoloadEmitters[0])
                {
                    emitterAssemblies.AddRange(Directory.GetFiles(
                                                   GetJSILDirectory(),
                                                   "JSIL.Emitters.*.dll"
                                                   ));
                }

                foreach (var filename in profileAssemblies)
                {
                    var fullPath = Path.GetFullPath(filename);

                    try {
                        IProfile profileInstance = CreateExtensionInstance <IProfile>(fullPath);
                        if (profileInstance != null)
                        {
                            profiles.Add(profileInstance.GetType().Name, profileInstance);
                        }
                    } catch (Exception exc) {
                        Console.Error.WriteLine("Warning: Failed to load profile '{0}': {1}", filename, exc);
                    }
                }

                foreach (var filename in analyzerAssemblies)
                {
                    var fullPath = Path.GetFullPath(filename);

                    try {
                        IAnalyzer analyzerInstance = CreateExtensionInstance <IAnalyzer>(fullPath);
                        if (analyzerInstance != null)
                        {
                            analyzers.Add(analyzerInstance.GetType().Name, analyzerInstance);
                        }
                    } catch (Exception exc) {
                        Console.Error.WriteLine("Warning: Failed to load analyzer '{0}': {1}", filename, exc);
                    }
                }

                foreach (var filename in emitterAssemblies)
                {
                    var fullPath = Path.GetFullPath(filename);

                    try {
                        IEmitterFactory factoryInstance = CreateExtensionInstance <IEmitterFactory>(fullPath);
                        if (factoryInstance != null)
                        {
                            emitterFactories.Add(factoryInstance.GetType().Name, factoryInstance);
                        }
                    } catch (Exception exc) {
                        Console.Error.WriteLine("Warning: Failed to load emitter '{0}': {1}", filename, exc);
                    }
                }
            }

            var commandLineConfigFilenames =
                (from fn in filenames
                 where Path.GetExtension(fn) == ".jsilconfig"
                 select fn).ToArray();

            // Fail early on nonexistent configuration files
            foreach (var filename in commandLineConfigFilenames)
            {
                if (!File.Exists(filename))
                {
                    throw new FileNotFoundException(filename);
                }
            }

            commandLineConfig = MergeConfigurations(
                commandLineConfig,
                (from fn in commandLineConfigFilenames
                 select LoadConfiguration(fn)).ToArray()
                );

            if (commandLineConfig.ApplyDefaults.GetValueOrDefault(true))
            {
                baseConfig = MergeConfigurations(
                    LoadConfiguration(Path.Combine(
                                          GetJSILDirectory(),
                                          "defaults.jsilconfig"
                                          )),
                    baseConfig
                    );
            }

            foreach (var solution in
                     (from fn in filenames where Path.GetExtension(fn) == ".sln" select fn)
                     )
            {
                var solutionFullPath = Path.GetFullPath(solution);
                var solutionDir      = Path.GetDirectoryName(solutionFullPath);

                if (solutionDir == null)
                {
                    Console.Error.WriteLine("// Can't process solution '{0}' - path seems malformed", solution);
                    continue;
                }

                // Fail early if a solution file is missing
                if (!File.Exists(solutionFullPath))
                {
                    throw new FileNotFoundException(solutionFullPath);
                }

                var solutionConfigPath = Path.Combine(
                    solutionDir,
                    String.Format("{0}.jsilconfig", Path.GetFileName(solutionFullPath))
                    );
                var solutionConfig = File.Exists(solutionConfigPath)
                    ? new Configuration[] { LoadConfiguration(solutionConfigPath) }
                    : new Configuration[] {  };

                var mergedSolutionConfig = MergeConfigurations(baseConfig, solutionConfig);
                var config       = MergeConfigurations(mergedSolutionConfig, commandLineConfig);
                var buildStarted = DateTime.UtcNow.Ticks;

                var buildResult = SolutionBuilder.SolutionBuilder.Build(
                    solutionFullPath,
                    config.SolutionBuilder.Configuration,
                    config.SolutionBuilder.Platform,
                    config.SolutionBuilder.Target ?? "Build",
                    config.SolutionBuilder.LogVerbosity
                    );

                var jss = new JavaScriptSerializer {
                    MaxJsonLength = (1024 * 1024) * 64
                };

                var buildResultJson = jss.Serialize(buildResult);
                buildResult = jss.Deserialize <SolutionBuilder.BuildResult>(buildResultJson);

                var buildEnded = DateTime.UtcNow.Ticks;

                IProfile profile = defaultProfile;

                foreach (var candidateProfile in profiles.Values)
                {
                    if (!candidateProfile.IsAppropriateForSolution(buildResult))
                    {
                        continue;
                    }

                    InformationWriteLine("// Auto-selected the profile '{0}' for this project.", candidateProfile.GetType().Name);
                    profile = candidateProfile;
                    break;
                }

                var localVariables = config.ApplyTo(new VariableSet());
                localVariables["SolutionDirectory"] = () => solutionDir;

                // HACK to let you use assemblyname/etc when copying output files.
                var buildResultAssembly =
                    buildResult.OutputFiles.FirstOrDefault((fn) => Path.GetExtension(fn) == ".exe") ??
                    buildResult.OutputFiles.FirstOrDefault((fn) => Path.GetExtension(fn) == ".dll");

                if (buildResultAssembly != null)
                {
                    localVariables.SetAssemblyPath(buildResultAssembly);
                }

                var processStarted = DateTime.UtcNow.Ticks;
                profile.ProcessBuildResult(
                    localVariables,
                    profile.GetConfiguration(config),
                    buildResult
                    );
                var processEnded = DateTime.UtcNow.Ticks;

                {
                    var logPath = localVariables.ExpandPath(String.Format(
                                                                "%outputdirectory%/{0}.buildlog", Path.GetFileName(solution)
                                                                ), false);

                    if (!Directory.Exists(Path.GetDirectoryName(logPath)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(logPath));
                    }

                    using (var logWriter = new StreamWriter(logPath, false, Encoding.UTF8)) {
                        logWriter.WriteLine(
                            "Build of solution '{0}' processed {1} task(s) and produced {2} result file(s):",
                            solution, buildResult.AllItemsBuilt.Length, buildResult.OutputFiles.Length
                            );

                        foreach (var of in buildResult.OutputFiles)
                        {
                            logWriter.WriteLine(of);
                        }

                        logWriter.WriteLine("----");
                        logWriter.WriteLine("Elapsed build time: {0:0000.0} second(s).", TimeSpan.FromTicks(buildEnded - buildStarted).TotalSeconds);
                        logWriter.WriteLine("Selected profile '{0}' to process results of this build.", profile.GetType().Name);
                        logWriter.WriteLine("Elapsed processing time: {0:0000.0} second(s).", TimeSpan.FromTicks(processEnded - processStarted).TotalSeconds);
                    }
                }

                var outputFiles = buildResult.OutputFiles.Concat(
                    (from eo in config.SolutionBuilder.ExtraOutputs
                     let expanded = localVariables.ExpandPath(eo, true)
                                    select expanded)
                    ).ToArray();

                if (outputFiles.Length > 0)
                {
                    var sa = new HashSet <string>();

                    var group = new BuildGroup {
                        BaseConfiguration = mergedSolutionConfig,
                        BaseVariables     = localVariables,
                        FilesToBuild      = PurgeDuplicateFilesFromBuildGroup(outputFiles, assemblyCache, sa),
                        Profile           = profile,
                    };
                    group.SkippedAssemblies = sa.ToArray();

                    buildGroups.Add(group);
                }
            }

            var assemblyNames = (from fn in filenames
                                 where Path.GetExtension(fn).Contains(",") ||
                                 Path.GetExtension(fn).Contains(" ") ||
                                 Path.GetExtension(fn).Contains("=")
                                 select fn).ToArray();

            var resolver           = new Mono.Cecil.DefaultAssemblyResolver();
            var metaResolver       = new CachingMetadataResolver(resolver);
            var resolverParameters = new ReaderParameters {
                AssemblyResolver = resolver,
                MetadataResolver = metaResolver,
                ReadSymbols      = false,
                ReadingMode      = ReadingMode.Deferred,
            };
            var resolvedAssemblyPaths = (from an in assemblyNames
                                         let asm = resolver.Resolve(an, resolverParameters)
                                                   where asm != null
                                                   select asm.MainModule.FullyQualifiedName).ToArray();

            var mainGroup = (from fn in filenames
                             where
                             (new[] { ".exe", ".dll" }.Contains(Path.GetExtension(fn)))
                             select fn)
                            .Concat(resolvedAssemblyPaths)
                            .ToArray();

            if (mainGroup.Length > 0)
            {
                var variables = commandLineConfig.ApplyTo(new VariableSet());

                // Fail early if any assemblies are missing
                foreach (var filename in mainGroup)
                {
                    if (!File.Exists(filename))
                    {
                        throw new FileNotFoundException(filename);
                    }
                }

                buildGroups.Add(new BuildGroup {
                    BaseConfiguration = baseConfig,
                    BaseVariables     = variables,
                    FilesToBuild      = mainGroup,
                    Profile           = defaultProfile
                });
            }

            return(commandLineConfig);
        }
コード例 #21
0
 protected override Rule OnCreate(AssemblyCache cache, IReportViolations reporter)
 {
     return(new AvoidReRegisterForFinalizeRule(cache, reporter));
 }
コード例 #22
0
ファイル: GenericTestFixture.cs プロジェクト: poizan42/JSIL
        private CompileResult RunComparisonTest(
            string filename, string[] stubbedAssemblies = null, TypeInfoProvider typeInfo = null, Action<string, string> errorCheckPredicate = null,
            List<string> failureList = null, string commonFile = null, bool shouldRunJs = true, AssemblyCache asmCache = null,
            Func<Configuration> makeConfiguration = null, Action<Exception> onTranslationFailure = null,
            string compilerOptions = ""
        )
        {
            CompileResult result = null;
            Console.WriteLine("// {0} ... ", Path.GetFileName(filename));
            filename = Portability.NormalizeDirectorySeparators(filename);

            try {
                var testFilenames = new List<string>() { filename };
                if (commonFile != null)
                    testFilenames.Add(commonFile);

                using (var test = new ComparisonTest(
                    EvaluatorPool,
                    testFilenames,
                    Path.Combine(
                        ComparisonTest.TestSourceFolder,
                        ComparisonTest.MapSourceFileToTestFile(filename)
                    ),
                    stubbedAssemblies, typeInfo, asmCache,
                    compilerOptions: compilerOptions
                )) {
                    result = test.CompileResult;

                    if (shouldRunJs) {
                        test.Run(makeConfiguration: makeConfiguration, onTranslationFailure: onTranslationFailure);
                    } else {
                        string js;
                        long elapsed;
                        try {
                            var csOutput = test.RunCSharp(new string[0], out elapsed);
                            test.GenerateJavascript(new string[0], out js, out elapsed, makeConfiguration, onTranslationFailure);

                            Console.WriteLine("generated");

                            if (errorCheckPredicate != null) {
                                errorCheckPredicate(csOutput, js);
                            }
                        } catch (Exception) {
                            Console.WriteLine("error");
                            throw;
                        }
                    }
                }
            } catch (Exception ex) {
                if (ex.Message == "JS test failed")
                    Debug.WriteLine(ex.InnerException);
                else
                    Debug.WriteLine(ex);

                if (failureList != null) {
                    failureList.Add(Path.GetFileNameWithoutExtension(filename));
                } else
                    throw;
            }

            return result;
        }
コード例 #23
0
ファイル: Key.ForeignT.cs プロジェクト: fagan2888/Schematic
            // Rather ugly, but this is where the magic happens.
            // Intended to parse what the selector function really points to so that we can bind
            // a PropertyInfo object on the resulting key before we use it later via reflection.
            private PropertyInfo GetTargetProperty()
            {
                if (Property == null)
                {
                    throw new InvalidOperationException("The property that the foreign key belongs to is not available.");
                }

                var sourceType    = Property.ReflectedType;
                var sourceAsm     = sourceType.Assembly;
                var sourceAsmName = sourceAsm.GetName();

                var sourceAsmDefinition = AssemblyCache.GetOrAdd(sourceAsmName, _ => new Lazy <AssemblyDefinition>(() => AssemblyDefinition.ReadAssembly(sourceAsm.Location))).Value;

                // Mono.Cecil uses '/' to declare nested type names instead of '+'
                var sourceSearchTypeName = sourceType.FullName.Replace('+', '/');
                var sourceTypeDefinition = sourceAsmDefinition.MainModule.GetType(sourceSearchTypeName);
                var sourceProperty       = sourceTypeDefinition.Properties.SingleOrDefault(p => p.Name == Property.Name && !p.HasParameters);

                if (sourceProperty == null)
                {
                    throw new ArgumentException(
                              "Could not find the source property "
                              + Property.ReflectedType.FullName + "." + Property.Name
                              + ". Check that assemblies are up to date.",
                              Property.ReflectedType.FullName + "." + Property.Name
                              );
                }

                var sourcePropInstructions = sourceProperty.GetMethod.Body.Instructions;
                var fnInstruction          = sourcePropInstructions.FirstOrDefault(i => i.OpCode.Code == Code.Ldftn);

                if (fnInstruction == null)
                {
                    throw new ArgumentException(
                              "Could not find function pointer instruction in the get method of the source property "
                              + Property.ReflectedType.FullName + "." + Property.Name
                              + ". Is the key selector method a simple lambda expression?",
                              Property.ReflectedType.FullName + "." + Property.Name
                              );
                }

                if (!(fnInstruction.Operand is MethodDefinition fnOperand))
                {
                    throw new ArgumentException(
                              "Expected to find a method definition associated with a function pointer instruction but could not find one for "
                              + Property.ReflectedType.FullName + "." + Property.Name + ".",
                              Property.ReflectedType.FullName + "." + Property.Name
                              );
                }

                var operandInstructions = fnOperand.Body.Instructions;
                var bodyCallInstr       = operandInstructions.FirstOrDefault(i => i.OpCode.Code == Code.Callvirt || i.OpCode.Code == Code.Call);

                if (bodyCallInstr == null)
                {
                    throw new ArgumentException(
                              "Could not find call or virtual call instruction in the key selector function that was provided to "
                              + Property.ReflectedType.FullName + "." + Property.Name
                              + ". Is the key selector method a simple lambda expression?",
                              Property.ReflectedType.FullName + "." + Property.Name
                              );
                }

                if (!(bodyCallInstr.Operand is MethodDefinition bodyMethodDef))
                {
                    throw new ArgumentException("Expected to find a method definition associated with the call or virtual call instruction but could not find one in the key selector.");
                }

                var targetPropertyName = bodyMethodDef.Name;
                var targetProp         = TargetType.GetProperties().SingleOrDefault(p => p.GetGetMethod().Name == targetPropertyName && p.GetIndexParameters().Length == 0);

                if (targetProp == null)
                {
                    throw new ArgumentException(
                              $"Expected to find a property named { targetPropertyName } in { TargetType.FullName } but could not find one.",
                              Property.ReflectedType.FullName + "." + Property.Name
                              );
                }

                return(targetProp);
            }
コード例 #24
0
 public RequireSerializableCtorRule(AssemblyCache cache, IReportViolations reporter)
     : base(cache, reporter, "R1019")
 {
 }
コード例 #25
0
 public WeakIdentityLockRule(AssemblyCache cache, IReportViolations reporter)
     : base(cache, reporter, "R1013")
 {
 }
コード例 #26
0
 public AvoidEmptyInterfacesRule(AssemblyCache cache, IReportViolations reporter)
     : base(cache, reporter, "D1005")
 {
 }
コード例 #27
0
 protected override Rule OnCreate(AssemblyCache cache, IReportViolations reporter)
 {
     return(new SpecialFolderRule(cache, reporter));
 }
コード例 #28
0
 protected override Rule OnCreate(AssemblyCache cache, IReportViolations reporter)
 {
     return(new TypedCollectionRule(cache, reporter));
 }
コード例 #29
0
 protected override Rule OnCreate(AssemblyCache cache, IReportViolations reporter)
 {
     return(new SwallowExceptionRule(cache, reporter));
 }
コード例 #30
0
 public TypedCollectionRule(AssemblyCache cache, IReportViolations reporter)
     : base(cache, reporter, "D1013")
 {
     Runtime = TargetRuntime.NET_2_0;
 }
コード例 #31
0
 protected override Rule OnCreate(AssemblyCache cache, IReportViolations reporter)
 {
     return(new DoubleCheckedLockingRule(cache, reporter));
 }
コード例 #32
0
ファイル: ComparisonTest.cs プロジェクト: elw00d/JSIL
        public ComparisonTest(
            EvaluatorPool pool,
            IEnumerable <string> filenames, string outputPath,
            string[] stubbedAssemblies  = null, TypeInfoProvider typeInfo = null,
            AssemblyCache assemblyCache = null, string compilerOptions    = ""
            )
        {
            var started = DateTime.UtcNow.Ticks;

            OutputPath    = outputPath;
            EvaluatorPool = pool;

            var extensions        = (from f in filenames select Path.GetExtension(f).ToLower()).Distinct().ToArray();
            var absoluteFilenames = (from f in filenames select Path.Combine(TestSourceFolder, Portability.NormalizeDirectorySeparators(f)));

            if (extensions.Length != 1)
            {
                throw new InvalidOperationException("Mixture of different source languages provided.");
            }

            var assemblyNamePrefix = Path.GetDirectoryName(outputPath).Split(new char[] { '\\', '/' }).Last();
            var assemblyName       = Path.Combine(
                assemblyNamePrefix,
                Path.GetFileName(outputPath).Replace(".js", "")
                );

            JSFilenames = null;

            switch (extensions[0])
            {
            case ".exe":
            case ".dll":
                var fns = absoluteFilenames.ToArray();
                if (fns.Length > 1)
                {
                    throw new InvalidOperationException("Multiple binary assemblies provided.");
                }

                Assembly = Assembly.LoadFile(fns[0]);
                break;

            case ".js":
                JSFilenames   = absoluteFilenames.ToArray();
                CompileResult = null;
                Assembly      = null;
                break;

            default:
                CompileResult = CompilerUtil.Compile(absoluteFilenames, assemblyName, compilerOptions: compilerOptions);
                Assembly      = CompileResult.Assembly;
                break;
            }

            if (typeInfo != null)
            {
                typeInfo.ClearCaches();
            }

            StubbedAssemblies = stubbedAssemblies;
            TypeInfo          = typeInfo;
            AssemblyCache     = assemblyCache;

            var ended = DateTime.UtcNow.Ticks;

            CompilationElapsed = TimeSpan.FromTicks(ended - started);
        }
コード例 #33
0
ファイル: GenericTestFixture.cs プロジェクト: poizan42/JSIL
        protected IEnumerable<TestCaseData> FolderTestSource(string folderName, TypeInfoProvider typeInfo = null, AssemblyCache asmCache = null)
        {
            var testPath = Path.GetFullPath(Path.Combine(ComparisonTest.TestSourceFolder, folderName));
            var testNames = Directory.GetFiles(testPath, "*.cs")
                .Concat(Directory.GetFiles(testPath, "*.vb"))
                .Concat(Directory.GetFiles(testPath, "*.fs"))
                .OrderBy((s) => s).ToArray();

            string commonFile = null;

            foreach (var testName in testNames) {
                if (Path.GetFileNameWithoutExtension(testName) == "Common") {
                    commonFile = testName;
                    break;
                }
            }

            for (int i = 0, l = testNames.Length; i < l; i++) {
                var testName = testNames[i];
                if (Path.GetFileNameWithoutExtension(testName) == "Common")
                    continue;

                yield return (new TestCaseData(new object[] { new object[] { testName, typeInfo, asmCache, commonFile, i == (l - 1) } }))
                    .SetName(PickTestNameForFilename(testName))
                    .SetDescription(String.Format("{0}\\{1}", folderName, Path.GetFileName(testName)))
                    .SetCategory(folderName);
            }
        }
コード例 #34
0
 protected override Rule OnCreate(AssemblyCache cache, IReportViolations reporter)
 {
     return(new BaseDisposeableRule(cache, reporter));
 }
コード例 #35
0
ファイル: Program.cs プロジェクト: simon-heinen/JSIL
        static void Main(string[] arguments)
        {
            SolutionBuilder.SolutionBuilder.HandleCommandLine();

            var buildGroups = new List<BuildGroup>();
            var profiles = new Dictionary<string, IProfile>();
            var manifest = new AssemblyManifest();
            var assemblyCache = new AssemblyCache();

            var commandLineConfiguration = ParseCommandLine(arguments, buildGroups, profiles);

            if ((buildGroups.Count < 1) || (commandLineConfiguration == null)) {
                Console.Error.WriteLine("// No assemblies specified to translate. Exiting.");
            }

            int totalFailureCount = 0;

            foreach (var buildGroup in buildGroups) {
                var config = buildGroup.BaseConfiguration;
                var variables = buildGroup.BaseVariables;

                foreach (var filename in buildGroup.FilesToBuild) {
                    if (config.Assemblies.Ignored.Any(
                        (ignoreRegex) => Regex.IsMatch(filename, ignoreRegex, RegexOptions.IgnoreCase))
                    ) {
                        Console.Error.WriteLine("// Ignoring build result '{0}' based on configuration.", Path.GetFileName(filename));
                        continue;
                    }

                    var fileConfigPath = Path.Combine(
                        Path.GetDirectoryName(filename),
                        String.Format("{0}.jsilconfig", Path.GetFileName(filename))
                    );
                    var fileConfig = File.Exists(fileConfigPath)
                        ? new Configuration[] { LoadConfiguration(fileConfigPath), commandLineConfiguration }
                        : new Configuration[] { commandLineConfiguration };

                    var localConfig = MergeConfigurations(config, fileConfig);

                    var localProfile = buildGroup.Profile;
                    if (localConfig.Profile != null) {
                        if (profiles.ContainsKey(localConfig.Profile))
                            localProfile = profiles[localConfig.Profile];
                        else
                            throw new Exception(String.Format(
                                "No profile named '{0}' was found. Did you load the correct profile assembly?", localConfig.Profile
                            ));
                    }

                    localConfig = localProfile.GetConfiguration(localConfig);
                    var localVariables = localConfig.ApplyTo(variables);

                    var assemblyPath = Path.GetDirectoryName(Path.GetFullPath(filename));
                    localVariables["AssemblyDirectory"] = () => assemblyPath;

                    var newProxies = (from p in localConfig.Assemblies.Proxies
                                      let newP = MapPath(p, localVariables, true, true)
                                      where newP != null
                                      select newP).ToArray();

                    localConfig.Assemblies.Proxies.Clear();
                    localConfig.Assemblies.Proxies.AddRange(newProxies);

                    using (var translator = CreateTranslator(localConfig, manifest, assemblyCache)) {
                        var ignoredMethods = new List<KeyValuePair<string, string[]>>();
                        translator.IgnoredMethod += (methodName, variableNames) =>
                            ignoredMethods.Add(new KeyValuePair<string, string[]>(methodName, variableNames));

                        var outputs = buildGroup.Profile.Translate(localVariables, translator, localConfig, filename, localConfig.UseLocalProxies.GetValueOrDefault(true));
                        if (localConfig.OutputDirectory == null)
                            throw new Exception("No output directory was specified!");

                        var outputDir = MapPath(localConfig.OutputDirectory, localVariables, false);
                        CopiedOutputGatherer.EnsureDirectoryExists(outputDir);

                        Console.Error.WriteLine("// Saving output to '{0}'.", ShortenPath(outputDir) + Path.DirectorySeparatorChar);

                        // Ensures that the log file contains the name of the profile that was actually used.
                        localConfig.Profile = localProfile.GetType().Name;

                        if (ignoredMethods.Count > 0)
                            Console.Error.WriteLine("// {0} method(s) were ignored during translation. See the log for a list.", ignoredMethods.Count);

                        EmitLog(outputDir, localConfig, filename, outputs, ignoredMethods);

                        buildGroup.Profile.WriteOutputs(localVariables, outputs, outputDir, Path.GetFileName(filename) + ".");

                        totalFailureCount += translator.Failures.Count;
                    }
                }
            }

            if (Environment.UserInteractive && Debugger.IsAttached) {
                Console.Error.WriteLine("// Press the any key to continue.");
                Console.ReadKey();
            }

            Environment.ExitCode = totalFailureCount;
        }
コード例 #36
0
 protected override Rule OnCreate(AssemblyCache cache, IReportViolations reporter)
 {
     return(new ConsistentEqualityRule(cache, reporter));
 }
コード例 #37
0
ファイル: Program.cs プロジェクト: yongweisun/JSIL
        static AssemblyTranslator CreateTranslator(
            Configuration configuration, AssemblyManifest manifest, AssemblyCache assemblyCache,
            Dictionary <string, IEmitterFactory> emitterFactories,
            Dictionary <string, IAnalyzer> analyzers
            )
        {
            TypeInfoProvider typeInfoProvider = null;

            InformationWriteLine(
                "// Using .NET framework {0} in {1} GC mode. Tuned GC {2}.",
                Environment.Version.ToString(),
                System.Runtime.GCSettings.IsServerGC ? "server" : "workstation",
                configuration.TuneGarbageCollection.GetValueOrDefault(true) ? "enabled" : "disabled"
                );

            if (
                configuration.ReuseTypeInfoAcrossAssemblies.GetValueOrDefault(true) &&
                (CachedTypeInfoProvider != null)
                )
            {
                if (CachedTypeInfoProviderConfiguration.Assemblies.Equals(configuration.Assemblies))
                {
                    typeInfoProvider = CachedTypeInfoProvider;
                }
            }

            IEmitterFactory emitterFactory = GetEmitterFactory(configuration, emitterFactories);

            var translator = new AssemblyTranslator(
                configuration, typeInfoProvider, manifest, new AssemblyDataResolver(configuration, assemblyCache),
                onProxyAssemblyLoaded: (name, classification) =>
                InformationWriteLine("// Loaded proxies from '{0}'", ShortenPath(name)),
                emitterFactory: emitterFactory,
                analyzers: analyzers.Values
                );

            translator.Decompiling       += MakeProgressHandler("Decompiling ");
            translator.RunningTransforms += MakeProgressHandler("Translating ");
            translator.Writing           += MakeProgressHandler("Writing JS  ");

            translator.AssemblyLoaded += (fn, classification) =>
                                         InformationWriteLine("// Loaded {0} ({1})", ShortenPath(fn), classification);
            translator.CouldNotLoadSymbols     += (fn, ex) => {
            };
            translator.CouldNotResolveAssembly += (fn, ex) =>
                                                  Console.Error.WriteLine("// Could not load module {0}: {1}", fn, ex.Message);
            translator.CouldNotDecompileMethod += (fn, ex) =>
                                                  Console.Error.WriteLine("// Could not decompile method {0}: {1}", fn, ex);

            if (configuration.ProxyWarnings.GetValueOrDefault(false))
            {
                translator.ProxyNotMatched += (ti) => {
                    Console.Error.WriteLine("// Proxy {0} never matched any types.", ti);
                };

                translator.ProxyMemberNotMatched += (qmi) => {
                    Console.Error.WriteLine("// Proxy member {0} never matched any members.", qmi);
                };
            }

            if (typeInfoProvider == null)
            {
                if (CachedTypeInfoProvider != null)
                {
                    CachedTypeInfoProvider.Dispose();
                }

                CachedTypeInfoProvider = translator.GetTypeInfoProvider();
                CachedTypeInfoProviderConfiguration = configuration;
            }

            return(translator);
        }
コード例 #38
0
 public WinExeRule(AssemblyCache cache, IReportViolations reporter)
     : base(cache, reporter, "PO1008")
 {
 }
コード例 #39
0
ファイル: Program.cs プロジェクト: yongweisun/JSIL
        static string[] PurgeDuplicateFilesFromBuildGroup(
            string[] buildGroupFiles,
            AssemblyCache assemblyCache,
            HashSet <string> skippedAssemblies
            )
        {
            var result = new List <string>();

            var topLevelAssemblies =
                (from fn in buildGroupFiles
                 select new {
                Filename = fn,
                Assembly = TryReadAssembly(fn)
            })
                .Where(o => o.Assembly != null)
                .ToArray();

            var executables =
                (from kvp in topLevelAssemblies
                 where kvp.Filename.EndsWith(".exe")
                 select new {
                Filename = kvp.Filename,
                Assembly = kvp.Assembly,
                AllReferencesRecursive = new List <AssemblyNameReference>()
            }).ToArray();

            foreach (var executable in executables)
            {
                var assembliesToScan = new Stack <AssemblyDefinition>();
                assembliesToScan.Push(executable.Assembly);

                while (assembliesToScan.Count > 0)
                {
                    var assembly = assembliesToScan.Pop();
                    foreach (var module in assembly.Modules)
                    {
                        foreach (var anr in module.AssemblyReferences)
                        {
                            executable.AllReferencesRecursive.Add(anr);

                            var matchingAssembly = topLevelAssemblies.FirstOrDefault(
                                (tla) => tla.Assembly.FullName == anr.FullName
                                );
                            if (matchingAssembly != null)
                            {
                                assembliesToScan.Push(matchingAssembly.Assembly);
                            }
                        }
                    }
                }
            }

            foreach (var kvpOuter in topLevelAssemblies)
            {
                foreach (var kvpInner in executables)
                {
                    if (kvpInner.Filename == kvpOuter.Filename)
                    {
                        continue;
                    }

                    // If an executable references a DLL, we can be sure the DLL is going to get built anyway.
                    foreach (var anr in kvpInner.AllReferencesRecursive)
                    {
                        if (anr.FullName == kvpOuter.Assembly.FullName)
                        {
                            InformationWriteLine("// Not translating '{0}' directly because '{1}' references it.", Path.GetFileName(kvpOuter.Filename), Path.GetFileName(kvpInner.Filename));
                            skippedAssemblies.Add(kvpOuter.Filename);
                            goto skip;
                        }
                    }
                }

                result.Add(kvpOuter.Filename);

skip:
                ;
            }

            return(result.ToArray());
        }
コード例 #40
0
ファイル: EqualsCantCastTest.cs プロジェクト: dbremner/smokey
 protected override Rule OnCreate(AssemblyCache cache, IReportViolations reporter)
 {
     return(new EqualsCantCastRule1(cache, reporter));
 }
コード例 #41
0
 public SecureOverridesRule(AssemblyCache cache, IReportViolations reporter)
     : base(cache, reporter, "S1016")
 {
 }
コード例 #42
0
 protected override Rule OnCreate(AssemblyCache cache, IReportViolations reporter)
 {
     return new PublicAbstractCtorRule(cache, reporter);
 }
コード例 #43
0
ファイル: ValidateArgs2Test.cs プロジェクト: dbremner/smokey
 protected override Rule OnCreate(AssemblyCache cache, IReportViolations reporter)
 {
     return(new ValidateArgs2Rule(cache, reporter));
 }
コード例 #44
0
		public SynchronizedAttributeRule(AssemblyCache cache, IReportViolations reporter) 
			: base(cache, reporter, "MS1015")
		{
		}
コード例 #45
0
ファイル: PrivateNeedsDoRule.cs プロジェクト: dbremner/smokey
		// The checkID must match the id in the xml. Note that multiple classes can
		// share the same checkID.
		public PrivateNeedsDoRule(AssemblyCache cache, IReportViolations reporter) 
			: base(cache, reporter, "CU1000 - example custom rules")
		{
		}
コード例 #46
0
ファイル: TooManyArgsRule.cs プロジェクト: dbremner/smokey
		public TooManyArgsRule(AssemblyCache cache, IReportViolations reporter) 
			: base(cache, reporter, "D1047")
		{
		}
コード例 #47
0
		public DllImportExtensionRule(AssemblyCache cache, IReportViolations reporter) 
			: base(cache, reporter, "PO1002")
		{
		}
コード例 #48
0
 public BaseDisposeableRule(AssemblyCache cache, IReportViolations reporter)
     : base(cache, reporter, "D1063")
 {
 }
コード例 #49
0
 protected override Rule OnCreate(AssemblyCache cache, IReportViolations reporter)
 {
     return new SealedInheritanceDemandRule(cache, reporter);
 }
コード例 #50
0
        private static void UnregisterDll(String moduleName, Boolean log = false)
        {
            ////String embedResourcePath = "DXApplication";
            ////String embedResourceCategoryPath = "Path";
            String dllModuleName = moduleName;

            //  Create an assembly cache enumerator.
            var assemblyCacheEnum = new AssemblyCacheEnumerator(null);

            //  Enumerate the assemblies.
            var assemblyName = assemblyCacheEnum.GetNextAssembly();

            while (assemblyName != null)
            {
                //  Create the assembly description.
                var desc = new AssemblyDescription(assemblyName);

                if (desc.Name.Equals(dllModuleName))
                {
                    //  We'll need a display name of the assembly to uninstall.
                    ////var displayName = @"Apex, Version=1.4.0.0, Culture=neutral, PublicKeyToken=98d06957926c086d, processorArchitecture=MSIL";
                    var displayName = desc.DisplayName;
                    //  When we try to uninstall an assembly, an uninstall disposition will be
                    //  set to indicate the success of the operation.
                    var uninstallDisposition = IASSEMBLYCACHE_UNINSTALL_DISPOSITION.Unknown;

                    //  Install the assembly, without an install reference.
                    try
                    {
                        AssemblyCache.UninstallAssembly(displayName, null, out uninstallDisposition);
                        //  Depending on the result, show the appropriate message.
                        string message = string.Empty;
                        switch (uninstallDisposition)
                        {
                        case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.Unknown:
                            message = "Failed to uninstall assembly.";
                            break;

                        case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_UNINSTALLED:
                            message = "The assembly was uninstalled successfully!";
                            break;

                        case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_STILL_IN_USE:
                            message = "Cannot uninstall this assembly - it is in use.";
                            break;

                        case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_ALREADY_UNINSTALLED:
                            message = "Cannot uninstall this assembly - it has already been uninstalled.";
                            break;

                        case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_DELETE_PENDING:
                            message = "Cannot uninstall this assembly - it has has a delete pending.";
                            break;

                        case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_HAS_INSTALL_REFERENCES:
                            message = "Cannot uninstall this assembly - it was installed as part of another product.";
                            break;

                        case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_REFERENCE_NOT_FOUND:
                            message = "Cannot uninstall this assembly - cannot find the assembly.";
                            break;

                        default:
                            break;
                        }
                        if (log)
                        {
                        }
                    }
                    catch (Exception exception)
                    {
                        //  We've failed to uninstall the assembly.
                        throw new InvalidOperationException("Failed to uninstall the assembly.", exception);
                    }
                    finally
                    {
                        ////////assemblyName = null;
                    }
                    //  Did we succeed?
                    if (uninstallDisposition == IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_UNINSTALLED)
                    {
                        //  Hooray!
                        if (false)
                        {
                            assemblyName = null;
                        }
                        else
                        {
                            //  Create an assembly cache enumerator.
                            assemblyCacheEnum = new AssemblyCacheEnumerator(null);
                            //  Enumerate the assemblies.
                            assemblyName = assemblyCacheEnum.GetNextAssembly();
                        }
                    }
                }
                else
                {
                    assemblyName = assemblyCacheEnum.GetNextAssembly();
                }
            }
        }
コード例 #51
0
 protected override Rule OnCreate(AssemblyCache cache, IReportViolations reporter)
 {
     return new OptionalSerializationRule(cache, reporter);
 }
コード例 #52
0
        private static AssemblyDescription GetGacAssemblyPath(String moduleName)
        {
            ////String embedResourcePath = "DXApplication";
            ////String embedResourceCategoryPath = "Path";
            String dllModuleName = moduleName;

            //  Create an assembly cache enumerator.
            var assemblyCacheEnum = new AssemblyCacheEnumerator(null);

            //  Enumerate the assemblies.
            var assemblyName = assemblyCacheEnum.GetNextAssembly();

            while (assemblyName != null)
            {
                //  Create the assembly description.
                var desc = new AssemblyDescription(assemblyName);

                if (desc.Name.Equals(dllModuleName))
                {
                    //  We'll need a display name of the assembly to uninstall.
                    ////var displayName = @"Apex, Version=1.4.0.0, Culture=neutral, PublicKeyToken=98d06957926c086d, processorArchitecture=MSIL";
                    var displayName = desc.DisplayName;
                    //  When we try to uninstall an assembly, an uninstall disposition will be
                    //  set to indicate the success of the operation.
                    var uninstallDisposition = IASSEMBLYCACHE_UNINSTALL_DISPOSITION.Unknown;

                    //  Install the assembly, without an install reference.
                    try
                    {
                        IAssemblyCache ac = AssemblyCache.GetIAssemblyCache(displayName, null);
                        if (ac != null)
                        {
                            return(desc);
                        }
                    }
                    catch (Exception exception)
                    {
                        //  We've failed to uninstall the assembly.
                        throw new InvalidOperationException("Failed to uninstall the assembly.", exception);
                    }
                    finally
                    {
                        ////////assemblyName = null;
                    }
                    //////////  Did we succeed?
                    ////////if (uninstallDisposition == IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_UNINSTALLED)
                    ////////{
                    ////////    //  Hooray!
                    ////////    if (false)
                    ////////    {
                    ////////        assemblyName = null;
                    ////////    }
                    ////////    else
                    ////////    {
                    ////////        //  Create an assembly cache enumerator.
                    ////////        assemblyCacheEnum = new AssemblyCacheEnumerator(null);
                    ////////        //  Enumerate the assemblies.
                    ////////        assemblyName = assemblyCacheEnum.GetNextAssembly();
                    ////////    }
                    ////////}
                }
                else
                {
                    assemblyName = assemblyCacheEnum.GetNextAssembly();
                }
            }
            return(null);
        }
コード例 #53
0
ファイル: EventHandlerTest.cs プロジェクト: dbremner/smokey
 protected override Rule OnCreate(AssemblyCache cache, IReportViolations reporter)
 {
     return new EventHandlerRule(cache, reporter);
 }
コード例 #54
0
 public Aptca2Rule(AssemblyCache cache, IReportViolations reporter)
     : base(cache, reporter, "S1001")
 {
 }
コード例 #55
0
ファイル: GenericTestFixture.cs プロジェクト: poizan42/JSIL
        /// <summary>
        /// Runs one or more comparison tests by compiling the source C# or VB.net file,
        ///     running the compiled test method, translating the compiled test method to JS,
        ///     then running the translated JS and comparing the outputs.
        /// </summary>
        /// <param name="filenames">The path to one or more test files. If a test file is named 'Common.cs' it will be linked into all tests.</param>
        /// <param name="stubbedAssemblies">The paths of assemblies to stub during translation, if any.</param>
        /// <param name="typeInfo">A TypeInfoProvider to use for type info. Using this parameter is not advised if you use proxies or JSIL.Meta attributes in your tests.</param>
        /// <param name="testPredicate">A predicate to invoke before running each test. If the predicate returns false, the JS version of the test will not be run (though it will be translated).</param>
        protected void RunComparisonTests(
            string[] filenames, string[] stubbedAssemblies = null,
            TypeInfoProvider typeInfo = null,
            Func<string, bool> testPredicate = null,
            Action<string, string> errorCheckPredicate = null,
            Func<Configuration> getConfiguration = null
        )
        {
            var started = DateTime.UtcNow.Ticks;

            string commonFile = null;
            for (var i = 0; i < filenames.Length; i++) {
                if (filenames[i].Contains(Path.Combine ("", "Common."))) {
                    commonFile = filenames[i];
                    break;
                }
            }

            const string keyName = @"Software\Squared\JSIL\Tests\PreviousFailures";

            StackFrame callingTest = null;
            for (int i = 1; i < 10; i++) {
                callingTest = new StackFrame(i);
                var method = callingTest.GetMethod();
                if ((method != null) && method.GetCustomAttributes(true).Any(
                    (ca) => ca.GetType().FullName == "NUnit.Framework.TestAttribute"
                )) {
                    break;
                } else {
                    callingTest = null;
                }
            }

            var previousFailures = new HashSet<string>();
            MethodBase callingMethod = null;
            if ((callingTest != null) && ((callingMethod = callingTest.GetMethod()) != null)) {
                try {
                    using (var rk = Registry.CurrentUser.CreateSubKey(keyName)) {
                        var names = rk.GetValue(callingMethod.Name) as string;
                        if (names != null) {
                            foreach (var name in names.Split(',')) {
                                previousFailures.Add(name);
                            }
                        }
                    }
                } catch (Exception ex) {
                    Console.WriteLine("Warning: Could not open registry key: {0}", ex);
                }
            }

            var failureList = new List<string>();
            var sortedFilenames = new List<string>(filenames);
            sortedFilenames.Sort(
                (lhs, rhs) => {
                    var lhsShort = Path.GetFileNameWithoutExtension(lhs);
                    var rhsShort = Path.GetFileNameWithoutExtension(rhs);

                    int result =
                        (previousFailures.Contains(lhsShort) ? 0 : 1).CompareTo(
                            previousFailures.Contains(rhsShort) ? 0 : 1
                        );

                    if (result == 0)
                        result = lhsShort.CompareTo(rhsShort);

                    return result;
                }
            );

            var asmCache = new AssemblyCache();

            foreach (var filename in sortedFilenames) {
                if (filename == commonFile)
                    continue;

                bool shouldRunJs = true;
                if (testPredicate != null)
                    shouldRunJs = testPredicate(filename);

                RunComparisonTest(
                    filename, stubbedAssemblies, typeInfo,
                    errorCheckPredicate, failureList,
                    commonFile, shouldRunJs, asmCache,
                    getConfiguration ?? MakeConfiguration
                );
            }

            if (callingMethod != null) {
                try {
                    using (var rk = Registry.CurrentUser.CreateSubKey(keyName))
                        rk.SetValue(callingMethod.Name, String.Join(",", failureList.ToArray()));
                } catch (Exception ex) {
                    Console.WriteLine("Warning: Could not open registry key: {0}", ex);
                }
            }

            var ended = DateTime.UtcNow.Ticks;
            var elapsedTotalSeconds = TimeSpan.FromTicks(ended - started).TotalSeconds;
            Console.WriteLine("// Ran {0} test(s) in {1:000.00}s.", sortedFilenames.Count, elapsedTotalSeconds);

            Assert.AreEqual(0, failureList.Count,
                String.Format("{0} test(s) failed:\r\n{1}", failureList.Count, String.Join("\r\n", failureList.ToArray()))
            );
        }
コード例 #56
0
 protected override Rule OnCreate(AssemblyCache cache, IReportViolations reporter)
 {
     return(new VisibleEventHandlerRule(cache, reporter));
 }
コード例 #57
0
 protected override Rule OnCreate(AssemblyCache cache, IReportViolations reporter)
 {
     return new IntegerOverflowRule(cache, reporter);
 }
コード例 #58
0
ファイル: Program.cs プロジェクト: yongweisun/JSIL
        static void InternalMain(string[] arguments)
        {
            SolutionBuilder.SolutionBuilder.HandleCommandLine();

            var buildGroups         = new List <BuildGroup>();
            var profiles            = new Dictionary <string, IProfile>();
            var analyzers           = new Dictionary <string, IAnalyzer>();
            var emitterFactories    = new Dictionary <string, IEmitterFactory>();
            var manifest            = new AssemblyManifest();
            var assemblyCache       = new AssemblyCache();
            var processedAssemblies = new HashSet <string>();

            var commandLineConfiguration = ParseCommandLine(arguments, buildGroups, profiles, analyzers, emitterFactories, assemblyCache);

            if ((buildGroups.Count < 1) || (commandLineConfiguration == null))
            {
                Console.Error.WriteLine("// No assemblies specified to translate. Exiting.");
            }

            int totalFailureCount = 0;

            foreach (var buildGroup in buildGroups)
            {
                var config    = buildGroup.BaseConfiguration;
                var variables = buildGroup.BaseVariables;

                foreach (var filename in buildGroup.FilesToBuild)
                {
                    if (config.Assemblies.Ignored.Any(
                            (ignoreRegex) => Regex.IsMatch(filename, ignoreRegex, RegexOptions.IgnoreCase))
                        )
                    {
                        InformationWriteLine("// Ignoring build result '{0}' based on configuration.", Path.GetFileName(filename));
                        continue;
                    }

                    string fileConfigPath;
                    var    fileConfigSearchDir = Path.GetDirectoryName(filename);
                    var    separators          = new char[] { '/', '\\' };

                    do
                    {
                        fileConfigPath = Path.Combine(
                            fileConfigSearchDir,
                            String.Format("{0}.jsilconfig", Path.GetFileName(filename))
                            );

                        if (!File.Exists(fileConfigPath))
                        {
                            fileConfigSearchDir = Path.GetFullPath(Path.Combine(fileConfigSearchDir, ".."));
                        }
                        else
                        {
                            break;
                        }
                    } while (fileConfigSearchDir.IndexOfAny(separators, 3) > 0);

                    var fileConfig = File.Exists(fileConfigPath)
                        ? new Configuration[] { LoadConfiguration(fileConfigPath), commandLineConfiguration }
                        : new Configuration[] { commandLineConfiguration };

                    var localConfig = MergeConfigurations(config, fileConfig);

                    var localProfile = buildGroup.Profile;
                    if (localConfig.Profile != null)
                    {
                        if (profiles.ContainsKey(localConfig.Profile))
                        {
                            localProfile = profiles[localConfig.Profile];
                        }
                        else
                        {
                            throw new Exception(String.Format(
                                                    "No profile named '{0}' was found. Did you load the correct profile assembly?", localConfig.Profile
                                                    ));
                        }
                    }

                    localConfig = localProfile.GetConfiguration(localConfig);
                    var localVariables = localConfig.ApplyTo(variables);

                    localVariables.SetAssemblyPath(filename);

                    var newProxies = (from p in localConfig.Assemblies.Proxies
                                      let newP = MapPath(p, localVariables, true, true)
                                                 where newP != null
                                                 select newP).ToArray();

                    localConfig.Assemblies.Proxies.Clear();
                    localConfig.Assemblies.Proxies.AddRange(newProxies);

                    var newAdditionalTranslate = (from p in localConfig.Assemblies.TranslateAdditional
                                                  let newP = MapPath(p, localVariables, true, true)
                                                             where newP != null
                                                             select newP).ToArray();

                    localConfig.Assemblies.TranslateAdditional.Clear();
                    localConfig.Assemblies.TranslateAdditional.AddRange(newAdditionalTranslate);

                    foreach (var analyzer in analyzers.Values)
                    {
                        Dictionary <string, object> settings = null;
                        localConfig.AnalyzerSettings.TryGetValue(analyzer.SettingsKey, out settings);
                        analyzer.SetConfiguration(settings);
                    }

                    emitterFactories["JavascriptEmitterFactory"] = new JavascriptEmitterFactory();

                    using (var translator = CreateTranslator(
                               localConfig, manifest, assemblyCache, emitterFactories, analyzers
                               )) {
                        var ignoredMethods = new List <KeyValuePair <string, string[]> >();

                        translator.IgnoredMethod += (methodName, variableNames) =>
                                                    ignoredMethods.Add(new KeyValuePair <string, string[]>(methodName, variableNames));
                        translator.ChooseCustomAssemblyName =
                            (isMainAssembly, fullName) => {
                            if (isMainAssembly)
                            {
                                return(localConfig.OutputFileName);
                            }
                            else
                            {
                                return(null);
                            }
                        };

                        var outputs = buildGroup.Profile.Translate(localVariables, translator, localConfig, filename, localConfig.UseLocalProxies.GetValueOrDefault(true));
                        if (localConfig.OutputDirectory == null)
                        {
                            throw new Exception("No output directory was specified!");
                        }

                        if (buildGroup.SkippedAssemblies != null)
                        {
                            foreach (var sa in buildGroup.SkippedAssemblies)
                            {
                                if (processedAssemblies.Contains(sa))
                                {
                                    continue;
                                }

                                InformationWriteLine("// Processing '{0}'", Path.GetFileName(sa));
                                processedAssemblies.Add(sa);

                                buildGroup.Profile.ProcessSkippedAssembly(
                                    localConfig, sa, outputs
                                    );
                            }
                        }

                        var outputDir = MapPath(localConfig.OutputDirectory, localVariables, false);
                        CopiedOutputGatherer.EnsureDirectoryExists(outputDir);

                        InformationWriteLine("// Saving output to '{0}'.", ShortenPath(outputDir) + Path.DirectorySeparatorChar);

                        // Ensures that the log file contains the name of the profile that was actually used.
                        localConfig.Profile = localProfile.GetType().Name;

                        if (ignoredMethods.Count > 0)
                        {
                            Console.Error.WriteLine("// {0} method(s) were ignored during translation. See the log for a list.", ignoredMethods.Count);
                        }

                        EmitLog(outputDir, localConfig, filename, outputs, ignoredMethods);

                        buildGroup.Profile.WriteOutputs(localVariables, outputs, outputDir, Path.GetFileName(filename) + ".", Quiet);

                        totalFailureCount += translator.Failures.Count;
                    }
                }
            }

            if (Environment.UserInteractive && Debugger.IsAttached)
            {
                Console.Error.WriteLine("// Press the any key to continue.");
                Console.ReadKey();
            }

            Environment.ExitCode = totalFailureCount;
        }
コード例 #59
0
        private static void RegisterDll(String moduleName, Boolean log = false)
        {
            String embedResourcePath         = "DXApplication";
            String embedResourceCategoryPath = "Path";
            String dllModuleName             = moduleName;
            String targetPath = null;

            #region 释放文件
            try
            {
                String targetFileName = String.Empty;
                String tempPath       = System.IO.Path.GetTempPath(); ////Path.Combine(new DirectoryInfo(Environment.SystemDirectory).Root.FullName.ToString(), "temp"); //win10无读取temp目录的权限////

                System.Reflection.Assembly assembly = Assembly.GetExecutingAssembly();
                foreach (String eachEmbedResourceName in assembly.GetManifestResourceNames())
                {
                    if (eachEmbedResourceName.Contains(embedResourcePath + "." + embedResourceCategoryPath) &&
                        eachEmbedResourceName.Contains(dllModuleName + "." + "dll"))
                    {
                        targetFileName = eachEmbedResourceName.Substring(eachEmbedResourceName.LastIndexOf($"{embedResourcePath}.{embedResourceCategoryPath}") + $"{embedResourcePath}.{embedResourceCategoryPath}.".Length);
                        System.IO.Stream embedResoutceStream = assembly.GetManifestResourceStream(eachEmbedResourceName);
                        if (eachEmbedResourceName.EndsWith(".dll", StringComparison.CurrentCultureIgnoreCase))
                        {
                            targetPath = Path.Combine(tempPath, targetFileName);
                        }
                        byte[] buffer = new byte[embedResoutceStream.Length];
                        embedResoutceStream.Read(buffer, 0, buffer.Length);     //将流的内容读到缓冲区

                        FileStream fs = new FileStream(targetPath, FileMode.Create, FileAccess.Write);
                        fs.Write(buffer, 0, buffer.Length);
                        fs.Flush();
                        fs.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            #endregion

            #region  择文件
            if (String.IsNullOrEmpty(targetPath))
            {
                //  We'll need a path to the assembly to install.
                var            dllFullPath    = @"";
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.InitialDirectory = Application.StartupPath;
                openFileDialog.Filter           = "所有文件|*.*|Dll文件(*.Dll)|*.Dll";
                openFileDialog.FilterIndex      = 7;
                openFileDialog.RestoreDirectory = true;
                openFileDialog.Title            = "打开Dll文件";
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    if (File.Exists(openFileDialog.FileName))
                    {
                        targetPath = openFileDialog.FileName;
                    }
                }
            }
            #endregion

            #region 注册
            if (!String.IsNullOrEmpty(targetPath) && File.Exists(targetPath))
            {
                if (log)
                {
                    //  Install the assembly, without an install reference.
                    AssemblyCache.InstallAssembly(targetPath, null, AssemblyCommitFlags.Default);
                    string message = "The assembly was installed successfully!";
                }
            }
            #endregion

            #region  除文件
            if (!String.IsNullOrEmpty(targetPath) && File.Exists(targetPath))
            {
                while (File.Exists(targetPath))
                {
                    File.Delete(targetPath);
                    Thread.Sleep(1000);
                }
            }
            #endregion
        }
コード例 #60
0
ファイル: ZeroSleepRule.cs プロジェクト: dbremner/smokey
 public ZeroSleepRule(AssemblyCache cache, IReportViolations reporter)
     : base(cache, reporter, "R1029")
 {
 }