Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
//
// AssemblyInfo.cs
//
// Author:
// Antonius Riha <antoniusriha@gmail.com>
//
// Copyright (c) 2013 Antonius Riha
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Resources;
using System.Runtime.InteropServices;
// General Information about the Mono.XBuild.Tasks assembly
[assembly: AssemblyTitle ("Mono.XBuild.Tasks.dll")]
[assembly: AssemblyDescription ("Mono.XBuild.Tasks.dll")]
[assembly: AssemblyDefaultAlias ("Mono.XBuild.Tasks.dll")]
[assembly: AssemblyCompany (Consts.MonoCompany)]
[assembly: AssemblyProduct (Consts.MonoProduct)]
[assembly: AssemblyCopyright (Consts.MonoCopyright)]
[assembly: AssemblyVersion (Consts.FxVersion)]
[assembly: SatelliteContractVersion (Consts.FxVersion)]
[assembly: AssemblyInformationalVersion (Consts.FxFileVersion)]
[assembly: NeutralResourcesLanguage ("en-US")]
[assembly: ComVisible (false)]
[assembly: CLSCompliant (true)]
[assembly: AssemblyDelaySign (true)]
[assembly: AssemblyKeyFile("../mono.pub")]
[assembly: AssemblyFileVersion (Consts.FxFileVersion)]

View File

@@ -0,0 +1,17 @@
thisdir = class/Mono.XBuild.Tasks
SUBDIRS =
include ../../build/rules.make
XBUILD_DIR=$(topdir)/tools/xbuild
include $(XBUILD_DIR)/xbuild.make
LIBRARY = Mono.XBuild.Tasks.dll
LIB_MCS_FLAGS = \
/r:$(corlib) \
/r:System.dll \
/r:System.Xml.dll
include $(XBUILD_DIR)/xbuild_test.make
include ../../build/library.make

View File

@@ -0,0 +1,6 @@
Assembly/AssemblyInfo.cs
../../build/common/Consts.cs
../../build/common/MonoTODOAttribute.cs
Mono.XBuild.Tasks/PcFileCache.cs
Mono.XBuild.Tasks/LibraryPcFileCache.cs
../Microsoft.Build.Utilities/Mono.XBuild.Utilities/MSBuildUtils.cs

View File

@@ -0,0 +1,321 @@
//
// PcFileCacheAssembly.cs
//
// Author:
// Lluis Sanchez Gual <lluis@novell.com>
//
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Text;
using System.Xml;
using System.IO;
using System.Collections.Generic;
// IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT
// This code is shared with xbuild, which has to build with .NET 2.0,
// so no c# 3.0 syntax is allowed here.
namespace Mono.PkgConfig
{
public class LibraryPcFileCache: PcFileCache<LibraryPackageInfo>
{
Dictionary<string, PackageAssemblyInfo> assemblyLocations;
public LibraryPcFileCache (IPcFileCacheContext<LibraryPackageInfo> ctx): base (ctx)
{
}
protected override string CacheDirectory {
get {
string path = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData);
path = Path.Combine (path, "xbuild");
return path;
}
}
// Returns the location of an assembly, given the full name
public PackageAssemblyInfo GetAssemblyLocation (string fullName)
{
return GetAssemblyLocation (fullName, null);
}
public PackageAssemblyInfo GetAssemblyLocation (string fullName, IEnumerable<string> searchPaths)
{
lock (SyncRoot) {
if (assemblyLocations == null) {
// Populate on demand
assemblyLocations = new Dictionary<string, PackageAssemblyInfo> ();
foreach (LibraryPackageInfo info in GetPackages (searchPaths)) {
if (info.IsValidPackage) {
foreach (PackageAssemblyInfo asm in info.Assemblies)
assemblyLocations [NormalizeAsmName (asm.FullName)] = asm;
}
}
}
}
// This collection is read-only once built, so there is no need for a lock
PackageAssemblyInfo pasm;
assemblyLocations.TryGetValue (NormalizeAsmName (fullName), out pasm);
return pasm;
}
public IEnumerable<PackageAssemblyInfo> ResolveAssemblyName (string name)
{
return ResolveAssemblyName (name, null);
}
public IEnumerable<PackageAssemblyInfo> ResolveAssemblyName (string name, IEnumerable<string> searchPaths)
{
foreach (LibraryPackageInfo pinfo in GetPackages (searchPaths)) {
if (pinfo.IsValidPackage) {
foreach (PackageAssemblyInfo asm in pinfo.Assemblies) {
if (asm.Name == name)
yield return asm;
}
}
}
}
protected override void WritePackageContent (XmlTextWriter tw, string file, LibraryPackageInfo pinfo)
{
foreach (PackageAssemblyInfo asm in pinfo.Assemblies) {
tw.WriteStartElement ("Assembly");
tw.WriteAttributeString ("name", asm.Name);
tw.WriteAttributeString ("version", asm.Version);
tw.WriteAttributeString ("culture", asm.Culture);
tw.WriteAttributeString ("publicKeyToken", asm.PublicKeyToken);
tw.WriteAttributeString ("file", asm.File);
tw.WriteEndElement (); // Assembly
}
}
protected override void ReadPackageContent (XmlReader tr, LibraryPackageInfo pinfo)
{
while (tr.NodeType == XmlNodeType.Element) {
PackageAssemblyInfo asm = new PackageAssemblyInfo ();
asm.Name = tr.GetAttribute ("name");
asm.Version = tr.GetAttribute ("version");
asm.Culture = tr.GetAttribute ("culture");
asm.PublicKeyToken = tr.GetAttribute ("publicKeyToken");
asm.File = tr.GetAttribute ("file");
if (pinfo.Assemblies == null)
pinfo.Assemblies = new List<PackageAssemblyInfo> ();
asm.ParentPackage = pinfo;
pinfo.Assemblies.Add (asm);
tr.Read ();
tr.MoveToContent ();
}
}
protected override void ParsePackageInfo (PcFile file, LibraryPackageInfo pinfo)
{
List<string> fullassemblies = null;
bool gacPackageSet = false;
if (file.Libs != null && file.Libs.IndexOf (".dll") != -1) {
if (file.Libs.IndexOf ("-lib:") != -1 || file.Libs.IndexOf ("/lib:") != -1) {
fullassemblies = GetAssembliesWithLibInfo (file.Libs);
} else {
fullassemblies = GetAssembliesWithoutLibInfo (file.Libs);
}
}
string value = file.GetVariable ("Libraries");
if (!string.IsNullOrEmpty (value))
fullassemblies = GetAssembliesFromLibrariesVar (value);
value = file.GetVariable ("GacPackage");
if (value != null) {
pinfo.IsGacPackage =
string.Equals (value, "yes", StringComparison.OrdinalIgnoreCase) ||
string.Equals (value, "true", StringComparison.OrdinalIgnoreCase);
gacPackageSet = true;
}
if (fullassemblies == null)
return;
string pcDir = Path.GetDirectoryName (file.FilePath);
string monoPrefix = Path.GetDirectoryName (Path.GetDirectoryName (pcDir));
monoPrefix = Path.GetFullPath (monoPrefix + Path.DirectorySeparatorChar + "lib" + Path.DirectorySeparatorChar + "mono" + Path.DirectorySeparatorChar);
List<PackageAssemblyInfo> list = new List<PackageAssemblyInfo> ();
foreach (string assembly in fullassemblies) {
string asm;
if (Path.IsPathRooted (assembly))
asm = Path.GetFullPath (assembly);
else {
if (Path.GetDirectoryName (assembly).Length == 0) {
asm = assembly;
} else {
asm = Path.GetFullPath (Path.Combine (pcDir, assembly));
}
}
if (File.Exists (asm)) {
PackageAssemblyInfo pi = new PackageAssemblyInfo ();
pi.File = asm;
pi.ParentPackage = pinfo;
pi.UpdateFromFile (pi.File);
list.Add (pi);
if (!gacPackageSet && !asm.StartsWith (monoPrefix) && Path.IsPathRooted (asm)) {
// Assembly installed outside $(prefix)/lib/mono. It is most likely not a gac package.
gacPackageSet = true;
pinfo.IsGacPackage = false;
}
}
}
pinfo.Assemblies = list;
}
private List<string> GetAssembliesWithLibInfo (string line)
{
List<string> references = new List<string> ();
List<string> libdirs = new List<string> ();
List<string> retval = new List<string> ();
foreach (string piece in line.Split (' ')) {
if (IsReferenceParameter (piece)) {
references.Add (piece.Substring (3).Trim ());
} else if (piece.TrimStart ().StartsWith ("/lib:", StringComparison.OrdinalIgnoreCase) ||
piece.TrimStart ().StartsWith ("-lib:", StringComparison.OrdinalIgnoreCase)) {
libdirs.Add (piece.Substring (5).Trim ());
}
}
foreach (string refrnc in references) {
foreach (string libdir in libdirs) {
if (File.Exists (libdir + Path.DirectorySeparatorChar + refrnc)) {
retval.Add (libdir + Path.DirectorySeparatorChar + refrnc);
}
}
}
return retval;
}
static bool IsReferenceParameter (string value)
{
return value.TrimStart ().StartsWith ("/r:", StringComparison.OrdinalIgnoreCase) ||
value.TrimStart ().StartsWith ("-r:", StringComparison.OrdinalIgnoreCase);
}
List<string> GetAssembliesFromLibrariesVar (string line)
{
List<string> references = new List<string> ();
foreach (string reference in line.Split (' ')) {
if (!string.IsNullOrEmpty (reference))
references.Add (reference);
}
return references;
}
private List<string> GetAssembliesWithoutLibInfo (string line)
{
List<string> references = new List<string> ();
foreach (string reference in line.Split (' ')) {
if (IsReferenceParameter (reference)) {
string final_ref = reference.Substring (3).Trim ();
references.Add (final_ref);
}
}
return references;
}
public static string NormalizeAsmName (string name)
{
int i = name.IndexOf (", publickeytoken=null", StringComparison.OrdinalIgnoreCase);
if (i != -1)
name = name.Substring (0, i).Trim ();
i = name.IndexOf (", processorarchitecture=", StringComparison.OrdinalIgnoreCase);
if (i != -1)
name = name.Substring (0, i).Trim ();
return name;
}
}
public class LibraryPackageInfo: PackageInfo
{
public bool IsGacPackage {
get { return GetData ("gacPackage") != "false"; }
set {
if (value)
RemoveData ("gacPackage");
else
SetData ("gacPackage", "false");
}
}
internal List<PackageAssemblyInfo> Assemblies { get; set; }
internal protected override bool IsValidPackage {
get { return Assemblies != null && Assemblies.Count > 0; }
}
}
public class PackageAssemblyInfo
{
public string File { get; set; }
public string Name;
public string Version;
public string Culture;
public string PublicKeyToken;
public string FullName {
get {
string fn = Name + ", Version=" + Version;
if (!string.IsNullOrEmpty (Culture))
fn += ", Culture=" + Culture;
if (!string.IsNullOrEmpty (PublicKeyToken))
fn += ", PublicKeyToken=" + PublicKeyToken;
return fn;
}
}
public LibraryPackageInfo ParentPackage { get; set; }
public void UpdateFromFile (string file)
{
Update (System.Reflection.AssemblyName.GetAssemblyName (file));
}
public void Update (System.Reflection.AssemblyName aname)
{
Name = aname.Name;
Version = aname.Version.ToString ();
if (aname.CultureInfo != null) {
if (aname.CultureInfo.LCID == System.Globalization.CultureInfo.InvariantCulture.LCID)
Culture = "neutral";
else
Culture = aname.CultureInfo.Name;
}
string fn = aname.ToString ();
string key = "publickeytoken=";
int i = fn.IndexOf (key, StringComparison.OrdinalIgnoreCase) + key.Length;
int j = fn.IndexOf (',', i);
if (j == -1) j = fn.Length;
PublicKeyToken = fn.Substring (i, j - i);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
Mono.XBuild.Tasks/PcFileCacheTest.cs

View File

@@ -0,0 +1,285 @@
//
// PcFileCacheTest.cs
//
// Author:
// Antonius Riha <antoniusriha@gmail.com>
//
// Copyright (c) 2013 Antonius Riha
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.IO;
using Mono.PkgConfig;
using NUnit.Framework;
namespace MonoTests.Mono.PkgConfig
{
[TestFixture]
public class PcFileCacheTest
{
static readonly string cacheDir = "testcache";
static readonly string pcCacheFileName = "pkgconfig-cache-2.xml";
static readonly string pcCacheFilePath = Path.Combine (cacheDir, pcCacheFileName);
static readonly string pkgConfigDir = "testpkgconfig";
[SetUp]
public void Setup ()
{
Directory.CreateDirectory (cacheDir);
Directory.CreateDirectory (pkgConfigDir);
}
[TearDown]
public void Teardown ()
{
if (Directory.Exists (cacheDir))
Directory.Delete (cacheDir, true);
if (Directory.Exists (pkgConfigDir))
Directory.Delete (pkgConfigDir, true);
}
[Test]
public void CreatePcFileCache ()
{
PcFileCacheStub.Create (cacheDir);
// cache dir should exist
Assert.IsTrue (Directory.Exists (cacheDir), "A1");
// cache file should not exist
Assert.IsFalse (File.Exists (pcCacheFilePath), "A2");
}
[Test]
public void CreatePcFileCacheWithExistingEmptyCacheFile ()
{
// Create pc cache file
WritePcCacheFileContent ("");
PcFileCache cache = PcFileCacheStub.Create (cacheDir);
// cache should be empty
string[] pkgConfigDirs = { pkgConfigDir };
CollectionAssert.IsEmpty (cache.GetPackages (pkgConfigDirs), "A1");
}
[Test]
public void CreatePcFileCacheWithCacheFileContaining1EntryForAnExistingPcFile ()
{
// Create pc cache file with an entry and corresponding pc file
string pkgConfigFileName = "gtk-sharp-2.0.pc";
string pkgConfigFullFilePath = Path.GetFullPath (Path.Combine (pkgConfigDir, pkgConfigFileName));
string pcCacheFileContent = @"<PcFileCache>
<File path=""" + pkgConfigFullFilePath + @""" lastWriteTime=""2013-11-23T21:18:31+01:00"" />
</PcFileCache>
";
string pkgConfigFileContent = @"prefix=${pcfiledir}/../..
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
gapidir=${prefix}/share/gapi-2.0
Name: Gtk#
Description: Gtk# - GNOME .NET Binding
Version: 2.12.10
Cflags: -I:${gapidir}/pango-api.xml -I:${gapidir}/atk-api.xml -I:${gapidir}/gdk-api.xml -I:${gapidir}/gtk-api.xml
Libs: -r:${libdir}/cli/pango-sharp-2.0/pango-sharp.dll -r:${libdir}/cli/atk-sharp-2.0/atk-sharp.dll -r:${libdir}/cli/gdk-sharp-2.0/gdk-sharp.dll -r:${libdir}/cli/gtk-sharp-2.0/gtk-sharp.dll
Requires: glib-sharp-2.0
";
AddPkgConfigFile (pkgConfigFileName, pkgConfigFileContent);
WritePcCacheFileContent (pcCacheFileContent);
PcFileCache cache = PcFileCacheStub.Create (cacheDir);
// cache should contain entry of pc file
Assert.IsNotNull (cache.GetPackageInfo (pkgConfigFullFilePath), "A1");
}
[Test]
public void CreatePcFileCacheWithCacheFileContainingOneOrphanedEntry ()
{
string pkgConfigFileName = "gtk-sharp-2.0.pc";
string pkgConfigFullFilePath = Path.GetFullPath (Path.Combine (pkgConfigDir, pkgConfigFileName));
string pcCacheFileContent = @"<PcFileCache>
<File path=""" + pkgConfigFullFilePath + @""" lastWriteTime=""2013-11-23T21:18:31+01:00"" />
</PcFileCache>
";
WritePcCacheFileContent (pcCacheFileContent);
PcFileCache cache = PcFileCacheStub.Create (cacheDir);
// cache should contain orphaned entry
Assert.IsNotNull (cache.GetPackageInfo (pkgConfigFullFilePath), "A1");
}
[Test]
public void CreatePcFileCacheWithoutCacheFileButWithPcFile ()
{
string pkgConfigFileName = "gtk-sharp-2.0.pc";
string pkgConfigFileContent = @"prefix=${pcfiledir}/../..
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
gapidir=${prefix}/share/gapi-2.0
Name: Gtk#
Description: Gtk# - GNOME .NET Binding
Version: 2.12.10
Cflags: -I:${gapidir}/pango-api.xml -I:${gapidir}/atk-api.xml -I:${gapidir}/gdk-api.xml -I:${gapidir}/gtk-api.xml
Libs: -r:${libdir}/cli/pango-sharp-2.0/pango-sharp.dll -r:${libdir}/cli/atk-sharp-2.0/atk-sharp.dll -r:${libdir}/cli/gdk-sharp-2.0/gdk-sharp.dll -r:${libdir}/cli/gtk-sharp-2.0/gtk-sharp.dll
Requires: glib-sharp-2.0
";
AddPkgConfigFile (pkgConfigFileName, pkgConfigFileContent);
PcFileCache cache = PcFileCacheStub.Create (cacheDir);
// cache file should exist
Assert.IsFalse (File.Exists (pcCacheFilePath), "A1");
// cache should be empty
string[] pkgConfigDirs = { pkgConfigDir };
CollectionAssert.IsEmpty (cache.GetPackages (pkgConfigDirs), "A2");
}
[Test]
public void GetPackagesOrderedByFolder ()
{
string pkgConfigDir1 = "testpkgconfigdir1";
string pkgConfigDir2 = "testpkgconfigdir2";
Directory.CreateDirectory (pkgConfigDir1);
Directory.CreateDirectory (pkgConfigDir2);
string pkgConfigFile11NameAttr = "gtk-sharp-2.0";
string pkgConfigFile11FullPath = Path.GetFullPath (Path.Combine (pkgConfigDir1, "gtk-sharp-2.0.pc"));
string pkgConfigFile21NameAttr = "art-sharp-2.0";
string pkgConfigFile21FullPath = Path.GetFullPath (Path.Combine (pkgConfigDir2, "art-sharp-2.0.pc"));
string pkgConfigFile12NameAttr = "cecil";
string pkgConfigFile12FullPath = Path.GetFullPath (Path.Combine (pkgConfigDir1, "cecil.pc"));
string pcCacheFileContent = @"<PcFileCache>
<File path=""" + pkgConfigFile11FullPath + @""" lastWriteTime=""2013-11-23T21:18:31+01:00"" name=""" + pkgConfigFile11NameAttr + @""" />
<File path=""" + pkgConfigFile21FullPath + @""" lastWriteTime=""2011-07-12T12:04:53+02:00"" name=""" + pkgConfigFile21NameAttr + @""" />
<File path=""" + pkgConfigFile12FullPath + @""" lastWriteTime=""2012-07-24T22:28:30+02:00"" name=""" + pkgConfigFile12NameAttr + @""" />
</PcFileCache>
";
WritePcCacheFileContent (pcCacheFileContent);
PcFileCache cache = PcFileCacheStub.Create (cacheDir);
string[] pkgConfigDirs = { pkgConfigDir1, pkgConfigDir2 };
IEnumerable<PackageInfo> packages = cache.GetPackages (pkgConfigDirs);
PackageInfo[] packageArray = new PackageInfo [3];
int i = 0;
foreach (PackageInfo package in packages)
packageArray [i++] = package;
Assert.AreEqual (pkgConfigFile11NameAttr, packageArray [0].Name, "A1");
Assert.AreEqual (pkgConfigFile12NameAttr, packageArray [1].Name, "A2");
Assert.AreEqual (pkgConfigFile21NameAttr, packageArray [2].Name, "A3");
Directory.Delete (pkgConfigDir1, true);
Directory.Delete (pkgConfigDir2, true);
}
[Test]
public void UpdatePcFileCacheWithOrphanedEntry ()
{
string pkgConfigFileNameAttr = "gtk-sharp-2.0";
string pkgConfigFileName = "gtk-sharp-2.0.pc";
string pkgConfigFullFilePath = Path.GetFullPath (Path.Combine (pkgConfigDir, pkgConfigFileName));
string pcCacheFileContent = @"<PcFileCache>
<File path=""" + pkgConfigFullFilePath + @""" lastWriteTime=""2013-11-23T21:18:31+01:00"" name=""" + pkgConfigFileNameAttr + @""" />
</PcFileCache>
";
WritePcCacheFileContent (pcCacheFileContent);
PcFileCache cache = PcFileCacheStub.Create (cacheDir);
// precondition
string[] pkgConfigDirs = { pkgConfigDir };
Assert.IsNotNull (cache.GetPackageInfoByName (pkgConfigFileNameAttr, pkgConfigDirs), "A1");
cache.Update (pkgConfigDirs);
Assert.IsNull (cache.GetPackageInfoByName (pkgConfigFileNameAttr, pkgConfigDirs), "A2");
}
static void WritePcCacheFileContent (string content)
{
File.WriteAllText (pcCacheFilePath, content);
}
static void AddPkgConfigFile (string fileName, string content)
{
AddPkgConfigFile (fileName, content, pkgConfigDir);
}
static void AddPkgConfigFile (string fileName, string content, string pkgConfigDir)
{
string path = Path.Combine (pkgConfigDir, fileName);
File.WriteAllText (path, content);
}
class PcFileCacheContextStub : IPcFileCacheContext
{
public void StoreCustomData (PcFile pcfile, PackageInfo pkg)
{
}
public bool IsCustomDataComplete (string pcfile, PackageInfo pkg)
{
return false;
}
public void ReportError (string message, Exception ex)
{
}
}
class PcFileCacheStub : PcFileCache
{
static string initCacheDirectory;
readonly string cacheDirectory;
PcFileCacheStub (string cacheDirectory) : base (new PcFileCacheContextStub ())
{
if (cacheDirectory == null)
throw new ArgumentNullException ("cacheDirectory");
this.cacheDirectory = cacheDirectory;
}
protected override string CacheDirectory {
get { return initCacheDirectory == null ? cacheDirectory : initCacheDirectory; }
}
public static PcFileCache Create (string cacheDirectory)
{
initCacheDirectory = cacheDirectory;
PcFileCache cache = new PcFileCacheStub (cacheDirectory);
initCacheDirectory = null;
return cache;
}
}
}
}