Beispiel #1
0
        public int Run(string[] arguments)
        {
            Console.WriteLine("MonoDevelop Build Tool");
            foreach (string s in arguments)
            {
                ReadArgument(s);
            }

            if (help)
            {
                Console.WriteLine("build [options] [build-file]");
                Console.WriteLine("-p --project:PROJECT  Name of the project to build.");
                Console.WriteLine("-t --target:TARGET    Name of the target: Build or Clean.");
                Console.WriteLine("-c --configuration:CONFIGURATION  Name of the solution configuration to build.");
                Console.WriteLine("-r --runtime:PREFIX  Prefix of the Mono runtime to build against.");
                Console.WriteLine();
                Console.WriteLine("Supported targets:");
                Console.WriteLine("  {0}: build the project (the default target).", ProjectService.BuildTarget);
                Console.WriteLine("  {0}: clean the project.", ProjectService.CleanTarget);
                Console.WriteLine();
                return(0);
            }

            string solFile  = null;
            string itemFile = null;

            if (file == null)
            {
                string[] files = Directory.GetFiles(".");
                foreach (string f in files)
                {
                    if (Services.ProjectService.IsWorkspaceItemFile(f))
                    {
                        solFile = f;
                        break;
                    }
                    else if (itemFile == null && Services.ProjectService.IsSolutionItemFile(f))
                    {
                        itemFile = f;
                    }
                }
                if (solFile == null && itemFile == null)
                {
                    Console.WriteLine("Project file not found.");
                    return(1);
                }
            }
            else
            {
                if (Services.ProjectService.IsWorkspaceItemFile(file))
                {
                    solFile = file;
                }
                else if (Services.ProjectService.IsSolutionItemFile(file))
                {
                    itemFile = file;
                }
                else
                {
                    Console.WriteLine("File '{0}' is not a project or solution.", file);
                    return(1);
                }
            }

            ConsoleProgressMonitor monitor = new ConsoleProgressMonitor();

            TargetRuntime targetRuntime  = null;
            TargetRuntime defaultRuntime = Runtime.SystemAssemblyService.DefaultRuntime;

            if (runtime != null)
            {
                targetRuntime = MonoTargetRuntimeFactory.RegisterRuntime(new MonoRuntimeInfo(runtime));
                if (targetRuntime != null)
                {
                    Runtime.SystemAssemblyService.DefaultRuntime = targetRuntime;
                }
            }

            IBuildTarget item;

            if (solFile != null)
            {
                item = Services.ProjectService.ReadWorkspaceItem(monitor, solFile);
            }
            else
            {
                item = Services.ProjectService.ReadSolutionItem(monitor, itemFile);
            }

            if (project != null)
            {
                Solution solution = item as Solution;
                item = null;

                if (solution != null)
                {
                    item = solution.FindProjectByName(project);
                }
                if (item == null)
                {
                    Console.WriteLine("The project '" + project + "' could not be found in " + file);
                    return(1);
                }
            }

            IConfigurationTarget configTarget = item as IConfigurationTarget;

            if (config == null && configTarget != null)
            {
                config = configTarget.DefaultConfigurationId;
            }

            ConfigurationSelector configuration;

            if (item is SolutionEntityItem)
            {
                configuration = new ItemConfigurationSelector(config);
            }
            else
            {
                configuration = new SolutionConfigurationSelector(config);
            }

            monitor = new ConsoleProgressMonitor();
            BuildResult res = item.RunTarget(monitor, command, configuration);

            if (targetRuntime != null)
            {
                Runtime.SystemAssemblyService.DefaultRuntime = defaultRuntime;
                MonoTargetRuntimeFactory.UnregisterRuntime((MonoTargetRuntime)targetRuntime);
            }

            return((res == null || res.ErrorCount == 0) ? 0 : 1);
        }
Beispiel #2
0
        public async Task <int> Run(string[] arguments)
        {
            Console.WriteLine(BrandingService.BrandApplicationName("MonoDevelop Build Tool"));
            foreach (string s in arguments)
            {
                ReadArgument(s);
            }

            if (help)
            {
                Console.WriteLine("build [options] [build-file]");
                Console.WriteLine("-p --project:PROJECT  Name of the project to build.");
                Console.WriteLine("-t --target:TARGET    Name of the target: Build or Clean.");
                Console.WriteLine("-c --configuration:CONFIGURATION  Name of the solution configuration to build.");
                Console.WriteLine("-r --runtime:PREFIX   Prefix of the Mono runtime to build against.");
                Console.WriteLine();
                Console.WriteLine("Supported targets:");
                Console.WriteLine("  {0}: build the project (the default target).", ProjectService.BuildTarget);
                Console.WriteLine("  {0}: clean the project.", ProjectService.CleanTarget);
                Console.WriteLine();
                return(0);
            }

            string solFile  = null;
            string itemFile = null;

            if (file == null)
            {
                var files = Directory.EnumerateFiles(".");
                foreach (string f in files)
                {
                    if (Services.ProjectService.IsWorkspaceItemFile(f))
                    {
                        solFile = f;
                        break;
                    }
                    else if (itemFile == null && Services.ProjectService.IsSolutionItemFile(f))
                    {
                        itemFile = f;
                    }
                }
                if (solFile == null && itemFile == null)
                {
                    Console.WriteLine("Project file not found.");
                    return(1);
                }
            }
            else
            {
                if (Services.ProjectService.IsWorkspaceItemFile(file))
                {
                    solFile = file;
                }
                else if (Services.ProjectService.IsSolutionItemFile(file))
                {
                    itemFile = file;
                }
                else
                {
                    Console.WriteLine("File '{0}' is not a project or solution.", file);
                    return(1);
                }
            }

            ProgressMonitor monitor = new ConsoleProjectLoadProgressMonitor(new ConsoleProgressMonitor());

            TargetRuntime targetRuntime  = null;
            TargetRuntime defaultRuntime = Runtime.SystemAssemblyService.DefaultRuntime;

            if (runtime != null)
            {
                targetRuntime = MonoTargetRuntimeFactory.RegisterRuntime(new MonoRuntimeInfo(runtime));
                if (targetRuntime != null)
                {
                    Runtime.SystemAssemblyService.DefaultRuntime = targetRuntime;
                }
            }

            IBuildTarget item;

            if (solFile != null)
            {
                item = await Services.ProjectService.ReadWorkspaceItem(monitor, solFile) as IBuildTarget;
            }
            else
            {
                item = await Services.ProjectService.ReadSolutionItem(monitor, itemFile);
            }

            if (item == null)
            {
                Console.WriteLine("The file '" + file + "' can't be built");
                return(1);
            }

            using (var readItem = (WorkspaceObject)item) {
                if (project != null)
                {
                    Solution solution = item as Solution;
                    item = null;

                    if (solution != null)
                    {
                        item = solution.FindProjectByName(project);
                    }
                    if (item == null)
                    {
                        Console.WriteLine("The project '" + project + "' could not be found in " + file);
                        return(1);
                    }
                }

                IConfigurationTarget configTarget = item as IConfigurationTarget;
                if (config == null && configTarget != null)
                {
                    config = configTarget.DefaultConfigurationId;
                }

                monitor = new ConsoleProgressMonitor();
                BuildResult res = null;
                if (item is SolutionItem && ((SolutionItem)item).ParentSolution == null)
                {
                    ConfigurationSelector configuration = new ItemConfigurationSelector(config);
                    if (command == ProjectService.BuildTarget)
                    {
                        res = await item.Build(monitor, configuration);
                    }
                    else if (command == ProjectService.CleanTarget)
                    {
                        res = await item.Clean(monitor, configuration);
                    }
                }
                else
                {
                    ConfigurationSelector configuration = new SolutionConfigurationSelector(config);

                    if (command == ProjectService.BuildTarget)
                    {
                        res = await item.Build(monitor, configuration, true);
                    }
                    else if (command == ProjectService.CleanTarget)
                    {
                        res = await item.Clean(monitor, configuration);
                    }
                    else
                    {
                        var p = item as Project;
                        if (p != null)
                        {
                            res = (await p.RunTarget(monitor, command, configuration)).BuildResult;
                        }
                        else
                        {
                            Console.WriteLine("Target '" + command + " not supported");
                            return(1);
                        }
                    }
                }

                if (targetRuntime != null)
                {
                    Runtime.SystemAssemblyService.DefaultRuntime = defaultRuntime;
                    MonoTargetRuntimeFactory.UnregisterRuntime((MonoTargetRuntime)targetRuntime);
                }

                if (res != null)
                {
                    foreach (var err in res.Errors)
                    {
                        Console.Error.WriteLine(err);
                    }
                }

                return((res == null || res.ErrorCount == 0) ? 0 : 1);
            }
        }