コード例 #1
0
 public void ReloadCMakeCache(IFrameworkHandle log = null)
 {
     var cMakeCacheFileName = Path.Combine(CMakeCacheDir, CMakeCacheFile);
     var newInfo = new FileInfo(cMakeCacheFileName);
     if (_cmakeCacheInfo != null)
     {
         log?.SendMessage(TestMessageLevel.Informational,
             "CMakeCache.ReloadCMakeCache: comparing already loaded cache");
         if (_cmakeCacheInfo.FullName == newInfo.FullName &&
             _cmakeCacheInfo.LastWriteTime == newInfo.LastWriteTime &&
             newInfo.Exists)
         {
             log?.SendMessage(TestMessageLevel.Informational,
                 "CMakeCache.ReloadCMakeCache: cache did not change, not reloading");
             return;
         }
     }
     log?.SendMessage(TestMessageLevel.Informational,
         $"CMakeCache.ReloadCMakeCache: reloading cmake cache from \"{cMakeCacheFileName}\"");
     _cmakeCacheInfo = newInfo;
     _cacheEntries.Clear();
     if (!File.Exists(cMakeCacheFileName))
     {
         log?.SendMessage(TestMessageLevel.Error, $"cache not found at:\"{cMakeCacheFileName}\"");
         return;
     }
     var stream = new FileStream(cMakeCacheFileName, FileMode.Open,
         FileAccess.Read, FileShare.ReadWrite);
     var r = new StreamReader(stream);
     while (!r.EndOfStream)
     {
         var line = r.ReadLine();
         if (null == line)
         {
             continue;
         }
         line = line.TrimStart(' ');
         if (line.Length == 0 || line.StartsWith("#") || line.StartsWith("//"))
         {
             continue;
         }
         var c = CacheEntryRegex.Split(line);
         if (c.Length != 5)
         {
             log?.SendMessage(TestMessageLevel.Error, "cache load: element count != 5: (" + c.Length + ")" + line);
             var count = 0;
             foreach (var asdf in c)
             {
                 log?.SendMessage(TestMessageLevel.Error, "v" + count + ": " + asdf);
                 count++;
             }
             continue;
         }
         CMakeCacheEntryType myType;
         if (!Enum.TryParse(c[2], out myType))
         {
             log?.SendMessage(TestMessageLevel.Error, "cache load: error parsing enum Type: " + c[2]);
             continue;
         }
         var entry = new CMakeCacheEntry()
         {
             Name = c[1],
             //Type = myType,
             Value = c[3]
         };
         _cacheEntries.Add(entry.Name, entry);
     }
     r.Close();
     stream.Close();
     r.Dispose();
     stream.Dispose();
     CacheChanged?.Invoke();
 }
コード例 #2
0
        public void LoadCMakeCache(string fileName)
        {
            this._cmakeCacheFile = fileName;
            if (null == this._cmakeCacheFile || !File.Exists(this._cmakeCacheFile))
            {
                this.Log(LogLevel.Debug, "LoadCMakeCache: clearing cmake CMakeCache");
                this._cacheEntries.Clear();
                return;
            }
            var newInfo = new FileInfo(this._cmakeCacheFile);

            if (this._cmakeCacheInfo != null)
            {
                this.Log(LogLevel.Debug, "LoadCMakeCache: comparing already loaded CMakeCache");
                if (this._cmakeCacheInfo.FullName == newInfo.FullName &&
                    this._cmakeCacheInfo.LastWriteTime == newInfo.LastWriteTime &&
                    newInfo.Exists)
                {
                    this.Log(LogLevel.Debug, "LoadCMakeCache: CMakeCache did not change, not reloading");
                    return;
                }
            }
            this.Log(LogLevel.Debug, "LoadCMakeCache: loading CMakeCache from \"" + this._cmakeCacheFile + "\"");
            this._cmakeCacheInfo = newInfo;
            this._cacheEntries.Clear();
            if (!File.Exists(this._cmakeCacheFile))
            {
                this.Log(LogLevel.Error, "LoadCMakeCache: CMakeCache not found at:\"" + this._cmakeCacheFile + "\"");
                return;
            }
            while (CTestAdapterConfig.IsFileLocked(this._cmakeCacheFile))
            {
                Thread.Sleep(50);
            }
            var stream = new FileStream(this._cmakeCacheFile, FileMode.Open,
                                        FileAccess.Read, FileShare.ReadWrite);
            var r = new StreamReader(stream);

            while (!r.EndOfStream)
            {
                var line = r.ReadLine();
                if (null == line)
                {
                    continue;
                }
                line = line.TrimStart(' ');
                if (line.Length == 0 || line.StartsWith("#") || line.StartsWith("//"))
                {
                    continue;
                }
                var c = CMakeCache.CacheEntryRegex.Split(line);
                if (c.Length != 5)
                {
                    this.Log(LogLevel.Warning, "LoadCMakeCache: CMakeCache load: element count != 5: (" + c.Length + ")" + line);
                    var count = 0;
                    foreach (var asdf in c)
                    {
                        this.Log(LogLevel.Warning, "v" + count + ": " + asdf);
                        count++;
                    }
                    continue;
                }
                CMakeCacheEntryType myType;
                if (!Enum.TryParse(c[2], out myType))
                {
                    this.Log(LogLevel.Error, "LoadCMakeCache: cache load: error parsing enum Type: " + c[2]);
                    continue;
                }
                var entry = new CMakeCacheEntry()
                {
                    Name  = c[1],
                    Value = c[3]
                };
                if (entry.Name.StartsWith("\"") && entry.Name.Length > 2)
                {
                    entry.Name = entry.Name.Substring(1, entry.Name.Length - 2);
                }
                this._cacheEntries.Add(entry.Name, entry);
            }
            r.Close();
            stream.Close();
            r.Dispose();
            stream.Dispose();
        }