Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation database guessing #232

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "server/src/rapidjson"]
path = server/src/rapidjson
url = https://github.com/miloyip/rapidjson
49 changes: 29 additions & 20 deletions irony-cdb-libclang.el → irony-cdb-server.el
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;;; irony-cdb-libclang.el --- Compilation Database for irony using libclang
;;; irony-cdb-server.el --- Compilation Database querying irony-server

;; Copyright (C) 2015 Karl Hylén

Expand All @@ -18,11 +18,6 @@
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:
;;
;; Compilation Database support for Irony using libclangs CXCompilationDatabase,
;; http://clang.llvm.org/doxygen/group__COMPILATIONDB.html

;;; Code:

(require 'irony-cdb)
Expand All @@ -31,24 +26,38 @@
(require 'cl-lib)

;;;###autoload
(defun irony-cdb-libclang (command &rest args)
(defun irony-cdb-server (command &rest args)
(cl-case command
(get-compile-options (irony-cdb-libclang--get-compile-options))))
(get-compile-options (irony-cdb-server--get-compile-options))))

(defun irony-cdb-libclang--get-compile-options ()
(defun irony-cdb-server--get-compile-options ()
(irony--awhen (irony-cdb-json--locate-db)
(irony-cdb-libclang--server-exact-flags it)))
(or (irony-cdb-server--server-exact-flags buffer-file-name it)
(irony-cdb-server--server-guess-flags buffer-file-name it))))

(defun irony-cdb-libclang--server-exact-flags (db-file)
(defun irony-cdb-server--server-exact-flags (src-file db-file)
"Get compilation options from irony-server.

The parameter DB-FILE is the database file."
(let ((build-dir (file-name-directory db-file))
(file buffer-file-name))
(irony-cdb-libclang--adjust-options-and-remove-compiler
file (irony--send-request-sync "get-compile-options" build-dir file))))

(defun irony-cdb-libclang--adjust-options-and-remove-compiler (file cmds)
The parameter SRC-FILE is the source file we seek the compile command of and
DB-FILE is the database file."
(irony-cdb-server--adjust-options-and-remove-compiler
src-file
(irony--send-request-sync "get-compile-options"
db-file
src-file)))

(defun irony-cdb-server--server-guess-flags (src-file db-file)
"Make irony-server guess compilation arguments of a file.

The parameter SRC-FILE is the source file we seek the compile command of and
DB-FILE is the database file."
(irony-cdb-server--adjust-options-and-remove-compiler
src-file
(list (irony--send-request-sync "guess-compile-options"
db-file
src-file))))

(defun irony-cdb-server--adjust-options-and-remove-compiler (file cmds)
"Remove compiler, target file FILE and output file from CMDS.

The parameter CMDS is a list of conses. In each cons, the car holds the options
Expand All @@ -61,10 +70,10 @@ and the cdr holds the working directory where the compile command was issued."
wdir)))
cmds))

(provide 'irony-cdb-libclang)
(provide 'irony-cdb-server)

;; Local Variables:
;; byte-compile-warnings: (not cl-functions)
;; End:

;;; irony-cdb-libclang ends here
;;; irony-cdb-server ends here
4 changes: 2 additions & 2 deletions irony-cdb.el
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

(autoload 'irony-cdb-clang-complete "irony-cdb-clang-complete")
(autoload 'irony-cdb-json "irony-cdb-json")
(autoload 'irony-cdb-libclang "irony-cdb-libclang")
(autoload 'irony-cdb-server "irony-cdb-server")


;;
Expand All @@ -48,7 +48,7 @@
:group 'irony)

(defcustom irony-cdb-compilation-databases '(irony-cdb-clang-complete
irony-cdb-libclang
irony-cdb-server
irony-cdb-json)
"List of active compilation databases.

Expand Down
20 changes: 17 additions & 3 deletions irony.el
Original file line number Diff line number Diff line change
Expand Up @@ -544,22 +544,26 @@ The installation requires CMake and the libclang developpement package."

When using a leading space, the buffer is hidden from the buffer
list (and undo information is not kept).")
(defvar irony--server-log nil
"The log file of irony-server.")

(defun irony--start-server-process ()
(when (setq irony--server-executable (or irony--server-executable
(irony--locate-server-executable)))
(let ((process-connection-type nil)
(process-adaptive-read-buffering nil)
process)
(setq irony--server-log (expand-file-name
(format-time-string
"irony.%Y-%m-%d_%Hh-%Mm-%Ss.log")
temporary-file-directory))
(setq process
(start-process-shell-command
"Irony" ;process name
irony--server-buffer ;buffer
(format "%s -i 2> %s" ;command
(shell-quote-argument irony--server-executable)
(expand-file-name
(format-time-string "irony.%Y-%m-%d_%Hh-%Mm-%Ss.log")
temporary-file-directory))))
irony--server-log)))
(buffer-disable-undo irony--server-buffer)
(set-process-query-on-exit-flag process nil)
(set-process-sentinel process 'irony--server-process-sentinel)
Expand All @@ -574,6 +578,16 @@ list (and undo information is not kept).")
(kill-process irony--server-process)
(setq irony--server-process nil)))

;;;###autoload
(defun irony-open-log-file ()
"Open irony server log file"
(interactive)
(if (and irony--server-log (file-exists-p irony--server-log))
(progn
(find-file irony--server-log)
(auto-revert-tail-mode))
(message "Log file doesn't exist yet!")))

(defun irony--get-server-process-create ()
(if (and irony--server-process
(process-live-p irony--server-process))
Expand Down
2 changes: 1 addition & 1 deletion server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif()

if(IRONY_COMPILER_IS_GCC_COMPATIBLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
elseif(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c- /D_HAS_EXCEPTIONS=0")
# irony-server uses some code that breaks when iterator debugging is enabled
Expand Down
9 changes: 8 additions & 1 deletion server/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ include(CheckLibClangBuiltinHeadersDir)

find_package(LibClang REQUIRED)

find_library(BOOST_SYSTEM boost_system)
find_library(BOOST_FILESYSTEM boost_filesystem)

include_directories(${LIBCLANG_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(rapidjson/include)

check_libclang_builtin_headers_dir()

Expand Down Expand Up @@ -32,6 +36,7 @@ add_executable(irony-server
Irony.h
TUManager.cpp
TUManager.h
CompilationDatabase.cpp

main.cpp)

Expand Down Expand Up @@ -65,6 +70,8 @@ set_source_files_properties(main.cpp
PROPERTIES
COMPILE_DEFINITIONS IRONY_PACKAGE_VERSION=\"${IRONY_PACKAGE_VERSION}\")

target_link_libraries(irony-server ${LIBCLANG_LIBRARIES})
target_link_libraries(irony-server ${LIBCLANG_LIBRARIES} ${BOOST_FILESYSTEM} ${BOOST_SYSTEM})

# add_subdirectory(json-test)

install(TARGETS irony-server DESTINATION bin)
5 changes: 3 additions & 2 deletions server/src/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ std::ostream &operator<<(std::ostream &os, const Command::Action &action) {
std::ostream &operator<<(std::ostream &os, const Command &command) {
os << "Command{action=" << command.action << ", "
<< "file='" << command.file << "', "
<< "dir='" << command.dir << "', "
<< "db='" << command.db << "', "
<< "line=" << command.line << ", "
<< "column=" << command.column << ", "
<< "flags=[";
Expand Down Expand Up @@ -173,7 +173,8 @@ Command *CommandParser::parse(const std::vector<std::string> &argv) {
break;

case Command::GetCompileOptions:
positionalArgs.push_back(StringConverter(&command_.dir));
case Command::GuessCompileOptions:
positionalArgs.push_back(StringConverter(&command_.db));
positionalArgs.push_back(StringConverter(&command_.file));
break;

Expand Down
4 changes: 2 additions & 2 deletions server/src/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct Command {
action = Unknown;
flags.clear();
file.clear();
dir.clear();
db.clear();
line = 0;
column = 0;
unsavedFiles.clear();
Expand All @@ -44,7 +44,7 @@ struct Command {

std::vector<std::string> flags;
std::string file;
std::string dir;
std::string db;
unsigned line;
unsigned column;
// pair of (filename, content)
Expand Down
2 changes: 2 additions & 0 deletions server/src/Commands.def
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ X(Diagnostics, "diagnostics", "print the diagnostics of the last parse")
X(Exit, "exit", "exit interactive mode, print nothing")
X(GetCompileOptions, "get-compile-options", "BUILD_DIR FILE - "
"get compile options for FILE from JSON database in PROJECT_ROOT")
X(GuessCompileOptions, "guess-compile-options", "BUILD_DIR FILE - "
"guess compile options for FILE from JSON database in PROJECT_ROOT")
X(Help, "help", "show this message")
X(Parse, "parse", "FILE - parse the given file")
X(SetDebug, "set-debug", "[on|off] - enable or disable verbose logging")
Expand Down
Loading