Пример #1
0
        public void Create()
        {
            ClearIfExists(IntDir);

            var sourceFile = $@"{CurrentDirectory}\Tests\New Folder\New Text Document.c";
            var objFile    = $@"{CurrentDirectory}\{IntDir}\New Folder\t1.c.o";
            var depFile    = $@"{CurrentDirectory}\{IntDir}\New Folder\t1.c.d";
            var wasmFile   = $@"{CurrentDirectory}\{IntDir}\New Folder\t 1 2.wasm";
            var trackerDir = $@"{CurrentDirectory}\{IntDir}\";

            if (!Directory.Exists(trackerDir))
            {
                Directory.CreateDirectory(trackerDir);
            }

            var be = new EmptyBuildEngine();

            var task = new EmCxx {
                BuildEngine            = be,
                TrackerLogDirectory    = trackerDir,
                ObjectFileName         = objFile,
                DependencyFileName     = depFile,
                GenerateDependencyFile = true,
                Sources = new ITaskItem[] { new TaskItem(sourceFile) },
            };

            for (int i = 0; i < 3; i++)
            {
                Assert.IsTrue(task.Execute());
            }

            var link = new EmLink {
                BuildEngine         = be,
                TrackerLogDirectory = trackerDir,
                OutputFile          = new TaskItem(wasmFile),
                Sources             = new ITaskItem[] { new TaskItem(task.ObjectFileName) },
            };

            Assert.IsTrue(link.Execute());
        }
Пример #2
0
        public void MultiDependencyRebuild()
        {
            ClearIfExists(IntDir);

            var engine = new EmptyBuildEngine();

            TLogSub = "StaticObjectLogs";
            var objects = SetupStaticLibrary(engine);

            CompileObjectFiles(objects);

            var ar = new EmAr {
                BuildEngine         = engine,
                TrackerLogDirectory = TLogDirectory,
                OutputFile          = new TaskItem($@"{CurrentDirectory}\{IntDir}\libInput.a"),
                Sources             = MergeObjectFiles(objects),
            };

            ExecuteAndAssertUpToDate(ar);

            Assert.IsTrue(File.Exists(ar.OutputFile.ItemSpec));
            File.Delete(ar.OutputFile.ItemSpec);
            Assert.IsTrue(ar.Execute());
            Assert.IsTrue(File.Exists(ar.OutputFile.ItemSpec));

            TLogSub = "ExecutableLogs";

            var exeObjects = SetupExecutable(engine);

            CompileObjectFiles(exeObjects);

            var lnk = new EmLink {
                ConfigurationType   = "Application",
                BuildEngine         = engine,
                TrackerLogDirectory = TLogDirectory,
                OutputFile          = new TaskItem($@"{CurrentDirectory}\{IntDir}\mdr.wasm"),
                Sources             = MergeObjectFiles(exeObjects, ar),
            };

            ExecuteAndAssertUpToDate(lnk);

            Assert.IsTrue(File.Exists(lnk.OutputFile.ItemSpec));
            File.Delete(lnk.OutputFile.ItemSpec);
            Assert.IsTrue(!File.Exists(lnk.OutputFile.ItemSpec));

            Assert.IsTrue(lnk.Execute());
            Assert.IsTrue(!lnk.SkippedExecution);
            Assert.IsTrue(File.Exists(lnk.OutputFile.ItemSpec));

            // delete the archive and attempt to rebuild
            File.Delete(ar.OutputFile.ItemSpec);

            Assert.AreEqual(false,
                            lnk.Execute(),
                            "EmLink.Execute did not fail with invalid input");

            // regenerate the archive
            ExecuteAndAssertUpToDate(ar);

            // it should link again
            ExecuteAndAssertUpToDate(lnk);

            var output = Spawn(Wavm, $"run {lnk.OutputFile.ItemSpec}");

            Assert.AreEqual("Called SomePrototypeInTheExecutableSource\n" +
                            "Called Input1PrototypeInTheStaticLibrarySource\n" +
                            "Called Input2PrototypeInTheStaticLibrarySource\n" +
                            "Called Input3PrototypeInTheStaticLibrarySource\n",
                            output);

            // modify the source files and assert that everything rebuilds

            SwapStringInFiles(objects, "PrototypeInTheStaticLibrarySource", "__Swapped_Text__");
            CompileObjectFiles(objects);
            ExecuteAndAssertUpToDate(ar);
            ExecuteAndAssertUpToDate(lnk);

            output = Spawn(Wavm, $"run {lnk.OutputFile.ItemSpec}");

            Assert.AreEqual("Called SomePrototypeInTheExecutableSource\n" +
                            "Called Input1__Swapped_Text__\n" +
                            "Called Input2__Swapped_Text__\n" +
                            "Called Input3__Swapped_Text__\n",
                            output);

            // swap it back to create a cycle
            SwapStringInFiles(objects, "__Swapped_Text__", "PrototypeInTheStaticLibrarySource");

            CompileObjectFiles(objects);
            ExecuteAndAssertUpToDate(ar);
            ExecuteAndAssertUpToDate(lnk);

            output = Spawn(Wavm, $"run {lnk.OutputFile.ItemSpec}");

            Assert.AreEqual("Called SomePrototypeInTheExecutableSource\n" +
                            "Called Input1PrototypeInTheStaticLibrarySource\n" +
                            "Called Input2PrototypeInTheStaticLibrarySource\n" +
                            "Called Input3PrototypeInTheStaticLibrarySource\n",
                            output);
        }