예제 #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
        private EmCxx[] SetupExecutable(EmptyBuildEngine engine)
        {
            var resultTasks = new List <EmCxx>();

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

            var file1 = new EmCxx {
                BuildEngine            = engine,
                TrackerLogDirectory    = TLogDirectory,
                ObjectFileName         = $@"{CurrentDirectory}\{IntDir}\Main1.cpp.o",
                DependencyFileName     = $@"{CurrentDirectory}\{IntDir}\Main1.cpp.d",
                GenerateDependencyFile = true,
                Sources = new ITaskItem[] {
                    new TaskItem($@"{CurrentDirectory}\Tests\MultiDependencyRebuild\Main1.cpp"),
                },
            };

            resultTasks.Add(file1);

            var file2 = new EmCxx {
                BuildEngine            = engine,
                TrackerLogDirectory    = TLogDirectory,
                ObjectFileName         = $@"{CurrentDirectory}\{IntDir}\Main.cpp.o",
                DependencyFileName     = $@"{CurrentDirectory}\{IntDir}\Main.cpp.d",
                GenerateDependencyFile = true,
                Sources = new ITaskItem[] {
                    new TaskItem($@"{CurrentDirectory}\Tests\MultiDependencyRebuild\Main.cpp"),
                },
            };

            resultTasks.Add(file2);

            return(resultTasks.ToArray());
        }
예제 #3
0
        private EmCxx[] SetupStaticLibrary(EmptyBuildEngine engine)
        {
            var resultTasks = new List <EmCxx>();

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

            // The source is modified during The test so,
            // make temporary copies

            File.Copy($@"{CurrentDirectory}\Tests\MultiDependencyRebuild\Input1.cpp",
                      $@"{CurrentDirectory}\{IntDir}\Input1.cpp");
            File.Copy($@"{CurrentDirectory}\Tests\MultiDependencyRebuild\Input2.cpp",
                      $@"{CurrentDirectory}\{IntDir}\Input2.cpp");
            File.Copy($@"{CurrentDirectory}\Tests\MultiDependencyRebuild\Input3.cpp",
                      $@"{CurrentDirectory}\{IntDir}\Input3.cpp");

            var file1 = new EmCxx {
                BuildEngine                  = engine,
                TrackerLogDirectory          = TLogDirectory,
                AdditionalIncludeDirectories = $@"{CurrentDirectory}\Tests\MultiDependencyRebuild\",
                ObjectFileName               = $@"{CurrentDirectory}\{IntDir}\Input1.cpp.o",
                DependencyFileName           = $@"{CurrentDirectory}\{IntDir}\Input1.cpp.d",
                GenerateDependencyFile       = true,
                Sources = new ITaskItem[] {
                    new TaskItem($@"{CurrentDirectory}\{IntDir}\Input1.cpp"),
                },
            };

            resultTasks.Add(file1);

            var file2 = new EmCxx {
                BuildEngine = engine,
                AdditionalIncludeDirectories = $@"{CurrentDirectory}\Tests\MultiDependencyRebuild\",
                TrackerLogDirectory          = TLogDirectory,
                ObjectFileName         = $@"{CurrentDirectory}\{IntDir}\Input2.cpp.o",
                DependencyFileName     = $@"{CurrentDirectory}\{IntDir}\Input2.cpp.d",
                GenerateDependencyFile = true,
                Sources = new ITaskItem[] {
                    new TaskItem($@"{CurrentDirectory}\{IntDir}\Input2.cpp"),
                },
            };

            resultTasks.Add(file2);

            var file3 = new EmCxx {
                BuildEngine                  = engine,
                TrackerLogDirectory          = TLogDirectory,
                AdditionalIncludeDirectories = $@"{CurrentDirectory}\Tests\MultiDependencyRebuild\",
                ObjectFileName               = $@"{CurrentDirectory}\{IntDir}\Input3.cpp.o",
                DependencyFileName           = $@"{CurrentDirectory}\{IntDir}\Input3.cpp.d",
                GenerateDependencyFile       = true,
                Sources = new ITaskItem[] {
                    new TaskItem($@"{CurrentDirectory}\{IntDir}\Input3.cpp"),
                },
            };

            resultTasks.Add(file3);

            return(resultTasks.ToArray());
        }
예제 #4
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);
        }