Exemplo n.º 1
0
        static async Task <int> Main(string[] argsArray)
        {
            var args = argsArray.Select(a => a.TrimStart('-').Split('='))
                       .ToDictionary(p => p[0], p => p[1]);

            var root = BazelEnvironment.TryGetWorkspaceRoot();

            if (root != null)
            {
                Directory.SetCurrentDirectory(root);
            }
            else
            {
                root = Directory.GetCurrentDirectory();
            }

            if (args.TryGetValue("tar", out var outputName))
            {
                outputName = outputName.Split(" ")[0];
            }
            else
            {
                outputName = "test.tar.gz";
            }

            var packages = Array.Empty <string>();

            if (args.TryGetValue("packages", out var packagesString))
            {
                packages = packagesString.Split(",");
            }
            using var tarMaker = new TarMaker(outputName, root, packages);
            return(await tarMaker.MakeTar());
        }
Exemplo n.º 2
0
        private static int Restore(RestoreOptions restore)
        {
            var workspace = BazelEnvironment.TryGetWorkspaceRoot();
            var cwd       = Directory.GetCurrentDirectory();

            if (workspace != null && !cwd.StartsWith(workspace))
            {
                Directory.SetCurrentDirectory(workspace);
            }

            var query = $"kind(msbuild_restore,{restore.Package})";

            Console.WriteLine($"bazel query {query} | xargs bazel build");
            var info = new ProcessStartInfo("bazel")
            {
                RedirectStandardOutput = true
            };

            info.ArgumentList.Add("query");
            info.ArgumentList.Add(query);

            var queryProcess = Process.Start(info) !;
            var output       = queryProcess.StandardOutput.ReadToEnd();

            queryProcess.WaitForExit();
            Console.WriteLine(output);
            if (queryProcess.ExitCode != 0)
            {
                return(queryProcess.ExitCode);
            }
            var targets = output.Split(Environment.NewLine);
            var build   = Process.Start("bazel", "build " + string.Join(' ', targets)) !;

            build.WaitForExit();

            return(build.ExitCode);
        }