Esempio n. 1
0
        public void Execute(string targets, bool writeTranspiledFilesAndCompile, int threadsNumber = DefaultThreads, string?buildPath = null)
        {
            if (!PreExecutionChecks(true, true, true, true))
            {
                return;
            }
            if (buildPath == null)
            {
                buildPath = Build.DEFAULT_BUILD_PATH;
            }
            Build build = new Build(buildPath);

            BuildTarget[] buildTargets = BuildTargetFactory.ParseCollection(targets, build);
            if (writeTranspiledFilesAndCompile && !buildTargets.CanBuildAndWarnIfNot())
            {
                return;
            }
            BuildTargetSimple[] buildTargetsSimple = BuildTargetFactory.GetCollection(buildTargets);
            using (BuildTargetAdvancedCollection buildTargetsAdvanced = BuildTargetFactory.GetCollection(build, buildTargetsSimple))
            {
                BuildTracker buildTracker = new BuildTracker(buildTargets);
                Transpile(build, buildTracker, buildTargetsAdvanced, threadsNumber);
                if (writeTranspiledFilesAndCompile)
                {
                    WriteTranspiled(buildTargetsAdvanced, buildTracker);
                }
            }
            if (writeTranspiledFilesAndCompile)
            {
                PrepareWorkspace(build, buildTargets);
                Compile(build, buildTargetsSimple);
                Console.WriteLine("Build Complete");
            }
        }
        public void Execute(string scriptName, string targets = BuildTargetFactory.DefaultNames, string?buildPath = null)
        {
            if (!PreExecutionChecks(true, true, true, true))
            {
                return;
            }
            if (buildPath == null)
            {
                buildPath = Build.DEFAULT_BUILD_PATH;
            }
            Build build = new Build(buildPath);

            BuildTarget[] buildTargets = BuildTargetFactory.ParseCollection(targets, build);
            if (!buildTargets.CanBuildAndWarnIfNot())
            {
                return;
            }
            BuildTargetSimple[] buildTargetsSimple = BuildTargetFactory.GetCollection(buildTargets);
            using (BuildTargetAdvancedCollection buildTargetsAdvanced = BuildTargetFactory.GetCollection(build, buildTargetsSimple))
            {
                TranspileScriptJob transpileJob = new TranspileScriptJob(buildTargetsAdvanced, scriptName);
                transpileJob.Run();
            }
            PrepareWorkspace(build, buildTargets);
            Compile(build, buildTargetsSimple);
            Console.WriteLine("Build Complete");
            string compileLog = File.ReadAllText(build.GetCompileStandardOutputPath());

            Console.WriteLine(compileLog);
        }
        public void Execute(string targets, string?buildPath = null)
        {
            if (!PreExecutionChecks(false, true, false, false))
            {
                return;
            }
            if (buildPath == null)
            {
                buildPath = Build.DEFAULT_BUILD_PATH;
            }
            Build build = new Build(buildPath);

            BuildTarget[] buildTargets = BuildTargetFactory.ParseCollection(targets, build);
            buildTargets.DeleteBuildFiles();
            Console.WriteLine("Deletion Complete");
        }
        public void Execute(string targets)
        {
            if (!PreExecutionChecks(true, true, false, false))
            {
                return;
            }
            Directory.CreateDirectory(DataDirectory.GetGraphDirectoryPath());
            Build build = new Build(Build.DEFAULT_BUILD_PATH); //This argument might well not be important in this case

            BuildTarget[]       buildTargets       = BuildTargetFactory.ParseCollection(targets, build);
            BuildTargetSimple[] buildTargetsSimple = BuildTargetFactory.GetCollection(buildTargets);
            ProgressWriter?     progressWriter     = null;
            Dictionary <string, List <string> > dependencyGraph = new Dictionary <string, List <string> >();
            Dictionary <string, List <string> > usageGraph      = new Dictionary <string, List <string> >();

            using (ESMAnalyzer esmAnalyzer = ESMAnalyzer.Load())
            {
                progressWriter = new ProgressWriter("Building Interoperable Compilation Graph", buildTargets.GetTotalSourceFiles());
                BuildSourceFilesCollection <BuildTargetSimple> sourceFiles = buildTargetsSimple.GetSourceFiles();
                using (StreamWriter errorLog = new StreamWriter(TES5ScriptDependencyGraph.ErrorLogPath, false))
                {
                    using (StreamWriter debugLog = new StreamWriter(TES5ScriptDependencyGraph.DebugLogPath, false))
                    {
                        foreach (var kvp in sourceFiles)
                        {
                            BuildTargetSimple buildTarget = kvp.Key;
                            var sourceBuildFiles          = kvp.Value;
                            foreach (var sourceFile in sourceBuildFiles)
                            {
                                string scriptName = sourceFile.Substring(0, sourceFile.Length - 4);//remove extension
                                string source     = buildTarget.GetSourceFromPath(scriptName);
                                ITES4CodeFilterable ast;
                                try
                                {
                                    ast = buildTarget.GetAST(source);
                                }
                                catch (EOFOnlyException) { continue; }//Ignore files that are only whitespace or comments.

                                /*catch (UnexpectedTokenException ex)
                                 * {//UnexpectedTokenExceptions no longer occur, so this code should not be invoked.
                                 *  errorLog.WriteLine(sourceFile + ":  " + ex.Message + Environment.NewLine);
                                 *  continue;
                                 * }*/
                                List <TES4ObjectProperty> propertiesAccesses = new List <TES4ObjectProperty>();
                                ast.Filter((data) =>
                                {
                                    TES4ObjectProperty?property = data as TES4ObjectProperty;
                                    if (property == null)
                                    {
                                        return(false);
                                    }
                                    propertiesAccesses.Add(property);
                                    return(true);
                                });
                                Dictionary <string, ITES5Type> preparedProperties = new Dictionary <string, ITES5Type>();
                                foreach (var property in propertiesAccesses)
                                {
                                    Match  match           = TES5ReferenceFactory.ReferenceAndPropertyNameRegex.Match(property.StringValue);
                                    string propertyName    = match.Groups[1].Value;
                                    string propertyKeyName = propertyName.ToLower();
                                    preparedProperties.AddIfNotContainsKey(propertyKeyName, () => esmAnalyzer.GetScriptTypeByEDID(propertyName));
                                }

                                debugLog.WriteLine(scriptName + " - " + preparedProperties.Count + " prepared");
                                string lowerScriptType = scriptName.ToLower();
                                foreach (var kvp2 in preparedProperties)
                                {
                                    var    preparedPropertyKey = kvp2.Key;
                                    string propertyTypeName    = preparedProperties[preparedPropertyKey].OriginalName;
                                    //Only keys are lowercased.
                                    string lowerPropertyType = propertyTypeName.ToLower();
                                    dependencyGraph.AddNewListIfNotContainsKeyAndAddValueToList(lowerPropertyType, lowerScriptType);
                                    usageGraph.AddNewListIfNotContainsKeyAndAddValueToList(lowerScriptType, lowerPropertyType);
                                    debugLog.WriteLine("Registering a dependency from " + scriptName + " to " + propertyTypeName);
                                }

                                progressWriter.IncrementAndWrite();
                            }
                        }
                    }
                }
            }
            progressWriter.Write("Saving");
            TES5ScriptDependencyGraph graph = new TES5ScriptDependencyGraph(dependencyGraph, usageGraph);

            buildTargets.WriteGraph(graph);
            progressWriter.WriteLast();
        }