Skip to content
Permalink
Browse files

[Assets] Removed LocalDependencies and fixed TemplateSampleGenerator

  • Loading branch information
xen2 committed Sep 7, 2018
1 parent 1d51c47 commit 5ec594f7a9b7df1b30d24534abaffef959091bd8
@@ -105,7 +105,7 @@ public void TestPackageLoadingWithAssets()
Assert.NotNull(project);
Assert.True(3 == project.Assets.Count, "Invalid number of assets loaded");

Assert.True(1 == project.LocalDependencies.Count, "Expecting subproject");
Assert.True(1 == project.Container.LoadedDependencies.Count, "Expecting subproject");

Assert.NotEqual(AssetId.Empty, project.Assets.First().Id);

@@ -137,19 +137,6 @@ public static void Clean(Package package, ICollection<AssetItem> inputItems, ICo
if (package != null)
{
UpdateRootAssets(package.RootAssets, idRemap);

// We check dependencies to be consistent with other places, but nothing should be changed in there
// (except if we were to instantiate multiple packages referencing each other at once?)
foreach (var dependency in package.LocalDependencies)
{
if (dependency.RootAssets != null)
UpdateRootAssets(dependency.RootAssets, idRemap);
}
foreach (var dependency in package.Meta.Dependencies)
{
if (dependency.RootAssets != null)
UpdateRootAssets(dependency.RootAssets, idRemap);
}
}
}

@@ -116,10 +116,9 @@ public static AssetResolver FromPackage(Package package)
{
if (package == null) throw new ArgumentNullException(nameof(package));

var packagesForLocation = package.FindDependencies(true);
var packagesForIds = package.Session != null ? package.Session.Packages : packagesForLocation;
var packages = package.FindDependencies(true);

return new AssetResolver(packagesForLocation.ContainsAsset, packagesForIds.ContainsAsset);
return new AssetResolver(packages.ContainsAsset, packages.ContainsAsset);
}

/// <summary>
@@ -80,18 +80,6 @@ public void Run(ILogger log)
if (Parameters.IsProcessingAssetReferences)
{
ProcessRootAssetReferences(package.RootAssets, package, log);
foreach (var dependency in package.LocalDependencies)
{
var referencedPackage = package.Session.Packages.Find(dependency.Id);
if (referencedPackage != null)
ProcessRootAssetReferences(dependency.RootAssets, referencedPackage, log);
}
foreach (var dependency in package.Meta.Dependencies)
{
var referencedPackage = package.Session.Packages.Find(dependency);
if (referencedPackage != null)
ProcessRootAssetReferences(dependency.RootAssets, referencedPackage, log);
}
}

ProcessAssets().CopyTo(log);
@@ -118,6 +106,8 @@ public LoggerResult CheckDependencies()
return log;
}

// TODO CSPROJ=XKPKG check deps
/*
// 1. Check all store package references
foreach (var packageDependency in package.Meta.Dependencies)
{
@@ -159,6 +149,7 @@ public LoggerResult CheckDependencies()
}
}
}
*/

// TODO: Check profiles

@@ -192,12 +183,12 @@ private void ProcessRootAssetReferences(RootAssetCollection rootAssets, Package
{
// Update Asset references (AssetReference, AssetBase, reference)
var id = rootAsset.Id;
var newItemReference = referencedPackage.Assets.Find(id);
var newItemReference = referencedPackage.FindAsset(id);

// If asset was not found by id try to find by its location
if (newItemReference == null)
{
newItemReference = referencedPackage.Assets.Find(rootAsset.Location);
newItemReference = referencedPackage.FindAsset(rootAsset.Location);
if (newItemReference != null)
{
// If asset was found by its location, just emit a warning
@@ -74,22 +74,9 @@ private void CollectReferences(Package package, HashSet<AssetItem> assetsReferen
}

// 2. Process referenced packages as well (for their roots)
foreach (var packageDependency in package.Meta.Dependencies)
foreach (var dependency in package.Container.LoadedDependencies)
{
var subPackage = package.Session.Packages.Find(packageDependency);
if (subPackage != null)
{
CollectReferences(subPackage, assetsReferenced, packagesProcessed);
}
}

foreach (var subPackageReference in package.LocalDependencies)
{
var subPackage = package.Session.Packages.Find(subPackageReference.Id);
if (subPackage != null)
{
CollectReferences(subPackage, assetsReferenced, packagesProcessed);
}
CollectReferences(dependency, assetsReferenced, packagesProcessed);
}

// 3. Some types are marked with AlwaysMarkAsRoot
@@ -154,14 +154,6 @@ public Guid Id
[DataMember(10)]
public PackageMeta Meta { get; set; } = new PackageMeta();

/// <summary>
/// Gets the local package dependencies used by this package (only valid for local references). Global dependencies
/// are defined through the <see cref="Meta"/> property in <see cref="PackageMeta.Dependencies"/>
/// </summary>
/// <value>The package local dependencies.</value>
[DataMember(30)]
public List<PackageReference> LocalDependencies { get; } = new List<PackageReference>();

/// <summary>
/// Gets the profile.
/// </summary>
@@ -56,7 +56,7 @@ internal static IEnumerable<Package> GetPackagesWithDependencies(this Package cu
/// <returns>List&lt;Package&gt;.</returns>
/// <exception cref="System.ArgumentNullException">rootPackage</exception>
/// <exception cref="System.ArgumentException">Root package must be part of a session;rootPackage</exception>
public static PackageCollection FindDependencies(this Package rootPackage, bool includeRootPackage = false, bool isRecursive = true, bool storeOnly = false)
public static PackageCollection FindDependencies(this Package rootPackage, bool includeRootPackage = false)
{
if (rootPackage == null) throw new ArgumentNullException("rootPackage");
var packages = new PackageCollection();
@@ -66,7 +66,7 @@ public static PackageCollection FindDependencies(this Package rootPackage, bool
packages.Add(rootPackage);
}

FillPackageDependencies(rootPackage, isRecursive, packages, storeOnly);
FillPackageDependencies(rootPackage, packages);

return packages;
}
@@ -93,60 +93,20 @@ public static bool ContainsAsset(this IEnumerable<Package> packages, UFile locat
return packages.Any(package => package.Assets.Find(location) != null);
}

private static void FillPackageDependencies(Package rootPackage, bool isRecursive, ICollection<Package> packagesFound, bool storeOnly = false)
private static void FillPackageDependencies(Package rootPackage, ICollection<Package> packagesFound)
{
var session = rootPackage.Session;

if (session == null && (rootPackage.Meta.Dependencies.Count > 0 || rootPackage.LocalDependencies.Count > 0))
if (session == null)
{
throw new InvalidOperationException("Cannot query package with dependencies when it is not attached to a session");
}

// 1. Load store package
foreach (var packageDependency in rootPackage.Meta.Dependencies)
foreach (var dependency in rootPackage.Container.LoadedDependencies)
{
var package = session.Packages.Find(packageDependency);
if (package == null)
{
continue;
}

if (!packagesFound.Contains(package))
{
packagesFound.Add(package);

if (isRecursive)
{
FillPackageDependencies(package, isRecursive, packagesFound, storeOnly);
}
}
}

if (storeOnly)
{
return;
if (!packagesFound.Contains(dependency))
packagesFound.Add(dependency);
}

// 2. Load local packages
foreach (var packageReference in rootPackage.LocalDependencies)
{
var package = session.Packages.Find(packageReference.Id);
if (package == null)
{
continue;
}

if (!packagesFound.Contains(package))
{
packagesFound.Add(package);

if (isRecursive)
{
FillPackageDependencies(package, isRecursive, packagesFound, storeOnly);
}
}
}

}
}
}
@@ -20,7 +20,6 @@ public PackageMeta()
{
Authors = new List<string>();
Owners = new List<string>();
Dependencies = new PackageDependencyCollection();
}

/// <summary>
@@ -184,23 +183,6 @@ public PackageMeta()
[DataMemberIgnore]
public DateTimeOffset? Published { get; internal set; }

/// <summary>
/// Copies local and store depdencies of this instance to the specified package
/// </summary>
/// <param name="packageMeta">The package meta.</param>
/// <exception cref="System.ArgumentNullException">packageMeta</exception>
public void CopyDependenciesTo(PackageMeta packageMeta)
{
if (packageMeta == null) throw new ArgumentNullException("packageMeta");
foreach (var packageDependency in Dependencies)
{
if (!packageMeta.Dependencies.Contains(packageDependency))
{
packageMeta.Dependencies.Add(packageDependency.Clone());
}
}
}

/// <summary>
/// Creates a new <see cref="PackageMeta" /> with default values.
/// </summary>
@@ -371,7 +371,7 @@ public AssetSourceTracker SourceTracker
/// <exception cref="System.ArgumentNullException">packagePath</exception>
/// <exception cref="System.ArgumentException">Invalid relative path. Expecting an absolute package path;packagePath</exception>
/// <exception cref="System.IO.FileNotFoundException">Unable to find package</exception>
public Package AddExistingPackage(UFile packagePath, ILogger logger, PackageLoadParameters loadParametersArg = null)
public PackageContainer AddExistingPackage(UFile packagePath, ILogger logger, PackageLoadParameters loadParametersArg = null)
{
if (packagePath == null) throw new ArgumentNullException(nameof(packagePath));
if (logger == null) throw new ArgumentNullException(nameof(logger));
@@ -381,13 +381,32 @@ public Package AddExistingPackage(UFile packagePath, ILogger logger, PackageLoad
var loadParameters = loadParametersArg ?? PackageLoadParameters.Default();

Package package;
PackageContainer project;
try
{
// Enable reference analysis caching during loading
AssetReferenceAnalysis.EnableCaching = true;

package = PreLoadPackage(logger, packagePath, false, loadParameters);
Projects.Add(new StandalonePackage(package));
if (Path.GetExtension(packagePath).ToLowerInvariant() == ".csproj")
{
var projectPath = packagePath;
packagePath = Path.ChangeExtension(packagePath, Package.PackageFileExtension);
package = PreLoadPackage(logger, packagePath, false, loadParameters);
Projects.Add(project = new SolutionProject(package, package.Id, projectPath));
}
else
{
package = PreLoadPackage(logger, packagePath, false, loadParameters);
var projectPath = Path.ChangeExtension(package.FullPath, ".csproj");
if (File.Exists(projectPath))
{
Projects.Add(project = new SolutionProject(package, package.Id, projectPath));
}
else
{
Projects.Add(project = new StandalonePackage(package));
}
}

if (loadParameters.AutoCompileProjects && loadParameters.ForceNugetRestore)
{
@@ -419,7 +438,7 @@ public Package AddExistingPackage(UFile packagePath, ILogger logger, PackageLoad
// Disable reference analysis caching after loading
AssetReferenceAnalysis.EnableCaching = false;
}
return package;
return project;
}

/// <summary>
@@ -1057,12 +1076,6 @@ private Package PreLoadPackage(ILogger log, string filePath, bool isSystemPackag
var package = Package.LoadRaw(log, filePath);
package.IsSystem = isSystemPackage;

// Remove all missing dependencies if they are not required
if (!loadParameters.LoadMissingDependencies)
{
package.LocalDependencies.Clear();
}

// Convert UPath to absolute (Package only)
// Removed for now because it is called again in PackageSession.LoadAssembliesAndAssets (and running it twice result in dirty package)
// If we remove it from here (and call it only in the other method), templates are not loaded (Because they are loaded via the package store that do not use PreLoadPackage)
@@ -1113,7 +1126,7 @@ private bool TryLoadAssets(PackageSession session, ILogger log, Package package,
{
// First, check that dependencies have their assets loaded
bool dependencyError = false;
foreach (var dependency in package.FindDependencies(false, false))
foreach (var dependency in package.FindDependencies(false))
{
if (!TryLoadAssets(session, log, dependency, loadParameters))
dependencyError = true;
@@ -1122,29 +1135,13 @@ private bool TryLoadAssets(PackageSession session, ILogger log, Package package,
if (dependencyError)
return false;

// TODO CSPROJ=XKPKG: get package upgraders from PreLoadPackageDependencies
var pendingPackageUpgrades = new List<PendingPackageUpgrade>();

// Note: Default state is upgrade failed (for early exit on error/exceptions)
// We will update to success as soon as loading is finished.
package.State = PackageState.UpgradeFailed;

// Process store dependencies for upgraders
foreach (var packageDependency in package.Meta.Dependencies)
{
var dependencyPackage = session.packages.Find(packageDependency);
if (dependencyPackage == null)
{
continue;
}

// Check for upgraders
var packageUpgrader = CheckPackageUpgrade(log, package, packageDependency, dependencyPackage);
if (packageUpgrader != null)
{
pendingPackageUpgrades.Add(new PendingPackageUpgrade(packageUpgrader, packageDependency, dependencyPackage));
}
}

// Prepare asset loading
var newLoadParameters = loadParameters.Clone();
newLoadParameters.AssemblyContainer = session.AssemblyContainer;
@@ -80,9 +80,6 @@ public static Package NewPackage(string name)
},
};

// Add dependency to latest Xenko package
package.Meta.Dependencies.Add(XenkoConfig.GetLatestPackageDependency());

return package;
}
}

0 comments on commit 5ec594f

Please sign in to comment.
You can’t perform that action at this time.