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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 (goto-char (point-min)) | 78 (goto-char (point-min)) |
79 | 79 |
80 ;; Fix up path references. | 80 ;; Fix up path references. |
81 (cond ((eq type-hint 'win) (trybot-fixup-win)) | 81 (cond ((eq type-hint 'win) (trybot-fixup-win)) |
82 ((eq type-hint 'mac) (trybot-fixup-maclin)) | 82 ((eq type-hint 'mac) (trybot-fixup-maclin)) |
83 ((eq type-hint 'linux) (trybot-fixup-maclin)) | 83 ((eq type-hint 'linux) (trybot-fixup-maclin)) |
84 (t (trybot-fixup-win) (trybot-fixup-maclin))) | 84 (t (trybot-fixup-win) (trybot-fixup-maclin))) |
85 | 85 |
86 (compilation-mode)) | 86 (compilation-mode)) |
87 | 87 |
| 88 (defun trybot-get-new-buffer () |
| 89 "Get a new clean buffer for trybot output." |
| 90 ; Use trybot-buffer-name if available; otherwise, "*trybot*". |
| 91 (let ((buffer-name (if (boundp 'trybot-buffer-name) |
| 92 trybot-buffer-name |
| 93 "*trybot*"))) |
| 94 (let ((old (get-buffer buffer-name))) |
| 95 (when old (kill-buffer old))) |
| 96 (get-buffer-create buffer-name))) |
| 97 |
| 98 (defun trybot-fetch (type-hint url) |
| 99 "Fetch a URL and postprocess it as trybot output." |
| 100 |
| 101 (let ((on-fetch-completion |
| 102 (lambda (process state) |
| 103 (switch-to-buffer (process-buffer process)) |
| 104 (when (equal state "finished\n") |
| 105 (trybot-fixup (process-get process 'type-hint))))) |
| 106 (command (concat "curl -s " url |
| 107 (when (eq type-hint 'mac) |
| 108 ; Pipe it through the output shortener. |
| 109 (concat " | " (get-chrome-root) |
| 110 "build/sanitize-mac-build-log.sed"))))) |
| 111 |
| 112 ; Start up the subprocess. |
| 113 (let* ((coding-system-for-read 'utf-8-dos) |
| 114 (buffer (trybot-get-new-buffer)) |
| 115 (process (start-process-shell-command "curl" buffer command))) |
| 116 ; Attach the type hint to the process so we can get it back when |
| 117 ; the process completes. |
| 118 (process-put process 'type-hint type-hint) |
| 119 (set-process-query-on-exit-flag process nil) |
| 120 (set-process-sentinel process on-fetch-completion)))) |
| 121 |
88 (defun trybot-test (type-hint filename) | 122 (defun trybot-test (type-hint filename) |
89 "Load the given test data filename and do the trybot parse on it." | 123 "Load the given test data filename and do the trybot parse on it." |
90 | 124 |
91 (switch-to-buffer (get-buffer-create "*trybot-test*")) | 125 (let ((trybot-buffer-name "*trybot-test*") |
92 (let ((inhibit-read-only t) | 126 (url (concat "file://" (get-chrome-root) "tools/emacs/" filename))) |
93 (coding-system-for-read 'utf-8-dos)) | 127 (trybot-fetch type-hint url))) |
94 (erase-buffer) | |
95 (insert-file-contents | |
96 (concat (get-chrome-root) "tools/emacs/" filename)) | |
97 | |
98 (trybot-fixup type-hint))) | |
99 | 128 |
100 (defun trybot-test-win () | 129 (defun trybot-test-win () |
101 "Load the Windows test data and do the trybot parse on it." | 130 "Load the Windows test data and do the trybot parse on it." |
102 (interactive) | 131 (interactive) |
103 (trybot-test 'win "trybot-windows.txt")) | 132 (trybot-test 'win "trybot-windows.txt")) |
104 (defun trybot-test-mac () | 133 (defun trybot-test-mac () |
105 "Load the Mac test data and do the trybot parse on it." | 134 "Load the Mac test data and do the trybot parse on it." |
106 (interactive) | 135 (interactive) |
107 (trybot-test 'mac "trybot-mac.txt")) | 136 (trybot-test 'mac "trybot-mac.txt")) |
108 (defun trybot-test-linux () | 137 (defun trybot-test-linux () |
109 "Load the Linux test data and do the trybot parse on it." | 138 "Load the Linux test data and do the trybot parse on it." |
110 (interactive) | 139 (interactive) |
111 (trybot-test 'linux "trybot-linux.txt")) | 140 (trybot-test 'linux "trybot-linux.txt")) |
112 | 141 |
113 (defun trybot (url) | 142 (defun trybot (url) |
114 "Fetch a trybot URL and fix up the output into a compilation-mode buffer." | 143 "Fetch a trybot URL and fix up the output into a compilation-mode buffer." |
115 (interactive "sURL to trybot stdout (leave empty to use clipboard): ") | 144 (interactive "sURL to trybot stdout (leave empty to use clipboard): ") |
116 | 145 |
117 ;; Yank URL from clipboard if necessary. | 146 ;; Yank URL from clipboard if necessary. |
118 (when (= (length url) 0) | 147 (when (= (length url) 0) |
119 (with-temp-buffer | 148 (with-temp-buffer |
120 (clipboard-yank) | 149 (clipboard-yank) |
121 (setq url (buffer-string)))) | 150 (setq url (buffer-string)))) |
122 | 151 |
123 ;; TODO: fixup URL to append /text if necessary. | 152 ;; TODO: fixup URL to append /text if necessary. |
124 | 153 |
125 ;; Extract the body out of the URL. | 154 (let ((type-hint (cond ((string-match "/win/" url) 'win) |
126 ; TODO: delete HTTP headers somehow. | |
127 (let ((inhibit-read-only t) | |
128 (coding-system-for-read 'utf-8-dos) | |
129 (type-hint (cond ((string-match "/win/" url) 'win) | |
130 ((string-match "/mac/" url) 'mac) | 155 ((string-match "/mac/" url) 'mac) |
131 ; Match /linux, /linux_view, etc. | 156 ; Match /linux, /linux_view, etc. |
132 ((string-match "/linux" url) 'linux) | 157 ((string-match "/linux" url) 'linux) |
133 (t 'unknown)))) | 158 (t 'unknown)))) |
134 (switch-to-buffer (get-buffer-create "*trybot*")) | 159 (trybot-fetch type-hint url))) |
135 (buffer-swap-text (url-retrieve-synchronously url)) | |
136 | |
137 (trybot-fixup type-hint))) | |
138 | 160 |
139 (provide 'trybot) | 161 (provide 'trybot) |
OLD | NEW |