mirror of
				https://github.com/MaskRay/ccls.git
				synced 2025-11-03 22:04:24 +00:00 
			
		
		
		
	WIP better command line parsing
This commit is contained in:
		
							parent
							
								
									9ffed9a253
								
							
						
					
					
						commit
						a97bd9d1c4
					
				@ -22,9 +22,61 @@ MAKE_REFLECT_STRUCT(CompileCommandsEntry, directory, file, command, args);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace {
 | 
					namespace {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const char* kBlacklistMulti[] = {
 | 
				
			||||||
 | 
					  "-MF",
 | 
				
			||||||
 | 
					  "-Xclang"
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Blacklisted flags which are always removed from the command line.
 | 
					// Blacklisted flags which are always removed from the command line.
 | 
				
			||||||
static const char *kBlacklist[] = {
 | 
					static const char *kBlacklist[] = {
 | 
				
			||||||
  "-stdlib=libc++"
 | 
					  "--param",
 | 
				
			||||||
 | 
					  "-M",
 | 
				
			||||||
 | 
					  "-MD",
 | 
				
			||||||
 | 
					  "-MG",
 | 
				
			||||||
 | 
					  "-MM",
 | 
				
			||||||
 | 
					  "-MMD",
 | 
				
			||||||
 | 
					  "-MP",
 | 
				
			||||||
 | 
					  "-MQ",
 | 
				
			||||||
 | 
					  "-MT",
 | 
				
			||||||
 | 
					  "-Og",
 | 
				
			||||||
 | 
					  "-Wa,--32",
 | 
				
			||||||
 | 
					  "-Wa,--64",
 | 
				
			||||||
 | 
					  "-Wl,--incremental-full",
 | 
				
			||||||
 | 
					  "-Wl,--incremental-patch,1",
 | 
				
			||||||
 | 
					  "-Wl,--no-incremental",
 | 
				
			||||||
 | 
					  "-fbuild-session-file=",
 | 
				
			||||||
 | 
					  "-fbuild-session-timestamp=",
 | 
				
			||||||
 | 
					  "-fembed-bitcode",
 | 
				
			||||||
 | 
					  "-fembed-bitcode-marker",
 | 
				
			||||||
 | 
					  "-fmodules-validate-once-per-build-session",
 | 
				
			||||||
 | 
					  "-fno-delete-null-pointer-checks",
 | 
				
			||||||
 | 
					  "-fno-use-linker-plugin"
 | 
				
			||||||
 | 
					  "-fno-var-tracking",
 | 
				
			||||||
 | 
					  "-fno-var-tracking-assignments",
 | 
				
			||||||
 | 
					  "-fno-enforce-eh-specs",
 | 
				
			||||||
 | 
					  "-fvar-tracking",
 | 
				
			||||||
 | 
					  "-fvar-tracking-assignments",
 | 
				
			||||||
 | 
					  "-fvar-tracking-assignments-toggle",
 | 
				
			||||||
 | 
					  "-gcc-toolchain",
 | 
				
			||||||
 | 
					  "-march=",
 | 
				
			||||||
 | 
					  "-masm=",
 | 
				
			||||||
 | 
					  "-mcpu=",
 | 
				
			||||||
 | 
					  "-mfpmath=",
 | 
				
			||||||
 | 
					  "-mtune=",
 | 
				
			||||||
 | 
					  "-s",
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  "-B",
 | 
				
			||||||
 | 
					  //"-f",
 | 
				
			||||||
 | 
					  //"-pipe",
 | 
				
			||||||
 | 
					  //"-W",
 | 
				
			||||||
 | 
					  // TODO: make sure we consume includes before stripping all path-like args.
 | 
				
			||||||
 | 
					  "/work/goma/gomacc",
 | 
				
			||||||
 | 
					  "../../third_party/llvm-build/Release+Asserts/bin/clang++",
 | 
				
			||||||
 | 
					  "-Wno-unused-lambda-capture",
 | 
				
			||||||
 | 
					  "/",
 | 
				
			||||||
 | 
					  "..",
 | 
				
			||||||
 | 
					  //"-stdlib=libc++"
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Arguments which are followed by a potentially relative path. We need to make
 | 
					// Arguments which are followed by a potentially relative path. We need to make
 | 
				
			||||||
@ -47,6 +99,12 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry(const std::vector<std:
 | 
				
			|||||||
    std::string arg = entry.args[i];
 | 
					    std::string arg = entry.args[i];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // If blacklist skip.
 | 
					    // If blacklist skip.
 | 
				
			||||||
 | 
					    if (std::any_of(std::begin(kBlacklistMulti), std::end(kBlacklistMulti), [&arg](const char* value) {
 | 
				
			||||||
 | 
					      return StartsWith(arg, value);
 | 
				
			||||||
 | 
					    })) {
 | 
				
			||||||
 | 
					      ++i;
 | 
				
			||||||
 | 
					      continue;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    if (std::any_of(std::begin(kBlacklist), std::end(kBlacklist), [&arg](const char* value) {
 | 
					    if (std::any_of(std::begin(kBlacklist), std::end(kBlacklist), [&arg](const char* value) {
 | 
				
			||||||
      return StartsWith(arg, value);
 | 
					      return StartsWith(arg, value);
 | 
				
			||||||
    })) {
 | 
					    })) {
 | 
				
			||||||
@ -88,9 +146,9 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry(const std::vector<std:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  // Clang does not have good hueristics for determining source language. We
 | 
					  // Clang does not have good hueristics for determining source language. We
 | 
				
			||||||
  // default to C++11 if the user has not specified.
 | 
					  // default to C++11 if the user has not specified.
 | 
				
			||||||
  if (!StartsWithAny(entry.args, "-x"))
 | 
					  if (!StartsWithAny(result.args, "-x"))
 | 
				
			||||||
    result.args.push_back("-xc++");
 | 
					    result.args.push_back("-xc++");
 | 
				
			||||||
  if (!StartsWithAny(entry.args, "-std="))
 | 
					  if (!StartsWithAny(result.args, "-std="))
 | 
				
			||||||
    result.args.push_back("-std=c++11");
 | 
					    result.args.push_back("-std=c++11");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return result;
 | 
					  return result;
 | 
				
			||||||
@ -337,4 +395,4 @@ TEST_CASE("Entry inference") {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST_SUITE_END();
 | 
					TEST_SUITE_END();
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user