Ejemplo n.º 1
0
 private IEnumerable <LibraryAsset> PopulateAssets(TargetLibraryWithAssets library, IEnumerable <LockFileItem> section)
 {
     foreach (var assemblyPath in section.Where(a => !PackageDependencyProvider.IsPlaceholderFile(a.Path)))
     {
         yield return(LibraryAsset.CreateFromRelativePath(library.Path, assemblyPath.Path));
     }
 }
Ejemplo n.º 2
0
        private LibraryExport ExportProject(ProjectDescription project)
        {
            var builder         = LibraryExportBuilder.Create(project);
            var compilerOptions = project.Project.GetCompilerOptions(project.TargetFrameworkInfo.FrameworkName, _configuration);

            if (!string.IsNullOrEmpty(project.TargetFrameworkInfo?.AssemblyPath))
            {
                // Project specifies a pre-compiled binary. We're done!
                var assemblyPath = ResolvePath(project.Project, _configuration, project.TargetFrameworkInfo.AssemblyPath);
                var pdbPath      = Path.ChangeExtension(assemblyPath, "pdb");

                var compileAsset = new LibraryAsset(
                    project.Project.Name,
                    Path.GetFileName(assemblyPath),
                    assemblyPath);

                builder.AddCompilationAssembly(compileAsset);
                builder.AddRuntimeAssemblyGroup(new LibraryAssetGroup(new[] { compileAsset }));
                if (File.Exists(pdbPath))
                {
                    builder.AddRuntimeAsset(new LibraryAsset(Path.GetFileName(pdbPath), Path.GetFileName(pdbPath), pdbPath));
                }
            }
            else if (HasSourceFiles(project, compilerOptions))
            {
                var outputPaths = project.GetOutputPaths(_buildBasePath, _solutionRootPath, _configuration, _runtime);

                var compilationAssembly      = outputPaths.CompilationFiles.Assembly;
                var compilationAssemblyAsset = LibraryAsset.CreateFromAbsolutePath(
                    outputPaths.CompilationFiles.BasePath,
                    compilationAssembly);

                builder.AddCompilationAssembly(compilationAssemblyAsset);

                if (ExportsRuntime(project))
                {
                    var runtimeAssemblyAsset = LibraryAsset.CreateFromAbsolutePath(
                        outputPaths.RuntimeFiles.BasePath,
                        outputPaths.RuntimeFiles.Assembly);

                    builder.AddRuntimeAssemblyGroup(new LibraryAssetGroup(new[] { runtimeAssemblyAsset }));
                    builder.WithRuntimeAssets(CollectAssets(outputPaths.RuntimeFiles));
                }
                else
                {
                    builder.AddRuntimeAssemblyGroup(new LibraryAssetGroup(new[] { compilationAssemblyAsset }));
                    builder.WithRuntimeAssets(CollectAssets(outputPaths.CompilationFiles));
                }

                builder.WithResourceAssemblies(outputPaths.CompilationFiles.Resources().Select(r => new LibraryResourceAssembly(
                                                                                                   LibraryAsset.CreateFromAbsolutePath(outputPaths.CompilationFiles.BasePath, r.Path),
                                                                                                   r.Locale)));
            }

            builder.WithSourceReferences(project.Project.Files.SharedFiles.Select(f =>
                                                                                  LibraryAsset.CreateFromAbsolutePath(project.Path, f)
                                                                                  ));

            return(builder.Build());
        }
Ejemplo n.º 3
0
 private IEnumerable <LibraryAsset> GetSharedSources(PackageDescription package)
 {
     return(package
            .PackageLibrary
            .Files
            .Select(f => PathUtility.GetPathWithDirectorySeparator(f))
            .Where(path => path.StartsWith("shared" + Path.DirectorySeparatorChar))
            .Select(path => LibraryAsset.CreateFromRelativePath(package.Path, path)));
 }
        public static AssemblyName GetAssemblyName(this LibraryAsset asset)
        {
            var name = asset.Name;

            if (asset.Name.EndsWith(NativeImageSufix))
            {
                name = name.Substring(0, name.Length - NativeImageSufix.Length);
            }

            return(new AssemblyName(name));
        }
Ejemplo n.º 5
0
        private IEnumerable <LibraryAsset> CollectAssets(CompilationOutputFiles files)
        {
            var assemblyPath = files.Assembly;

            foreach (var path in files.All().Except(files.Resources().Select(r => r.Path)))
            {
                if (string.Equals(assemblyPath, path))
                {
                    continue;
                }
                yield return(LibraryAsset.CreateFromAbsolutePath(files.BasePath, path));
            }
        }
Ejemplo n.º 6
0
 private IEnumerable <LibraryResourceAssembly> PopulateResources(TargetLibraryWithAssets library, IEnumerable <LockFileItem> section)
 {
     foreach (var assemblyPath in section.Where(a => !PackageDependencyProvider.IsPlaceholderFile(a.Path)))
     {
         string locale;
         if (!assemblyPath.Properties.TryGetValue(Constants.LocaleLockFilePropertyName, out locale))
         {
             locale = null;
         }
         yield return(new LibraryResourceAssembly(
                          LibraryAsset.CreateFromRelativePath(library.Path, assemblyPath.Path),
                          locale));
     }
 }
        public static Stream GetTransformedStream(this LibraryAsset asset)
        {
            if (asset.Transform == null)
            {
                return(File.OpenRead(asset.ResolvedPath));
            }

            using (var input = File.OpenRead(asset.ResolvedPath))
            {
                var output = new MemoryStream();
                asset.Transform(input, output);
                return(output);
            }
        }
        public static string GetTransformedFile(this LibraryAsset asset, string tempLocation, string tempName = null)
        {
            if (asset.Transform == null)
            {
                return(asset.ResolvedPath);
            }

            tempName = tempName ?? Path.GetFileName(asset.RelativePath);
            using (var input = File.OpenRead(asset.ResolvedPath))
            {
                var transformedName = Path.Combine(tempLocation, tempName);
                using (var output = File.OpenWrite(transformedName))
                {
                    asset.Transform(input, output);
                }
                return(transformedName);
            }
        }
 public LibraryExportBuilder AddEmbedddedResource(LibraryAsset asset)
 {
     Add(ref _embeddedResources, asset);
     return(this);
 }
 public LibraryExportBuilder AddSourceReference(LibraryAsset asset)
 {
     Add(ref _sourceReferences, asset);
     return(this);
 }
 public LibraryExportBuilder AddCompilationAssembly(LibraryAsset asset)
 {
     Add(ref _compilationAssemblies, asset);
     return(this);
 }
 public LibraryExportBuilder AddRuntimeAsset(LibraryAsset asset)
 {
     Add(ref _runtimeAssets, asset);
     return(this);
 }
Ejemplo n.º 13
0
        private LibraryExport ExportPackage(TargetLibraryWithAssets library)
        {
            var builder = LibraryExportBuilder.Create(library);

            builder.AddNativeLibraryGroup(new LibraryAssetGroup(PopulateAssets(library, library.NativeLibraries)));
            builder.AddRuntimeAssemblyGroup(new LibraryAssetGroup(PopulateAssets(library, library.RuntimeAssemblies)));
            builder.WithResourceAssemblies(PopulateResources(library, library.ResourceAssemblies));
            builder.WithCompilationAssemblies(PopulateAssets(library, library.CompileTimeAssemblies));

            if (library.Identity.Type.Equals(LibraryType.Package))
            {
                builder.WithSourceReferences(GetSharedSources((PackageDescription)library));
                builder.WithAnalyzerReference(GetAnalyzerReferences((PackageDescription)library));
            }

            if (library.ContentFiles.Any())
            {
                var parameters = PPFileParameters.CreateForProject(_rootProject.Project);
                Action <Stream, Stream> transform = (input, output) => PPFilePreprocessor.Preprocess(input, output, parameters);

                var sourceCodeLanguage = _rootProject.Project.GetSourceCodeLanguage();
                var languageGroups     = library.ContentFiles.GroupBy(file => file.CodeLanguage);

                var selectedGroup = languageGroups.FirstOrDefault(g => g.Key == sourceCodeLanguage) ??
                                    languageGroups.FirstOrDefault(g => g.Key == "any") ??
                                    languageGroups.FirstOrDefault(g => g.Key == null);
                if (selectedGroup != null)
                {
                    foreach (var contentFile in selectedGroup)
                    {
                        if (contentFile.CodeLanguage != null &&
                            contentFile.CodeLanguage != "any" &&
                            string.Compare(contentFile.CodeLanguage, sourceCodeLanguage, StringComparison.OrdinalIgnoreCase) != 0)
                        {
                            continue;
                        }

                        var fileTransform = contentFile.PPOutputPath != null ? transform : null;

                        var fullPath = Path.Combine(library.Path, contentFile.Path);
                        if (contentFile.BuildAction == BuildAction.Compile)
                        {
                            builder.AddSourceReference(LibraryAsset.CreateFromRelativePath(library.Path, contentFile.Path, fileTransform));
                        }
                        else if (contentFile.BuildAction == BuildAction.EmbeddedResource)
                        {
                            builder.AddEmbedddedResource(LibraryAsset.CreateFromRelativePath(library.Path, contentFile.Path, fileTransform));
                        }
                        if (contentFile.CopyToOutput)
                        {
                            builder.AddRuntimeAsset(new LibraryAsset(contentFile.Path, contentFile.OutputPath, fullPath, fileTransform));
                        }
                    }
                }
            }
            if (library.RuntimeTargets.Any())
            {
                foreach (var targetGroup in library.RuntimeTargets.GroupBy(t => t.Runtime))
                {
                    var runtime = new List <LibraryAsset>();
                    var native  = new List <LibraryAsset>();

                    foreach (var lockFileRuntimeTarget in targetGroup)
                    {
                        if (string.Equals(lockFileRuntimeTarget.AssetType, "native", StringComparison.OrdinalIgnoreCase))
                        {
                            native.Add(LibraryAsset.CreateFromRelativePath(library.Path, lockFileRuntimeTarget.Path));
                        }
                        else if (string.Equals(lockFileRuntimeTarget.AssetType, "runtime", StringComparison.OrdinalIgnoreCase))
                        {
                            runtime.Add(LibraryAsset.CreateFromRelativePath(library.Path, lockFileRuntimeTarget.Path));
                        }
                    }

                    if (runtime.Any())
                    {
                        builder.AddRuntimeAssemblyGroup(new LibraryAssetGroup(targetGroup.Key, runtime.Where(a => !PackageDependencyProvider.IsPlaceholderFile(a.RelativePath))));
                    }

                    if (native.Any())
                    {
                        builder.AddNativeLibraryGroup(new LibraryAssetGroup(targetGroup.Key, native.Where(a => !PackageDependencyProvider.IsPlaceholderFile(a.RelativePath))));
                    }
                }
            }

            return(builder.Build());
        }
Ejemplo n.º 14
0
 public bool Equals(LibraryAsset other)
 {
     return(string.Equals(Name, other.Name) &&
            string.Equals(RelativePath, other.RelativePath) &&
            string.Equals(ResolvedPath, other.ResolvedPath));
 }