Skip to content

Instantly share code, notes, and snippets.

@johnfredcee
Created April 24, 2012 20:27
Show Gist options
  • Select an option

  • Save johnfredcee/2483457 to your computer and use it in GitHub Desktop.

Select an option

Save johnfredcee/2483457 to your computer and use it in GitHub Desktop.
Flymake SCons support
(defun flymake-get-scons-cmdline (source base-dir)
(list "scons"
(list "-suC"
(expand-file-name base-dir)
"SYNTAX=1"
(concat (file-name-sans-extension source) ".o"))))
(defun flymake-master-scons-init (get-incl-dirs-f master-file-masks include-regexp)
"Create make command line for a source file checked via master file compilation."
(let* ((make-args nil)
(temp-master-file-name (flymake-init-create-temp-source-and-master-buffer-copy
get-incl-dirs-f 'flymake-create-temp-inplace
master-file-masks include-regexp)))
(when temp-master-file-name
(let* ((buildfile-dir (flymake-init-find-buildfile-dir temp-master-file-name "SConstruct")))
(if buildfile-dir
(setq make-args (flymake-get-syntax-check-program-args
temp-master-file-name buildfile-dir nil nil 'flymake-get-scons-cmdline)))))
make-args))
(defun flymake-get-scons-include-dirs-imp (basedir)
(if (flymake-get-project-include-dirs-from-cache basedir)
(progn
(flymake-get-project-include-dirs-from-cache basedir))
(let* ((command-line (concat "scons -u DUMPENV=1 -C " (shell-quote-argument basedir)))
(output (shell-command-to-string command-line))
(lines (flymake-split-string output "\n"))
(count (length lines))
(idx 0)
(inc-dirs nil))
(while (and (< idx count) (not (string-match "^\\[" (nth idx lines))))
(setq idx (1+ idx)))
(while (and (< idx count)
(not (string-match "]$" (nth idx lines))))
(when (string-match "\\'\\([^\\']*\\)\\'" (nth idx lines))
(let ((inc-dir (match-string 1 (nth idx lines))))
(when (not (file-name-absolute-p inc-dir))
(message "Found include.. %s" inc-dir)
(push inc-dir inc-dirs))))
(setq idx (1+ idx)))
(flymake-add-project-include-dirs-to-cache basedir inc-dirs))))
(defun flymake-master-scons-header-init ()
(flymake-master-scons-init
'flymake-get-scons-include-dirs-imp
'("\\.\\(?:c\\(?:pp\\|xx\\|\\+\\+\\)?\\|CC\\)\\'")
"[ \t]*#[ \t]*include[ \t]*\"\\([[:word:]0-9/\\_.]*%s\\)\""))
(defun flymake-simple-scons-init ()
(flymake-simple-make-init-impl 'flymake-create-temp-inplace t t "SConstruct" '
flymake-get-scons-cmdline))
(defun flymake-scons-init ()
(list "sh" (list "-c" (format "'scons -Dcu && scons -u SYNTAX=1 %s'"
(file-relative-name
(flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace)
(file-name-directory buffer-file-name))))))
(add-to-list 'flymake-allowed-file-name-masks
'("\\.\\(?:c\\(?:pp\\|xx\\|\\+\\+\\)?\\|CC\\)\\'" flymake-simple-scons-init))
(add-to-list 'flymake-allowed-file-name-masks
'("\\.h\\'" flymake-master-scons-header-init flymake-master-cleanup))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment