Exemple #1
0
        internal static void GetSharpmakeIncludesFromLine(
            string line,
            FileInfo sourceFilePath,
            int lineNumber,
            ref List <string> includes
            )
        {
            Match match = s_includeRegex.Match(line);

            for (; match.Success; match = match.NextMatch())
            {
                string includeFilename         = match.Groups["INCLUDE"].ToString();
                string resolvedIncludeFilename = "";

                if (!Path.IsPathRooted(includeFilename))
                {
                    resolvedIncludeFilename = Util.PathGetAbsolute(sourceFilePath.DirectoryName, includeFilename);
                }
                else
                {
                    resolvedIncludeFilename = includeFilename;
                }

                if (!Util.FileExists(resolvedIncludeFilename))
                {
                    resolvedIncludeFilename = Util.GetCapitalizedPath(resolvedIncludeFilename);
                }
                if (!Util.FileExists(resolvedIncludeFilename))
                {
                    throw new Error("\t" + sourceFilePath.FullName + "(" + lineNumber + "): error: Sharpmake.Include file not found {0}", includeFilename);
                }

                includes.Add(resolvedIncludeFilename);
            }
        }
Exemple #2
0
            public override void SetConfiguration(IDictionary <string, CompilerSettings.Configuration> configurations, string compilerName, string projectRootPath, DevEnv devEnv, bool useCCompiler)
            {
                string configName = ".win64Config";

                if (!configurations.ContainsKey(configName))
                {
                    var    fastBuildCompilerSettings = PlatformRegistry.Get <IWindowsFastBuildCompilerSettings>(Platform.win64);
                    string binPath;
                    if (!fastBuildCompilerSettings.BinPath.TryGetValue(devEnv, out binPath))
                    {
                        binPath = devEnv.GetVisualStudioBinPath(Platform.win64);
                    }

                    string linkerPath;
                    if (!fastBuildCompilerSettings.LinkerPath.TryGetValue(devEnv, out linkerPath))
                    {
                        linkerPath = binPath;
                    }

                    string linkerExe;
                    if (!fastBuildCompilerSettings.LinkerExe.TryGetValue(devEnv, out linkerExe))
                    {
                        linkerExe = "link.exe";
                    }

                    string librarianExe;
                    if (!fastBuildCompilerSettings.LibrarianExe.TryGetValue(devEnv, out librarianExe))
                    {
                        librarianExe = "lib.exe";
                    }

                    string resCompiler;
                    if (!fastBuildCompilerSettings.ResCompiler.TryGetValue(devEnv, out resCompiler))
                    {
                        resCompiler = devEnv.GetWindowsResourceCompiler(Platform.win64);
                    }

                    configurations.Add(
                        configName,
                        new CompilerSettings.Configuration(
                            Platform.win64,
                            binPath: Util.GetCapitalizedPath(Util.PathGetAbsolute(projectRootPath, binPath)),
                            linkerPath: Util.GetCapitalizedPath(Util.PathGetAbsolute(projectRootPath, linkerPath)),
                            resourceCompiler: Util.GetCapitalizedPath(Util.PathGetAbsolute(projectRootPath, resCompiler)),
                            librarian: Path.Combine(@"$LinkerPath$", librarianExe),
                            linker: Path.Combine(@"$LinkerPath$", linkerExe)
                            )
                        );

                    configurations.Add(
                        ".win64ConfigMasm",
                        new CompilerSettings.Configuration(
                            Platform.win64,
                            compiler: @"$BinPath$\ml64.exe",
                            usingOtherConfiguration: @".win64Config"
                            )
                        );
                }
            }
Exemple #3
0
        public override void ParseParameter(string[] parameters, FileInfo sourceFilePath, int lineNumber, IAssemblerContext context)
        {
            string      includeFilename = parameters[0];
            IncludeType matchType       = IncludeType.Relative;

            if (parameters.Length > 1)
            {
                string incType = parameters[1].Replace("Sharpmake.", "");
                incType = incType.Replace("IncludeType.", "");
                if (!Enum.TryParse <IncludeType>(incType, out matchType))
                {
                    throw new Error("\t" + sourceFilePath.FullName + "(" + lineNumber + "): error: Sharpmake.Include invalid include type used ({0})", parameters[1]);
                }
            }
            string includeAbsolutePath = Path.IsPathRooted(includeFilename) ? includeFilename : null;

            if (Util.IsPathWithWildcards(includeFilename))
            {
                if (matchType != IncludeType.Relative)
                {
                    throw new Error("\t" + sourceFilePath.FullName + "(" + lineNumber + "): error: Sharpmake.Include with non-relative match types, wildcards are not supported ({0})", includeFilename);
                }
                includeAbsolutePath = includeAbsolutePath ?? Path.Combine(sourceFilePath.DirectoryName, includeFilename);
                context.AddSourceFiles(Util.DirectoryGetFilesWithWildcards(includeAbsolutePath));
            }
            else
            {
                includeAbsolutePath = includeAbsolutePath ?? Util.PathGetAbsolute(sourceFilePath.DirectoryName, includeFilename);

                if (matchType == IncludeType.Relative)
                {
                    if (!Util.FileExists(includeAbsolutePath))
                    {
                        includeAbsolutePath = Util.GetCapitalizedPath(includeAbsolutePath);
                    }
                }
                else
                {
                    string matchIncludeInParentPath = MatchIncludeInParentPath(includeFilename, sourceFilePath.DirectoryName, matchType);
                    if (matchIncludeInParentPath == null)
                    {
                        throw new Error("\t" + sourceFilePath.FullName + "(" + lineNumber + "): error: Sharpmake.Include file not found '{0}'[{1}]. Search started from '{2}'", includeFilename, matchType, sourceFilePath.DirectoryName);
                    }

                    includeAbsolutePath = Util.GetCapitalizedPath(matchIncludeInParentPath);
                }

                if (!Util.FileExists(includeAbsolutePath))
                {
                    throw new Error("\t" + sourceFilePath.FullName + "(" + lineNumber + "): error: Sharpmake.Include file not found {0}", includeFilename);
                }

                context.AddSourceFile(includeAbsolutePath);
            }
        }
Exemple #4
0
        public override void ParseParameter(string[] parameters, FileInfo sourceFilePath, int lineNumber, IAssemblerContext context)
        {
            string includeFilename = parameters[0];
            string includeAbsolutePath;

            if (Path.IsPathRooted(includeFilename))
            {
                includeAbsolutePath = includeFilename;
            }
            else if (Util.IsPathWithWildcards(includeFilename))
            {
                includeAbsolutePath = Path.Combine(sourceFilePath.DirectoryName, includeFilename);
            }
            else
            {
                includeAbsolutePath = Util.PathGetAbsolute(sourceFilePath.DirectoryName, includeFilename);
            }

            IAssemblyInfo assemblyInfo;

            if (s_assemblies.TryGetValue(includeAbsolutePath, out assemblyInfo))
            {
                if (assemblyInfo == null)
                {
                    throw new Error($"Circular Sharpmake.Package dependency on {includeFilename}");
                }
                context.AddReference(assemblyInfo);
                return;
            }
            s_assemblies[includeAbsolutePath] = null;

            string[] files;
            if (Util.IsPathWithWildcards(includeFilename))
            {
                files = Util.DirectoryGetFilesWithWildcards(includeAbsolutePath);
            }
            else
            {
                if (!Util.FileExists(includeAbsolutePath))
                {
                    includeAbsolutePath = Util.GetCapitalizedPath(includeAbsolutePath);
                }
                if (!Util.FileExists(includeAbsolutePath))
                {
                    throw new Error("\t" + sourceFilePath.FullName + "(" + lineNumber + "): error: Sharpmake.Package file not found {0}", includeFilename);
                }

                files = new string[] { includeAbsolutePath };
            }

            assemblyInfo = context.BuildLoadAndAddReferenceToSharpmakeFilesAssembly(files);
            s_assemblies[includeAbsolutePath] = assemblyInfo;
        }
Exemple #5
0
            private CompilerSettings GetMasterCompilerSettings(IDictionary <string, CompilerSettings> masterCompilerSettings, string compilerName, DevEnv devEnv, string projectRootPath, bool useCCompiler)
            {
                CompilerSettings compilerSettings;

                if (masterCompilerSettings.ContainsKey(compilerName))
                {
                    compilerSettings = masterCompilerSettings[compilerName];
                }
                else
                {
                    var fastBuildSettings = PlatformRegistry.Get <IFastBuildCompilerSettings>(Platform.linux);

                    string binPath;
                    if (!fastBuildSettings.BinPath.TryGetValue(devEnv, out binPath))
                    {
                        binPath = ClangForWindows.GetWindowsClangExecutablePath();
                    }

                    string pathToCompiler = Util.GetCapitalizedPath(Util.PathGetAbsolute(projectRootPath, binPath));

                    Strings extraFiles = new Strings();
                    {
                        Strings userExtraFiles;
                        if (fastBuildSettings.ExtraFiles.TryGetValue(devEnv, out userExtraFiles))
                        {
                            extraFiles.AddRange(userExtraFiles);
                        }
                    }

                    var compilerFamily    = Sharpmake.CompilerFamily.Clang;
                    var compilerFamilyKey = new FastBuildCompilerKey(devEnv);
                    if (!fastBuildSettings.CompilerFamily.TryGetValue(compilerFamilyKey, out compilerFamily))
                    {
                        compilerFamily = Sharpmake.CompilerFamily.Clang;
                    }

                    string executable = useCCompiler ? @"$ExecutableRootPath$\clang.exe" : @"$ExecutableRootPath$\clang++.exe";

                    compilerSettings = new CompilerSettings(compilerName, compilerFamily, Platform.linux, extraFiles, executable, pathToCompiler, devEnv, new Dictionary <string, CompilerSettings.Configuration>());
                    masterCompilerSettings.Add(compilerName, compilerSettings);
                }

                return(compilerSettings);
            }
Exemple #6
0
            private void SetConfiguration(CompilerSettings compilerSettings, string compilerName, string projectRootPath, DevEnv devEnv, bool useCCompiler)
            {
                string configName = useCCompiler ? ".linuxConfig" : ".linuxppConfig";

                IDictionary <string, CompilerSettings.Configuration> configurations = compilerSettings.Configurations;

                if (!configurations.ContainsKey(configName))
                {
                    var    fastBuildSettings = PlatformRegistry.Get <IFastBuildCompilerSettings>(Platform.linux);
                    string binPath           = compilerSettings.RootPath;
                    string linkerPath;
                    if (!fastBuildSettings.LinkerPath.TryGetValue(devEnv, out linkerPath))
                    {
                        linkerPath = binPath;
                    }

                    string linkerExe;
                    if (!fastBuildSettings.LinkerExe.TryGetValue(devEnv, out linkerExe))
                    {
                        linkerExe = "ld.lld.exe";
                    }

                    string librarianExe;
                    if (!fastBuildSettings.LibrarianExe.TryGetValue(devEnv, out librarianExe))
                    {
                        librarianExe = "llvm-ar.exe";
                    }

                    configurations.Add(configName,
                                       new CompilerSettings.Configuration(
                                           Platform.linux,
                                           compiler: compilerName,
                                           binPath: binPath,
                                           linkerPath: Util.GetCapitalizedPath(Util.PathGetAbsolute(projectRootPath, linkerPath)),
                                           librarian: @"$LinkerPath$\" + librarianExe,
                                           linker: @"$LinkerPath$\" + linkerExe,
                                           fastBuildLinkerType: CompilerSettings.LinkerType.GCC // Workaround: set GCC linker type since it will only enable response files
                                           )
                                       );
                }
            }
Exemple #7
0
            public override void SetConfiguration(IDictionary <string, CompilerSettings.Configuration> configurations, string compilerName, string projectRootPath, DevEnv devEnv, bool useCCompiler)
            {
                string configName = ".win64Config";

                if (!configurations.ContainsKey(configName))
                {
                    var    fastBuildCompilerSettings = PlatformRegistry.Get <IWindowsFastBuildCompilerSettings>(Platform.win64);
                    string binPath     = fastBuildCompilerSettings.BinPath[devEnv];
                    string linkerPath  = fastBuildCompilerSettings.LinkerPath[devEnv];
                    string resCompiler = fastBuildCompilerSettings.ResCompiler[devEnv];
                    configurations.Add(configName,
                                       new CompilerSettings.Configuration(
                                           Platform.win64,
                                           binPath: Util.GetCapitalizedPath(Util.PathGetAbsolute(projectRootPath, binPath)),
                                           linkerPath: Util.GetCapitalizedPath(Util.PathGetAbsolute(projectRootPath, linkerPath)),
                                           resourceCompiler: Util.GetCapitalizedPath(Util.PathGetAbsolute(projectRootPath, resCompiler)),
                                           librarian: @"$LinkerPath$\lib.exe",
                                           linker: @"$LinkerPath$\link.exe"
                                           )
                                       );

                    configurations.Add(".win64ConfigMasm", new CompilerSettings.Configuration(Platform.win64, compiler: @"$BinPath$\ml64.exe", usingOtherConfiguration: @".win64Config"));
                }
            }
Exemple #8
0
            private void SetConfiguration(
                Project.Configuration conf,
                IDictionary <string, CompilerSettings.Configuration> configurations,
                string configName,
                string projectRootPath,
                DevEnv devEnv,
                bool useCCompiler)
            {
                if (configurations.ContainsKey(configName))
                {
                    return;
                }

                string linkerPathOverride   = null;
                string linkerExeOverride    = null;
                string librarianExeOverride = null;

                GetLinkerExecutableInfo(conf, out linkerPathOverride, out linkerExeOverride, out librarianExeOverride);

                var    fastBuildCompilerSettings = PlatformRegistry.Get <IWindowsFastBuildCompilerSettings>(Platform.win64);
                string binPath;

                if (!fastBuildCompilerSettings.BinPath.TryGetValue(devEnv, out binPath))
                {
                    binPath = devEnv.GetVisualStudioBinPath(Platform.win64);
                }

                string linkerPath;

                if (!string.IsNullOrEmpty(linkerPathOverride))
                {
                    linkerPath = linkerPathOverride;
                }
                else if (!fastBuildCompilerSettings.LinkerPath.TryGetValue(devEnv, out linkerPath))
                {
                    linkerPath = binPath;
                }

                string linkerExe;

                if (!string.IsNullOrEmpty(linkerExeOverride))
                {
                    linkerExe = linkerExeOverride;
                }
                else if (!fastBuildCompilerSettings.LinkerExe.TryGetValue(devEnv, out linkerExe))
                {
                    linkerExe = "link.exe";
                }

                string librarianExe;

                if (!string.IsNullOrEmpty(librarianExeOverride))
                {
                    librarianExe = librarianExeOverride;
                }
                else if (!fastBuildCompilerSettings.LibrarianExe.TryGetValue(devEnv, out librarianExe))
                {
                    librarianExe = "lib.exe";
                }

                string resCompiler;

                if (!fastBuildCompilerSettings.ResCompiler.TryGetValue(devEnv, out resCompiler))
                {
                    resCompiler = devEnv.GetWindowsResourceCompiler(Platform.win64);
                }

                string capitalizedBinPath = Util.GetCapitalizedPath(Util.PathGetAbsolute(projectRootPath, binPath));

                configurations.Add(
                    configName,
                    new CompilerSettings.Configuration(
                        Platform.win64,
                        binPath: capitalizedBinPath,
                        linkerPath: Util.GetCapitalizedPath(Util.PathGetAbsolute(projectRootPath, linkerPath)),
                        resourceCompiler: Util.GetCapitalizedPath(Util.PathGetAbsolute(projectRootPath, resCompiler)),
                        librarian: Path.Combine(@"$LinkerPath$", librarianExe),
                        linker: Path.Combine(@"$LinkerPath$", linkerExe)
                        )
                    );

                string masmConfigurationName = configName + "Masm";
                var    masmConfiguration     = new CompilerSettings.Configuration(
                    Platform.win64,
                    compiler: "ML" + masmConfigurationName,
                    usingOtherConfiguration: configName
                    );

                masmConfiguration.Masm = Path.Combine(capitalizedBinPath, "ml64.exe");

                configurations.Add(
                    masmConfigurationName,
                    masmConfiguration
                    );
            }
Exemple #9
0
        public IEnumerable <ResolvedProject> GetResolvedProjects(IEnumerable <Configuration> solutionConfigurations, out bool projectsWereFiltered)
        {
            if (!_dependenciesResolved)
            {
                throw new InternalError("Solution not resolved: {0}", GetType().FullName);
            }
            projectsWereFiltered = false;
            var result = new Dictionary <string, ResolvedProject>();

            Dictionary <Project.Configuration, ResolvedProject> configurationsToProjects = new Dictionary <Project.Configuration, ResolvedProject>();

            foreach (Configuration solutionConfiguration in solutionConfigurations)
            {
                foreach (Configuration.IncludedProjectInfo includedProjectInfo in solutionConfiguration.IncludedProjectInfos)
                {
                    if (solutionConfiguration.IncludeOnlyFilterProject && !(includedProjectInfo.Project.IsFastBuildAll) && (includedProjectInfo.Project.SourceFilesFiltersCount == 0 || includedProjectInfo.Project.SkipProjectWhenFiltersActive))
                    {
                        projectsWereFiltered = true;
                        continue;
                    }

                    ResolvedProject resolvedProject = result.GetValueOrAdd(
                        includedProjectInfo.Configuration.ProjectFullFileName,
                        new ResolvedProject
                    {
                        Project                = includedProjectInfo.Project,
                        TargetDefault          = includedProjectInfo.Target,
                        OriginalProjectFile    = includedProjectInfo.Configuration.ProjectFullFileName,
                        ProjectFile            = Util.GetCapitalizedPath(includedProjectInfo.Configuration.ProjectFullFileNameWithExtension),
                        ProjectName            = includedProjectInfo.Configuration.ProjectName,
                        SolutionFolder         = includedProjectInfo.SolutionFolder,
                        SolutionFolderOverride = includedProjectInfo.SolutionFolder
                    });

                    resolvedProject.Configurations.Add(includedProjectInfo.Configuration);

                    if (!configurationsToProjects.ContainsKey(includedProjectInfo.Configuration))
                    {
                        configurationsToProjects[includedProjectInfo.Configuration] = resolvedProject;
                    }
                }
            }


            foreach (ResolvedProject resolvedProject in result.Values)
            {
                foreach (Project.Configuration resolvedProjectConf in resolvedProject.Configurations)
                {
                    // If the solution provides the folder, the configuration should be ignored
                    if (string.IsNullOrEmpty(resolvedProject.SolutionFolderOverride))
                    {
                        // Folder must all be the same for all config, else will be emptied.
                        if (string.IsNullOrEmpty(resolvedProject.SolutionFolder) &&
                            !string.IsNullOrEmpty(resolvedProjectConf.SolutionFolder))
                        {
                            resolvedProject.SolutionFolder = resolvedProjectConf.SolutionFolder;
                        }
                        else if (resolvedProject.SolutionFolder != resolvedProjectConf.SolutionFolder)
                        {
                            resolvedProject.SolutionFolder = "";
                        }
                    }

                    foreach (Project.Configuration dependencyConfiguration in resolvedProjectConf.ResolvedDependencies)
                    {
                        if (configurationsToProjects.ContainsKey(dependencyConfiguration))
                        {
                            var resolvedProjectToAdd = configurationsToProjects[dependencyConfiguration];

                            if (!resolvedProject.Dependencies.Contains(resolvedProjectToAdd))
                            {
                                resolvedProject.Dependencies.Add(resolvedProjectToAdd);
                            }
                        }
                    }
                }
            }

            return(result.Values);
        }
Exemple #10
0
        public IEnumerable <ResolvedProject> GetResolvedProjects(IEnumerable <Configuration> solutionConfigurations, out bool projectsWereFiltered)
        {
            if (!_dependenciesResolved)
            {
                throw new InternalError("Solution not resolved: {0}", GetType().FullName);
            }
            projectsWereFiltered = false;
            List <ResolvedProject> result = new List <ResolvedProject>();

            foreach (Configuration solutionConfiguration in solutionConfigurations)
            {
                foreach (Configuration.IncludedProjectInfo includedProjectInfo in solutionConfiguration.IncludedProjectInfos)
                {
                    if (solutionConfiguration.IncludeOnlyFilterProject && !(includedProjectInfo.Project is FastBuildAllProject) && (includedProjectInfo.Project.SourceFilesFiltersCount == 0 || includedProjectInfo.Project.SkipProjectWhenFiltersActive))
                    {
                        projectsWereFiltered = true;
                        continue;
                    }

                    ResolvedProject resolvedProject = result.Find(p => p.OriginalProjectFile == includedProjectInfo.Configuration.ProjectFullFileName);
                    if (resolvedProject == null)
                    {
                        resolvedProject = new ResolvedProject
                        {
                            Project             = includedProjectInfo.Project,
                            TargetDefault       = includedProjectInfo.Target,
                            OriginalProjectFile = includedProjectInfo.Configuration.ProjectFullFileName,
                            ProjectFile         = Util.GetCapitalizedPath(includedProjectInfo.Configuration.ProjectFullFileNameWithExtension),
                            ProjectName         = includedProjectInfo.Configuration.ProjectName
                        };
                        result.Add(resolvedProject);
                    }

                    resolvedProject.Configurations.Add(includedProjectInfo.Configuration);
                }
            }


            foreach (ResolvedProject resolvedProject in result)
            {
                // Folder must all be the same for all config, else will be emptied.
                foreach (Project.Configuration projectConfiguration in resolvedProject.Configurations)
                {
                    if (resolvedProject.SolutionFolder == null)
                    {
                        resolvedProject.SolutionFolder = projectConfiguration.SolutionFolder;
                    }
                    else if (resolvedProject.SolutionFolder != projectConfiguration.SolutionFolder)
                    {
                        resolvedProject.SolutionFolder = "";
                    }
                }

                foreach (Project.Configuration resolvedProjectConf in resolvedProject.Configurations)
                {
                    foreach (Project.Configuration dependencyConfiguration in resolvedProjectConf.ResolvedDependencies)
                    {
                        foreach (ResolvedProject resolvedProjectToAdd in result)
                        {
                            if (resolvedProjectToAdd.Configurations.Contains(dependencyConfiguration))
                            {
                                if (!resolvedProject.Dependencies.Contains(resolvedProjectToAdd))
                                {
                                    resolvedProject.Dependencies.Add(resolvedProjectToAdd);
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }
Exemple #11
0
        private void AnalyseSourceFile(string sourceFile, List <string> includes)
        {
            using (StreamReader reader = new StreamReader(sourceFile))
            {
                FileInfo sourceFilePath = new FileInfo(sourceFile);

                int    lineNumber = 0;
                string line       = reader.ReadLine();
                while (line != null)
                {
                    ++lineNumber;

                    Match match = s_includeRegex.Match(line);
                    for (; match.Success; match = match.NextMatch())
                    {
                        string includeFilename         = match.Groups["INCLUDE"].ToString();
                        string resolvedIncludeFilename = "";

                        if (!Path.IsPathRooted(includeFilename))
                        {
                            resolvedIncludeFilename = Util.PathGetAbsolute(sourceFilePath.DirectoryName, includeFilename);
                        }

                        if (!File.Exists(resolvedIncludeFilename))
                        {
                            resolvedIncludeFilename = Util.GetCapitalizedPath(resolvedIncludeFilename);
                        }
                        if (!File.Exists(resolvedIncludeFilename))
                        {
                            throw new Error("\t" + sourceFilePath.FullName + "(" + lineNumber + "): error: Sharpmake.Include file not found {0}", includeFilename);
                        }

                        includes.Add(resolvedIncludeFilename);
                    }

                    match = s_referenceRegex.Match(line);
                    for (; match.Success; match = match.NextMatch())
                    {
                        string referenceRelativePath = match.Groups["REFERENCE"].ToString();
                        string referencePath         = "";

                        if (!Path.IsPathRooted(referenceRelativePath))
                        {
                            referencePath = Util.PathGetAbsolute(sourceFilePath.DirectoryName, referenceRelativePath);
                        }

                        if (!File.Exists(referencePath))
                        {
                            referencePath = Util.PathGetAbsolute(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), referenceRelativePath);
                            if (!File.Exists(referencePath))
                            {
                                // try using .net framework locations
                                referencePath = GetAssemblyDllPath(referenceRelativePath);

                                if (referencePath == null)
                                {
                                    throw new Error("\t" + sourceFilePath.FullName + "(" + lineNumber + "): error: Sharpmake.Reference file not found: {0}", referenceRelativePath);
                                }
                            }
                        }

                        _references.Add(referencePath);
                    }
                    line = reader.ReadLine();
                }
            }
        }