Esempio n. 1
0
        public static void WriteIfDifferent(string path, string contents)
        {
            var tmp = path + ".tmp";

            try {
                if (!File.Exists(path))
                {
                    File.WriteAllText(path, contents);
                    Log(3, "File '{0}' does not exist, creating it.", path);
                    return;
                }

                // Don't read the entire file into memory, it can be quite big in certain cases.

                bool move = false;
                File.WriteAllText(tmp, contents);

                using (var fs1 = new FileStream(path, FileMode.Open, FileAccess.Read)) {
                    using (var fs2 = new FileStream(tmp, FileMode.Open, FileAccess.Read)) {
                        if (fs1.Length != fs2.Length)
                        {
                            Log(3, "New file '{0}' has different length, writing new file.", path);
                            move = true;
                        }
                        else
                        {
                            move = !Cache.CompareStreams(fs1, fs2);
                        }
                    }
                }

                if (move)
                {
                    FileMove(tmp, path);
                }
                else
                {
                    Log(3, "Target {0} is up-to-date.", path);
                }
            } catch (Exception e) {
                File.WriteAllText(path, contents);
                ErrorHelper.Warning(1014, e, "Failed to re-use cached version of '{0}': {1}.", path, e.Message);
            } finally {
                Application.TryDelete(tmp);
            }
        }
Esempio n. 2
0
        public static void WriteIfDifferent(string path, byte[] contents)
        {
            var tmp = path + ".tmp";

            try {
                if (!File.Exists(path))
                {
                    File.WriteAllBytes(path, contents);
                    Log(3, "File '{0}' does not exist, creating it.", path);
                    return;
                }

                File.WriteAllBytes(tmp, contents);
                MoveIfDifferent(path, tmp);
            } catch (Exception e) {
                File.WriteAllBytes(path, contents);
                ErrorHelper.Warning(1014, e, "Failed to re-use cached version of '{0}': {1}.", path, e.Message);
            } finally {
                Application.TryDelete(tmp);
            }
        }
Esempio n. 3
0
        public void Symlink()
        {
            foreach (var a in Assemblies)
            {
                a.Symlink();
            }

            var targetExecutable = Executable;

            Application.TryDelete(targetExecutable);

            try {
                var launcher = new StringBuilder();
                launcher.Append(Path.Combine(Driver.MonoTouchDirectory, "bin", "simlauncher"));
                if (App.IsUnified)
                {
                    if (Is32Build)
                    {
                        launcher.Append("32");
                    }
                    else if (Is64Build)
                    {
                        launcher.Append("64");
                    }
                }
                launcher.Append("-sgen");
                File.Copy(launcher.ToString(), Executable);
            } catch (MonoTouchException) {
                throw;
            } catch (Exception ex) {
                throw new MonoTouchException(1015, true, ex, "Failed to create the executable '{0}': {1}", targetExecutable, ex.Message);
            }

            Symlinked = true;

            if (Driver.Verbosity > 0)
            {
                Console.WriteLine("Application ({0}) was built using fast-path for simulator.", string.Join(", ", Abis.ToArray()));
            }
        }
Esempio n. 4
0
        public static void WriteIfDifferent(string path, string contents, bool use_stamp = false)
        {
            var tmp = path + ".tmp";

            try {
                if (!File.Exists(path))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(path));
                    File.WriteAllText(path, contents);
                    Log(3, "File '{0}' does not exist, creating it.", path);
                    return;
                }

                File.WriteAllText(tmp, contents);
                MoveIfDifferent(path, tmp, use_stamp);
            } catch (Exception e) {
                File.WriteAllText(path, contents);
                ErrorHelper.Warning(1014, e, "Failed to re-use cached version of '{0}': {1}.", path, e.Message);
            } finally {
                Application.TryDelete(tmp);
            }
        }
Esempio n. 5
0
        // The input file is either a .s or a .bc file
        BuildTask CreateCompileTask(string assembly_name, string infile_path, Abi abi)
        {
            var ext          = App.FastDev ? "dylib" : "o";
            var ofile        = Path.ChangeExtension(infile_path, ext);
            var install_name = string.Empty;

            if (App.FastDev)
            {
                if (dylibs == null)
                {
                    dylibs = new List <string> ();
                }
                dylibs.Add(ofile);
                install_name = "lib" + Path.GetFileName(assembly_name) + ".dylib";
            }
            else
            {
                Target.LinkWith(ofile);
            }

            if (Application.IsUptodate(new string [] { infile_path, Driver.CompilerPath }, new string [] { ofile }))
            {
                Driver.Log(3, "Target {0} is up-to-date.", ofile);
                return(null);
            }
            else
            {
                Application.TryDelete(ofile);                  // otherwise the next task might not detect that it will have to rebuild.
                Driver.Log(3, "Target {0} needs to be rebuilt.", ofile);
            }

            var compiler_flags = new CompilerFlags()
            {
                Target = Target
            };

            BuildTask bitcode_task = null;
            BuildTask link_task = null;
            string    link_task_input, link_language = "";

            if (App.EnableAsmOnlyBitCode)
            {
                link_task_input = infile_path + ".ll";
                link_language   = "";
                // linker_flags.Add (" -fembed-bitcode");

                bitcode_task = new BitCodeify()
                {
                    Input            = infile_path,
                    OutputFile       = link_task_input,
                    Platform         = App.Platform,
                    Abi              = abi,
                    DeploymentTarget = App.DeploymentTarget,
                };
            }
            else
            {
                link_task_input = infile_path;
                if (infile_path.EndsWith(".s"))
                {
                    link_language = "assembler";
                }
            }

            if (App.FastDev)
            {
                compiler_flags.AddFrameworks(Frameworks, WeakFrameworks);
                compiler_flags.AddLinkWith(LinkWith, ForceLoad);
                compiler_flags.LinkWithMono();
                compiler_flags.LinkWithXamarin();
                compiler_flags.AddOtherFlags(LinkerFlags);
                if (Target.GetEntryPoints().ContainsKey("UIApplicationMain"))
                {
                    compiler_flags.AddFramework("UIKit");
                }
            }

            link_task = new LinkTask()
            {
                Target        = Target,
                AssemblyName  = assembly_name,
                Abi           = abi,
                InputFile     = link_task_input,
                OutputFile    = ofile,
                InstallName   = install_name,
                CompilerFlags = compiler_flags,
                SharedLibrary = App.FastDev,
                Language      = link_language,
            };

            if (bitcode_task != null)
            {
                bitcode_task.NextTasks = new BuildTask[] { link_task };
                return(bitcode_task);
            }
            return(link_task);
        }
Esempio n. 6
0
        IEnumerable <BuildTask> CreateManagedToAssemblyTasks(string s, Abi abi, string build_dir)
        {
            var    arch = abi.AsArchString();
            var    asm_dir = Cache.Location;
            var    asm = Path.Combine(asm_dir, Path.GetFileName(s)) + "." + arch + ".s";
            var    llvm_asm = Path.Combine(asm_dir, Path.GetFileName(s)) + "." + arch + "-llvm.s";
            var    data = Path.Combine(asm_dir, Path.GetFileNameWithoutExtension(s)) + "." + arch + ".aotdata";
            string llvm_ofile, llvm_aot_ofile = "";
            var    is_llvm       = (abi & Abi.LLVM) == Abi.LLVM;
            bool   assemble_llvm = is_llvm && Driver.LLVMAsmWriter;

            if (!File.Exists(s))
            {
                throw new MonoTouchException(3004, true, "Could not AOT the assembly '{0}' because it doesn't exist.", s);
            }

            HashSet <string> dependencies = null;
            List <string>    deps         = null;
            List <string>    outputs      = new List <string> ();
            var warnings = new List <Exception> ();

            dependencies = ComputeDependencies(warnings);

            if (warnings.Count > 0)
            {
                ErrorHelper.Show(warnings);
                ErrorHelper.Warning(3006, "Could not compute a complete dependency map for the project. This will result in slower build times because Xamarin.iOS can't properly detect what needs to be rebuilt (and what does not need to be rebuilt). Please review previous warnings for more details.");
            }
            else
            {
                deps = new List <string> (dependencies.ToArray());
                deps.Add(s);
                deps.Add(Driver.GetAotCompiler(Target.Is64Build));
            }

            if (App.EnableLLVMOnlyBitCode)
            {
                //
                // In llvm-only mode, the AOT compiler emits a .bc file and no .s file for JITted code
                //
                llvm_ofile = Path.Combine(asm_dir, Path.GetFileName(s)) + "." + arch + ".bc";
                outputs.Add(llvm_ofile);
                llvm_aot_ofile = llvm_ofile;
            }
            else
            {
                llvm_ofile = Path.Combine(asm_dir, Path.GetFileName(s)) + "." + arch + "-llvm.o";
                outputs.Add(asm);

                if (is_llvm)
                {
                    if (assemble_llvm)
                    {
                        llvm_aot_ofile = llvm_asm;
                    }
                    else
                    {
                        llvm_aot_ofile = llvm_ofile;
                        Target.LinkWith(llvm_ofile);
                    }
                    outputs.Add(llvm_aot_ofile);
                }
            }

            if (deps != null && Application.IsUptodate(deps, outputs))
            {
                Driver.Log(3, "Target {0} is up-to-date.", asm);
                if (App.EnableLLVMOnlyBitCode)
                {
                    return(CreateCompileTasks(s, null, llvm_ofile, abi));
                }
                else
                {
                    return(CreateCompileTasks(s, asm, assemble_llvm ? llvm_asm : null, abi));
                }
            }
            else
            {
                Application.TryDelete(asm);                  // otherwise the next task might not detect that it will have to rebuild.
                Application.TryDelete(llvm_asm);
                Application.TryDelete(llvm_ofile);
                Driver.Log(3, "Target {0} needs to be rebuilt.", asm);
            }

            var aotCompiler = Driver.GetAotCompiler(Target.Is64Build);
            var aotArgs     = Driver.GetAotArguments(s, abi, build_dir, asm, llvm_aot_ofile, data);

            Driver.Log(3, "Aot compiler: {0} {1}", aotCompiler, aotArgs);

            AotDataFiles.Add(data);

            IEnumerable <BuildTask> nextTasks;

            if (App.EnableLLVMOnlyBitCode)
            {
                nextTasks = CreateCompileTasks(s, null, llvm_ofile, abi);
            }
            else
            {
                nextTasks = CreateCompileTasks(s, asm, assemble_llvm ? llvm_asm : null, abi);
            }

            return(new BuildTask [] { new AOTTask()
                                      {
                                          AssemblyName = s,
                                          ProcessStartInfo = Driver.CreateStartInfo(aotCompiler, aotArgs, Path.GetDirectoryName(s)),
                                          NextTasks = nextTasks
                                      } });
        }
Esempio n. 7
0
 static void FileMove(string source, string target)
 {
     Application.TryDelete(target);
     File.Move(source, target);
 }