Example #1
0
        public void AssertExecute(MTouchAction action, string message = null)
        {
            var rv = Execute(action);

            if (rv == 0)
            {
                return;
            }
            var errors = Messages.Where((v) => v.IsError).ToList();

            Assert.Fail($"Expected execution to succeed, but exit code was {rv}, and there were {errors.Count} error(s): {message}\n\t" +
                        string.Join("\n\t", errors.Select((v) => v.ToString())));
        }
Example #2
0
 public void AssertExecuteFailure(MTouchAction action, string message = null)
 {
     Action = action;
     NUnit.Framework.Assert.AreEqual(1, Execute(), message);
 }
Example #3
0
 public void AssertExecute(MTouchAction action, string message = null)
 {
     this.Action = action;
     base.AssertExecute(message);
 }
Example #4
0
 public int Execute(MTouchAction action)
 {
     this.Action = action;
     return(base.Execute());
 }
Example #5
0
        string BuildArguments(MTouchAction action)
        {
            var sb       = new StringBuilder();
            var isDevice = false;

            switch (action)
            {
            case MTouchAction.None:
                break;

            case MTouchAction.BuildDev:
                MTouch.AssertDeviceAvailable();
                if (AppPath == null)
                {
                    throw new Exception("No AppPath specified.");
                }
                isDevice = true;
                sb.Append(" --dev ").Append(StringUtils.Quote(AppPath));
                break;

            case MTouchAction.BuildSim:
                isDevice = false;
                if (AppPath == null)
                {
                    throw new Exception("No AppPath specified.");
                }
                sb.Append(" --sim ").Append(StringUtils.Quote(AppPath));
                break;

            case MTouchAction.LaunchSim:
                isDevice = false;
                if (AppPath == null)
                {
                    throw new Exception("No AppPath specified.");
                }
                sb.Append(" --launchsim ").Append(StringUtils.Quote(AppPath));
                break;

            default:
                throw new NotImplementedException();
            }

            if (SdkRoot == None)
            {
                // do nothing
            }
            else if (!string.IsNullOrEmpty(SdkRoot))
            {
                sb.Append(" --sdkroot ").Append(StringUtils.Quote(SdkRoot));
            }
            else
            {
                sb.Append(" --sdkroot ").Append(StringUtils.Quote(Configuration.xcode_root));
            }

            sb.Append(" ").Append(GetVerbosity());

            if (Sdk == None)
            {
                // do nothing
            }
            else if (!string.IsNullOrEmpty(Sdk))
            {
                sb.Append(" --sdk ").Append(Sdk);
            }
            else
            {
                sb.Append(" --sdk ").Append(MTouch.GetSdkVersion(Profile));
            }

            if (TargetVer == None)
            {
                // do nothing
            }
            else if (!string.IsNullOrEmpty(TargetVer))
            {
                sb.Append(" --targetver ").Append(TargetVer);
            }

            if (Debug.HasValue && Debug.Value)
            {
                sb.Append(" --debug");
            }

            if (FastDev.HasValue && FastDev.Value)
            {
                sb.Append(" --fastdev");
            }

            if (PackageMdb.HasValue)
            {
                sb.Append(" --package-mdb:").Append(PackageMdb.Value ? "true" : "false");
            }

            if (NoStrip.HasValue && NoStrip.Value)
            {
                sb.Append(" --nostrip");
            }

            if (NoSymbolStrip != null)
            {
                if (NoSymbolStrip.Length == 0)
                {
                    sb.Append(" --nosymbolstrip");
                }
                else
                {
                    sb.Append(" --nosymbolstrip:").Append(NoSymbolStrip);
                }
            }

            if (Profiling.HasValue)
            {
                sb.Append(" --profiling:").Append(Profiling.Value ? "true" : "false");
            }

            if (!string.IsNullOrEmpty(SymbolList))
            {
                sb.Append(" --symbollist=").Append(StringUtils.Quote(SymbolList));
            }

            if (MSym.HasValue)
            {
                sb.Append(" --msym:").Append(MSym.Value ? "true" : "false");
            }

            if (DSym.HasValue)
            {
                sb.Append(" --dsym:").Append(DSym.Value ? "true" : "false");
            }

            if (Extension == true)
            {
                sb.Append(" --extension");
            }

            foreach (var appext in AppExtensions)
            {
                sb.Append(" --app-extension ").Append(StringUtils.Quote(appext.AppPath));
            }

            foreach (var framework in Frameworks)
            {
                sb.Append(" --framework ").Append(StringUtils.Quote(framework));
            }

            if (!string.IsNullOrEmpty(Mono))
            {
                sb.Append(" --mono:").Append(StringUtils.Quote(Mono));
            }

            if (!string.IsNullOrEmpty(GccFlags))
            {
                sb.Append(" --gcc_flags ").Append(StringUtils.Quote(GccFlags));
            }

            if (!string.IsNullOrEmpty(HttpMessageHandler))
            {
                sb.Append(" --http-message-handler=").Append(StringUtils.Quote(HttpMessageHandler));
            }

            if (Dlsym.HasValue)
            {
                sb.Append(" --dlsym:").Append(Dlsym.Value ? "true" : "false");
            }

            if (References != null)
            {
                foreach (var r in References)
                {
                    sb.Append(" -r:").Append(StringUtils.Quote(r));
                }
            }

            if (!string.IsNullOrEmpty(Executable))
            {
                sb.Append(" --executable ").Append(StringUtils.Quote(Executable));
            }

            if (!string.IsNullOrEmpty(RootAssembly))
            {
                sb.Append(" ").Append(StringUtils.Quote(RootAssembly));
            }

            if (TargetFramework == None)
            {
                // do nothing
            }
            else if (!string.IsNullOrEmpty(TargetFramework))
            {
                sb.Append(" --target-framework ").Append(TargetFramework);
            }
            else if (!NoPlatformAssemblyReference)
            {
                // make the implicit default the way tests have been running until now, and at the same time the very minimum to make apps build.
                switch (Profile)
                {
                case Profile.iOS:
                    sb.Append(" -r:").Append(StringUtils.Quote(Configuration.XamarinIOSDll));
                    break;

                case Profile.tvOS:
                case Profile.watchOS:
                    sb.Append(" --target-framework ").Append(MTouch.GetTargetFramework(Profile));
                    sb.Append(" -r:").Append(StringUtils.Quote(MTouch.GetBaseLibrary(Profile)));
                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            if (Abi == None)
            {
                // add nothing
            }
            else if (!string.IsNullOrEmpty(Abi))
            {
                sb.Append(" --abi ").Append(Abi);
            }
            else
            {
                switch (Profile)
                {
                case Profile.iOS:
                    break;                     // not required

                case Profile.tvOS:
                    sb.Append(isDevice ? " --abi arm64" : " --abi x86_64");
                    break;

                case Profile.watchOS:
                    sb.Append(isDevice ? " --abi armv7k" : " --abi i386");
                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            switch (Linker)
            {
            case MTouchLinker.LinkAll:
            case MTouchLinker.Unspecified:
                break;

            case MTouchLinker.DontLink:
                sb.Append(" --nolink");
                break;

            case MTouchLinker.LinkSdk:
                sb.Append(" --linksdkonly");
                break;

            default:
                throw new NotImplementedException();
            }

            if (Optimize != null)
            {
                foreach (var opt in Optimize)
                {
                    sb.Append(" --optimize:").Append(opt);
                }
            }

            switch (SymbolMode)
            {
            case MTouchSymbolMode.Ignore:
                sb.Append(" --dynamic-symbol-mode=ignore");
                break;

            case MTouchSymbolMode.Code:
                sb.Append(" --dynamic-symbol-mode=code");
                break;

            case MTouchSymbolMode.Default:
                sb.Append(" --dynamic-symbol-mode=default");
                break;

            case MTouchSymbolMode.Linker:
                sb.Append(" --dynamic-symbol-mode=linker");
                break;

            case MTouchSymbolMode.Unspecified:
                break;

            default:
                throw new NotImplementedException();
            }

            if (NoFastSim.HasValue && NoFastSim.Value)
            {
                sb.Append(" --nofastsim");
            }

            switch (Registrar)
            {
            case MTouchRegistrar.Unspecified:
                break;

            case MTouchRegistrar.Dynamic:
                sb.Append(" --registrar:dynamic");
                break;

            case MTouchRegistrar.Static:
                sb.Append(" --registrar:static");
                break;

            default:
                throw new NotImplementedException();
            }

            if (I18N != I18N.None)
            {
                sb.Append(" --i18n ");
                int count = 0;
                if ((I18N & I18N.CJK) == I18N.CJK)
                {
                    sb.Append(count++ == 0 ? string.Empty : ",").Append("cjk");
                }
                if ((I18N & I18N.MidEast) == I18N.MidEast)
                {
                    sb.Append(count++ == 0 ? string.Empty : ",").Append("mideast");
                }
                if ((I18N & I18N.Other) == I18N.Other)
                {
                    sb.Append(count++ == 0 ? string.Empty : ",").Append("other");
                }
                if ((I18N & I18N.Rare) == I18N.Rare)
                {
                    sb.Append(count++ == 0 ? string.Empty : ",").Append("rare");
                }
                if ((I18N & I18N.West) == I18N.West)
                {
                    sb.Append(count++ == 0 ? string.Empty : ",").Append("west");
                }
            }

            if (!string.IsNullOrEmpty(Cache))
            {
                sb.Append(" --cache ").Append(StringUtils.Quote(Cache));
            }

            if (!string.IsNullOrEmpty(Device))
            {
                sb.Append(" --device:").Append(StringUtils.Quote(Device));
            }

            if (!string.IsNullOrEmpty(LLVMOptimizations))
            {
                sb.Append(" --llvm-opt=").Append(StringUtils.Quote(LLVMOptimizations));
            }

            if (CustomArguments != null)
            {
                foreach (var arg in CustomArguments)
                {
                    sb.Append(" ").Append(arg);
                }
            }

            if (NoWarn != null)
            {
                if (NoWarn.Length > 0)
                {
                    sb.Append(" --nowarn:");
                    foreach (var code in NoWarn)
                    {
                        sb.Append(code).Append(',');
                    }
                    sb.Length--;
                }
                else
                {
                    sb.Append(" --nowarn");
                }
            }

            if (WarnAsError != null)
            {
                if (WarnAsError.Length > 0)
                {
                    sb.Append(" --warnaserror:");
                    foreach (var code in WarnAsError)
                    {
                        sb.Append(code).Append(',');
                    }
                    sb.Length--;
                }
                else
                {
                    sb.Append(" --warnaserror");
                }
            }

            if (Bitcode != MTouchBitcode.Unspecified)
            {
                sb.Append(" --bitcode:").Append(Bitcode.ToString().ToLower());
            }

            foreach (var abt in AssemblyBuildTargets)
            {
                sb.Append(" --assembly-build-target=").Append(StringUtils.Quote(abt));
            }

            if (!string.IsNullOrEmpty(AotArguments))
            {
                sb.Append(" --aot:").Append(StringUtils.Quote(AotArguments));
            }

            if (!string.IsNullOrEmpty(AotOtherArguments))
            {
                sb.Append(" --aot-options:").Append(StringUtils.Quote(AotOtherArguments));
            }

            if (LinkSkip?.Length > 0)
            {
                foreach (var ls in LinkSkip)
                {
                    sb.Append(" --linkskip:").Append(StringUtils.Quote(ls));
                }
            }

            if (XmlDefinitions?.Length > 0)
            {
                foreach (var xd in XmlDefinitions)
                {
                    sb.Append(" --xml:").Append(StringUtils.Quote(xd));
                }
            }

            if (!string.IsNullOrEmpty(ResponseFile))
            {
                sb.Append(" @").Append(StringUtils.Quote(ResponseFile));
            }

            return(sb.ToString());
        }
Example #6
0
 public int Execute(MTouchAction action)
 {
     return(Execute(BuildArguments(action), always_show_output: Verbosity > 0));
 }
Example #7
0
 public void AssertExecute(MTouchAction action, string message = null)
 {
     NUnit.Framework.Assert.AreEqual(0, Execute(action), message);
 }
Example #8
0
 public int Execute(MTouchAction action)
 {
     return(Execute(BuildArguments(action)));
 }
Example #9
0
        string BuildArguments(MTouchAction action)
        {
            var sb       = new StringBuilder();
            var isDevice = false;

            switch (action)
            {
            case MTouchAction.None:
                break;

            case MTouchAction.BuildDev:
                MTouch.AssertDeviceAvailable();
                if (AppPath == null)
                {
                    throw new Exception("No AppPath specified.");
                }
                isDevice = true;
                sb.Append(" --dev ").Append(MTouch.Quote(AppPath));
                break;

            case MTouchAction.BuildSim:
                isDevice = false;
                if (AppPath == null)
                {
                    throw new Exception("No AppPath specified.");
                }
                sb.Append(" --sim ").Append(MTouch.Quote(AppPath));
                break;

            case MTouchAction.LaunchSim:
                isDevice = false;
                if (AppPath == null)
                {
                    throw new Exception("No AppPath specified.");
                }
                sb.Append(" --launchsim ").Append(MTouch.Quote(AppPath));
                break;

            default:
                throw new NotImplementedException();
            }

            if (SdkRoot == None)
            {
                // do nothing
            }
            else if (!string.IsNullOrEmpty(SdkRoot))
            {
                sb.Append(" --sdkroot ").Append(MTouch.Quote(SdkRoot));
            }
            else
            {
                sb.Append(" --sdkroot ").Append(MTouch.Quote(Configuration.xcode_root));
            }

            sb.Append(" ").Append(GetVerbosity());

            if (Sdk == None)
            {
                // do nothing
            }
            else if (!string.IsNullOrEmpty(Sdk))
            {
                sb.Append(" --sdk ").Append(Sdk);
            }
            else
            {
                sb.Append(" --sdk ").Append(MTouch.GetSdkVersion(Profile));
            }

            if (TargetVer == None)
            {
                // do nothing
            }
            else if (!string.IsNullOrEmpty(TargetVer))
            {
                sb.Append(" --targetver ").Append(TargetVer);
            }

            if (Debug.HasValue && Debug.Value)
            {
                sb.Append(" --debug");
            }

            if (FastDev.HasValue && FastDev.Value)
            {
                sb.Append(" --fastdev");
            }

            if (Extension == true)
            {
                sb.Append(" --extension");
            }

            foreach (var appext in AppExtensions)
            {
                sb.Append(" --app-extension ").Append(MTouch.Quote(appext));
            }

            foreach (var framework in Frameworks)
            {
                sb.Append(" --framework ").Append(MTouch.Quote(framework));
            }

            if (!string.IsNullOrEmpty(HttpMessageHandler))
            {
                sb.Append(" --http-message-handler=").Append(MTouch.Quote(HttpMessageHandler));
            }

            if (Dlsym.HasValue)
            {
                sb.Append(" --dlsym:").Append(Dlsym.Value ? "true" : "false");
            }

            if (References != null)
            {
                foreach (var r in References)
                {
                    sb.Append(" -r:").Append(MTouch.Quote(r));
                }
            }

            if (!string.IsNullOrEmpty(Executable))
            {
                sb.Append(" ").Append(MTouch.Quote(Executable));
            }

            if (TargetFramework == None)
            {
                // do nothing
            }
            else if (!string.IsNullOrEmpty(TargetFramework))
            {
                sb.Append(" --target-framework ").Append(TargetFramework);
            }
            else if (!NoPlatformAssemblyReference)
            {
                // make the implicit default the way tests have been running until now, and at the same time the very minimum to make apps build.
                switch (Profile)
                {
                case MTouch.Profile.Unified:
                    sb.Append(" -r:").Append(MTouch.Quote(Configuration.XamarinIOSDll));
                    break;

                case MTouch.Profile.TVOS:
                case MTouch.Profile.WatchOS:
                    sb.Append(" --target-framework ").Append(MTouch.GetTargetFramework(Profile));
                    sb.Append(" -r:").Append(MTouch.Quote(MTouch.GetBaseLibrary(Profile)));
                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            if (!string.IsNullOrEmpty(Abi))
            {
                sb.Append(" --abi ").Append(Abi);
            }
            else
            {
                switch (Profile)
                {
                case MTouch.Profile.Unified:
                    break;                     // not required

                case MTouch.Profile.TVOS:
                    sb.Append(isDevice ? " --abi arm64" : " --abi x86_64");
                    break;

                case MTouch.Profile.WatchOS:
                    sb.Append(isDevice ? " --abi armv7k" : " --abi i386");
                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            switch (Linker)
            {
            case MTouchLinker.LinkAll:
            case MTouchLinker.Unspecified:
                break;

            case MTouchLinker.DontLink:
                sb.Append(" --nolink");
                break;

            case MTouchLinker.LinkSdk:
                sb.Append(" --linksdkonly");
                break;

            default:
                throw new NotImplementedException();
            }

            if (NoFastSim.HasValue && NoFastSim.Value)
            {
                sb.Append(" --nofastsim");
            }

            switch (Registrar)
            {
            case MTouchRegistrar.Unspecified:
                break;

            case MTouchRegistrar.Dynamic:
                sb.Append(" --registrar:dynamic");
                break;

            case MTouchRegistrar.Static:
                sb.Append(" --registrar:static");
                break;

            default:
                throw new NotImplementedException();
            }

            if (I18N != I18N.None)
            {
                sb.Append(" --i18n ");
                int count = 0;
                if ((I18N & I18N.CJK) == I18N.CJK)
                {
                    sb.Append(count++ == 0 ? string.Empty : ",").Append("cjk");
                }
                if ((I18N & I18N.MidEast) == I18N.MidEast)
                {
                    sb.Append(count++ == 0 ? string.Empty : ",").Append("mideast");
                }
                if ((I18N & I18N.Other) == I18N.Other)
                {
                    sb.Append(count++ == 0 ? string.Empty : ",").Append("other");
                }
                if ((I18N & I18N.Rare) == I18N.Rare)
                {
                    sb.Append(count++ == 0 ? string.Empty : ",").Append("rare");
                }
                if ((I18N & I18N.West) == I18N.West)
                {
                    sb.Append(count++ == 0 ? string.Empty : ",").Append("west");
                }
            }

            if (!string.IsNullOrEmpty(Cache))
            {
                sb.Append(" --cache ").Append(MTouch.Quote(Cache));
            }

            if (!string.IsNullOrEmpty(Device))
            {
                sb.Append(" --device:").Append(MTouch.Quote(Device));
            }

            return(sb.ToString());
        }