Search in sources :

Example 1 with CompileCommandParser

use of com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser in project synopsys-detect by blackducksoftware.

the class CommandParserFunctionalTest method testComplexNestedQuoting.

@Test
public void testComplexNestedQuoting() throws IOException {
    CompileCommandDatabaseParser compileCommandDatabaseParser = new CompileCommandDatabaseParser(new Gson());
    List<CompileCommand> compileCommands = compileCommandDatabaseParser.parseCompileCommandDatabase(FunctionalTestFiles.asFile("/clang/compile_commands_nestedquoting_small.json"));
    CompileCommand first = compileCommands.get(0);
    CompileCommandParser commandParser = new CompileCommandParser(new CommandParser());
    List<String> result = commandParser.parseCommand(first, Collections.emptyMap());
    assertEquals(15, result.size());
    int i = 0;
    assertEquals("cc", result.get(i++));
    assertEquals("-c", result.get(i++));
    assertEquals("-I/usr/include/mit-krb5", result.get(i++));
    String valConfigureAssignment = result.get(i++);
    assertTrue(valConfigureAssignment.startsWith("-DVAL_CONFIGURE"));
    assertTrue(valConfigureAssignment.contains("--with-tclconfig="));
    assertEquals("-DVAL_CC=\\\"gcc\\\"", result.get(i++));
    assertEquals("-DVAL_CPPFLAGS=\\\"-I/usr/include/x86_64-linux-gnu -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include/mit-krb5\\\"", result.get(i++));
}
Also used : CompileCommandDatabaseParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandDatabaseParser) CompileCommandParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser) CompileCommand(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand) Gson(com.google.gson.Gson) CommandParser(com.synopsys.integration.common.util.parse.CommandParser) CompileCommandParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser) Test(org.junit.jupiter.api.Test) FunctionalTest(com.synopsys.integration.detectable.annotations.FunctionalTest)

Example 2 with CompileCommandParser

use of com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser in project synopsys-detect by blackducksoftware.

the class CommandParserFunctionalTest method testCanParseArgumentsFromCommandDatabase.

@Test
public void testCanParseArgumentsFromCommandDatabase() throws IOException {
    CompileCommandDatabaseParser compileCommandDatabaseParser = new CompileCommandDatabaseParser(new Gson());
    List<CompileCommand> compileCommands = compileCommandDatabaseParser.parseCompileCommandDatabase(FunctionalTestFiles.asFile("/clang/compile_commands_args.json"));
    CompileCommand first = compileCommands.get(0);
    CompileCommandParser commandParser = new CompileCommandParser(new CommandParser());
    List<String> result = commandParser.parseCommand(first, Collections.emptyMap());
    assertEquals(66, result.size());
    int i = 0;
    assertEquals("/usr/bin/env", result.get(i++));
    assertEquals("CCACHE_CPP2=yes", result.get(i++));
    assertEquals("/usr/bin/ccache", result.get(i++));
    assertEquals("/usr/bin/clang++-3.6", result.get(i++));
    assertEquals("-DAVX2=1", result.get(i++));
    assertEquals("-DCMAKE_BUILD_TYPE=\\\"Debug\\\"", result.get(i++));
    assertEquals("-DCMAKE_CC_FLAGS=\"\\\" -ggdb -Werror -Wall -Wstrict-aliasing=2 -pedantic -fPIC -fopenmp --std=c11 -ggdb -Werror -Wall -Wstrict-aliasing=2 -pedantic -fPIC --std=c11\\\"\"", result.get(i++));
    assertTrue(result.get(i++).startsWith("-DCMAKE_CXX_FLAGS=\"\\\" -ggdb"));
    assertEquals("-DCMAKE_CXX_FLAGS_DEBUG=\"\\\" -ggdb -Werror -Wall -Wstrict-aliasing=2 -pedantic -fPIC -fopenmp -stdlib=libc++ -std=c++14 -DLOG_INTERNAL_ERROR=LOG_DEBUG -mcx16 -msse4.2 -mavx2  \\\"\"", result.get(i++));
    assertEquals("-DCMAKE_CXX_FLAGS_RELEASE=\"\\\"-O3 -DNDEBUG -O3 \\\"\"", result.get(i++));
    assertEquals("-DCMAKE_VERSION=\\\"3.5.1\\\"", result.get(i++));
    assertEquals("-DNSULATE_PROJECT_COMMIT=\"\\\"b079181 Create smoke Test suites\\\"\"", result.get(i++));
    assertEquals("-DNSULATE_SYSTEM=\"\\\"Ubuntu 16045 LTS\\\"\"", result.get(i++));
    assertEquals("-DNSULATE_SYSTEM_PROCESSOR=\"\\\"Linux srv-narnia 4.15.0-36-generic x86_64 GNU/Linux\\\"\"", result.get(i++));
    assertEquals("-DNSULATE_TIME_OF_BUILD=\"\\\"Wednesday 14-11-2018 03:22 UTC\\\"\"", result.get(i++));
    assertEquals("-DNSULATE_VERSION=\\\"1.2.82\\\"", result.get(i++));
    assertEquals("-I/home/jslave/sean/mainline/nsulate/include", result.get(i++));
    assertEquals("-I/home/jslave/sean/mainline/nsulate/src", result.get(i++));
}
Also used : CompileCommandDatabaseParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandDatabaseParser) CompileCommandParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser) CompileCommand(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand) Gson(com.google.gson.Gson) CommandParser(com.synopsys.integration.common.util.parse.CommandParser) CompileCommandParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser) Test(org.junit.jupiter.api.Test) FunctionalTest(com.synopsys.integration.detectable.annotations.FunctionalTest)

Example 3 with CompileCommandParser

use of com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser in project synopsys-detect by blackducksoftware.

the class CompileCommandParserTest method testGetCompilerCmd.

@Test
public void testGetCompilerCmd() {
    CompileCommand sampleCommand = new CompileCommand();
    sampleCommand.setCommand("g++ -DDOUBLEQUOTED=\"A value for the compiler\" -DSINGLEQUOTED='Another value for the compiler' file.c -o file.o");
    CompileCommandParser commandParser = new CompileCommandParser(new CommandParser());
    List<String> compilerCommand = commandParser.parseCommand(sampleCommand, Collections.emptyMap());
    assertEquals("g++", compilerCommand.get(0));
}
Also used : CompileCommandParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser) CompileCommand(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand) CommandParser(com.synopsys.integration.common.util.parse.CommandParser) CompileCommandParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 4 with CompileCommandParser

use of com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser in project synopsys-detect by blackducksoftware.

the class CompileCommandParserTest method testGetCompilerArgs.

@Test
public void testGetCompilerArgs() {
    CompileCommand sampleCommand = new CompileCommand();
    sampleCommand.setCommand("g++ -DDOUBLEQUOTED=\"A value for the compiler\" -DSINGLEQUOTED='Another value for the compiler' file.c -o file.o");
    Map<String, String> optionOverrides = new HashMap<>();
    optionOverrides.put("-o", "/dev/null");
    CompileCommandParser commandParser = new CompileCommandParser(new CommandParser());
    List<String> result = commandParser.parseCommand(sampleCommand, optionOverrides);
    for (String part : result) {
        System.out.printf("compiler arg: %s\n", part);
    }
    assertEquals(6, result.size());
    int i = 0;
    assertEquals("g++", result.get(i++));
    assertEquals("-DDOUBLEQUOTED=\"A value for the compiler\"", result.get(i++));
    assertEquals("-DSINGLEQUOTED='Another value for the compiler'", result.get(i++));
    assertEquals("file.c", result.get(i++));
    assertEquals("-o", result.get(i++));
    assertEquals("/dev/null", result.get(i++));
}
Also used : CompileCommandParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser) HashMap(java.util.HashMap) CompileCommand(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand) CommandParser(com.synopsys.integration.common.util.parse.CommandParser) CompileCommandParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 5 with CompileCommandParser

use of com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser in project synopsys-detect by blackducksoftware.

the class CompileCommandParserTest method testEscapedDoubleQuotedTerm.

@Test
public void testEscapedDoubleQuotedTerm() {
    CompileCommand command = new CompileCommand();
    command.setDirectory("dir");
    command.setCommand("X=\\\"'a' 'b'\\\"");
    command.setFile("test.cc");
    CompileCommandParser commandParser = new CompileCommandParser(new CommandParser());
    List<String> result = commandParser.parseCommand(command, Collections.emptyMap());
    assertEquals(1, result.size());
    assertEquals("X=\\\"'a' 'b'\\\"", result.get(0));
}
Also used : CompileCommandParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser) CompileCommand(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand) CommandParser(com.synopsys.integration.common.util.parse.CommandParser) CompileCommandParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Aggregations

CommandParser (com.synopsys.integration.common.util.parse.CommandParser)7 CompileCommand (com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand)7 CompileCommandParser (com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser)7 Test (org.junit.jupiter.api.Test)7 UnitTest (com.synopsys.integration.detectable.annotations.UnitTest)5 Gson (com.google.gson.Gson)2 FunctionalTest (com.synopsys.integration.detectable.annotations.FunctionalTest)2 CompileCommandDatabaseParser (com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandDatabaseParser)2 HashMap (java.util.HashMap)1