Esempio n. 1
0
        /// <summary>
        /// Runs this instance.
        /// </summary>
        /// <returns></returns>
        public CppModule Run()
        {
            // If config is updated, we need to run the
            if (masterConfigHasChanged)
            {
                log.Info("Config files changed.");


                StreamReader xmlReader = null;
                try
                {
                    xmlReader = castXML.Process(masterHeaderFile);
                    if (xmlReader != null)
                    {
                        Parse(xmlReader);
                    }

                    // Save back the C++ parsed includes
                    masterCppModule.Write(MasterModuleFileName);
                }
                catch (Exception ex)
                {
                    log.Error("Unexpected error", ex);
                }
                finally
                {
                    if (xmlReader != null)
                    {
                        xmlReader.Close();
                    }

                    // Write back GCCXML document on the disk
                    if (CastXmlDoc != null)
                    {
                        CastXmlDoc.Save(CastXmlFileName);
                    }

                    log.Info("Parsing headers is finished.");
                }
            }
            else
            {
                masterCppModule = CppModule.Read(MasterModuleFileName);
            }

            return(masterCppModule);
        }
        protected override bool Execute(ConfigFile config)
        {
            var resolver = new IncludeDirectoryResolver(SharpGenLogger);

            resolver.Configure(config);

            var castXml = new CastXmlRunner(SharpGenLogger, resolver, CastXmlExecutablePath, CastXmlArguments)
            {
                OutputPath = OutputPath
            };

            // Run the parser
            var parser = new CppParser(SharpGenLogger, config)
            {
                OutputPath = OutputPath
            };

            if (SharpGenLogger.HasErrors)
            {
                return(false);
            }

            var module = CppModule.Read(PartialCppModuleCache.ItemSpec);

            // Run the C++ parser
            CppModule group;

            using (var xmlReader = castXml.Process(parser.RootConfigHeaderFileName))
            {
                group = parser.Run(module, xmlReader);
            }

            if (SharpGenLogger.HasErrors)
            {
                return(false);
            }

            group.Write(ParsedCppModule.ItemSpec);

            return(true);
        }
        protected override bool Execute(ConfigFile config)
        {
            var resolver = new IncludeDirectoryResolver(SharpGenLogger);

            resolver.Configure(config);

            var castXml = new CastXml(SharpGenLogger, resolver, CastXmlExecutablePath)
            {
                OutputPath = OutputPath
            };

            // Run the parser
            var parser = new CppParser(SharpGenLogger, castXml)
            {
                OutputPath = OutputPath
            };

            parser.Initialize(config);

            if (SharpGenLogger.HasErrors)
            {
                return(false);
            }

            var module = CppModule.Read(PartialCppModuleCache.ItemSpec);

            // Run the parser
            var group = parser.Run(module, CastXmlArguments ?? Array.Empty <string>());

            if (SharpGenLogger.HasErrors)
            {
                return(false);
            }

            group.Write(ParsedCppModule.ItemSpec);

            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// Run CodeGenerator
        /// </summary>
        public void Run()
        {
            Logger.Progress(0, "Starting code generation...");

            try
            {
                var consumerConfig = new ConfigFile
                {
                    Id = ConsumerBindMappingConfigId
                };

                var(filesWithIncludes, filesWithExtensions) = Config.GetFilesWithIncludesAndExtensionHeaders();

                var configsWithIncludes = new HashSet <ConfigFile>();

                foreach (var config in Config.ConfigFilesLoaded)
                {
                    if (filesWithIncludes.Contains(config.Id))
                    {
                        configsWithIncludes.Add(config);
                    }
                }

                var sdkResolver = new SdkResolver(Logger);

                foreach (var config in Config.ConfigFilesLoaded)
                {
                    foreach (var sdk in config.Sdks)
                    {
                        config.IncludeDirs.AddRange(sdkResolver.ResolveIncludeDirsForSdk(sdk));
                    }
                }

                var cppHeadersUpdated = GenerateHeaders(filesWithExtensions, configsWithIncludes, consumerConfig);

                if (Logger.HasErrors)
                {
                    Logger.Fatal("Failed to generate C++ headers.");
                }

                CppModule group;
                var       groupFileName = $"{Config.Id}-out.xml";

                if (cppHeadersUpdated.Count != 0)
                {
                    var resolver = new IncludeDirectoryResolver(Logger);
                    resolver.Configure(Config);

                    var castXml = new CastXml(Logger, resolver, CastXmlExecutablePath, Array.Empty <string>())
                    {
                        OutputPath = IntermediateOutputPath,
                    };

                    group = GenerateExtensionHeaders(filesWithExtensions, cppHeadersUpdated, castXml);
                    group = ParseCpp(castXml, group);

                    if (IsGeneratingDoc)
                    {
                        ApplyDocumentation(DocumentationCache, group);
                    }
                }
                else
                {
                    Logger.Progress(10, "Config files unchanged. Read previous C++ parsing...");
                    if (File.Exists(Path.Combine(IntermediateOutputPath, groupFileName)))
                    {
                        group = CppModule.Read(Path.Combine(IntermediateOutputPath, groupFileName));
                    }
                    else
                    {
                        group = new CppModule();
                    }
                }

                // Save back the C++ parsed includes
                group.Write(Path.Combine(IntermediateOutputPath, groupFileName));

                Config.ExpandDynamicVariables(Logger, group);

                var(docAggregator, asm) = ExecuteMappings(group, consumerConfig);

                asm.Write(Path.Combine(IntermediateOutputPath, "Assembly.xml"));

                asm = CsAssembly.Read(Path.Combine(IntermediateOutputPath, "Assembly.xml"));

                GenerateConfigForConsumers(consumerConfig);

                GenerateCode(docAggregator, asm, new ExternalDocCommentsReader(ExternalDocumentation));

                if (Logger.HasErrors)
                {
                    Logger.Fatal("Code generation failed");
                }

                // Update Checkfile for assembly
                File.WriteAllText(_assemblyCheckFile, "");
                File.SetLastWriteTime(_assemblyCheckFile, _assemblyDatetime);

                // Update Checkfile for all config files
                File.WriteAllText(_allConfigCheck, "");
                File.SetLastWriteTime(_allConfigCheck, DateTime.Now);
            }
            finally
            {
                Logger.Progress(100, "Finished");
            }
        }