Exemplo n.º 1
0
        private void CreateToolBox()
        {
            try
            {
                progs = ProgramFinder.findAll();
                MenuItem menu = new MenuItem();
                menu.Header = "Tools";
                foreach (Program p in progs)
                {
                    MenuItem m = new MenuItem();
                    m.Header = p.Navn.Split('.')[0];
                    m.Click += ToolMenu_Click;
                    menu.Items.Add(m);
                }

                MainMenu.Items.Add(menu);
            }

            catch (Exception ex)
            {
                FileHandler.Error(ex);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Set up environment and paths to use mingw
        /// </summary>
        /// <param name="arch">A string indicating the target platform</param>
        private void SetMingwCompiler( string arch)
        {
            if (_verbose) {

                using (new ConsoleColors(ConsoleColor.White, ConsoleColor.Black)) {
                    Console.Write("Setting Compiler: ");
                }
                using (new ConsoleColors(ConsoleColor.Green, ConsoleColor.Black)) {
                    Console.Write("mingw");
                }
                using (new ConsoleColors(ConsoleColor.Yellow, ConsoleColor.Black)) {
                    Console.WriteLine(" for [{0}]", arch);
                }
            }

            var mingwProgramFinder = new ProgramFinder("", Directory.GetDirectories(@"c:\\", "M*").Aggregate(_searchPaths+@"%ProgramFiles(x86)%;%ProgramFiles%;%ProgramW6432%", (current, dir) => dir + ";" + current));

            var gcc = mingwProgramFinder.ScanForFile("mingw32-gcc.exe");
            var msysmnt = mingwProgramFinder.ScanForFile("msysmnt.exe");

            if( string.IsNullOrEmpty(gcc)) {
                throw new ConsoleException("Unable to locate MinGW install location. Use --mingw-install=<path>\r\n   (it will remember after that.)");
            }

            if (string.IsNullOrEmpty(msysmnt)) {
                throw new ConsoleException("Unable to locate MSYS install location. Use --msys-install=<path>\r\n   (it will remember after that.)");
            }

            var msysBin = Path.GetDirectoryName(msysmnt);
            var msysPath = Path.GetDirectoryName(msysBin);

            var msysLocalBin = Path.Combine(msysPath, "local", "bin");
            var mingwBin = Path.GetDirectoryName(gcc);
            var mingwPath = Path.GetDirectoryName(mingwBin);
            var username = Environment.GetEnvironmentVariable("USERNAME") ?? "";

            var newPath = ".;" + mingwBin + ";" + msysBin + ";" + msysLocalBin + ";" + Environment.GetEnvironmentVariable("PATH");
            Environment.SetEnvironmentVariable("PATH", newPath);

            var tmpPath = Environment.GetEnvironmentVariable("TMP") ??
                Environment.GetEnvironmentVariable("TEMP") ??
                    Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Temp").Replace("\\", "/");

            Environment.SetEnvironmentVariable("TMP", tmpPath);
            Environment.SetEnvironmentVariable("TEMP", tmpPath);

            Environment.SetEnvironmentVariable("WD", msysBin);
            Environment.SetEnvironmentVariable("TERM", "cygwin");

            var homedir = Environment.GetEnvironmentVariable("HOME");
            if( string.IsNullOrEmpty(homedir) ) {
                homedir = Path.Combine(Path.Combine(msysPath, "home"), username);
                if (!Directory.Exists(homedir)) {
                    homedir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
                }
                Environment.SetEnvironmentVariable("HOME", homedir.Replace("\\", "/"));
            }

            Environment.SetEnvironmentVariable("HISTFILE", Path.Combine(homedir, ".bashhistory").Replace("\\", "/"));

            Environment.SetEnvironmentVariable("LOGNAME", username);
            Environment.SetEnvironmentVariable("MAKE_MODE", "unix");
            Environment.SetEnvironmentVariable("MSYSCON", "sh.exe");
            Environment.SetEnvironmentVariable("MSYSTEM", "MINGW32");
        }
Exemplo n.º 3
0
        private void Load(string[] args)
        {
            var options    = args.Switches();
            var parameters = args.Parameters();

            foreach (var arg in args)
            {
                var argumentParameters = options[arg];

                if (arg.StartsWith("exe-"))
                {
                    var appname = arg.Substring(4);

                    var t = AddEXE(GetItemName(appname), GetItemVersion(appname));
                    t.Ignore = false;
                    foreach (var item in argumentParameters)
                    {
                        t.Dependencies.Add(AddDLL(GetItemName(item), GetItemVersion(item)));
                    }
                    break;
                }

                else if (arg.StartsWith("dll-"))
                {
                    var dllname = arg.Substring(4);

                    var t = AddDLL(GetItemName(dllname), GetItemVersion(dllname));
                    t.Ignore = false;
                    foreach (var item in argumentParameters)
                    {
                        if (!String.IsNullOrEmpty(item))
                        {
                            t.Dependencies.Add(AddDLL(GetItemName(item), GetItemVersion(item)));
                        }
                    }
                    break;
                }

                else if (arg.StartsWith("policy-"))
                {
                    var dllname = arg.Substring(7);
                    var t       = AddDLL(GetItemName(dllname), GetItemVersion(dllname));

                    foreach (var policyText in argumentParameters)
                    {
                        var policy = policyText.Split('-');
                        t.Policies.Add(new Tuple <string, string>(policy[0], policy.Length == 2 ? policy[1] : policy[0]));
                    }
                    break;
                }
            }

            cl_x86 = new ProcessUtility(ProgramFinder.ProgramFilesAndDotNet.ScanForFile("cl.exe", ExecutableInfo.x86, new[] { @"*\x86_amd64\*", @"*\x86_ia64\*" }));
            cl_x64 = new ProcessUtility(ProgramFinder.ProgramFilesAndDotNet.ScanForFile("cl.exe", ExecutableInfo.x64));

            //This only works if
            var cscpf = new ProgramFinder("C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319");

            csc_msil = new ProcessUtility(cscpf.ScanForFile("csc.exe"));
            al_msil  = new ProcessUtility(ProgramFinder.ProgramFilesAndDotNet.ScanForFile("al.exe"));

            lib_x86 = new ProcessUtility(ProgramFinder.ProgramFilesAndDotNet.ScanForFile("lib.exe", ExecutableInfo.x86, new[] { @"*\x86_amd64\*", @"*\x86_ia64\*" }));
            lib_x64 = new ProcessUtility(ProgramFinder.ProgramFilesAndDotNet.ScanForFile("lib.exe", ExecutableInfo.x64));

            pktExtract = new ProcessUtility(ProgramFinder.ProgramFilesAndDotNet.ScanForFile("pktExtract.exe"));
        }
Exemplo n.º 4
0
        /// <summary>
        /// This is the main procedure
        /// </summary>
        /// <param name="args">Command line parameters</param>
        /// <returns>Error codes (0 for success, non-zero on Error)</returns>
        private int main(IEnumerable<string> args)
        {
            var options = args.Switches();
            var parameters = args.Parameters();
            var tempBuildinfo = (from a in @".\COPKG\".DirectoryEnumerateFilesSmarter("*.buildinfo", SearchOption.TopDirectoryOnly)
                                 orderby a.Length ascending
                                 select a.GetFullPath()).FirstOrDefault();
            // find PropertySheet location
            //we'll just use the default even though it won't work so I don't need to change the code much :)
            var buildinfo = tempBuildinfo ?? @".\COPKG\.buildinfo".GetFullPath();

            Console.CancelKeyPress += (x, y) => {
                Console.WriteLine("Stopping ptk.");
                if (_cmdexe != null)
                    _cmdexe.Kill();
                if (_gitexe != null)
                    _gitexe.Kill();
                if (_hgexe != null)
                    _hgexe.Kill();
                if (_ptk != null)
                    _ptk.Kill();
                if (_traceexe != null) {
                    _traceexe.Kill();
                }
            };

            #region Parse Options

            // set up options which were defined by the user
            foreach (string arg in options.Keys) {
                IEnumerable<string> argumentParameters = options[arg];

                switch (arg) {
                    case "nologo":
                        // disable logo (will print "\n" anyway)
                        this.Assembly().SetLogo("");
                        break;

                    case "verbose":
                        _verbose = true;
                        break;

                    case "load":
                        // user specified a custom PropertySheet
                        buildinfo = argumentParameters.LastOrDefault().GetFullPath();
                        break;

                    case "mingw-install":
                    case "msys-install":
                        _searchPaths += argumentParameters.LastOrDefault().GetFullPath() + ";";
                        break;

                    case "rescan-tools":
                        ProgramFinder.IgnoreCache = true;
                        break;

                    case "show-tools":
                        _showTools = true;
                        break;

                    case "help":
                        return Help();
                }
            }

            if (!File.Exists(buildinfo)) {
                return Fail("Unable to find buildinfo file [{0}]. \r\n\r\n    Use --help for command line help.", buildinfo);
            }

            // make sure that we're in the parent directory of the .buildinfo file.
            Environment.CurrentDirectory = Path.GetDirectoryName(Path.GetDirectoryName(buildinfo));

            // tell the user what we are
            Logo();

            // tell the user we can't work without instructions
            if (parameters.Count() < 1) {
                return Fail("Missing action . \r\n\r\n    Use --help for command line help.");
            }

            #endregion

            // set up several tools we need
            _cmdexe = new ProcessUtility("cmd.exe");
            var f = new ProgramFinder("").ScanForFile("trace.exe");

            if(!string.IsNullOrEmpty(f)) {
                _traceexe = new ProcessUtility(new ProgramFinder("").ScanForFile("trace.exe"));
            }

            _ptk = new ProcessUtility(Assembly.GetEntryAssembly().Location);
            // if this package is tracked by git, we can use git
            _useGit = Directory.Exists(".git".GetFullPath());            // if this package is tracked by mercurial, we can use mercurial
            _useHg = _useGit ? false : Directory.Exists(".hg".GetFullPath());

            // source control is mandatory! create a repository for this package
            if (!(_useGit || _useHg)) {
                return Fail("Source must be checked out using git or hg-git.");
            }

            // find git in the file system
            // - we prefer the CMD script over git.exe
            // git.exe may be located at "C:\Program Files\Git\bin"
            // git.cmd may be located at "C:\Program Files\Git\cmd"
            if (_useGit) {
                if (_verbose) {
                    Console.WriteLine("Using git for verification");
                }
                // attemt to find git.cmd
                _gitcmd = ProgramFinder.ProgramFilesAndDotNet.ScanForFile("git.cmd");
                _gitexe = null;
                if (string.IsNullOrEmpty(_gitcmd)) {
                    f = ProgramFinder.ProgramFilesAndDotNet.ScanForFile("git.exe");
                    if (string.IsNullOrEmpty(f)) {
                        return Fail("Can not find git.cmd or git.exe (required to perform verification.)");
                    }
                    _gitexe = new ProcessUtility(ProgramFinder.ProgramFilesAndDotNet.ScanForFile("git.exe"));
                }
            }

            if (_useHg) {
                 f = ProgramFinder.ProgramFilesAndDotNet.ScanForFile("hg.exe");
                if (string.IsNullOrEmpty(f)) {
                    return Fail("Can not find hg.exe (required to perform verification.)");
                }
                _hgexe = new ProcessUtility(f);
            }

            // find sdk batch files.

            _setenvcmd71 = ProgramFinder.ProgramFilesAndDotNetAndSdk.ScanForFile("setenv.cmd", excludeFilters: new[] { @"\Windows Azure SDK\**" , "winddk**" }, includeFilters: new [] {"sdk**", "v7.1**"}, rememberMissingFile:true, tagWithCosmeticVersion:"7.1");
            _setenvcmd7 = ProgramFinder.ProgramFilesAndDotNetAndSdk.ScanForFile("setenv.cmd", excludeFilters: new[] { @"\Windows Azure SDK\**", "7.1**", "winddk**" }, includeFilters: new[] { "sdk**", "v7**" }, rememberMissingFile: true, tagWithCosmeticVersion: "7.0");
            _setenvcmd6 = ProgramFinder.ProgramFilesAndDotNetAndSdk.ScanForFile("setenv.cmd", excludeFilters: new[] { @"\Windows Azure SDK\**", "winddk**" }, includeFilters: new[] { "sdk**", "6**" }, rememberMissingFile: true, tagWithCosmeticVersion: "6");

            _wdksetenvcmd7600 = ProgramFinder.ProgramFilesAndDotNetAndSdk.ScanForFile("setenv.bat", excludeFilters: new[] { @"\Windows Azure SDK\**"}, includeFilters: new[] { "winddk**"  }, rememberMissingFile: true, tagWithCosmeticVersion: "7600.16385.1");

            _vcvarsallbat10 = ProgramFinder.ProgramFilesAndDotNetAndSdk.ScanForFile("vcvarsall.bat", includeFilters: new[] { "vc**", "10.0**" }, rememberMissingFile: true, tagWithCosmeticVersion: "10.0");
            _vcvarsallbat9 = ProgramFinder.ProgramFilesAndDotNetAndSdk.ScanForFile("vcvarsall.bat", includeFilters: new[] { "vc**", "9.0**" }, rememberMissingFile: true, tagWithCosmeticVersion: "9.0");
            _vcvarsallbat8 = ProgramFinder.ProgramFilesAndDotNetAndSdk.ScanForFile("vcvarsall.bat", includeFilters: new[] { "vc**", "8.0**" }, rememberMissingFile: true, tagWithCosmeticVersion: "8.0");
            _vcvarsallbat7 = ProgramFinder.ProgramFilesAndDotNetAndSdk.ScanForFile("vcvarsall.bat", includeFilters: new[] { "vc**", "7.0**" }, rememberMissingFile: true, tagWithCosmeticVersion: "7.0");
            _vcvarsallbat71 = ProgramFinder.ProgramFilesAndDotNetAndSdk.ScanForFile("vcvarsall.bat", includeFilters: new[] { "vc**", "7.1**" }, rememberMissingFile: true, tagWithCosmeticVersion: "7.1");
            _vcvars32bat = ProgramFinder.ProgramFilesAndDotNetAndSdk.ScanForFile("vcvars32.bat", includeFilters: new[] { "vc98**" }, rememberMissingFile: true, tagWithCosmeticVersion: "6");

            if (_showTools) {
                if (_useGit) {
                    Console.Write("Git: {0}", _gitcmd ?? "");
                    if (_gitexe != null) {
                        Console.WriteLine(_gitexe.Executable ?? "");
                    }
                }
                if (_useHg) {
                    Console.WriteLine("hg: {0}", _hgexe.Executable);
                }
                Console.WriteLine("SDK Setenv (7.1): {0}", _vcvarsallbat10 ?? "Not-Found");
                Console.WriteLine("SDK Setenv (7.0): {0}", _setenvcmd7 ?? "Not-Found");
                Console.WriteLine("SDK Setenv (6): {0}", _setenvcmd6 ?? "Not-Found");

                Console.WriteLine("VC vcvarsall (10.0): {0}", _vcvarsallbat10 ?? "Not-Found");
                Console.WriteLine("VC vcvarsall (9.0): {0}", _vcvarsallbat9 ?? "Not-Found");
                Console.WriteLine("VC vcvarsall (8.0): {0}", _vcvarsallbat8 ?? "Not-Found");
                Console.WriteLine("VC vcvarsall (7.0): {0}", _vcvarsallbat7 ?? "Not-Found");
                Console.WriteLine("VC vcvarsall (7.1): {0}", _vcvarsallbat71 ?? "Not-Found");
                Console.WriteLine("VC vcvars32 (6): {0}", _vcvars32bat ?? "Not-Found");

                Console.WriteLine("ptk: {0}", _ptk.Executable);
                Console.WriteLine("trace: {0}", _traceexe.Executable);
            }

            // load property sheet (that is the .buildinfo file by default)
            PropertySheet propertySheet = null;
            try {
                // load and parse. propertySheet will contain everything else we need for later
                propertySheet = PropertySheet.Load(buildinfo);
                propertySheet.GetMacroValue += (valueName) => {
                    return null;
                };
                propertySheet.GetCollection += (collectionName) => {
                    return Enumerable.Empty<object>();
                };
            }
            catch (EndUserParseException pspe) {
                using (new ConsoleColors(ConsoleColor.Yellow, ConsoleColor.Black)) {
                    Console.Write(pspe.Message);
                    Console.WriteLine("--found '{0}'", pspe.Token.Data);
                }

                return Fail("Error parsing .buildinfo file");
            }
            var builds = from rule in propertySheet.Rules where rule.Name != "*" select rule;
            if (parameters.Count() > 1) {
                var allbuilds = builds;
                builds = parameters.Skip(1).Aggregate(Enumerable.Empty<Rule>(), (current, p) => current.Union(from build in allbuilds where build.Name.IsWildcardMatch(p) select build));
            }

            // are there even builds present?
            if(builds.Count() == 0 ) {
                return Fail("No valid build configurations selected.");
            }

            // do the user's bidding
            try {
                switch (parameters.FirstOrDefault().ToLower()) {
                    case "build":
                        Build(builds);

                        break;
                    case "clean":
                        Clean(builds);
                        using (new ConsoleColors(ConsoleColor.White, ConsoleColor.Black)) {
                            Console.WriteLine("Project Cleaned.");
                        }
                        break;
                    case "verify":
                        Clean(builds); // clean up other builds in the list first.
                        Verify(builds);
                        using (new ConsoleColors(ConsoleColor.White, ConsoleColor.Black)) {
                            Console.WriteLine("Project Verified.");
                        }
                        break;
                    case "status":
                        Status(builds);
                        using (new ConsoleColors(ConsoleColor.White, ConsoleColor.Black)) {
                            Console.WriteLine("Project is in clean state.");
                        }
                        break;
                    case "trace":
                        Trace(builds);
                        break;
                    case "list":
                        Console.WriteLine("Buildinfo from [{0}]", buildinfo);
                        (from build in builds
                            let compiler = build["compiler"]
                            let sdk = build["sdk"]
                            let platform = build["platform"]
                            let targets = build["targets"]
                            select new {
                                Configuration = build.Name,
                                Compiler = compiler != null ? compiler.Value : "sdk7.1",
                                Sdk = sdk != null ? sdk.Value : "sdk7.1",
                                Platform = platform != null ? platform.Value : "x86",
                                Number_of_Outputs = targets != null ? targets.Values.Count() : 0
                            }).ToTable().ConsoleOut();
                        break;
                    default:
                        return Fail("'{0}' is not a valid command. \r\n\r\n    Use --help for assistance.");
                }
            }
            catch (ConsoleException e) {
                // these exceptions are expected
                return Fail("   {0}", e.Message);
            }
            catch (Exception e) {
                // it's probably okay to crash within proper commands (because something else crashed)
                Console.WriteLine(e.StackTrace);
                return Fail("   {0}", e.Message);
            }

            return 0;
        }