OLD | NEW |
1 ; To use this, | 1 ; To use this, |
2 ; 1) Add to init.el: | 2 ; 1) Add to init.el: |
3 ; (setq-default chrome-root "/path/to/chrome/src/") | 3 ; (setq-default chrome-root "/path/to/chrome/src/") |
4 ; (add-to-list 'load-path (concat chrome-root "tools/emacs")) | 4 ; (add-to-list 'load-path (concat chrome-root "tools/emacs")) |
5 ; (require 'trybot) | 5 ; (require 'trybot) |
6 ; 2) Run on trybot output: | 6 ; 2) Run on trybot output: |
7 ; M-x trybot | 7 ; M-x trybot |
8 ; | 8 ; |
9 ; To hack on this, | 9 ; To hack on this, |
10 ; M-x eval-buffer | 10 ; M-x eval-buffer |
(...skipping 22 matching lines...) Expand all Loading... |
33 (setq corrected-path | 33 (setq corrected-path |
34 (and next-component | 34 (and next-component |
35 (file-name-as-directory | 35 (file-name-as-directory |
36 (concat corrected-path next-component)))))))) | 36 (concat corrected-path next-component)))))))) |
37 path-components) | 37 path-components) |
38 (if corrected-path | 38 (if corrected-path |
39 (file-relative-name (directory-file-name corrected-path) | 39 (file-relative-name (directory-file-name corrected-path) |
40 (get-chrome-root)) | 40 (get-chrome-root)) |
41 nil)))) | 41 nil)))) |
42 | 42 |
43 (defun trybot-fixup () | 43 (defun trybot-fixup-win () |
| 44 "Fix up Windows-specific output." |
| 45 |
| 46 ; Fix Windows paths ("d:\...\src\"). |
| 47 (save-excursion |
| 48 (while (re-search-forward "\\(^.:\\\\.*\\\\src\\\\\\)\\(.*?\\)[(:]" nil t) |
| 49 (replace-match "" nil t nil 1) |
| 50 ; Line now looks like: |
| 51 ; foo\bar\baz.cc error message here |
| 52 ; We want to fixup backslashes in path into forward slashes, |
| 53 ; without modifying the error message - by matching up to the |
| 54 ; first colon above (which will be just beyond the end of the |
| 55 ; filename) we can use the end of the match as a limit. |
| 56 (subst-char-in-region (point) (match-end 0) ?\\ ?/) |
| 57 ; See if we can correct the file name casing. |
| 58 (let ((filename (buffer-substring (match-beginning 2) (match-end 2)))) |
| 59 (if (and (not (file-exists-p filename)) |
| 60 (setq filename (case-corrected-filename filename))) |
| 61 (replace-match filename t t nil 2)))))) |
| 62 |
| 63 (defun trybot-fixup-maclin () |
| 64 "Fix up Mac/Linux output." |
| 65 (save-excursion |
| 66 (while (re-search-forward "^/b/build/[^ ]*/src/" nil t) |
| 67 (replace-match "")))) |
| 68 |
| 69 (defun trybot-fixup (type-hint) |
44 "Parse and fixup the contents of the current buffer as trybot output." | 70 "Parse and fixup the contents of the current buffer as trybot output." |
45 | 71 |
| 72 ; XXX is there something I should so so this stuff doesn't end up on the |
| 73 ; undo stack? |
| 74 |
46 ;; Fixup paths. | 75 ;; Fixup paths. |
47 (cd (get-chrome-root)) | 76 (cd (get-chrome-root)) |
48 | 77 |
| 78 (goto-char (point-min)) |
| 79 |
49 ;; Fix up path references. | 80 ;; Fix up path references. |
50 ; XXX is there something I should so so this stuff doesn't end up on the | 81 (cond ((eq type-hint 'win) (trybot-fixup-win)) |
51 ; undo stack? | 82 ((eq type-hint 'mac) (trybot-fixup-maclin)) |
52 (goto-char (point-min)) | 83 ((eq type-hint 'linux) (trybot-fixup-maclin)) |
53 ; Fix Windows paths ("d:\...\src\"). | 84 (t (trybot-fixup-win) (trybot-fixup-maclin))) |
54 (while (re-search-forward "\\(^.:\\\\.*\\\\src\\\\\\)\\(.*?\\)[(:]" nil t) | |
55 (replace-match "" nil t nil 1) | |
56 ; Line now looks like: | |
57 ; foo\bar\baz.cc error message here | |
58 ; We want to fixup backslashes in path into forward slashes, without | |
59 ; modifying the error message - by matching up to the first colon above | |
60 ; (which will be just beyond the end of the filename) we can use the end of | |
61 ; the match as a limit. | |
62 (subst-char-in-region (point) (match-end 0) ?\\ ?/) | |
63 ; See if we can correct the file name casing. | |
64 (let ((filename (buffer-substring (match-beginning 2) (match-end 2)))) | |
65 (if (and (not (file-exists-p filename)) | |
66 (setq filename (case-corrected-filename filename))) | |
67 (replace-match filename t t nil 2)))) | |
68 | 85 |
69 ; Fix Linux/Mac paths ("/b/build/.../src/"). | |
70 (goto-char (point-min)) | |
71 (while (re-search-forward "^/b/build/[^ ]*/src/" nil t) | |
72 (replace-match "")) | |
73 | |
74 ;; Clean up and switch into compilation mode. | |
75 (goto-char (point-min)) | |
76 (compilation-mode)) | 86 (compilation-mode)) |
77 | 87 |
78 (defun trybot-test (filename) | 88 (defun trybot-test (type-hint filename) |
79 "Load the given test data filename and do the trybot parse on it." | 89 "Load the given test data filename and do the trybot parse on it." |
80 | 90 |
81 (switch-to-buffer (get-buffer-create "*trybot-test*")) | 91 (switch-to-buffer (get-buffer-create "*trybot-test*")) |
82 (let ((inhibit-read-only t) | 92 (let ((inhibit-read-only t) |
83 (coding-system-for-read 'utf-8-dos)) | 93 (coding-system-for-read 'utf-8-dos)) |
84 (erase-buffer) | 94 (erase-buffer) |
85 (insert-file-contents | 95 (insert-file-contents |
86 (concat (get-chrome-root) "tools/emacs/" filename)) | 96 (concat (get-chrome-root) "tools/emacs/" filename)) |
87 | 97 |
88 (trybot-fixup))) | 98 (trybot-fixup type-hint))) |
89 | 99 |
90 (defun trybot-test-win () | 100 (defun trybot-test-win () |
91 "Load the Windows test data and do the trybot parse on it." | 101 "Load the Windows test data and do the trybot parse on it." |
92 (interactive) | 102 (interactive) |
93 (trybot-test "trybot-windows.txt")) | 103 (trybot-test 'win "trybot-windows.txt")) |
94 (defun trybot-test-mac () | 104 (defun trybot-test-mac () |
95 "Load the Mac test data and do the trybot parse on it." | 105 "Load the Mac test data and do the trybot parse on it." |
96 (interactive) | 106 (interactive) |
97 (trybot-test "trybot-mac.txt")) | 107 (trybot-test 'mac "trybot-mac.txt")) |
98 (defun trybot-test-linux () | 108 (defun trybot-test-linux () |
99 "Load the Linux test data and do the trybot parse on it." | 109 "Load the Linux test data and do the trybot parse on it." |
100 (interactive) | 110 (interactive) |
101 (trybot-test "trybot-linux.txt")) | 111 (trybot-test 'linux "trybot-linux.txt")) |
102 | 112 |
103 (defun trybot (url) | 113 (defun trybot (url) |
104 "Fetch a trybot URL and fix up the output into a compilation-mode buffer." | 114 "Fetch a trybot URL and fix up the output into a compilation-mode buffer." |
105 (interactive "sURL to trybot stdout (leave empty to use clipboard): ") | 115 (interactive "sURL to trybot stdout (leave empty to use clipboard): ") |
106 | 116 |
107 ;; Yank URL from clipboard if necessary. | 117 ;; Yank URL from clipboard if necessary. |
108 (when (= (length url) 0) | 118 (when (= (length url) 0) |
109 (with-temp-buffer | 119 (with-temp-buffer |
110 (clipboard-yank) | 120 (clipboard-yank) |
111 (setq url (buffer-string)))) | 121 (setq url (buffer-string)))) |
112 | 122 |
113 ;; TODO: fixup URL to append /text if necessary. | 123 ;; TODO: fixup URL to append /text if necessary. |
114 | 124 |
115 ;; Extract the body out of the URL. | 125 ;; Extract the body out of the URL. |
116 ; TODO: delete HTTP headers somehow. | 126 ; TODO: delete HTTP headers somehow. |
117 (let ((inhibit-read-only t) | 127 (let ((inhibit-read-only t) |
118 (coding-system-for-read 'utf-8-dos)) | 128 (coding-system-for-read 'utf-8-dos) |
| 129 (type-hint (cond ((string-match "/win/" url) 'win) |
| 130 ((string-match "/mac/" url) 'mac) |
| 131 ; Match /linux, /linux_view, etc. |
| 132 ((string-match "/linux" url) 'linux) |
| 133 (t 'unknown)))) |
119 (switch-to-buffer (get-buffer-create "*trybot*")) | 134 (switch-to-buffer (get-buffer-create "*trybot*")) |
120 (buffer-swap-text (url-retrieve-synchronously url)) | 135 (buffer-swap-text (url-retrieve-synchronously url)) |
121 | 136 |
122 (trybot-fixup))) | 137 (trybot-fixup type-hint))) |
123 | 138 |
124 (provide 'trybot) | 139 (provide 'trybot) |
OLD | NEW |