Bari.Plugins.PythonScripts.Scripting.ProjectBuildScriptRunner.Run C# (CSharp) Метод

Run() публичный Метод

Executes the given build script on the given project, returning the set of target files the script generated.

The script's global scope has the following predefined variables set: - project refers to the project being built - sourceSet is the project's source set associated with the build script - targetRoot is the root target directory where all the files are generated - targetDir is where the project's output should be built

A special global function get_tool is available which accepts a reference URI and a file name. The same protocols are supported as for references in the suite definition. The function's return value is the absolute path of the given file, where the tool has been deployed.

public Run ( Project project, IBuildScript buildScript ) : ISet
project Project The input project to build
buildScript IBuildScript The build script to execute
Результат ISet
        public ISet<TargetRelativePath> Run(Project project, IBuildScript buildScript)
        {
            var engine = CreateEngine();

            var runtime = engine.Runtime;
            try
            {
                var scope = runtime.CreateScope();

                scope.SetVariable("is_mono", parameters.UseMono);
                scope.SetVariable("project", project);
                scope.SetVariable("sourceSet",
                                  project.GetSourceSet(buildScript.SourceSetName)
                                         .Files.Select(srp => (string) srp)
                                         .ToList());
                AddGetToolToScope(scope, project);

                var targetDir = TargetRoot.GetChildDirectory(project.Module.Name, createIfMissing: true);
                var localTargetDir = targetDir as LocalFileSystemDirectory;
                var localTargetRoot = TargetRoot as LocalFileSystemDirectory;
                if (localTargetDir != null && localTargetRoot != null)
                {
                    scope.SetVariable("targetRoot", localTargetRoot.AbsolutePath);
                    scope.SetVariable("targetDir", localTargetDir.AbsolutePath);

                    var pco = (PythonCompilerOptions)engine.GetCompilerOptions();
                    pco.Module |= ModuleOptions.Optimized;

                    try
                    {
                        var script = engine.CreateScriptSourceFromString(buildScript.Source, SourceCodeKind.File);
                        script.Compile(pco);
                        script.Execute(scope);

                        return new HashSet<TargetRelativePath>(
                            scope.GetVariable<IList<object>>("results")
                                .Cast<string>()
                                .Select(t => GetTargetRelativePath(targetDir, t)));
                    }
                    catch (Exception ex)
                    {
                        var eo = engine.GetService<ExceptionOperations>();

                        string msg, typeName;
                        eo.GetExceptionMessage(ex, out msg, out typeName);

                        foreach (var line in msg.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            output.Error(line);
                        }

                        output.Error("Call stack:");
                        foreach (var frame in eo.GetStackFrames(ex))
                        {
                            var line = frame.GetFileLineNumber();
                            var method = frame.GetMethodName();

                            output.Error(String.Format("Line {0} in {1}", line, method));
                        }

                        throw new ScriptException(buildScript);
                    }
                }
                else
                {
                    throw new NotSupportedException("Only local file system is supported for python scripts!");
                }
            }
            finally
            {
                runtime.Shutdown();
            }
        }
ProjectBuildScriptRunner