ajwillia-ms pushed a commit to branch master.

http://git.enlightenment.org/tools/edi.git/commit/?id=0483196de47345b77ecbd4c9a6d37962c74601eb

commit 0483196de47345b77ecbd4c9a6d37962c74601eb
Author: Andy Williams <a...@andywilliams.me>
Date:   Sun Feb 19 22:25:12 2017 +0000

    clang: Update clang command database to support cmake too
---
 src/bin/language/edi_language_provider_c.c | 55 +++++++++++++++++++++---------
 src/lib/edi_build_provider_cmake.c         |  3 ++
 2 files changed, 41 insertions(+), 17 deletions(-)

diff --git a/src/bin/language/edi_language_provider_c.c 
b/src/bin/language/edi_language_provider_c.c
index 067dd58..e04c08f 100644
--- a/src/bin/language/edi_language_provider_c.c
+++ b/src/bin/language/edi_language_provider_c.c
@@ -30,44 +30,65 @@ _clang_commands_fallback_get(const char ***args, unsigned 
int *argc)
 static void
 _clang_commands_get(const char *path, const char ***args, unsigned int *argc)
 {
-   CXCompilationDatabase_Error compilationDatabaseError;
-   CXCompilationDatabase compilationDatabase = 
clang_CompilationDatabase_fromDirectory(edi_project_get(), 
&compilationDatabaseError );
+   CXCompilationDatabase_Error error;
+   CXCompilationDatabase database = NULL;
+   CXCompileCommands commands;
+   CXCompileCommand command;
+   const char** arguments;
+   unsigned int i, numargs, ignored = 0;
+
+   if (edi_project_file_exists("compile_commands.json"))
+     {
+        database = clang_CompilationDatabase_fromDirectory(edi_project_get(), 
&error);
+     }
+   else if (edi_project_file_exists("build/compile_commands.json"))
+     {
+        char *build = edi_project_file_path_get("build");
+        database = clang_CompilationDatabase_fromDirectory(build, &error);
+        free(build);
+     }
 
-   if ( compilationDatabaseError == CXCompilationDatabase_CanNotLoadDatabase)
+   if (database == NULL || error == CXCompilationDatabase_CanNotLoadDatabase)
      {
         INF("Could not load compile_commands.json in %s", edi_project_get());
         _clang_commands_fallback_get(args, argc);
         return;
      }
 
-   CXCompileCommands compileCommands         = 
clang_CompilationDatabase_getCompileCommands( compilationDatabase, path);
-   CXCompileCommand compileCommand = clang_CompileCommands_getCommand( 
compileCommands, 0 );
-   unsigned int numArguments       = clang_CompileCommand_getNumArgs( 
compileCommand );
+   commands = clang_CompilationDatabase_getCompileCommands(database, path);
+   command = clang_CompileCommands_getCommand(commands, 0);
+   numargs = clang_CompileCommand_getNumArgs(command);
 
-   if (numArguments == 0)
+   if (numargs == 0)
      {
         INF("File %s not found in compile_commands.json", path);
         _clang_commands_fallback_get(args, argc);
         return;
      }
 
-   const char** arguments                = malloc(sizeof(char*) * 
numArguments);
+   arguments = malloc(sizeof(char*) * (numargs + 1));
+   INF("Loading clang parameters for %s", path);
 
    arguments[0] = CLANG_INCLUDES;
-   for( unsigned int i = 1; numArguments > i + 4; i++ )
-   {
-     CXString argument = clang_CompileCommand_getArg( compileCommand, i + 1 );
-     const char * strArgument = clang_getCString( argument );
+   for(i = 1; i <= numargs; i++ )
+     {
+        const char *argstr;
+        CXString argument = clang_CompileCommand_getArg(command, i + 1);
+        argstr = clang_getCString(argument);
 
-     arguments[i] = strdup(strArgument);
+        if (argstr && strlen(argstr) > 2 && argstr[0] == '-' &&
+            (argstr[1] == 'I' || argstr[1] == 'D'))
+          arguments[i - ignored] = strdup(argstr);
+        else
+          ignored++;
 
-     clang_disposeString( argument );
-   }
+        clang_disposeString(argument);
+     }
 
    *args = arguments;
-   *argc = numArguments <= 4 ? 1 : numArguments - 4;
+   *argc = numargs + 1 - ignored;
 
-   clang_CompilationDatabase_dispose(compilationDatabase);
+   clang_CompilationDatabase_dispose(database);
 }
 
 static void
diff --git a/src/lib/edi_build_provider_cmake.c 
b/src/lib/edi_build_provider_cmake.c
index 9a352fb..3bee684 100644
--- a/src/lib/edi_build_provider_cmake.c
+++ b/src/lib/edi_build_provider_cmake.c
@@ -22,6 +22,9 @@ _cmake_file_hidden_is(const char *file)
    if (!file || strlen(file) == 0)
      return EINA_FALSE;
 
+   if (!strcmp("build", ecore_file_file_get(file)))
+     return EINA_TRUE;
+
    if (eina_str_has_extension(file, ".o") || eina_str_has_extension(file, 
".so") ||
        eina_str_has_extension(file, ".lo"))
      return EINA_TRUE;

-- 


Reply via email to