コード例 #1
0
        private static void AppendGameAssemblies(List <string> references, CommandLineArguments options, AssemblyType assemblyType)
        {
            var assemblies = new string[0];
            var libraryScriptAssembliesFolder = Path.Combine(options.ProjectPath, "Library/ScriptAssemblies");

            switch (assemblyType)
            {
            case AssemblyType.RuntimePlugins:
                return;

            case AssemblyType.EditorPlugins:
            case AssemblyType.Runtime:
                assemblies = Directory.GetFiles(libraryScriptAssembliesFolder, "*-firstpass.dll");
                break;

            case AssemblyType.Editor:
                assemblies = Directory.GetFiles(libraryScriptAssembliesFolder, "*.dll").Where(assemblyPath => assemblyPath.Contains("-firstpass") || !assemblyPath.Contains("-Editor")).ToArray();
                break;
            }

            if (assemblies.Length == 0 && Directory.GetFiles(libraryScriptAssembliesFolder, "*.dll").Length == 0)
            {
                using (WithConsoleColors.SetTo(ConsoleColor.DarkYellow, ConsoleColor.Black))
                {
                    Console.WriteLine($"Warning: No game assemblies found in '{libraryScriptAssembliesFolder}'. Conversion may not be possible");
                }
            }

            references.AddRange(assemblies);
        }
コード例 #2
0
        private static void ConvertScripts(AssemblyType assemblyType, IList <SourceFile> scripts, UnityScript2CSharpConverter converter, CommandLineArguments args, List <SymbolInfo> referencedSymbols, HashSet <CompilerError> compilerErrors)
        {
            IEnumerable <string> references = AssemblyReferencesFor(args, assemblyType);

            Console.WriteLine("Converting '{0}' ({1} scripts)", assemblyType, scripts.Count);

            Action <string, string, int> handler = (scriptPath, context, unsupportedCount) => HandleConvertedScript(scriptPath, context, args.RemoveOriginalFiles, args.Verbose, unsupportedCount);

            if (args.DryRun)
            {
                handler = (_, __, ___) => {}
            }
            ;

            converter.Convert(scripts, args.Symbols, references, handler);

            referencedSymbols.AddRange(converter.ReferencedPreProcessorSymbols);
            foreach (var error in converter.CompilerErrors)
            {
                compilerErrors.Add(error);
            }

            using (WithConsoleColors.SetTo(ConsoleColor.Yellow, ConsoleColor.Black))
            {
                foreach (var warning in converter.CompilerWarnings)
                {
                    Console.WriteLine("\t{0}", warning);
                }
            }
        }
コード例 #3
0
        private static bool ReportConversionFinished(int totalScripts, CommandLineArguments args, IEnumerable <SymbolInfo> referencedSymbols, IEnumerable <CompilerError> compilerErrors)
        {
            var errorCount = compilerErrors.Count();

            Console.WriteLine();
            Console.WriteLine("Finished converting {0} scripts in '{1}' with {2} error(s).", totalScripts, args.ProjectPath, errorCount);

            if (errorCount > 0)
            {
                using (WithConsoleColors.SetTo(ConsoleColor.DarkRed, ConsoleColor.Black))
                {
                    Console.WriteLine("(some scripts may not have been converted)");
                    Console.WriteLine();

                    Console.Write("Issues found during conversion");
                    var converterIsTheCulprit = HasInternalCompilerErrors(compilerErrors);
                    if (converterIsTheCulprit)
                    {
                        Console.Write(" (at least one of those were caused by a converter issue/limitation)");
                    }
                    Console.WriteLine(" :");
                    Console.WriteLine();

                    foreach (var error in compilerErrors)
                    {
                        Console.WriteLine($"{error.LexicalInfo}{Environment.NewLine}\t{error.Message}{CallStackFrom(error)}");
                        Console.WriteLine();
                    }
                }
            }

            if (!referencedSymbols.Any())
            {
                return(false);
            }

            var projectPathLength = args.ProjectPath.Length;

            using (WithConsoleColors.SetTo(ConsoleColor.Cyan, ConsoleColor.Black))
            {
                Console.WriteLine();
                Console.WriteLine("Your project contains scripts that relies on conditional compilation; this may cause parts of those scripts to not be converted.");
                Console.WriteLine("See below a list of scripts that uses conditional compilation:");
                foreach (var symbolInfo in referencedSymbols)
                {
                    Console.WriteLine($"\t{symbolInfo.Source.Substring(projectPathLength)}({symbolInfo.LineNumber}) : {symbolInfo.PreProcessorExpression}");
                }
            }

            return(true);
        }
コード例 #4
0
        static int Main(string[] args)
        {
            ParserResult <CommandLineArguments> options = null;

            try
            {
                options = Parser.Default.ParseArguments <CommandLineArguments>(args);
                if (!IsValid(options))
                {
                    return(-2);
                }
            }
            catch
            {
                Console.WriteLine();
                Console.WriteLine("Failed to parse command line arguments. See valid command line arguments below:");

                var h = new HelpText {
                    AddDashesToOption = true, AdditionalNewLineAfterOption = true
                };

                h.AddOptions(new CommandLineArguments());
                Console.WriteLine(h.ToString());

                return(-3);
            }

            RedirectConsoleOutput(options.Value.OutputFile);

            if (!ReadResponseFile(options.Value))
            {
                return(-4);
            }

            try
            {
                options.Value.ProjectPath = Path.GetFullPath(options.Value.ProjectPath);

                // We should ignore scripts in assets/WebGLTemplates
                var ignoredPathsRegex = new Regex(string.Format("assets{0}{0}webgltemplates{0}{0}", Path.DirectorySeparatorChar), RegexOptions.Compiled | RegexOptions.IgnoreCase);

                var editorSubFolder        = String.Format("{0}Editor{0}", Path.DirectorySeparatorChar);
                var pluginsEditorSubFolder = String.Format("{0}Plugins{0}Editor{0}", Path.DirectorySeparatorChar);
                var pluginSubFolder        = String.Format("{0}Plugins{0}", Path.DirectorySeparatorChar);

                var allFiles = Directory.GetFiles(Path.Combine(options.Value.ProjectPath, "Assets"), "*.js", SearchOption.AllDirectories).Where(path => !ignoredPathsRegex.IsMatch(path));
                var filter   = new Regex(string.Format(@"{0}|{1}|{2}", editorSubFolder, pluginSubFolder, pluginsEditorSubFolder).Replace("\\", "\\\\"), RegexOptions.Compiled);

                var runtimeScripts = allFiles.Where(scriptPath => !filter.IsMatch(scriptPath)).Select(scriptPath => new SourceFile {
                    FileName = scriptPath, Contents = File.ReadAllText(scriptPath)
                }).ToArray();
                var editorScripts = allFiles.Where(scriptPath => scriptPath.Contains(editorSubFolder) && !scriptPath.Contains(pluginsEditorSubFolder)).Select(scriptPath => new SourceFile {
                    FileName = scriptPath, Contents = File.ReadAllText(scriptPath)
                }).ToArray();
                var pluginScripts = allFiles.Where(scriptPath => scriptPath.Contains(pluginSubFolder) && !scriptPath.Contains(pluginsEditorSubFolder)).Select(scriptPath => new SourceFile {
                    FileName = scriptPath, Contents = File.ReadAllText(scriptPath)
                }).ToArray();
                var pluginEditorScritps = allFiles.Where(scriptPath => scriptPath.Contains(pluginsEditorSubFolder)).Select(scriptPath => new SourceFile {
                    FileName = scriptPath, Contents = File.ReadAllText(scriptPath)
                }).ToArray();

                if (!ValidateAssemblyReferences(options))
                {
                    return(-1);
                }

                if (options.Value.DumpScripts)
                {
                    DumpScripts("Runtime", runtimeScripts);
                    DumpScripts("Editor", editorScripts);
                    DumpScripts("Plugin", pluginScripts);
                    DumpScripts("Plugin/Editor", pluginEditorScritps);
                }

                var converter = new UnityScript2CSharpConverter(options.Value.IgnoreErrors, options.Value.SkipComments, options.Value.ShowOrphanComments);

                var referencedSymbols = new List <SymbolInfo>();
                var errors            = new HashSet <CompilerError>(new CompilerErrorComparer());

                ConvertScripts(AssemblyType.Runtime, runtimeScripts, converter, options.Value, referencedSymbols, errors);
                ConvertScripts(AssemblyType.Editor, editorScripts, converter, options.Value, referencedSymbols, errors);
                ConvertScripts(AssemblyType.RuntimePlugins, pluginScripts, converter, options.Value, referencedSymbols, errors);
                ConvertScripts(AssemblyType.EditorPlugins, pluginEditorScritps, converter, options.Value, referencedSymbols, errors);

                var foundConditionalCompilation = ReportConversionFinished(runtimeScripts.Length + editorScripts.Length + pluginScripts.Length, options.Value, referencedSymbols, errors);
                return(foundConditionalCompilation ? 1 : 0);
            }
            catch (Exception ex)
            {
                using (WithConsoleColors.SetTo(ConsoleColor.DarkRed, ConsoleColor.Black))
                {
                    Console.WriteLine(ex.Message);
                    if (options.Value.Verbose)
                    {
                        Console.WriteLine();
                        Console.WriteLine(ex.StackTrace);
                    }

                    if (!options.Value.IgnoreErrors)
                    {
                        Console.WriteLine("Consider running converter with '-i' option.");
                    }
                }

                return(-5);
            }
        }