Пример #1
0
 // $$ProjectDefaultValues disable
 // used to compile without project
 public CompilerProjectReader GetDefaultProject()
 {
     string projectFile = GetRunSourceConfig().Get("DefaultProject");
     bool createCompilerProject = false;
     if (projectFile == null)
     {
         _defaultProjectFile = null;
         _defaultProjectXmlConfig = null;
         _defaultProject = null;
         Trace.WriteLine("no default project");
     }
     else if (projectFile != _defaultProjectFile)
     {
         _defaultProjectFile = projectFile;
         _defaultProjectXmlConfig = new XmlConfig(projectFile);
         createCompilerProject = true;
         Trace.WriteLine("create default project from \"{0}\"", _defaultProjectFile);
     }
     else
     {
         createCompilerProject = _defaultProjectXmlConfig.Refresh();
         if (createCompilerProject)
             Trace.WriteLine("refresh default project from \"{0}\"", _defaultProjectFile);
     }
     if (createCompilerProject)
         _defaultProject = CompilerProjectReader.Create(_defaultProjectXmlConfig.GetConfigElement("/AssemblyProject"));
     return _defaultProject;
 }
Пример #2
0
        private ProjectCompiler RunCode_CompileCode(CompilerProjectReader compilerProject, string assemblyFilename, string sourceFile)
        {
            ProjectCompiler compiler = new ProjectCompiler(CompilerManager.Current.Win32ResourceCompiler, CompilerManager.Current.ResourceCompiler);

            //try
            //{
            compiler.SetOutputAssembly(assemblyFilename + ".dll");
            compiler.AddSource(new CompilerFile(sourceFile));

            if (compilerProject != null)
                compiler.SetProjectCompilerFile(compilerProject.GetProjectCompilerFile());

            // CompilerDefaultValues from runsource.runsource.config.xml runsource.runsource.config.local.xml
            //compiler.SetParameters(GetRunSourceConfigCompilerDefaultValues(), runCode: true);
            compiler.SetParameters(compilerProject, runCode: true);
            compiler.SetTarget("library");

            CompilerManager.Current.UpdateAssemblies(compiler.Assemblies.Values);
            compiler.Compile();

            return compiler;
        }
Пример #3
0
        // RunCode_ExecuteCode must throw an exception if he can't execute run method
        // if no error thrown RunCode_ExecuteCode must call RunCode_EndRun()
        //private void RunCode_ExecuteCode(Assembly assembly, GenerateCSharpCodeResult codeResult, CompilerProject compilerProject, Compiler compiler, bool useNewThread)
        private void RunCode_ExecuteCode(Assembly assembly, GenerateCSharpCodeResult codeResult, CompilerProjectReader compilerProject, ProjectCompiler compiler, bool runOnMainThread, bool callInit)
        {
            RunCode runCode = new RunCode(++_runCodeId);
            runCode.RunAssembly = assembly;
            //runCode.CompilerAssemblies = compiler.Assemblies;
            runCode.RunMethodName = codeResult.GetFullRunMethodName();
            runCode.EndRun += error => RunCode_EndRun(runCode, error);

            //if (forceCallInit)
            //    _runSourceInitEndMethods.CallInit = true;

            _executionAborted = false;

            foreach (CompilerAssembly compilerAssembly in compiler.Assemblies.Values)
            {
                //WriteLine(2, "  Assembly              \"{0}\" resolve {1}", assembly.File, assembly.Resolve);
                if (compilerAssembly.Resolve)
                    AssemblyResolve.Add(compilerAssembly.File, compilerAssembly.ResolveName);
            }

            //_runSourceInitEndMethods.CallInit = callInit;
            //if (callInit)
            //_runSourceInitEndMethods.CallInitMethods(compilerProject.GetInitMethods(), compilerProject.GetEndMethods(), callInit, methodName => runCode.GetMethod(methodName));
            _runSourceInitEndMethods.CallInitMethods(compilerProject.GetInitMethods(), compilerProject.GetEndMethods(), callInit, methodName => zReflection.GetMethod(methodName, assembly, ErrorOptions.TraceWarning));

            // add runCode to _runCodes after call init, if call init fail runCode is not in _runCodes
            if (!_runCodes.TryAdd(runCode.Id, runCode))
                throw new PBException("unable to add RunCode id {0} to ConcurrentDictionary", runCode.Id);

            runCode.Run(runOnMainThread);

            // problem with AssemblyResolve.Clear() end method may need to resolve assembly
            //AssemblyResolve.Clear();
        }
Пример #4
0
 //public void SetOutputAssembly(string outputAssembly, ICompilerProjectReader project = null)
 public void SetOutputAssembly(string outputAssembly, CompilerProjectReader project = null)
 {
     if (outputAssembly != null)
     {
         if (_outputAssembly != null)
             WriteLine(1, "Compiler warning : redefine output assembly \"{0}\" as \"{1}\" from project \"{2}\"", _outputAssembly, outputAssembly, project != null ? project.ProjectFile : "(no project)");
         _outputAssembly = outputAssembly;
         //string ext = zPath.GetExtension(outputAssembly);
         //if (ext != null)
         //{
         //    if (ext.ToLower() == ".exe")
         //        _generateExecutable = true;
         //    else if (ext.ToLower() == ".dll")
         //        _generateExecutable = false;
         //}
     }
 }
Пример #5
0
        private GenerateCSharpCodeResult RunCode_GenerateCode(string code, CompilerProjectReader compilerProject, string assemblyFilename)
        {
            GenerateCSharpCode generateCSharpCode = new GenerateCSharpCode(assemblyFilename);
            generateCSharpCode.RunTypeName = GetRunSourceConfig().Get("GenerateCodeRunTypeName", "_RunCode");  // "w"
            generateCSharpCode.RunMethodName = GetRunSourceConfig().Get("GenerateCodeRunMethodName", "Run");

            if (compilerProject != null)
            {
                generateCSharpCode.NameSpace = compilerProject.GetNameSpace();
                generateCSharpCode.AddUsings(compilerProject.GetUsings());
            }

            return generateCSharpCode.GenerateCode(code);
        }
Пример #6
0
 //public void SetPlatform(string platform, ICompilerProjectReader project = null)
 public void SetPlatform(string platform, CompilerProjectReader project = null)
 {
     if (platform != null)
     {
         if (_platform != null)
             WriteLine(1, "Compiler warning : redefine platform \"{0}\" as \"{1}\" from project \"{2}\"", _platform, platform, project != null ? project.ProjectFile : "(no project)");
         _platform = platform;
     }
 }
Пример #7
0
 //public void SetTarget(string target, ICompilerProjectReader project = null)
 public void SetTarget(string target, CompilerProjectReader project = null)
 {
     if (target != null)
     {
         if (_target != null)
             WriteLine(1, "Compiler warning : redefine target \"{0}\" as \"{1}\" from project \"{2}\"", _target, target, project != null ? project.ProjectFile : "(no project)");
         _target = target;
     }
 }
Пример #8
0
 //public void SetFrameworkVersion(string frameworkVersion, ICompilerProjectReader project = null)
 public void SetFrameworkVersion(string frameworkVersion, CompilerProjectReader project = null)
 {
     if (frameworkVersion != null)
     {
         if (_frameworkVersion != null)
             //WriteLine(1, "Compiler warning : redefine framework version \"{0}\" as \"{1}\" from project \"{2}\"", _frameworkVersion, frameworkVersion, project != null ? project.ProjectFile : "(no project)");
             throw new PBException($"Compiler warning : redefine framework version \"{_frameworkVersion}\" as \"{frameworkVersion}\" from project \"{(project != null ? project.ProjectFile : "(no project)")}\"");
         _frameworkVersion = frameworkVersion;
     }
 }
Пример #9
0
 //public void SetLanguage(CompilerLanguage language, ICompilerProjectReader project = null)
 public void SetLanguage(CompilerLanguage language, CompilerProjectReader project = null)
 {
     if (language != null)
     {
         if (_language != null)
             //WriteLine(1, );
             throw new PBException($"Compiler warning : redefine language \"{_language.Name}\"-\"{_language.Version}\" as \"{language.Name}\"-\"{language.Version}\" from project \"{project.ProjectFile}\"");
         //else
         //    WriteLine(1, "Compiler info    : set language \"{0}\"-\"{1}\" from project \"{2}\"", language.Name, language.Version, project.ProjectFile);
         _language = language;
     }
 }
Пример #10
0
        // runCode : true when executing code from runsource, true for CompilerDefaultValues and ProjectDefaultValues, otherwise false
        // includeProject : true reading and include project, false reading the main project
        // set parameters for :
        //   main project : Win32Resource
        //   main project but not run code : Target, Platform, Output, Icon, KeyFile, CopySourceFiles, CopyRunSourceSourceFiles, CopyOutputDirectories
        //   not run code : GenerateInMemory
        //   always : DebugInformation, WarningLevel, CompilerOptions, PreprocessorSymbols, Sources, Files, SourceFiles, Assemblies
        //   always but only once : Language, FrameworkVersion
        public void SetParameters(CompilerProjectReader project, bool runCode = false, bool includeProject = false)
        {
            if (project == null)
                return;

            //if (!includeProject)
            //{
                SetLanguage(project.GetLanguage(), project);
                SetFrameworkVersion(project.GetFrameworkVersion(), project);
            //}

            if (!runCode && !includeProject)
            {
                //s = project.GetTarget();
                //if (s != null)
                //    AddCompilerOption("/target:" + s);
                SetTarget(project.GetTarget(), project);
                SetPlatform(project.GetPlatform(), project);
            }

            bool? b;

            if (!runCode)
            {
                b = project.GetGenerateInMemory();
                if (b != null)
                    _generateInMemory = (bool)b;
            }

            b = project.GetDebugInformation();
            if (b != null)
                _debugInformation = (bool)b;

            int? i = project.GetWarningLevel();
            if (i != null)
                _warningLevel = (int)i;

            AddCompilerOptions(project.GetCompilerOptions());
            AddPreprocessorSymbols(project.GetPreprocessorSymbols());

            string s;

            if (!runCode && !includeProject)
            {
                s = project.GetOutput();
                if (s != null)
                    SetOutputAssembly(s, project);
            }

            if (!includeProject)
            {
                SetWin32Resource(project.GetWin32Resource());
            }

            //if (!includeProject)
            if (!includeProject && !includeProject)
            {
                s = project.GetIcon();
                if (s != null)
                    AddCompilerOption("/win32icon:\"" + s + "\"");
            }

            //if (!includeProject)
            if (!includeProject && !includeProject)
            {
                s = project.GetKeyFile();
                if (s != null)
                    AddCompilerOption("/keyfile:\"" + s + "\"");
            }

            if (!includeProject)
            {
                // GetIncludeProjects() get include project recursively
                foreach (CompilerProjectReader project2 in project.GetIncludeProjects())
                {
                    SetParameters(project2, runCode: runCode, includeProject: true);
                }
            }

            AddSources(project.GetSources());

            AddFiles(project.GetFiles());

            AddSourceFiles(project.GetSourceFiles());

            AddAssemblies(project.GetAssemblies());

            if (!runCode && !includeProject)
            {
                b = project.GetCopySourceFiles();
                if (b != null)
                    _copySourceFiles = (bool)b;

                b = project.GetCopyRunSourceSourceFiles();
                if (b != null)
                    _copyRunSourceSourceFiles = (bool)b;
            }

            if (!runCode && !includeProject)
            {
                AddCopyOutputDirectories(project.GetCopyOutputs());
            }
        }