public void When_translating_from_a_storage_url_that_has_been_translated_to_it_will_return_original_url() { var toTranslate = format("/home/ack/src/MySolution/Project/Project.csproj"); var translator = new PathTranslator(format("/StorageLocation/"), format("/home/ack/src/MySolution"), _directoryExists, _createDirectory); var directory = translator.Translate(toTranslate); Assert.That(translator.TranslateFrom(directory), Is.EqualTo(toTranslate)); }
public void BasicTest() { PathTranslator pt = new PathTranslator(PathGeneratorUtilities.GetAbsolutePath("b", "foo"), PathGeneratorUtilities.GetAbsolutePath("d", "src", "123")); XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath(" d", "src", "123", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(" b", "foo", "bar"))); XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath("d", "src", "123", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath("b", "foo", "bar"))); XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath("d", "src", "123", "bar '") + PathGeneratorUtilities.GetAbsolutePath("d", "src", "123", "BAR"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath("b", "foo", "bar '") + PathGeneratorUtilities.GetAbsolutePath("B", "FOO", "BAR"))); XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath(" d", "src", "123", "bar '") + PathGeneratorUtilities.GetAbsolutePath("d", "src", "123", "BAR"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(" b", "foo", "bar '") + PathGeneratorUtilities.GetAbsolutePath("B", "FOO", "BAR"))); XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath("where is my head", "src", "foo", "bar '") + PathGeneratorUtilities.GetAbsolutePath("d", "src", "123", "BAR"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath("where is my head", "src", "foo", "bar '") + PathGeneratorUtilities.GetAbsolutePath("B", "FOO", "BAR"))); XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath(@"logging a path: [d", "src", "123", "bar]"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"logging a path: [b", "foo", "bar]"))); XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath(@" \\?\d", "src", "123", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@" \\?\b", "foo", "bar"))); XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath(@"\\?\d", "src", "123", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"\\?\b", "foo", "bar"))); XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath(@"\??\d", "src", "123", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"\??\b", "foo", "bar"))); // Don't match the patterns. Validate for off by one errors & false positives if (OperatingSystemHelper.IsUnixOS) { XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath(null, @"\\?b", "foo", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(null, @"\\?b", "foo", "bar"))); XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath(null, @"comb", "foo", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(null, @"comb", "foo", "bar"))); } else { XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath(@"\\?b", "foo", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"\\?b", "foo", "bar"))); XAssert.AreEqual(PathGeneratorUtilities.GetAbsolutePath(@"comb", "foo", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"comb", "foo", "bar"))); } }
private string TranslateBuildXLPath(string path) => m_buildXLToUserPathTranslator != null?m_buildXLToUserPathTranslator.Translate(path) : path;
private string TranslateUserPath(string path) => m_userToBuildXLPathTranslator != null?m_userToBuildXLPathTranslator.Translate(path) : path;
private string TranslatePaths(string path) => m_pathTranslator?.Translate(path) ?? path;
public static void WriteCmd(string commandLine, IIdeConfiguration config, AbsolutePath configFile, PathTable pathTable, [CanBeNull] PathTranslator translator) { var enlistmentRoot = configFile.GetParent(pathTable).ToString(pathTable); var builder = new StringBuilder(); builder.AppendLine("@echo off"); if (translator == null) { builder.AppendLine("cd " + enlistmentRoot); } else { enlistmentRoot = translator.Translate(enlistmentRoot); } // Remove trailing file path separators. enlistmentRoot = enlistmentRoot.TrimEnd('\\'); foreach (DictionaryEntry envVar in Environment.GetEnvironmentVariables()) { var key = (string)envVar.Key; var value = (string)envVar.Value; // If the value contains '<' or '>', add escape character; otherwise we will see syntax error when running build.cmd. value = Regex.Replace(value, @"[<>]", m => $"^{m.Value}"); // Scrub newlines and tabs as they will break the generated build.cmd value = Regex.Replace(value, @"[\r,\n,\t]", m => " "); builder.AppendLine("Set " + key + "=" + value); } commandLine = FixCommandLine(commandLine); // Prepend to the command line the RunInSubst executable and its parameters int exeIndex = commandLine.IndexOf($"\\{Branding.ProductExecutableName}", StringComparison.OrdinalIgnoreCase); string binRoot = exeIndex > -1 ? commandLine.Substring(0, exeIndex) : Path.GetDirectoryName(AssemblyHelper.GetAssemblyLocation(System.Reflection.Assembly.GetEntryAssembly())); if (translator != null) { binRoot = translator.Translate(binRoot); } string substedCommandLine = I($@"""{binRoot}\RunInSubst.exe"" B={enlistmentRoot} {commandLine} /server+ @%~dp0\build.cmd.rsp @%~dp0\domino.cmd.rsp %*"); // Also add the legacy response file domino.rsp for old plugins builder.AppendLine(substedCommandLine); builder.AppendLine("set RETURN_CODE=%ERRORLEVEL%"); // Map the drive back. // RunInSubst is unmapping the drive to follow WDG protocol, but to run unit tests we need the drive still mapped. builder.AppendLine(string.Format(CultureInfo.InvariantCulture, "subst B: {0}", enlistmentRoot)); // Return the exit code of BuildXL. builder.AppendLine("exit /b %RETURN_CODE%"); builder.AppendLine(); var solutionDirPath = GetSolutionPath(config, pathTable).GetParent(pathTable).ToString(pathTable); File.WriteAllText(Path.Combine(solutionDirPath, "build.cmd.rsp"), string.Empty); File.WriteAllText(Path.Combine(solutionDirPath, "build.cmd"), builder.ToString()); // Legacy file to support old plugins File.WriteAllText(Path.Combine(solutionDirPath, "domino.cmd"), "@call %~dp0build.cmd %*"); File.WriteAllText(Path.Combine(solutionDirPath, "domino.cmd.rsp"), string.Empty); // Legacy response file for old plugin }