Skip to content
Permalink
Browse files

[Assets] Fix project loading

  • Loading branch information
xen2 committed Aug 30, 2018
1 parent 1653165 commit 284cccdd2e351e84ce1000329e1f24162a21b998
@@ -29,7 +29,7 @@ public IEnumerable<AssetItem> GetAssets(AssetCompilerResult assetCompilerResult)
yield break;
}

var packages = package.GetPackagesWithRecursiveDependencies();
var packages = package.GetPackagesWithDependencies();
foreach (var pack in packages)
{
foreach (var asset in pack.Assets)
@@ -40,64 +40,9 @@ internal static IEnumerable<Package> GetPackagesWithDependencies(this Package cu

var session = currentPackage.Session;

foreach (var storeDep in currentPackage.Meta.Dependencies)
foreach (var package in currentPackage.LoadedDependencies)
{
var package = session.Packages.Find(storeDep);
// In case the package is not found (when working with session not fully loaded/resolved with all deps)
if (package != null)
{
yield return package;
}
}

foreach (var localDep in currentPackage.LocalDependencies)
{
var package = session.Packages.Find(localDep.Id);
// In case the package is not found (when working with session not fully loaded/resolved with all deps)
if (package != null)
{
yield return package;
}
}
}

public static IEnumerable<Package> GetPackagesWithRecursiveDependencies(this Package startPackage)
{
// Non-recursive Depth First Search
var packagesToVisit = new Stack<Package>();
var visitedPackages = new HashSet<Package>();
packagesToVisit.Push(startPackage);

var session = startPackage.Session;

while (packagesToVisit.Count > 0)
{
var packageToVisit = packagesToVisit.Pop();
if (visitedPackages.Add(packageToVisit))
{
yield return packageToVisit;

// Push references
foreach (var storeDep in packageToVisit.Meta.Dependencies)
{
var package = session.Packages.Find(storeDep);
// In case the package is not found (when working with session not fully loaded/resolved with all deps)
if (package != null)
{
packagesToVisit.Push(package);
}
}

foreach (var localDep in packageToVisit.LocalDependencies)
{
var package = session.Packages.Find(localDep.Id);
// In case the package is not found (when working with session not fully loaded/resolved with all deps)
if (package != null)
{
packagesToVisit.Push(package);
}
}
}
yield return package;
}
}

@@ -383,16 +383,20 @@ public static void Load(string filePath, PackageSessionResult sessionResult, Pac
{
if (project.TypeGuid == KnownProjectTypeGuid.CSharp)
{
var package = session.PreLoadPackage(sessionResult, project.FullPath, false, packagesLoaded, loadParameters);
package.VSProject = project;
// TODO CSPROJ=XKPKG move that code inside Package load code, and add support for projects without xkpkg too
var packageFile = Path.ChangeExtension(project.FullPath, Package.PackageFileExtension);
if (File.Exists(packageFile))
{
var package = session.PreLoadPackage(sessionResult, packageFile, false, packagesLoaded, loadParameters, project);

if (firstPackage == null)
firstPackage = package;
if (firstPackage == null)
firstPackage = package;

// Output the session only if there is no cancellation
if (cancelToken.HasValue && cancelToken.Value.IsCancellationRequested)
{
return;
// Output the session only if there is no cancellation
if (cancelToken.HasValue && cancelToken.Value.IsCancellationRequested)
{
return;
}
}
}
}
@@ -803,7 +807,10 @@ private void RegisterPackage(Package package)

if (package.Type == PackageType.ProjectAndPackage || package.Type == PackageType.ProjectOnly)
{
VSSolution.Projects.Add(package.VSProject);
// Note: when loading, package might already be there
// TODO CSPROJ=XKPKG: skip it in a proper way? (context info)
if (!VSSolution.Projects.Contains(package.VSProject))
VSSolution.Projects.Add(package.VSProject);
}

IsDirty = true;
@@ -847,7 +854,7 @@ private void OnAssetDirtyChanged(AssetItem asset, bool oldValue, bool newValue)
AssetDirtyChanged?.Invoke(asset, oldValue, newValue);
}

private Package PreLoadPackage(ILogger log, string filePath, bool isSystemPackage, PackageCollection loadedPackages, PackageLoadParameters loadParameters)
private Package PreLoadPackage(ILogger log, string filePath, bool isSystemPackage, PackageCollection loadedPackages, PackageLoadParameters loadParameters, VisualStudio.Project project = null)
{
if (log == null) throw new ArgumentNullException(nameof(log));
if (filePath == null) throw new ArgumentNullException(nameof(filePath));
@@ -874,6 +881,14 @@ private Package PreLoadPackage(ILogger log, string filePath, bool isSystemPackag
var package = Package.LoadRaw(log, filePath);
package.IsSystem = isSystemPackage;

// TODO CSPROJ=XKPKG temp code until Package loading supports csproj format natively
if (project != null)
{
package.ProjectFullPath = project.FullPath;
package.Type = PackageType.ProjectAndPackage;
package.VSProject = project;
}

// Remove all missing dependencies if they are not required
if (!loadParameters.LoadMissingDependencies)
{
@@ -1191,9 +1206,10 @@ private void PreLoadPackageDependencies(ILogger log, Package package, PackageCol

// Recursive load of the system package
loadedPackage = PreLoadPackage(log, file, true, loadedPackages, loadParameters);
package.LoadedDependencies.Add(loadedPackage);
}

if (loadedPackage != null)
package.LoadedDependencies.Add(loadedPackage);
if (loadedPackage == null || loadedPackage.State < PackageState.DependenciesReady)
packageDependencyErrors = true;
}
@@ -83,7 +83,7 @@ public ListBuildStep CreateSystemShaderBuildSteps(SessionViewModel session)
}

importShadersProjectSession.Packages.Add(mapPackage);
importShadersRootProject.LocalDependencies.Add(mapPackage);
importShadersRootProject.LoadedDependencies.Add(mapPackage);
}

// compile the fake project (create the build steps)
@@ -119,7 +119,7 @@ public ListBuildStep CreateUserShaderBuildSteps(SessionViewModel session)
}

importShadersProjectSession.Packages.Add(mapPackage);
importShadersRootProject.LocalDependencies.Add(mapPackage);
importShadersRootProject.LoadedDependencies.Add(mapPackage);
}

// compile the fake project (create the build steps)

0 comments on commit 284cccd

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