示例#1
0
        private void AddNativeLibraries(ArchiveFileList files, string [] supportedAbis)
        {
            var frameworkLibs = FrameworkNativeLibraries.Select(v => new LibInfo {
                Path            = v.ItemSpec,
                Link            = v.GetMetadata("Link"),
                Abi             = GetNativeLibraryAbi(v),
                ArchiveFileName = GetArchiveFileName(v)
            });

            AddNativeLibraries(files, supportedAbis, frameworkLibs);

            var libs = NativeLibraries.Concat(BundleNativeLibraries ?? Enumerable.Empty <ITaskItem> ())
                       .Where(v => IncludeNativeLibrary(v))
                       .Select(v => new LibInfo {
                Path            = v.ItemSpec,
                Link            = v.GetMetadata("Link"),
                Abi             = GetNativeLibraryAbi(v),
                ArchiveFileName = GetArchiveFileName(v)
            }
                               );

            AddNativeLibraries(files, supportedAbis, libs);

            if (String.IsNullOrWhiteSpace(CheckedBuild))
            {
                return;
            }

            string mode = CheckedBuild;
            string sanitizerName;

            if (String.Compare("asan", mode, StringComparison.Ordinal) == 0)
            {
                sanitizerName = "asan";
            }
            else if (String.Compare("ubsan", mode, StringComparison.Ordinal) == 0)
            {
                sanitizerName = "ubsan_standalone";
            }
            else
            {
                LogSanitizerWarning($"Unknown checked build mode '{CheckedBuild}'");
                return;
            }

            if (!IncludeWrapSh)
            {
                LogSanitizerError("Checked builds require the wrapper script to be packaged. Please set the `$(AndroidIncludeWrapSh)` MSBuild property to `true` in your project.");
                return;
            }

            if (!libs.Any(info => IsWrapperScript(info.Path, info.Link)))
            {
                LogSanitizerError($"Checked builds require the wrapper script to be packaged. Please add `wrap.sh` appropriate for the {CheckedBuild} checker to your project.");
                return;
            }

            NdkUtil.Init(AndroidNdkDirectory);
            string clangDir = NdkUtil.GetClangDeviceLibraryPath(AndroidNdkDirectory);

            if (String.IsNullOrEmpty(clangDir))
            {
                LogSanitizerError($"Unable to find the clang compiler directory. Is NDK installed?");
                return;
            }

            foreach (string abi in supportedAbis)
            {
                string clangAbi = MonoAndroidHelper.MapAndroidAbiToClang(abi);
                if (String.IsNullOrEmpty(clangAbi))
                {
                    LogSanitizerError($"Unable to map Android ABI {abi} to clang ABI");
                    return;
                }

                string sanitizerLib     = $"libclang_rt.{sanitizerName}-{clangAbi}-android.so";
                string sanitizerLibPath = Path.Combine(clangDir, sanitizerLib);
                if (!File.Exists(sanitizerLibPath))
                {
                    LogSanitizerError($"Unable to find sanitizer runtime for the {CheckedBuild} checker at {sanitizerLibPath}");
                    return;
                }

                AddNativeLibrary(files, sanitizerLibPath, abi, sanitizerLib);
            }
        }