Пример #1
0
        private static void AddDependency(CPPProject.Profile Profile, string Dependency)
        {
            SourceBuilder builder = BuildSystem.GetSourceBuilder(Dependency);

            if (builder == null)
            {
                return;
            }

            Profile.AddIncludeDirectories(FileSystemUtilites.GetParentDirectory(builder.sourcePathRoot));
            Profile.AddIncludeDirectories(FileSystemUtilites.PathSeperatorCorrection(builder.sourcePathRoot));

            if (builder.SelectedRule.GenerateReflection)
            {
                Profile.AddIncludeDirectories(builder.generatedFilesPath);

                AddDependency(Profile, BuildSystemHelper.ReflectionModuleName);
            }

            if (builder.SelectedRule.IncludesPath != null)
            {
                foreach (string includePath in builder.SelectedRule.IncludesPath)
                {
                    Profile.AddIncludeDirectories(FileSystemUtilites.PathSeperatorCorrection(builder.sourcePathRoot + includePath));
                }
            }

            if (builder.SelectedRule.LibraryUseType == BuildRules.LibraryUseTypes.UseOnly)
            {
                string[] temp = builder.SelectedRule.LibrariesPath;

                if (temp != null)
                {
                    foreach (string file in temp)
                    {
                        Profile.AddIncludeLibraries(builder.sourcePathRoot + FileSystemUtilites.PathSeperatorCorrection(file));
                    }
                }
            }
            //else
            //{
            //	profile.AddPreprocessorDefinition(BuildSystemHelper.GetAPIPreprocessor(builder.SelectedRule.TargetName, BuildSystemHelper.APIPreprocessorValues.Import));

            //	string[] libFiles = FileSystemUtilites.GetAllFiles(builder.BinariesPath, "*" + EnvironmentHelper.StaticLibraryExtentions);

            //	if (libFiles != null)
            //		foreach (string libFile in libFiles)
            //			profile.AddIncludeLibraries(libFile);
            //}

            AddAllInclusionsFromDependencies(Profile, builder);
        }
Пример #2
0
        public bool Build(bool ForceToRebuild)
        {
            if (state == States.Built || state == States.AlreadyUpdated)
            {
                return(true);
            }
            else if (state == States.Failed)
            {
                return(false);
            }

            if (SelectedRule.LibraryUseType == BuildRules.LibraryUseTypes.UseOnly)
            {
                string[] temp = SelectedRule.BinariesPath;

                if (temp != null)
                {
                    foreach (string file in temp)
                    {
                        string srcFilePath = sourcePathRoot + FileSystemUtilites.PathSeperatorCorrection(file);

                        if (!File.Exists(srcFilePath))
                        {
                            ConsoleHelper.WriteError("Couldn't find file [" + srcFilePath + "]");
                            state = States.Failed;
                            break;
                        }

                        string dstFilePath = EnvironmentHelper.FinalOutputDirectory + Path.GetFileName(file);

                        File.Copy(srcFilePath, dstFilePath, true);
                    }
                }

                state = States.Built;
            }
            else if (SelectedRule.LibraryUseType == BuildRules.LibraryUseTypes.ProjectFile)
            {
                BuildProjectFile();
            }
            else
            {
                GenerateAndBuildProjectFile(ForceToRebuild);
            }

            return(state == States.Built || state == States.AlreadyUpdated);
        }
        public static bool Create()
        {
            RuleLibraryBuilder rulesBuilder = new RuleLibraryBuilder(EnvironmentHelper.ProcessDirectory);

            if (!rulesBuilder.Build())
            {
                return(false);
            }

            CPPProject projectFile = new CPPProject();

            foreach (ProjectBase.ProfileBase.BuildConfigurations configuration in BuildConfigurations)
            {
                foreach (ProjectBase.ProfileBase.PlatformTypes platform in PlatformTypes)
                {
                    foreach (BuildRules buildRule in rulesBuilder.Rules)
                    {
                        foreach (BuildRules.RuleBase rule in buildRule.Rules)
                        {
                            if (rule.LibraryUseType != BuildRules.LibraryUseTypes.Executable)
                            {
                                continue;
                            }

                            CPPProject.Profile profile = (CPPProject.Profile)projectFile.CreateProfile();

                            profile.Name = buildRule.ModuleName;
                            profile.BuildConfiguration = configuration;
                            profile.PlatformType       = platform;
                            profile.OutputType         = ProjectBase.ProfileBase.OutputTypes.Makefile;
                            profile.OutputPath         = EnvironmentHelper.FinalOutputDirectory + rule.TargetName + EnvironmentHelper.ExecutableExtentions;
                            profile.IntermediatePath   = EnvironmentHelper.IntermediateDirectory;

                            profile.NMakeBuildCommandLine   = string.Format("\"$(SolutionDir)Binaries/Frontend.exe\" -Action BuildEngine -Architecture {0} -Configuration {1}", platform, configuration);
                            profile.NMakeReBuildCommandLine = string.Format("\"$(SolutionDir)Binaries/Frontend.exe\" -Action RebuildEngine -Architecture {0} -Configuration {1}", platform, configuration);
                            profile.NMakeCleanCommandLine   = string.Format("\"$(SolutionDir)Binaries/Frontend.exe\" -Action CleanEngine -Architecture {0} -Configuration {1}", platform, configuration);

                            //profile.AddIncludeDirectories("$(ProjectDir)");

                            foreach (BuildRules buildRule1 in rulesBuilder.Rules)
                            {
                                foreach (BuildRules.RuleBase rule1 in buildRule1.Rules)
                                {
                                    profile.AddIncludeDirectories(FileSystemUtilites.GetParentDirectory(buildRule1.Path));
                                    profile.AddIncludeDirectories(FileSystemUtilites.PathSeperatorCorrection(buildRule1.Path));
                                    profile.AddIncludeDirectories(FileSystemUtilites.PathSeperatorCorrection(profile.IntermediatePath + rule1.TargetName + EnvironmentHelper.PathSeparator + BuildSystemHelper.GeneratedPathName));

                                    if (rule1.IncludesPath != null)
                                    {
                                        foreach (string includePath in rule1.IncludesPath)
                                        {
                                            profile.AddIncludeDirectories(FileSystemUtilites.PathSeperatorCorrection(buildRule1.Path + includePath));
                                        }
                                    }

                                    profile.AddPreprocessorDefinition(BuildSystemHelper.GetAPIPreprocessor(rule1.TargetName, BuildSystemHelper.APIPreprocessorTypes.Empty));
                                    profile.AddPreprocessorDefinition(BuildSystemHelper.GetExternPreprocessor(rule1.TargetName, BuildSystemHelper.ExternPreprocessorTypes.Empty));

                                    if (rule1.PreprocessorDefinitions != null)
                                    {
                                        foreach (string pd in rule1.PreprocessorDefinitions)
                                        {
                                            profile.AddPreprocessorDefinition(pd);
                                        }
                                    }
                                }
                            }

                            profile.AddPreprocessorDefinition(BuildSystemHelper.GetConfigurationModePreprocessor(configuration));
                            profile.AddPreprocessorDefinition(BuildSystemHelper.GetPlatformPreprocessor(EnvironmentHelper.Platform));
                            profile.AddPreprocessorDefinition(BuildSystemHelper.GetPlatformTypesPreprocessor(platform));
                            profile.AddPreprocessorDefinition(BuildSystemHelper.GetModuleNamePreprocessor(""));
                        }
                    }
                }
            }

            string[] files = FileSystemUtilites.GetAllFiles(WorkingDirectory, EnvironmentHelper.CSharpFileExtensions);

            foreach (string file in files)
            {
                projectFile.AddExtraFile(file);
            }

            files = FileSystemUtilites.GetAllFiles(WorkingDirectory, EnvironmentHelper.HeaderFileExtensions);
            foreach (string file in files)
            {
                projectFile.AddIncludeFile(file);
            }

            files = FileSystemUtilites.GetAllFiles(WorkingDirectory, EnvironmentHelper.CompileFileExtensions);
            foreach (string file in files)
            {
                projectFile.AddCompileFile(file);
            }

            MicrosoftVCProjectGenerator generator = new MicrosoftVCProjectGenerator();

            generator.ToolsVersion = MSBuildProcess.Info.ToolsVersion;

            File.WriteAllText(ProjectFilePath, generator.Generate(projectFile, true));
            File.WriteAllText(ProjectFilePath + ".filters", generator.GenerateFilter(projectFile, WorkingDirectory));

            return(true);
        }
Пример #4
0
        private void GenerateAndBuildProjectFile(bool ForceToRebuild)
        {
            LogCurrentInfo();

            if (!ForceToRebuild && !MustCompile())
            {
                state = States.AlreadyUpdated;
                return;
            }

            CPPProject cppProj = new CPPProject();

            CPPProject.Profile profile = (CPPProject.Profile)cppProj.CreateProfile();

            profile.AssemblyName       = SelectedRule.TargetName;
            profile.OutputType         = BuildSystemHelper.LibraryUseTypesToOutputType(SelectedRule.LibraryUseType);
            profile.OutputPath         = BinariesPath;
            profile.Optimization       = CPPProject.Profile.Optimizations.Disabled;
            profile.MinimalRebuild     = true;
            profile.PlatformType       = BuildSystem.PlatformType;
            profile.BuildConfiguration = BuildSystem.BuildConfiguration;

            if (profile.BuildConfiguration == ProjectBase.ProfileBase.BuildConfigurations.Debug)
            {
                profile.GenerateDebugInformation = true;

                //if (SelectedRule.LibraryUseType == BuildRules.LibraryUseTypes.Executable)
                //	profile.RuntimeLibrary = CPPProject.Profile.RuntimeLibraries.MultiThreadedDebug;
                //else
                profile.RuntimeLibrary = CPPProject.Profile.RuntimeLibraries.MultiThreadedDebugDLL;
            }
            else if (profile.BuildConfiguration == ProjectBase.ProfileBase.BuildConfigurations.Release)
            {
                profile.GenerateDebugInformation = false;

                //if (SelectedRule.LibraryUseType == BuildRules.LibraryUseTypes.Executable)
                //	profile.RuntimeLibrary = CPPProject.Profile.RuntimeLibraries.MultiThreaded;
                //else
                profile.RuntimeLibrary = CPPProject.Profile.RuntimeLibraries.MultiThreadedDLL;
            }

            profile.AddIncludeDirectories(EnvironmentHelper.ProcessDirectory);
            profile.AddIncludeDirectories(sourcePathRoot);
            profile.AddIncludeDirectories(generatedFilesPath);
            if (SelectedRule.DependencyModulesName != null)
            {
                foreach (string dep in SelectedRule.DependencyModulesName)
                {
                    AddDependency(profile, dep);
                }
            }

            if (SelectedRule.GenerateReflection)
            {
                AddDependency(profile, BuildSystemHelper.ReflectionModuleName);
            }

            profile.AddPreprocessorDefinition(BuildSystemHelper.GetModuleNamePreprocessor(BuildRule.ModuleName));
            profile.AddPreprocessorDefinition(BuildSystemHelper.GetAPIPreprocessor(BuildRule.ModuleName, BuildSystemHelper.APIPreprocessorTypes.Export));
            profile.AddPreprocessorDefinition(BuildSystemHelper.GetExternPreprocessor(BuildRule.ModuleName, BuildSystemHelper.ExternPreprocessorTypes.Fill));
            if (SelectedRule.PreprocessorDefinitions != null)
            {
                foreach (string def in SelectedRule.PreprocessorDefinitions)
                {
                    profile.AddPreprocessorDefinition(def);
                }
            }

            profile.AddPreprocessorDefinition(BuildSystemHelper.GetConfigurationModePreprocessor(BuildSystem.BuildConfiguration));
            profile.AddPreprocessorDefinition(BuildSystemHelper.GetPlatformPreprocessor(EnvironmentHelper.Platform));
            profile.AddPreprocessorDefinition(BuildSystemHelper.GetPlatformTypesPreprocessor(BuildSystem.PlatformType));

            if (SelectedRule.DependencyStaticLibraries != null)
            {
                foreach (string lib in SelectedRule.DependencyStaticLibraries)
                {
                    profile.AddIncludeLibraries(lib);
                }
            }

            string[] files = FileSystemUtilites.GetAllFiles(sourcePathRoot, EnvironmentHelper.HeaderFileExtensions);
            foreach (string file in files)
            {
                cppProj.AddIncludeFile(file);

                string outputBasePath = generatedFilesPath + Path.GetFileNameWithoutExtension(file);

                if (SelectedRule.GenerateReflection)
                {
                    string outputBaseFileName = outputBasePath + ".Reflection";
                    if (ParseForReflection(file, outputBaseFileName))
                    {
                        cppProj.AddIncludeFile(outputBaseFileName + ".h");
                        cppProj.AddCompileFile(outputBaseFileName + ".cpp");
                    }
                }

                if (SelectedRule.GenerateWrapper)
                {
                    string outputBaseFileName = outputBasePath + ".Wrapper";
                    if (ParseForWrapper(file, outputBaseFileName))
                    {
                        cppProj.AddIncludeFile(outputBaseFileName + ".h");
                        cppProj.AddCompileFile(outputBaseFileName + ".cpp");

                        wrapperCSFiles.Add(outputBaseFileName + ".cs");
                    }
                }
            }

            if (SelectedRule.IncludeModulesName != null)
            {
                foreach (string moduleName in SelectedRule.IncludeModulesName)
                {
                    SourceBuilder builder = BuildSystem.GetSourceBuilder(moduleName);

                    if (builder == null)
                    {
                        continue;
                    }

                    profile.AddIncludeDirectories(builder.sourcePathRoot);
                    profile.AddPreprocessorDefinition(BuildSystemHelper.GetAPIPreprocessor(builder.BuildRule.ModuleName, BuildSystemHelper.APIPreprocessorTypes.Empty));
                    profile.AddPreprocessorDefinition(BuildSystemHelper.GetExternPreprocessor(builder.BuildRule.ModuleName, BuildSystemHelper.ExternPreprocessorTypes.Empty));
                }
            }

            if (SelectedRule.AdditionalIncludeDirectory != null)
            {
                foreach (string dir in SelectedRule.AdditionalIncludeDirectory)
                {
                    string dirInfo = FileSystemUtilites.PathSeperatorCorrection(dir);

                    if (dirInfo.StartsWith("" + EnvironmentHelper.PathSeparator))
                    {
                        dirInfo = dirInfo.Substring(1);
                    }

                    profile.AddIncludeLibraryDirectories(sourcePathRoot + dirInfo);
                }
            }

            files = FileSystemUtilites.GetAllFiles(sourcePathRoot, EnvironmentHelper.CompileFileExtensions);
            foreach (string file in files)
            {
                cppProj.AddCompileFile(file);
            }

            if (SelectedRule.AdditionalCompileFile != null)
            {
                foreach (string file in SelectedRule.AdditionalCompileFile)
                {
                    cppProj.AddCompileFile(EnvironmentHelper.ProcessDirectory + file);
                }
            }

            profile.IntermediatePath = intermediateModulePath;

            BuildProjectFile(profile);
        }
Пример #5
0
        public bool Build()
        {
            string projectDir = EnvironmentHelper.IntermediateDirectory + ProjectName + EnvironmentHelper.PathSeparator;

            if (!Directory.Exists(projectDir))
            {
                Directory.CreateDirectory(projectDir);
            }

            CSProject csproj = new CSProject();

            CSProject.Profile profile = (CSProject.Profile)csproj.CreateProfile();

            profile.FrameworkVersion = CSProject.Profile.FrameworkVersions.v4_5;
            profile.AssemblyName     = ProjectName;
            profile.OutputPath       = projectDir + "Build" + EnvironmentHelper.PathSeparator;
            profile.IntermediatePath = projectDir;
            profile.OutputType       = ProjectBase.ProfileBase.OutputTypes.DynamicLinkLibrary;
            csproj.AddReferenceBinaryFile(Assembly.GetExecutingAssembly().Location);

            string[] files = FileSystemUtilites.GetAllFiles(processDirectory, "*" + BuildRules.BuildRuleFilePostfix);

            DateTime startTime = DateTime.Now;

            ConsoleHelper.WriteInfo("Building rules starts at " + startTime.ToString());
            ConsoleHelper.WriteInfo("Found rules :");

            if (files.Length == 0)
            {
                ConsoleHelper.WriteInfo("No building rules found, aborting process");
                return(false);
            }

            foreach (string rules in files)
            {
                csproj.AddCompileFile(rules);

                ConsoleHelper.WriteInfo("\t" + Path.GetFileName(rules));
            }

            Compiler compiler = new Compiler();

            compiler.ErrorRaised += OnError;

            if (compiler.Build(profile))
            {
                Assembly rulesLibrary = Assembly.LoadFile(profile.OutputPath + ProjectName + EnvironmentHelper.DynamicLibraryExtentions);

                List <string>     buildRulesFiles = new List <string>();
                List <BuildRules> buildRules      = new List <BuildRules>();

                foreach (string buildRuleName in files)
                {
                    string fileName = Path.GetFileNameWithoutExtension(buildRuleName);
                    string typeName = fileName.Replace(".", "");
                    Type   type     = rulesLibrary.GetType(BuildRules.NamespacePrefix + typeName);

                    if (type == null)
                    {
                        ConsoleHelper.WriteWarning("In " + fileName + ", type " + typeName + " doesn't exists, building related module will be ignore");
                        continue;
                    }

                    buildRulesFiles.Add(buildRuleName);

                    BuildRules buildRule = (BuildRules)Activator.CreateInstance(type);
                    buildRule.Path = FileSystemUtilites.PathSeperatorCorrection(Path.GetDirectoryName(buildRuleName)) + EnvironmentHelper.PathSeparator;

                    Type[] types = buildRule.GetType().GetNestedTypes();

                    buildRule.Rules = new BuildRules.RuleBase[types.Length];

                    for (int i = 0; i < types.Length; ++i)
                    {
                        buildRule.Rules[i] = (BuildRules.RuleBase)Activator.CreateInstance(types[i]);
                    }

                    buildRules.Add(buildRule);
                }

                RulesFiles = buildRulesFiles.ToArray();
                Rules      = buildRules.ToArray();

                return(true);
            }

            ConsoleHelper.WriteInfo("Building rules takes " + (DateTime.Now - startTime).ToHHMMSS());

            return(false);
        }