Search in sources :

Example 1 with CompileCommand

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

the class ClangExtractor method extract.

public Extraction extract(ClangPackageManager currentPackageManager, ClangPackageManagerRunner packageManagerRunner, File sourceDirectory, File outputDirectory, File jsonCompilationDatabaseFile, boolean cleanup) {
    try {
        logger.debug(String.format("Analyzing %s", jsonCompilationDatabaseFile.getAbsolutePath()));
        logger.debug(String.format("extract() called; compileCommandsJsonFilePath: %s", jsonCompilationDatabaseFile.getAbsolutePath()));
        List<CompileCommand> compileCommands = compileCommandDatabaseParser.parseCompileCommandDatabase(jsonCompilationDatabaseFile);
        Set<File> dependencyFileDetails = dependencyFileDetailGenerator.fromCompileCommands(compileCommands, outputDirectory, cleanup);
        PackageDetailsResult results = packageManagerRunner.getAllPackages(currentPackageManager, sourceDirectory, executableRunner, dependencyFileDetails);
        logger.trace("Found : " + results.getFoundPackages() + " packages.");
        logger.trace("Found : " + results.getUnRecognizedDependencyFiles() + " non-package files.");
        List<Forge> packageForges = forgeChooser.determineForges(currentPackageManager);
        CodeLocation codeLocation = clangPackageDetailsTransformer.toCodeLocation(packageForges, results.getFoundPackages());
        logFileCollection("Unrecognized dependency files (all)", results.getUnRecognizedDependencyFiles());
        List<File> unrecognizedIncludeFiles = results.getUnRecognizedDependencyFiles().stream().filter(file -> !isFileUnderDir(sourceDirectory, file)).collect(Collectors.toList());
        logFileCollection(String.format("Unrecognized dependency files that are outside the compile_commands.json directory (%s) and will be collected", sourceDirectory), unrecognizedIncludeFiles);
        return new Extraction.Builder().unrecognizedPaths(unrecognizedIncludeFiles).success(codeLocation).build();
    } catch (Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : Logger(org.slf4j.Logger) Forge(com.synopsys.integration.bdio.model.Forge) PackageDetailsResult(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetailsResult) Extraction(com.synopsys.integration.detectable.extraction.Extraction) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) ClangPackageManagerRunner(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerRunner) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ClangPackageDetailsTransformer(com.synopsys.integration.detectable.detectables.clang.dependencyfile.ClangPackageDetailsTransformer) File(java.io.File) ArrayList(java.util.ArrayList) CompileCommandDatabaseParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandDatabaseParser) CompileCommand(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand) List(java.util.List) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) ClangPackageManager(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManager) DependencyFileDetailGenerator(com.synopsys.integration.detectable.detectables.clang.dependencyfile.DependencyFileDetailGenerator) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Forge(com.synopsys.integration.bdio.model.Forge) IOException(java.io.IOException) CompileCommand(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand) Extraction(com.synopsys.integration.detectable.extraction.Extraction) PackageDetailsResult(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetailsResult) File(java.io.File)

Example 2 with CompileCommand

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

the class CommandParserFunctionalTest method testCanParseCommandDatabase.

@Test
public void testCanParseCommandDatabase() throws IOException {
    CompileCommandDatabaseParser compileCommandDatabaseParser = new CompileCommandDatabaseParser(new Gson());
    List<CompileCommand> compileCommands = compileCommandDatabaseParser.parseCompileCommandDatabase(FunctionalTestFiles.asFile("/clang/compile_commands.json"));
    assertEquals(182, compileCommands.size());
    CompileCommand first = compileCommands.get(0);
    assertEquals("/home/jslave/sean/mainline/nsulate/src", first.getDirectory());
    assertTrue(first.getCommand().startsWith("/usr/bin/env CCACHE_CPP2=yes /usr/bin/ccache /usr/bin/clang++-3.6   -DAVX2=1 -DCMAKE_BUILD_TYPE=\\\"Debug\\\""));
    assertEquals("/home/jslave/sean/mainline/nsulate/src/cli.pb.cc", first.getFile());
    assertEquals(0, first.getArguments().length);
}
Also used : CompileCommandDatabaseParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandDatabaseParser) CompileCommand(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand) Gson(com.google.gson.Gson) Test(org.junit.jupiter.api.Test) FunctionalTest(com.synopsys.integration.detectable.annotations.FunctionalTest)

Example 3 with CompileCommand

use of com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand 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 4 with CompileCommand

use of com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand 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 5 with CompileCommand

use of com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand 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)

Aggregations

CompileCommand (com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand)10 Test (org.junit.jupiter.api.Test)9 CommandParser (com.synopsys.integration.common.util.parse.CommandParser)7 CompileCommandParser (com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser)7 UnitTest (com.synopsys.integration.detectable.annotations.UnitTest)5 CompileCommandDatabaseParser (com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandDatabaseParser)4 Gson (com.google.gson.Gson)3 FunctionalTest (com.synopsys.integration.detectable.annotations.FunctionalTest)3 DependencyFileDetailGenerator (com.synopsys.integration.detectable.detectables.clang.dependencyfile.DependencyFileDetailGenerator)2 File (java.io.File)2 Forge (com.synopsys.integration.bdio.model.Forge)1 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)1 DetectableExecutableRunner (com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner)1 ClangPackageDetailsTransformer (com.synopsys.integration.detectable.detectables.clang.dependencyfile.ClangPackageDetailsTransformer)1 FilePathGenerator (com.synopsys.integration.detectable.detectables.clang.dependencyfile.FilePathGenerator)1 ClangPackageManager (com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManager)1 ClangPackageManagerRunner (com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerRunner)1 PackageDetailsResult (com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetailsResult)1 Extraction (com.synopsys.integration.detectable.extraction.Extraction)1 IOException (java.io.IOException)1