Пример #1
0
        public void BuildTranslationUnitCompilerArguments_Simple()
        {
            var targetRootDirectory = new Path("C:/target/");
            var arguments           = new TranslationUnitCompileArguments()
            {
                SourceFile = new Path("module.cpp"),
                TargetFile = new Path("module.obj"),
            };

            var responseFile    = new Path("ResponseFile.txt");
            var internalModules = new List <Path>();

            var actualArguments = ArgumentBuilder.BuildTranslationUnitCompilerArguments(
                targetRootDirectory,
                arguments,
                responseFile,
                internalModules);

            var expectedArguments = new List <string>()
            {
                "@./ResponseFile.txt",
                "./module.cpp",
                "/Fo\"C:/target/module.obj\"",
            };

            Assert.Equal(expectedArguments, actualArguments);
        }
Пример #2
0
        public void Compile_Simple()
        {
            var uut = new Compiler(
                new Path("C:/bin/mock.cl.exe"),
                new Path("C:/bin/mock.link.exe"),
                new Path("C:/bin/mock.lib.exe"),
                new Path("C:/bin/mock.rc.exe"));

            var arguments = new SharedCompileArguments()
            {
                SourceRootDirectory = new Path("C:/source/"),
                TargetRootDirectory = new Path("C:/target/"),
                ObjectDirectory     = new Path("ObjectDir/"),
            };

            var translationUnitArguments = new TranslationUnitCompileArguments()
            {
                SourceFile = new Path("File.cpp"),
                TargetFile = new Path("obj/File.obj"),
            };

            arguments.ImplementationUnits = new List <TranslationUnitCompileArguments>()
            {
                translationUnitArguments,
            };

            var result = uut.CreateCompileOperations(arguments);

            // Verify result
            var expected = new List <BuildOperation>()
            {
                new BuildOperation(
                    "WriteFile [./ObjectDir/SharedCompileArguments.rsp]",
                    new Path("C:/target/"),
                    new Path("./writefile.exe"),
                    "\"./ObjectDir/SharedCompileArguments.rsp\" \"/nologo /FC /permissive- /Zc:__cplusplus /Zc:externConstexpr /Zc:inline /Zc:throwingNew /W4 /std:c++11 /Od /X /RTC1 /EHsc /MT /bigobj /c\"",
                    new List <Path>(),
                    new List <Path>()
                {
                    new Path("./ObjectDir/SharedCompileArguments.rsp"),
                }),
                new BuildOperation(
                    "./File.cpp",
                    new Path("C:/source/"),
                    new Path("C:/bin/mock.cl.exe"),
                    "@C:/target/ObjectDir/SharedCompileArguments.rsp ./File.cpp /Fo\"C:/target/obj/File.obj\"",
                    new List <Path>()
                {
                    new Path("File.cpp"),
                    new Path("C:/target/ObjectDir/SharedCompileArguments.rsp"),
                },
                    new List <Path>()
                {
                    new Path("C:/target/obj/File.obj"),
                }),
            };

            Assert.Equal(expected, result);
        }
Пример #3
0
        public static IList <string> BuildTranslationUnitCompilerArguments(
            Path targetRootDirectory,
            TranslationUnitCompileArguments arguments,
            Path responseFile,
            IList <Path> internalModules)
        {
            // Calculate object output file
            var commandArguments = new List <string>();

            // Add the response file
            commandArguments.Add("@" + responseFile.ToString());

            // Add the internal module references as input
            foreach (var moduleFile in arguments.IncludeModules)
            {
                AddFlag(commandArguments, "reference");
                AddValueWithQuotes(commandArguments, moduleFile.ToString());
            }

            // Add the internal module references as input
            foreach (var moduleFile in internalModules)
            {
                AddFlag(commandArguments, "reference");
                AddValueWithQuotes(commandArguments, moduleFile.ToString());
            }

            // Add the source file as input
            commandArguments.Add(arguments.SourceFile.ToString());

            // Add the target file as outputs
            var absoluteTargetFile = targetRootDirectory + arguments.TargetFile;

            AddFlagValueWithQuotes(
                commandArguments,
                Compiler_ArgumentParameter_ObjectFile,
                absoluteTargetFile.ToString());

            return(commandArguments);
        }