Exemplo n.º 1
0
        public static void Command(CommandLineApplication command)
        {
            command.Description = "Strips code from the specified assembly.";
            command.HelpOption("-?|-h|--help");

            var assemblyOption = command.Option(
                "-a|--assembly",
                "The assembly from which code should be stripped.",
                CommandOptionType.SingleValue);

            var specFileOption = command.Option(
                "-s|--spec",
                "The spec file describing which members to strip from the assembly.",
                CommandOptionType.SingleValue);

            var verboseOption = command.Option(
                "-v|--verbose",
                "If set, logs additional information to the console.",
                CommandOptionType.NoValue);

            var outputOption = command.Option(
                "-o|--output",
                "The location where the stripped assembly should be written.",
                CommandOptionType.SingleValue);

            command.OnExecute(() =>
            {
                if (!RequiredOptions.AssertHasValue(assemblyOption, specFileOption))
                {
                    return(1);
                }

                var inputPath = assemblyOption.Value();
                var specLines = File.ReadAllLines(specFileOption.Value());

                var outputPath = StripAssembly.Exec(
                    inputPath,
                    outputOption.Value(),
                    specLines,
                    verboseOption.HasValue());

                Console.WriteLine(
                    $" Input: {inputPath} ({FormatFileSize(inputPath)})");
                Console.WriteLine(
                    $"Output: {outputPath} ({FormatFileSize(outputPath)})");

                return(0);
            });
        }
Exemplo n.º 2
0
        // this will copy (and optionally strip) the assembly and almost all the related files:
        // * debug file (.mdb)
        // * config file (.config)
        // * satellite assemblies (<language id>/.dll)
        //
        // Aot data is copied separately, because we might want to copy aot data
        // even if we don't want to copy the assembly (if 32/64-bit assemblies are identical,
        // only one is copied, but we still want the aotdata for both).
        public void CopyToDirectory(string directory, bool reload = true, bool check_case = false, bool only_copy = false, bool copy_debug_symbols = true, StripAssembly strip = null)
        {
            var target = Path.Combine(directory, FileName);

            var fileNameNoExtension = Path.GetFileNameWithoutExtension(FileName);
            var assemblyName        = AssemblyDefinition.Name.Name;

            if (check_case && fileNameNoExtension != assemblyName && string.Equals(fileNameNoExtension, assemblyName, StringComparison.OrdinalIgnoreCase))
            {
                // Fix up the name of the target file to match the assembly name.
                target = Path.Combine(directory, assemblyName + Path.GetExtension(FileName));
            }

            // our Copy code deletes the target (so copy'ing over itself is a bad idea)
            if (directory != Path.GetDirectoryName(FullPath))
            {
                CopyAssembly(FullPath, target, copy_debug_symbols: copy_debug_symbols, strip: strip);
            }

            CopySatellitesToDirectory(directory);

            if (!only_copy)
            {
                if (reload)
                {
                    LoadAssembly(target);
                }
                else
                {
                    FullPath = target;
                }
            }
        }
Exemplo n.º 3
0
        // returns false if the assembly was not copied (because it was already up-to-date).
        public bool CopyAssembly(string source, string target, bool copy_debug_symbols = true, StripAssembly strip = null)
        {
            var copied = false;

            try {
                var strip_assembly = strip != null && strip(source);
                if (!Application.IsUptodate(source, target) && (strip_assembly || !Cache.CompareAssemblies(source, target)))
                {
                    copied = true;
                    if (strip_assembly)
                    {
                        Driver.FileDelete(target);
                        Directory.CreateDirectory(Path.GetDirectoryName(target));
                        MonoTouch.Tuner.Stripper.Process(source, target);
                    }
                    else
                    {
                        Application.CopyFile(source, target);
                    }
                }
                else
                {
                    Driver.Log(3, "Target '{0}' is up-to-date.", target);
                }

                // Update the debug symbols file even if the assembly didn't change.
                if (copy_debug_symbols)
                {
                    if (File.Exists(source + ".mdb"))
                    {
                        Application.UpdateFile(source + ".mdb", target + ".mdb", true);
                    }

                    var spdb = Path.ChangeExtension(source, "pdb");
                    if (File.Exists(spdb))
                    {
                        Application.UpdateFile(spdb, Path.ChangeExtension(target, "pdb"), true);
                    }
                }

                CopyConfigToDirectory(Path.GetDirectoryName(target));
            } catch (Exception e) {
                throw new MonoTouchException(1009, true, e, Errors.MX1009, source, target, e.Message);
            }

            return(copied);
        }