Skip to content

Commit

Permalink
[unix] Fix rebuilds caused by resx containing fileref with windows pa…
Browse files Browse the repository at this point in the history
…th (dotnet#44)

When running on !windows, if a resx contains a fileRef like ..

```
  <data name="TextFile1" type="System.Resources.ResXFileRef, System.Windows.Forms">
	<value>..\Resources\TextFile1.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
  </data>
```

.. with the path containing backslashes, then we end up treating the whole
thing as filename and thus subsequent checks for file changes etc fail. This
causes the resx to be processed every time `GenerateResource` task is run, which
can cause costly rebuilds.

Issue: mono/mono#7184
  • Loading branch information
radical committed Apr 26, 2018
1 parent c448729 commit 382b29c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
49 changes: 49 additions & 0 deletions src/Tasks.UnitTests/GenerateResource_Tests.cs
Expand Up @@ -3135,6 +3135,55 @@ public void ResxValueNewlines(string newline)
}
}
}

[Fact]
public void RebuildsInPresenceOfFileRefWithWindowsPath()
{
using (var env = TestEnvironment.Create())
{
env.SetCurrentDirectory(env.DefaultTestDirectory.FolderPath);

string fileRef = "<data name=\"TextFile1\" type=\"System.Resources.ResXFileRef, System.Windows.Forms\">" +
$"<value>.\\tmp_dir\\test_file.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value></data>";

env.CreateFile(
env.CreateFolder(Path.Combine(env.DefaultTestDirectory.FolderPath, "tmp_dir")),
"test_file.txt", "xyz");

string resxFile = env.CreateFile("test.resx").Path;
Utilities.WriteTestResX(false, null, fileRef, false, resxFile);

GenerateResource ExecuteTask()
{
GenerateResource task = Utilities.CreateTask(_output);
task.Sources = new ITaskItem[] { new TaskItem(resxFile) };

Utilities.ExecuteTask(task);

string outputResourceFile = task.OutputResources[0].ItemSpec;
Assert.Equal(Path.GetExtension(outputResourceFile), ".resources");
outputResourceFile = task.FilesWritten[0].ItemSpec;
Assert.Equal(Path.GetExtension(outputResourceFile), ".resources");

return task;
}

GenerateResource t = ExecuteTask();
string resourcesFile = t.OutputResources[0].ItemSpec;
DateTime initialWriteTime = File.GetLastWriteTime(resourcesFile);

// fs granularity on HFS is 1 sec!
System.Threading.Thread.Sleep(NativeMethodsShared.IsOSX ? 1000 : 100);

// Rebuild, it shouldn't regen .resources file since the sources
// haven't changed
t = ExecuteTask();
resourcesFile = t.OutputResources[0].ItemSpec;

Assert.False(Utilities.FileUpdated(resourcesFile, initialWriteTime));
}
}

}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Tasks/ResGenDependencies.cs
Expand Up @@ -266,7 +266,7 @@ internal static string[] GetLinkedFiles(string filename, string baseLinkedFileDi
{
ResXFileRef resxFileRef = ((ResXDataNode)dictEntry.Value).FileRef;
if (resxFileRef != null)
retVal.Add(resxFileRef.FileName);
retVal.Add(FileUtilities.MaybeAdjustFilePath(resxFileRef.FileName));
}
}
}
Expand Down

0 comments on commit 382b29c

Please sign in to comment.