Пример #1
0
        private IEnumerable <string> EnumerateReferencePathCandidates(FileInfo sourceFilePath, string reference)
        {
            // Try with the full path
            if (Path.IsPathRooted(reference))
            {
                yield return(reference);
            }

            // Try relative from the sharpmake file
            yield return(Util.PathGetAbsolute(sourceFilePath.DirectoryName, reference));

            // Try next to the Sharpmake binary
            string pathToBinary = System.Reflection.Assembly.GetEntryAssembly()?.Location;

            if (!string.IsNullOrEmpty(pathToBinary))
            {
                yield return(Util.PathGetAbsolute(Path.GetDirectoryName(pathToBinary), reference));
            }

            // In some cases, the main module is not the current binary, so try it if so
            string mainModule = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;

            if (!string.IsNullOrEmpty(mainModule) && pathToBinary != mainModule)
            {
                yield return(Util.PathGetAbsolute(Path.GetDirectoryName(mainModule), reference));
            }

            // Try in the current working directory
            yield return(Util.PathGetAbsolute(Directory.GetCurrentDirectory(), reference));
        }
Пример #2
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);
            }
        }
Пример #3
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"
                            )
                        );
                }
            }
Пример #4
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);
            }
        }
Пример #5
0
        protected void FixupPrecompiledHeaderOptions(IGenerationContext context)
        {
            var options        = context.Options;
            var cmdLineOptions = context.CommandLineOptions;
            var conf           = context.Configuration;

            if (options["UsePrecompiledHeader"] == "NotUsing")
            {
                options["UsePrecompiledHeader"] = FileGeneratorUtilities.RemoveLineTag;
            }
            else
            {
                Strings pathsToConsider = new Strings(context.ProjectSourceCapitalized);
                pathsToConsider.AddRange(context.Project.AdditionalSourceRootPaths);
                pathsToConsider.AddRange(GetIncludePaths(context));

                string pchFileSourceRelative = context.Options["PrecompiledHeaderThrough"];

                string pchFileVcxprojRelative = null;
                bool   foundPchInclude        = false;

                foreach (var includePath in pathsToConsider)
                {
                    var pchFile = Util.PathGetAbsolute(includePath, pchFileSourceRelative);
                    if (conf.Project.ResolvedSourceFiles.Contains(pchFile))
                    {
                        pchFileVcxprojRelative = Util.PathGetRelative(context.ProjectDirectory, pchFile, true);
                        foundPchInclude        = true;
                        break;
                    }
                }

                if (!foundPchInclude)
                {
                    foreach (var includePath in pathsToConsider)
                    {
                        var pchFile = Util.PathGetAbsolute(includePath, pchFileSourceRelative);
                        if (Util.FileExists(pchFile))
                        {
                            pchFileVcxprojRelative = Util.PathGetRelative(context.ProjectDirectory, pchFile, true);
                            foundPchInclude        = true;
                            break;
                        }
                    }
                }

                if (!foundPchInclude)
                {
                    throw new Error($"Sharpmake couldn't locate the PCH '{pchFileSourceRelative}' in {conf}");
                }

                context.Options["PrecompiledHeaderThrough"] = pchFileVcxprojRelative;
            }
        }
Пример #6
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;
        }
Пример #7
0
        public static bool ProjectLogFiles(string projectFile)
        {
            List <string> sourceFiles     = new List <string>();
            FileInfo      projectFileInfo = new FileInfo(projectFile);

            if (!projectFileInfo.Exists)
            {
                return(false);
            }

            using (StreamReader projectStream = projectFileInfo.OpenText())
            {
                string line = projectStream.ReadLine();
                while (line != null)
                {
                    Match match = s_vcprojLogFileRegex.Match(line);

                    if (match.Success)
                    {
                        string relativeFileName = match.Groups["FILE"].ToString();
                        string fileName         = Util.PathGetAbsolute(projectFileInfo.Directory.FullName, relativeFileName);
                        sourceFiles.Add(fileName);
                    }
                    line = projectStream.ReadLine();
                }
            }

            if (sourceFiles.Count == 0)
            {
                return(false);
            }

            sourceFiles.Sort();


            MemoryStream memoryStream = new MemoryStream();
            StreamWriter streamWriter = new StreamWriter(memoryStream);

            foreach (string file in sourceFiles)
            {
                streamWriter.WriteLine(file);
            }

            streamWriter.Flush();
            FileInfo outputFileInfo = new FileInfo(projectFileInfo.FullName + ".files.log");

            Builder.Instance.Context.WriteGeneratedFile(null, outputFileInfo, memoryStream);
            streamWriter.Close();

            return(true);
        }
Пример #8
0
        internal static void GetSharpmakeReferencesFromLine(
            string line,
            FileInfo sourceFilePath,
            int lineNumber,
            ref List <string> references
            )
        {
            Match match = s_referenceRegex.Match(line);

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

                // Try next to the source file that reference it (if relative path)
                if (!Path.IsPathRooted(referenceRelativePath))
                {
                    referencePath = Util.PathGetAbsolute(sourceFilePath.DirectoryName, referenceRelativePath);
                }

                if (!Util.FileExists(referencePath))
                {
                    // Try next to the Sharpmake binary
                    referencePath = Util.PathGetAbsolute(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), referenceRelativePath);

                    if (!File.Exists(referencePath))
                    {
                        // Try in the current working directory
                        referencePath = Util.PathGetAbsolute(Directory.GetCurrentDirectory(), 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);
            }
        }
Пример #9
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);
            }
Пример #10
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
                                           )
                                       );
                }
            }
Пример #11
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"));
                }
            }
Пример #12
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
                    );
            }
Пример #13
0
 public static string ResolvePath(string root, string path)
 {
     return(Util.PathGetAbsolute(root, Util.PathMakeStandard(path)));
 }
Пример #14
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();
                }
            }
        }