Example #1
0
        public Boolean AddProjectFile(ProjectFile pf)
        {
            if (ProjectFiles.Contains(pf))
            {
                // TODO: maybe the build system is dumb and recompiles the same file multiple times?
                return(false);
            }

            ProjectFiles.Add(pf);

            if (pf.ProjectFolder != null)
            {
                // create project structure
                RelativeCrosspath projectFolder = new RelativeCrosspath(pf.ProjectFolder);
                Stack <String>    todo          = new Stack <String>();
                while (true)
                {
                    String fldr = projectFolder.ToString().Replace('/', '\\');
                    if (fldr == "." || ProjectFilters.Contains(fldr))
                    {
                        break;
                    }

                    todo.Push(fldr);
                    projectFolder.ToContainingDirectory();
                }

                foreach (String filter in todo)
                {
                    ProjectFilters.Add(filter);
                }
            }

            return(true);
        }
        public void RelativizeTestWin1()
        {
            AbsoluteCrosspath xIncludeDirectory = AbsoluteCrosspath.FromString(@"C:\Windows\system32\config");
            AbsoluteCrosspath xFile             = AbsoluteCrosspath.FromString(@"C:\Program Files (x86)\Common Files\Microsoft");
            RelativeCrosspath relPath           = xFile.Relativized(xIncludeDirectory);

            Assert.AreEqual(@"..\..\..\Program Files (x86)\Common Files\Microsoft", relPath.ToString());
        }
        public void RelativizeTest2()
        {
            AbsoluteCrosspath xIncludeDirectory = AbsoluteCrosspath.FromString("/local/store/bin-src/qemu");
            AbsoluteCrosspath xFile             = AbsoluteCrosspath.FromString("/local/store/fast/bin-src/ccache/ccache.c");
            RelativeCrosspath relPath           = xFile.Relativized(xIncludeDirectory);

            Assert.AreEqual("../../fast/bin-src/ccache/ccache.c", relPath.ToString());
        }
        public void RelativizeTest1()
        {
            AbsoluteCrosspath xIncludeDirectory = AbsoluteCrosspath.FromString("/local/store/bin-src/qemu");
            AbsoluteCrosspath xFile             = AbsoluteCrosspath.FromString("/local/store/bin-src/qemu/hw/mips/serial.c");
            RelativeCrosspath relPath           = xFile.Relativized(xIncludeDirectory);

            Assert.AreEqual("hw/mips/serial.c", relPath.ToString());
        }
        public void AppendedTest()
        {
            AbsoluteCrosspath xLocalIncludeDirectory = AbsoluteCrosspath.GetCurrentDirectory();
            RelativeCrosspath xRelPath = RelativeCrosspath.FromString("lzcintrin.h");
            AbsoluteCrosspath xPath    = xLocalIncludeDirectory.Appended(xRelPath);

            Assert.AreEqual(xPath.ToString(), xLocalIncludeDirectory + @"\" + xRelPath);
        }
        public void RelativizeTest3()
        {
            AbsoluteCrosspath xIncludeDirectory = AbsoluteCrosspath.FromString("/local/store/bin-src/qemu");
            AbsoluteCrosspath xFile             = AbsoluteCrosspath.FromString("/local/store/fast/bin-src/ccache/ccache.c");

            try {
                RelativeCrosspath unused = xFile.Relativized(xIncludeDirectory, true);
                Assert.Fail("should fail");
            }
            catch (CrosspathLibException) {
            }
        }
        public void RelativizeTestWin2()
        {
            AbsoluteCrosspath xIncludeDirectory = AbsoluteCrosspath.FromString(@"C:\Windows\system32\config");
            AbsoluteCrosspath xFile             = AbsoluteCrosspath.FromString(@"D:\Games\Call of Duty 2");

            try {
                RelativeCrosspath unused = xFile.Relativized(xIncludeDirectory);
                Assert.Fail("should fail");
            }
            catch {
                // ignored
            }
        }
Example #8
0
 public void FilterOutEntries()
 {
     foreach (Compiler compiler in solutionCompilers)
     {
         RelativeCrosspath compilerFilename = RelativeCrosspath.FromString(compiler.ExePath.LastEntry);
         if (config.ExcludeCompilers.Contains(compiler.ExePath) || config.ExcludeCompilers.Contains(compilerFilename))
         {
             // Remove projects
             compiler.Skip = true;
             Logger.WriteLine(LogLevel.Debug, $"Skipping compiler {compiler}, all inherent instances and projects");
         }
     }
 }
        public void HashDiversedEquality()
        {
            HashSet <Crosspath> hs = new HashSet <Crosspath> {
                Crosspath.FromString("/tmp/VCXProjWriter")
                , AbsoluteCrosspath.FromString("/tmp/VCXProjWriter1")
                , RelativeCrosspath.FromString("tmp/VCXProjWriter")
            };
            RelativeCrosspath relativeCrosspath = RelativeCrosspath.FromString("VCXProjWriter");

            relativeCrosspath.SetWorkingDirectory(AbsoluteCrosspath.FromString("/tmp"));
            Boolean has_added = hs.Add(relativeCrosspath);

            Assert.AreEqual(false, has_added);
            Assert.AreEqual(3, hs.Count);
        }
Example #10
0
 public ProjectFile(Solution sln, AbsoluteCrosspath filePath, CompilerInstance compilerInstance)
 {
     CompilerOfFile     = compilerInstance;
     IncludeDirectories = new IncludeDirectoryList();
     DoNotUseStandardIncludeDirectories = false;
     Defines       = new Dictionary <String, Define>();
     SetOfDefines  = new HashSet <Define>(DefineExactComparer.Instance);
     ForceIncludes = new HashSet <AbsoluteCrosspath>();
     FilePath      = filePath;
     OwnerSolution = sln;
     if (sln.config.BaseDir != null)
     {
         ProjectFolder = RelativeCrosspath.CreateRelativePath(filePath, sln.config.BaseDir, true).ToContainingDirectory() as RelativeCrosspath;
     }
 }
Example #11
0
        public void DownloadStandardIncludeDirectories(RemoteHost remote)
        {
            if (Skip)
            {
                return;
            }
            // use sftp, or, when not possible, ssh cat
            AbsoluteCrosspath xpwd         = AbsoluteCrosspath.GetCurrentDirectory();
            AbsoluteCrosspath xCompilerDir = xpwd.Appended(RelativeCrosspath.FromString($@"compilers\{ShortName}"));

            Directory.CreateDirectory(xCompilerDir.ToString());
            foreach (IncludeDirectory includeDirectory in IncludeDirectories)
            {
                includeDirectory.RebaseToLocal(remote, xCompilerDir);
            }
        }
Example #12
0
        /// <summary>
        /// Writes compiler_${ShortName}.props and compiler_$(ShortName}_compat.h
        /// </summary>
        public void WriteToFile(AbsoluteCrosspath solutionDir)
        {
            if (Skip)
            {
                return;
            }

            AbsoluteCrosspath compilerDir = RelativeCrosspath.FromString(PropsFileName).Absolutized(AbsoluteCrosspath.GetCurrentDirectory()).ToContainingDirectory();

            Directory.CreateDirectory(compilerDir.ToString());

            foreach (CompilerInstance compilerInstance in Instances)
            {
                compilerInstance.WriteToFile(solutionDir);
            }

            XmlDocument doc = new XmlDocument();

            doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", null));

            XmlElement projectNode = doc.CreateElement("Project");

            projectNode.SetAttribute("DefaultTargets", "Build");
            projectNode.SetAttribute("ToolsVersion", "Current");
            projectNode.SetAttribute("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");

            XmlElement projectImportProps = doc.CreateElement("Import");

            projectImportProps.SetAttribute("Project", @"$(SolutionDir)\Solution.props");
            projectNode.AppendChild(projectImportProps);

            XmlElement projectPropertyGroupCompiler = doc.CreateElement("PropertyGroup");
            XmlElement projectCompilerExeName       = doc.CreateElement("RemoteCCompileToolExe");

            projectCompilerExeName.InnerText = ExePath.ToString();
            projectPropertyGroupCompiler.AppendChild(projectCompilerExeName);
            XmlElement projectCompilerCppExeName = doc.CreateElement("RemoteCppCompileToolExe");

            projectCompilerCppExeName.InnerText = ExePath.ToString();
            projectPropertyGroupCompiler.AppendChild(projectCompilerCppExeName);

            projectNode.AppendChild(projectPropertyGroupCompiler);

            doc.AppendChild(projectNode);
            doc.Save(PropsFileName);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="remote">Remote host to download from</param>
        /// <param name="localXpath">Local directory for remote include directories, e.g. D:\Project1\remote\192.168.0.1.</param>
        public void RebaseToLocal(RemoteHost remote, AbsoluteCrosspath localXpath)
        {
            if (this.Flavor == CrosspathFlavor.Windows)
            {
                return;
            }

            int xtractBufSize = 65536;

            Byte[] zipExtractBuf = new Byte[xtractBufSize];

            String remoteFilename        = $"/tmp/{ShortName}.zip";
            String localDirectoryPattern = $@"include\{ShortName}";
            String localFilenamePattern  = $"{ShortName}.zip";

            AbsoluteCrosspath xLocalIncludeDirectory = localXpath.Appended(RelativeCrosspath.FromString(localDirectoryPattern));
            String            localIncludeDirectory  = xLocalIncludeDirectory.ToString();
            String            localFilename          = localXpath.Appended(RelativeCrosspath.FromString(localFilenamePattern)).ToString();

            Logger.WriteLine(LogLevel.Info, $"Rolling {this} into {localFilenamePattern}...");
            Directory.CreateDirectory(localIncludeDirectory);
            if (remote.Execute($"pushd {this} && zip -1 -r -q {remoteFilename} . && popd", out String result) != RemoteHost.Success)
            {
                Logger.WriteLine(LogLevel.Error, result);
                // FIXME, hack
                this.Rebase(this, xLocalIncludeDirectory);
                autoDownloaded = true;
                return;
            }

            remote.DownloadFile(remoteFilename, localFilename);
            File.WriteAllText(xLocalIncludeDirectory.Appended(RelativeCrosspath.FromString($@"..\{ShortName}_origin.txt")).ToString(), this.ToString());

            // not working bcz of NTFS case & special names restrictions. extract manually.
            //ZipFile.ExtractToDirectory(localFilename, localDirectory, Encoding.UTF8);

            using (FileStream fs = new FileStream(localFilename, FileMode.Open)) {
                ZipArchive za = new ZipArchive(fs, ZipArchiveMode.Read);
                foreach (ZipArchiveEntry zaEntry in za.Entries)
                {
                    RelativeCrosspath xRelPath = RelativeCrosspath.FromString(zaEntry.FullName);
                    AbsoluteCrosspath xPath    = xLocalIncludeDirectory.Appended(xRelPath);
                    if (zaEntry.FullName.EndsWith("/"))
                    {
                        // packed directory
                        continue;
                    }

                    String path = xPath.ToString();
                    if (File.Exists(path))
                    {
                        Logger.WriteLine(LogLevel.Warning, $"file '{zaEntry.FullName}' already exists as '{path}' - case problems?");
                        continue;
                    }

                    // hax, remove leading / from path
                    if (xRelPath.ToString() == Compiler.RemoteTempFile.Substring(1))
                    {
                        continue;
                    }

                    String dirname = new AbsoluteCrosspath(xPath).ToContainingDirectory().ToString();
                    try {
                        Directory.CreateDirectory(dirname);
                        // packed file
                        using (FileStream xfs = new FileStream(path, FileMode.CreateNew)) {
                            using (Stream zas = zaEntry.Open()) {
                                while (true)
                                {
                                    int len = zas.Read(zipExtractBuf, 0, xtractBufSize);
                                    if (len == 0)
                                    {
                                        // EOF
                                        break;
                                    }

                                    xfs.Write(zipExtractBuf, 0, len);
                                }
                                zas.Close();
                            }
                        }
                    }
                    catch (Exception e) {
                        Logger.WriteLine(LogLevel.Error, $"Could not extract '${zaEntry.FullName}': ${e.Message}");
                    }
                }
            }

            // if extraction went ok, we can remove files
            remote.Execute($"rm {remoteFilename}", out String _);
            File.Delete(localFilename);

            // since we definitely have a local copy of include directory, rebase on it
            this.Rebase(this, xLocalIncludeDirectory);
            autoDownloaded = true;
        }
Example #14
0
        private static void Main(String[] args)
        {
#if !DEBUG
            try {
#endif
            ProcessArgs(args);
            if (config.InputFile == null)
            {
                ShowHelp();
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();
            Solution sln = new Solution(config);
            sln.ParseCompileDB(config.InputFile);
            sw.Stop();
            Int64 parseAndGroup = sw.ElapsedMilliseconds;

            sw.Reset();
            sw.Start();
            if (config.Remote != null)
            {
                sln.RetrieveExtraInfoFromRemote(config.Remote);
            }
            sw.Stop();
            Int64 remoteInfo = sw.ElapsedMilliseconds;

            sln.FilterOutEntries();

            sw.Reset();
            sw.Start();
            foreach (Tuple <AbsoluteCrosspath, AbsoluteCrosspath> substitution in config.Substitutions)
            {
                sln.Rebase(substitution.Item1, substitution.Item2);
            }
            sw.Stop();
            Int64 rebase = sw.ElapsedMilliseconds;

            // DONE: also check for:
            //   - project file accessibility
            //   - include dirs accessibility
            List <IncludeDirectory> remoteNotRebased = new List <IncludeDirectory>();
            sln.CheckForTotalRebase(ref remoteNotRebased);

            try {
                Directory.Delete(config.Outdir, true);
            }
            catch {
                // ignored
            }

            if (config.Remote != null)
            {
                sln.DownloadCompilerIncludeDirectoriesFromRemote(config.Remote, config.Outdir);
                foreach (IncludeDirectory includeDirectory in remoteNotRebased)
                {
                    Crosspath outdir = Crosspath.FromString(config.Outdir);
                    if (outdir is RelativeCrosspath relativeCrosspath)
                    {
                        outdir = relativeCrosspath.Absolutized(AbsoluteCrosspath.GetCurrentDirectory());
                    }

                    includeDirectory.RebaseToLocal(config.Remote
                                                   , ((AbsoluteCrosspath)outdir).Append(
                                                       RelativeCrosspath.FromString(String.Format(SolutionStructure.RemoteIncludePath
                                                                                                  , config.Remote.Host))));
                }
            }

            sw.Reset();
            sw.Start();
            sln.WriteToDirectory(config.Outdir);
            sw.Stop();
            Int64 write = sw.ElapsedMilliseconds;

            Console.WriteLine();
            Console.WriteLine($"Elapsed time: parseAndGroup = {parseAndGroup} ms, remoteInfo = {remoteInfo} ms"
                              + $", rebase = {rebase} ms, write = {write} ms.");

            if (config.OpenSolution)
            {
                Process.Start(new ProcessStartInfo(Path.Combine(config.Outdir, SolutionStructure.SolutionFilename))
                {
                    UseShellExecute = true
                });
            }
#if !DEBUG
        }

        catch (Exception e) {
            Console.WriteLine($"[x] {e.Message}");
            Console.WriteLine();
            Console.WriteLine("Stack trace for debugging purposes:");
            Console.WriteLine($"{e.StackTrace}");
            Console.WriteLine("Press Enter to continue...");
            Console.ReadLine();
        }
#endif
        }
 public void Polymorphism()
 {
     Crosspath         cpath   = Crosspath.FromString(@"/");
     AbsoluteCrosspath unused  = cpath as AbsoluteCrosspath;
     RelativeCrosspath unused1 = cpath as RelativeCrosspath;
 }
        /// <summary>
        /// Writes compiler_${ShortName}.props and compiler_$(ShortName}_compat.h
        /// </summary>
        public void WriteToFile(AbsoluteCrosspath solutionDir)
        {
            if (BaseCompiler.Skip)
            {
                return;
            }

            AbsoluteCrosspath xpath = solutionDir.Appended(RelativeCrosspath.FromString(CompilerInstanceCompatHeaderPath)).ToContainingDirectory();

            Directory.CreateDirectory(xpath.ToString());
            using (StreamWriter sw = new StreamWriter(CompilerInstanceCompatHeaderPath, false, Encoding.UTF8)) {
                sw.WriteLine(@"#pragma once");
                sw.WriteLine($"/* This is generated from compiler instance {BaseCompiler} {this} */");
                foreach (Define compilerInternalDefine in Defines)
                {
                    sw.WriteLine($"#define {compilerInternalDefine.Name} {compilerInternalDefine.Value}");
                }
            }

            XmlDocument doc = new XmlDocument();

            doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", null));

            XmlElement projectNode = doc.CreateElement("Project");

            projectNode.SetAttribute("DefaultTargets", "Build");
            projectNode.SetAttribute("ToolsVersion", "Current");
            projectNode.SetAttribute("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");

            XmlElement projectImportProps = doc.CreateElement("Import");

            projectImportProps.SetAttribute("Project", $@"$(SolutionDir)\{BaseCompiler.PropsFileName}");
            projectNode.AppendChild(projectImportProps);

            // Platform settings

            /*
             * <ItemGroup Label="ProjectConfigurations">
             * <ProjectConfiguration Include="Debug|x64">
             * <Configuration>Debug</Configuration>
             * <Platform>x64</Platform>
             * </ProjectConfiguration>
             * <ProjectConfiguration Include="Release|x64">
             * <Configuration>Release</Configuration>
             * <Platform>x64</Platform>
             * </ProjectConfiguration>
             * </ItemGroup>
             */
            XmlElement projectItemGroupPlatform = doc.CreateElement("ItemGroup");

            projectItemGroupPlatform.SetAttribute("Label", "ProjectConfigurations");

            foreach (String buildConfiguration in SolutionStructure.SolutionConfigurations)
            {
                XmlElement projectPlatformConfiguration = doc.CreateElement("ProjectConfiguration");
                projectPlatformConfiguration.SetAttribute("Include", $"{buildConfiguration}|{VSPlatform}");
                XmlElement projectPlatformConfiguration_Configuration = doc.CreateElement("Configuration");
                projectPlatformConfiguration_Configuration.InnerText = buildConfiguration;
                projectPlatformConfiguration.AppendChild(projectPlatformConfiguration_Configuration);
                XmlElement projectPlatformConfiguration_Platform = doc.CreateElement("Platform");
                projectPlatformConfiguration_Platform.InnerText = VSPlatform.ToString();
                projectPlatformConfiguration.AppendChild(projectPlatformConfiguration_Platform);
                projectItemGroupPlatform.AppendChild(projectPlatformConfiguration);
            }

            projectNode.AppendChild(projectItemGroupPlatform);

            // IDU settings
            XmlElement projectPropertyGroupIDU = doc.CreateElement("PropertyGroup");

            XmlElement projectIncludePaths = doc.CreateElement("NMakeIncludeSearchPath");

            // DONE: intermix project include directories with compiler include directories
            foreach (IncludeDirectory includePath in IncludeDirectories)
            {
                projectIncludePaths.InnerText += includePath.GetLocalProjectPath(solutionDir) + ";";
            }
            projectIncludePaths.InnerText += "$(CompilerIncludeDirAfter);$(NMakeIncludeSearchPath)";
            projectPropertyGroupIDU.AppendChild(projectIncludePaths);

            // maybe someday this will be helpful, but now it can be inherited from Solution.props
            XmlElement projectForcedIncludes = doc.CreateElement("NMakeForcedIncludes");

            // DONE: add compiler compat header to forced includes
            projectForcedIncludes.InnerText = $@"$(SolutionDir)\solution_compat.h;$(SolutionDir)\{CompilerInstanceCompatHeaderPath};$(SolutionDir)\solution_post_compiler_compat.h";
            projectPropertyGroupIDU.AppendChild(projectForcedIncludes);

            XmlElement compilerForcedIncludes = doc.CreateElement("CompilerCompat");

            // DONE: add compiler compat header to forced includes
            compilerForcedIncludes.InnerText = $@"$(SolutionDir)\{CompilerInstanceCompatHeaderPath}";
            projectPropertyGroupIDU.AppendChild(compilerForcedIncludes);

            projectNode.AppendChild(projectPropertyGroupIDU);

            doc.AppendChild(projectNode);
            doc.Save(PropsFileName);
        }