Exemplo n.º 1
0
        /// <summary>
        /// Constructs a new NugetAnalyzed Package.
        /// </summary>
        /// <remarks>
        /// In case of failure it will log a detailed message and return null.
        /// </remarks>
        public static NugetAnalyzedPackage TryAnalyzeNugetPackage(
            FrontEndContext context,
            NugetFrameworkMonikers nugetFrameworkMonikers,
            XDocument nuSpec,
            PackageOnDisk packageOnDisk,
            Dictionary <string, INugetPackage> packagesOnConfig,
            bool doNotEnforceDependencyVersions)
        {
            Contract.Requires(context != null);
            Contract.Requires(nuSpec != null);
            Contract.Requires(packageOnDisk != null);
            Contract.Requires(packageOnDisk.NuSpecFile.IsValid);

            var analyzedPackage = new NugetAnalyzedPackage(context, nugetFrameworkMonikers, nuSpec, packageOnDisk,
                                                           packagesOnConfig, doNotEnforceDependencyVersions);

            if (!analyzedPackage.TryParseDependenciesFromNuSpec())
            {
                return(null);
            }

            analyzedPackage.ParseManagedSemantics();
            analyzedPackage.UpdateForMissingQualifierConversionFunction();

            return(analyzedPackage);
        }
Exemplo n.º 2
0
        /// <nodoc />
        public NugetSpecGenerator(PathTable pathTable, NugetAnalyzedPackage analyzedPackage)
        {
            m_pathTable              = pathTable;
            m_analyzedPackage        = analyzedPackage;
            m_packageOnDisk          = analyzedPackage.PackageOnDisk;
            m_nugetFrameworkMonikers = new NugetFrameworkMonikers(pathTable.StringTable);

            m_xmlExtension = PathAtom.Create(pathTable.StringTable, ".xml");
            m_pdbExtension = PathAtom.Create(pathTable.StringTable, ".pdb");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Given a dictionary of packageID -> NugetAnalyzedPackage that is closed under dependencies (if a nuget package A depends on B, if
        /// A is in the dictionary then B is in the dictionary), updates the set of supported target frameworks for each package considering its package
        /// dependencies.
        /// </summary>
        /// <remarks>
        /// The way the patch works is as follows:
        /// - For a managed package, the set of supported frameworks is explicit given the package directory structure, so it is left as is
        /// - For a non-managed package, the patched set of supported frameworks is the union of the supported frameworks of all its dependencies, considering
        /// that all its dependencies were already patched
        /// </remarks>
        public static bool TryPatchSupportedTargetFrameworksForPackageExtent(NugetFrameworkMonikers nugetFrameworkMonikers, IDictionary <string, NugetAnalyzedPackage> packageExtent, out NugetFailure failure)
        {
            // We topo sort the list of packages, where dependents are always after their dependencies
            if (!TryToposortPackages(packageExtent, out List <NugetAnalyzedPackage> sortedAnalyzedPackages, out failure))
            {
                return(false);
            }

            // We traverse the list from head to tail, so when we retrieve a dependency, it is already patched
            foreach (var analyzedPackage in sortedAnalyzedPackages)
            {
                var targetFrameworkWithFallBacks = analyzedPackage.TargetFrameworkWithFallbacks;

                // If the package is managed, the qualifier space is already the right one
                if (analyzedPackage.IsManagedPackage)
                {
                    /*
                     *  TODO:Nuget: Another workaround to make Nuget packages that are already exposing .NET Standard targets compatible to .NET Framework 452 qualifiers,
                     *  unfortunately we have many of those in use with BuildXL already e.g. ProtocolReader. This makes coercing between .NETStandard1.1 packages and
                     *  .NET Framework 4.5.1 work, until we have proper support built in. If we encounter more packages with different .NETStandard this would
                     *  at least be the only place we introduce more special casing.
                     */
                    if (targetFrameworkWithFallBacks.Count == 1)
                    {
                        if (targetFrameworkWithFallBacks.Keys.FirstOrDefault().Equals(nugetFrameworkMonikers.NetStandard10) ||
                            targetFrameworkWithFallBacks.Keys.FirstOrDefault().Equals(nugetFrameworkMonikers.NetStandard11))
                        {
                            targetFrameworkWithFallBacks.Add(nugetFrameworkMonikers.Net472);
                            targetFrameworkWithFallBacks.Add(nugetFrameworkMonikers.Net462);
                            targetFrameworkWithFallBacks.Add(nugetFrameworkMonikers.Net461);
                            targetFrameworkWithFallBacks.Add(nugetFrameworkMonikers.Net46);
                            targetFrameworkWithFallBacks.Add(nugetFrameworkMonikers.Net452);
                            targetFrameworkWithFallBacks.Add(nugetFrameworkMonikers.Net451);
                            targetFrameworkWithFallBacks.Add(nugetFrameworkMonikers.Net45);
                        }
                    }

                    continue;
                }

                // Otherwise, we compute the union of the qualifier spaces of its dependencies
                foreach (var dependency in analyzedPackage.Dependencies)
                {
                    Contract.Assert(packageExtent.Keys.Contains(dependency.GetPackageIdentity()));
                    var analyzedDependency = packageExtent[dependency.GetPackageIdentity()];
                    CombineTargetFrameworksForUnmanagedPackage(targetFrameworkWithFallBacks, analyzedDependency.TargetFrameworkWithFallbacks);
                }
            }

            return(true);
        }
Exemplo n.º 4
0
 /// <nodoc/>
 private NugetAnalyzedPackage(
     FrontEndContext context,
     NugetFrameworkMonikers nugetFrameworkMonikers,
     XDocument nuSpec,
     PackageOnDisk packageOnDisk,
     Dictionary <string, INugetPackage> packagesOnConfig,
     bool doNotEnforceDependencyVersions)
 {
     m_context                        = context;
     m_nuSpec                         = nuSpec;
     PackageOnDisk                    = packageOnDisk;
     NugetFrameworkMonikers           = nugetFrameworkMonikers;
     m_packagesOnConfig               = packagesOnConfig;
     m_doNotEnforceDependencyVersions = doNotEnforceDependencyVersions;
     TargetFrameworkWithFallbacks     = new MultiValueDictionary <Moniker, Moniker>();
 }
Exemplo n.º 5
0
 /// <nodoc/>
 private NugetAnalyzedPackage(
     FrontEndContext context,
     NugetFrameworkMonikers nugetFrameworkMonikers,
     PackageOnDisk packageOnDisk,
     Dictionary <string, INugetPackage> packagesOnConfig,
     bool doNotEnforceDependencyVersions)
 {
     m_context                        = context;
     PackageOnDisk                    = packageOnDisk;
     NugetFrameworkMonikers           = nugetFrameworkMonikers;
     m_packagesOnConfig               = packagesOnConfig;
     m_doNotEnforceDependencyVersions = doNotEnforceDependencyVersions;
     TargetFrameworks                 = new List <Moniker>();
     References                       = new MultiValueDictionary <NugetTargetFramework, RelativePath>();
     Libraries                        = new MultiValueDictionary <NugetTargetFramework, RelativePath>();
     AssemblyToTargetFramework        = new MultiValueDictionary <PathAtom, NugetTargetFramework>();
     m_dependencies                   = new List <INugetPackage>();
     DependenciesPerFramework         = new MultiValueDictionary <PathAtom, INugetPackage>();
 }
Exemplo n.º 6
0
        /// <summary>
        /// Constructs a new NugetAnalyzed Package.
        /// </summary>
        /// <remarks>
        /// In case of failure it will log a detailed message and return null.
        /// </remarks>
        public static NugetAnalyzedPackage TryAnalyzeNugetPackage(
            FrontEndContext context,
            NugetFrameworkMonikers nugetFrameworkMonikers,
            [CanBeNull] XDocument nuSpec,
            PackageOnDisk packageOnDisk,
            Dictionary <string, INugetPackage> packagesOnConfig,
            bool doNotEnforceDependencyVersions)
        {
            Contract.Requires(context != null);
            Contract.Requires(packageOnDisk != null);

            var analyzedPackage = new NugetAnalyzedPackage(context, nugetFrameworkMonikers, packageOnDisk,
                                                           packagesOnConfig, doNotEnforceDependencyVersions);

            analyzedPackage.ParseManagedSemantics();
            if (nuSpec != null && !analyzedPackage.TryParseDependenciesFromNuSpec(nuSpec))
            {
                return(null);
            }

            return(analyzedPackage);
        }