Ejemplo n.º 1
0
        protected async Task <List <RefInfo> > GetRefInfosImpl(string configDir, string pack)
        {
            var sdk = await ZipDownloader.DownloadIfNedeed(configDir, WindowsUrl);

            var brokenDependencies = new[] { "system.printing", "presentationframework" };

            var result = new List <RefInfo>();

            var refDir   = GetRefsDir(sdk, pack);
            var relative = Path.GetRelativePath(sdk, refDir).Replace('\\', '/');
            var dlls     = Directory.GetFiles(refDir, "*.dll");

            PathAssemblyResolver resolver = null;

            if (dlls.All(x => Path.GetFileName(x) != "mscorlib.dll"))
            {
                // Locate mscorlib require for MetadataLoadContext
                var mscorlibDir = GetRefsDir(sdk, "Microsoft.NETCore.App.Ref");
                resolver = new PathAssemblyResolver(dlls.Union(new[] { Path.Combine(mscorlibDir, "mscorlib.dll") }));
            }
            else
            {
                resolver = new PathAssemblyResolver(dlls);
            }

            using var lc = new MetadataLoadContext(resolver);
            var known = dlls.Select(x => Path.GetFileNameWithoutExtension(x).ToLower()).ToArray();

            foreach (var d in dlls)
            {
                try
                {
                    var metadata = lc.LoadFromAssemblyPath(d);
                    var deps     = metadata.GetReferencedAssemblies();
                    var depNames = deps
                                   .Where(y => !brokenDependencies.Contains(y.Name.ToLower()) && known.Contains(y.Name.ToLower()))
                                   .Select(x => $"\":{x.Name.ToLower()}.dll\"");
                    var name       = Path.GetFileName(d);
                    var refname    = $"@core_sdk_{Version}//:core/{relative}/{name}";
                    var stdlibname = GetStdlibPath(sdk, name, pack, InternalVersionFolder, Version);

                    var refInfo = new RefInfo();
                    refInfo.Name       = name.ToLower();
                    refInfo.Version    = metadata.GetName().Version.ToString();
                    refInfo.Ref        = refname;
                    refInfo.StdlibPath = stdlibname;
                    refInfo.Pack       = pack;
                    refInfo.Deps.AddRange(depNames);
                    if (stdlibname != null)
                    {
                        result.Add(refInfo);
                    }
                }
                catch (Exception)
                {
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        private async Task Handle(string outpath, string package, string version, string sdkVersion, string sdk)
        {
            var packageDir = await PackageDownloader.DownloadPackageIfNedeed(_configDir, package, version);

            var sdkDir = await ZipDownloader.DownloadIfNedeed(_configDir, sdk);

            var refs = GetRefInfos(packageDir, package, version, sdkDir, sdkVersion);

            await GenerateBazelFile(outpath, refs);
        }
Ejemplo n.º 3
0
        public override async Task <List <RefInfo> > GetRefInfos(string configDir)
        {
            var package = await PackageDownloader.DownloadPackageIfNedeed(configDir, "Microsoft.NETCore.App", InternalVersionFolder);

            var sdkDir = await ZipDownloader.DownloadIfNedeed(configDir, WindowsUrl);

            var brokenDependencies = new string[] { "netstandard" };

            var result = new List <RefInfo>();

            var packageDir   = Path.Combine(package, "packages", $"Microsoft.NETCore.App.{InternalVersionFolder}");
            var frameworkDir = Path.Combine(packageDir, "ref");

            frameworkDir = Directory.GetDirectories(frameworkDir).OrderByDescending(x => x).First();

            var relative = Path.GetRelativePath(packageDir, frameworkDir).Replace('\\', '/');
            var dlls     = Directory.GetFiles(frameworkDir, "*.dll");

            var resolver = new PathAssemblyResolver(dlls);

            using var lc = new MetadataLoadContext(resolver);
            var known = dlls.Select(x => Path.GetFileNameWithoutExtension(x).ToLower()).ToArray();

            foreach (var d in dlls)
            {
                try
                {
                    var metadata = lc.LoadFromAssemblyPath(d);
                    var deps     = metadata.GetReferencedAssemblies();
                    var depNames = deps
                                   .Where(y => !brokenDependencies.Contains(y.Name.ToLower()) && known.Contains(y.Name.ToLower()))
                                   .Select(x => $"\":{x.Name.ToLower()}.dll\"");
                    var name       = Path.GetFileName(d);
                    var refname    = $"@Microsoft.NETCore.App.{InternalVersionFolder}//:{relative}/{name}";
                    var stdlibpath = GetStdlibPath(sdkDir, name, InternalVersionFolder, Version);

                    var refInfo = new RefInfo();
                    refInfo.Name       = name.ToLower();
                    refInfo.Version    = metadata.GetName().Version.ToString();
                    refInfo.Ref        = refname;
                    refInfo.StdlibPath = stdlibpath;
                    refInfo.Pack       = null;
                    refInfo.Deps.AddRange(depNames);
                    result.Add(refInfo);
                }
                catch (Exception)
                {
                }
            }

            return(result);
        }
Ejemplo n.º 4
0
        private async Task Handle(string outpath, string version, string sdkVersion, string sdk, string[] packs)
        {
            var sdkDir = await ZipDownloader.DownloadIfNedeed(_configDir, sdk);

            var packRefs = new Dictionary <string, List <RefInfo> >();

            foreach (var pack in packs)
            {
                var refs = GetRefInfos(sdkDir, version, sdkVersion, pack);
                packRefs.Add(pack, refs);
            }
            await GenerateBazelFile(outpath, packRefs);
        }
Ejemplo n.º 5
0
        private async Task Handle(StreamWriter f, Sdk sdk, bool defaultSdk)
        {
            var sdkDirWin = await ZipDownloader.DownloadIfNedeed(_configDir, sdk.WindowsUrl);

            var sdkDirLinux = await ZipDownloader.DownloadIfNedeed(_configDir, sdk.LinuxUrl);

            var sdkDirOsx = await ZipDownloader.DownloadIfNedeed(_configDir, sdk.DarwinUrl);

            await f.WriteLineAsync("load(\"@io_bazel_rules_dotnet//dotnet/private:rules/stdlib.bzl\", \"core_stdlib_internal\")");

            await f.WriteLineAsync("load(\"@io_bazel_rules_dotnet//dotnet/private:rules/libraryset.bzl\", \"core_libraryset\")");

            await f.WriteLineAsync();

            await f.WriteLineAsync("def define_runtime(context_data):");

            if (sdk.Packs != null)
            {
                await f.WriteLineAsync("    native.alias(name=\"system.security.accesscontrol.dll\", actual=\":p1_system.security.accesscontrol.dll\")");

                await f.WriteLineAsync("    native.alias(name=\"system.security.principal.windows.dll\", actual=\":p1_system.security.principal.windows.dll\")");

                await f.WriteLineAsync("    native.alias(name=\"microsoft.win32.registry.dll\", actual=\":p1_microsoft.win32.registry.dll\")");

                await f.WriteLineAsync("    native.alias(name=\"system.security.cryptography.cng.dll\", actual=\":p1_system.security.cryptography.cng.dll\")");
            }

            var infosWindows = await ProcessDirectory(f, $"windows_runtime_deps", sdkDirWin, sdk, defaultSdk);

            var infosLinux = await ProcessDirectory(f, $"linux_runtime_deps", sdkDirLinux, sdk, defaultSdk);

            var infosDarwin = await ProcessDirectory(f, $"darwin_runtime_deps", sdkDirOsx, sdk, defaultSdk);

            await f.WriteLineAsync();

            await f.WriteLineAsync($"    core_libraryset(");

            await f.WriteLineAsync($"        name = \"runtime\",");

            await f.WriteLineAsync($"        deps = select({{");

            await f.WriteLineAsync($"            \"@bazel_tools//src/conditions:windows\": [");

            foreach (var i in infosWindows.Item1)
            {
                await f.WriteLineAsync($"                \":{i.Name}\",");
            }
            await f.WriteLineAsync($"            ],");

            await f.WriteLineAsync($"            \"@bazel_tools//src/conditions:darwin\": [");

            foreach (var i in infosDarwin.Item1)
            {
                await f.WriteLineAsync($"                \":{i.Name}\",");
            }
            await f.WriteLineAsync($"            ],");

            await f.WriteLineAsync($"            \"//conditions:default\": [");

            foreach (var i in infosLinux.Item1)
            {
                await f.WriteLineAsync($"                \":{i.Name}\",");
            }
            await f.WriteLineAsync($"            ],");

            await f.WriteLineAsync($"        }}),");

            await f.WriteLineAsync($"        data = select({{");

            await f.WriteLineAsync($"            \"@bazel_tools//src/conditions:windows\": [");

            foreach (var i in infosWindows.Item2)
            {
                await f.WriteLineAsync($"                \"{i}\",");
            }
            await f.WriteLineAsync($"            ],");

            await f.WriteLineAsync($"            \"@bazel_tools//src/conditions:darwin\": [");

            foreach (var i in infosDarwin.Item2)
            {
                await f.WriteLineAsync($"                \"{i}\",");
            }
            await f.WriteLineAsync($"            ],");

            await f.WriteLineAsync($"            \"//conditions:default\": [");

            foreach (var i in infosLinux.Item2)
            {
                await f.WriteLineAsync($"                \"{i}\",");
            }
            await f.WriteLineAsync($"            ],");

            await f.WriteLineAsync($"        }}),");

            await f.WriteLineAsync($"    )");
        }