Example #1
0
        public void RootTranslation()
        {
            var rootTranslator = new RootTranslator();
            var pathTable      = Context.PathTable;

            // Source is shorter than target
            var shortCaseSourceTranslatedRootPath = GetFullPath(pathTable, "ShortSource").Expand(pathTable);
            var shortCaseTargetTranslatedRootPath = GetFullPath(pathTable, "Short___Target").Expand(pathTable);

            rootTranslator.AddTranslation(
                shortCaseSourceTranslatedRootPath.ExpandedPath,
                shortCaseTargetTranslatedRootPath.ExpandedPath);

            // Source is longer than target
            var longCaseSourceTranslatedRootPath = GetFullPath(pathTable, "LongSourceSource").Expand(pathTable);
            var longCaseTargetTranslatedRootPath = GetFullPath(pathTable, "LongTarget").Expand(pathTable);

            rootTranslator.AddTranslation(
                longCaseSourceTranslatedRootPath.ExpandedPath,
                longCaseTargetTranslatedRootPath.ExpandedPath);

            rootTranslator.Seal();

            var cache = new CacheCoreArtifactContentCache(Session, rootTranslator);

            // SHORTER SOURCE, SAME ROOT: Path should NOT be translated
            VerifyExpandedPathForCacheEquals(cache, shortCaseSourceTranslatedRootPath, shortCaseSourceTranslatedRootPath);

            // LONGER SOURCE, SAME ROOT: Path SHOULD be translated
            VerifyExpandedPathForCacheEquals(cache, longCaseSourceTranslatedRootPath, longCaseTargetTranslatedRootPath);
        }
Example #2
0
        /// <summary>
        /// Returns a cache initializer to a real instance of the cache
        /// </summary>
        protected CacheInitializer GetRealCacheInitializerForTests()
        {
            var          tempDir         = OperatingSystemHelper.IsUnixOS ? "/tmp/buildxl-temp" : TemporaryDirectory;
            string       cacheDirectory  = Path.Combine(tempDir, "cache");
            AbsolutePath cacheConfigPath = WriteTestCacheConfigToDisk(cacheDirectory);

            var translator = new RootTranslator();

            if (TryGetSubstSourceAndTarget(out var substSource, out var substTarget))
            {
                translator.AddTranslation(substTarget, substSource);
            }

            translator.Seal();

            Configuration.Cache.CacheConfigFile  = cacheConfigPath;
            Configuration.Cache.CacheLogFilePath = AbsolutePath.Create(Context.PathTable, tempDir).Combine(Context.PathTable, "cache.log");

            var maybeCacheInitializer = CacheInitializer.GetCacheInitializationTask(
                LoggingContext,
                Context.PathTable,
                cacheDirectory,
                Configuration.Cache,
                translator,
                recoveryStatus: false,
                cancellationToken: CancellationToken.None).GetAwaiter().GetResult();

            if (!maybeCacheInitializer.Succeeded)
            {
                throw new BuildXLException("Unable to initialize the real cache: " + maybeCacheInitializer.Failure.DescribeIncludingInnerFailures());
            }

            return(maybeCacheInitializer.Result);
        }
Example #3
0
        public void RootTranslationDifferentRoots()
        {
            var rootTranslator = new RootTranslator();
            var pathTable      = Context.PathTable;

            // Source is shorter than target but has different root
            var shortCaseChangeRootSourceTranslatedRootPath = ChangeRoot(GetFullPath(pathTable, "ShortChangeRootSrc"), pathTable, newRoot: 'A');
            var shortCaseChangeRootTargetTranslatedRootPath = ChangeRoot(GetFullPath(pathTable, "ShortChangeRootTarget"), pathTable, newRoot: 'B');

            rootTranslator.AddTranslation(
                shortCaseChangeRootSourceTranslatedRootPath.ExpandedPath,
                shortCaseChangeRootTargetTranslatedRootPath.ExpandedPath);

            rootTranslator.Seal();

            var cache = new CacheCoreArtifactContentCache(Session, rootTranslator);

            // SHORTER SOURCE, DIFFERENT ROOT: Path SHOULD be translated
            VerifyExpandedPathForCacheEquals(cache, shortCaseChangeRootSourceTranslatedRootPath, shortCaseChangeRootTargetTranslatedRootPath);
        }
Example #4
0
 private void AddTranslation(string sourcePath, string targetPath)
 {
     m_translator.AddTranslation(sourcePath, targetPath);
 }