public void Execute(string targets, 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);

            using (BuildLogServices buildLogServices = new BuildLogServices(build))
            {
                BuildTargetCollection buildTargets = BuildTargetFactory.GetCollection(targets, build, buildLogServices);
                if (!buildTargets.CanBuildAndWarnIfNot())
                {
                    return;
                }
                BuildTracker buildTracker = new BuildTracker(buildTargets);
                Transpile(build, buildTracker, buildTargets, buildLogServices, threadsNumber);
                WriteTranspiled(buildTargets, buildTracker);
                ESMAnalyzer.Deallocate();//Hack - force ESM analyzer deallocation.
                PrepareWorkspace(buildTargets);
                Compile(build, buildTargets);
            }
            Console.WriteLine("Build Complete");
        }
        private static void PrepareWorkspace(BuildTargetCollection buildTargets)
        {
            ProgressWriter      preparingBuildWorkspaceProgressWriter = new ProgressWriter("Preparing Build Workspace", buildTargets.Count() * PrepareWorkspaceJob.CopyOperationsPerBuildTarget);
            PrepareWorkspaceJob prepareCommand = new PrepareWorkspaceJob(buildTargets);

            prepareCommand.Run(preparingBuildWorkspaceProgressWriter);
            preparingBuildWorkspaceProgressWriter.WriteLast();
        }
Exemple #3
0
 /*
  * No injection is done here because of multithreaded enviroment which messes it up.
  * Maybe at some point we will have a proper DI into the jobs.
  * TranspileChunkJob constructor.
  */
 public TranspileChunkJob(Build build, BuildTracker buildTracker, BuildLogServices buildLogServices, List <Dictionary <string, List <string> > > buildPlan)
 {
     this.buildPlan        = buildPlan;
     this.buildTracker     = buildTracker;
     this.build            = build;
     this.buildLogServices = buildLogServices;
     this.buildTargets     = new BuildTargetCollection();
     this.esmAnalyzer      = new ESMAnalyzer(DataDirectory.TES4GameFileName);
 }
        private static void WriteTranspiled(BuildTargetCollection buildTargets, BuildTracker buildTracker)
        {
            ProgressWriter writingTranspiledScriptsProgressWriter = new ProgressWriter("Writing Transpiled Scripts", buildTargets.Sum(bt => bt.GetSourceFileList().Count()));

            foreach (var buildTarget in buildTargets)
            {
                buildTarget.Write(buildTracker, writingTranspiledScriptsProgressWriter);
            }
            writingTranspiledScriptsProgressWriter.WriteLast();
        }
        private static void Transpile(Build build, BuildTracker buildTracker, BuildTargetCollection buildTargets, BuildLogServices buildLogServices, int threadsNumber)
        {
            var            buildPlan      = buildTargets.GetBuildPlan(threadsNumber);
            int            totalScripts   = buildPlan.Sum(p => p.Value.Sum(chunk => chunk.Sum(c => c.Value.Count)));
            ProgressWriter progressWriter = new ProgressWriter("Transpiling Scripts", totalScripts);

            using (StreamWriter errorLog = new StreamWriter(build.GetErrorLogPath(), false))
            {
                foreach (var threadBuildPlan in buildPlan)
                {
                    TranspileChunkJob task = new TranspileChunkJob(build, buildTracker, buildLogServices, threadBuildPlan.Value);
                    task.RunTask(errorLog, progressWriter);
                }
            }
            progressWriter.WriteLast();
        }
Exemple #6
0
        public void Execute(string targets, string buildPath = null)
        {
            PreExecutionChecks(false, false, false, false);
            if (buildPath == null)
            {
                buildPath = Build.DEFAULT_BUILD_PATH;
            }
            Build build = new Build(buildPath);

            using (BuildLogServices buildLogServices = new BuildLogServices(build))
            {
                BuildTargetCollection buildTargets = BuildTargetFactory.GetCollection(targets, build, buildLogServices, false);
                buildTargets.DeleteBuildFiles();
            }
            Console.WriteLine("Deletion Complete");
        }
        public void Execute(string scriptName, string targets = BuildTarget.DEFAULT_TARGETS, string buildPath = null)
        {
            if (!PreExecutionChecks(true, true, true, true))
            {
                return;
            }
            if (buildPath == null)
            {
                buildPath = Build.DEFAULT_BUILD_PATH;
            }
            Build build = new Build(buildPath);

            using (BuildLogServices buildLogServices = new BuildLogServices(build))
            {
                BuildTargetCollection buildTargets = BuildTargetFactory.GetCollection(targets, build, buildLogServices);
                if (!buildTargets.CanBuildAndWarnIfNot())
                {
                    return;
                }
                TranspileScriptJob transpileJob = new TranspileScriptJob(buildTargets, scriptName);
#if !DEBUG
                try
                {
#endif
                transpileJob.Run();
#if !DEBUG
            }
            catch (ConversionException ex)
            {
                Console.WriteLine("Exception occured." + Environment.NewLine + ex.GetType().FullName + ":  " + ex.Message);
                return;
            }
#endif
                PrepareWorkspace(buildTargets);
                Compile(build, buildTargets);
            }
            Console.WriteLine("Build Complete");
            string compileLog = File.ReadAllText(build.GetCompileStandardOutputPath());
            Console.WriteLine(compileLog);
        }
 public PrepareWorkspaceJob(BuildTargetCollection buildTargetCollection)
 {
     this.buildTargetCollection = buildTargetCollection;
 }
 public CompileScriptJob(Build build, BuildTargetCollection buildTargetCollection)
 {
     this.standardOutputFilePath = build.GetCompileStandardOutputPath();
     this.standardErrorFilePath  = build.GetCompileStandardErrorPath();
     this.buildTargetCollection  = buildTargetCollection;
 }
        private static void Compile(Build build, BuildTargetCollection buildTargets)
        {
            CompileScriptJob task = new CompileScriptJob(build, buildTargets);

            task.Run();
        }
 /*
  * TranspileScriptJob constructor.
  */
 public TranspileScriptJob(BuildTargetCollection buildTargets, string scriptName)
 {
     this.buildTargets = buildTargets;
     this.scriptName   = scriptName;
     this.esmAnalyzer  = new ESMAnalyzer(DataDirectory.TES4GameFileName);
 }
        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

            using (BuildLogServices buildLogServices = new BuildLogServices(build))
            {
                BuildTargetCollection buildTargets = BuildTargetFactory.GetCollection(targets, build, buildLogServices);
                //if (!buildTargets.CanBuildAndWarnIfNot()) { return; }//WTM:  Change:  This doesn't matter for building graphs.
                Dictionary <string, List <string> > dependencyGraph = new Dictionary <string, List <string> >();
                Dictionary <string, List <string> > usageGraph      = new Dictionary <string, List <string> >();
                BuildSourceFilesCollection          sourceFiles     = buildTargets.GetSourceFiles();
                ProgressWriter     progressWriter = new ProgressWriter("Building Interoperable Compilation Graph", buildTargets.GetTotalSourceFiles());
                TES5TypeInferencer inferencer     = new TES5TypeInferencer(new ESMAnalyzer(), BuildTarget.StandaloneSourcePath);
                using (StreamWriter errorLog = new StreamWriter(TES5ScriptDependencyGraph.ErrorLogPath, false))
                {
                    using (StreamWriter debugLog = new StreamWriter(TES5ScriptDependencyGraph.DebugLogPath, false))
                    {
                        foreach (var kvp in sourceFiles)
                        {
                            var         buildTargetName  = kvp.Key;
                            var         sourceBuildFiles = kvp.Value;
                            BuildTarget buildTarget      = buildTargets.GetByName(buildTargetName);
                            foreach (var sourceFile in sourceBuildFiles)
                            {
                                string scriptName = sourceFile.Substring(0, sourceFile.Length - 4);
                                ITES4CodeFilterable AST;
                                try
                                {
                                    AST = buildTarget.GetAST(buildTarget.GetSourceFromPath(scriptName));
                                }
                                catch (EOFOnlyException) { continue; }//Ignore files that are only whitespace or comments.

                                /*catch (UnexpectedTokenException ex)
                                 * {//Exceptions 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, TES5Property> preparedProperties      = new Dictionary <string, TES5Property>();
                                Dictionary <string, ITES5Type>    preparedPropertiesTypes = new Dictionary <string, ITES5Type>();
                                foreach (var property in propertiesAccesses)
                                {
                                    Match        match           = TES5ReferenceFactory.PropertyNameRegex.Match(property.StringValue);
                                    string       propertyName    = match.Groups[1].Value;
                                    string       propertyKeyName = propertyName.ToLower();
                                    bool         containedKey;
                                    TES5Property preparedProperty = preparedProperties.GetOrAdd(propertyKeyName, () => new TES5Property(propertyName, TES5BasicType.T_FORM, propertyName), out containedKey);
                                    ITES5Type    inferencingType  = inferencer.ResolveInferenceTypeByReferenceEdid(preparedProperty);
                                    if (!containedKey)
                                    {
                                        preparedPropertiesTypes.Add(propertyKeyName, inferencingType);
                                    }
                                    else
                                    {
                                        if (!inferencingType.Equals(preparedPropertiesTypes[propertyKeyName]))
                                        {
                                            throw new ConversionException("Cannot settle up the properties types - conflict.");
                                        }
                                    }
                                }

                                debugLog.WriteLine(scriptName + " - " + preparedProperties.Count + " prepared");
                                string lowerScriptType = scriptName.ToLower();
                                foreach (var kvp2 in preparedProperties)
                                {
                                    var    preparedPropertyKey = kvp2.Key;
                                    var    preparedProperty    = kvp2.Value;
                                    string propertyTypeName    = preparedPropertiesTypes[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();
            }
        }