Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/go/src/golang.org/x/mobile/app/stdio_android.go

Issue 1275153002: Remove third_party/golang.org/x/mobile as it is no longer used with Go 1.5. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Remove golang.org/x/mobile Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package app
6
7 // Android redirects stdout and stderr to /dev/null.
8 // As these are common debugging utilities in Go,
9 // we redirect them to logcat.
10 //
11 // Unfortunately, logcat is line oriented, so we must buffer.
12
13 /*
14 #cgo LDFLAGS: -llog
15 #include <android/log.h>
16 #include <string.h>
17 */
18 import "C"
19
20 import (
21 "bufio"
22 "log"
23 "os"
24 "unsafe"
25 )
26
27 var (
28 ctag = C.CString("GoStdio")
29 ctagLog = C.CString("GoLog")
30 )
31
32 type infoWriter struct{}
33
34 func (infoWriter) Write(p []byte) (n int, err error) {
35 cstr := C.CString(string(p))
36 C.__android_log_write(C.ANDROID_LOG_INFO, ctagLog, cstr)
37 C.free(unsafe.Pointer(cstr))
38 return len(p), nil
39 }
40
41 func lineLog(f *os.File, priority C.int) {
42 const logSize = 1024 // matches android/log.h.
43 r := bufio.NewReaderSize(f, logSize)
44 for {
45 line, _, err := r.ReadLine()
46 str := string(line)
47 if err != nil {
48 str += " " + err.Error()
49 }
50 cstr := C.CString(str)
51 C.__android_log_write(priority, ctag, cstr)
52 C.free(unsafe.Pointer(cstr))
53 if err != nil {
54 break
55 }
56 }
57 }
58
59 func init() {
60 log.SetOutput(infoWriter{})
61 // android logcat includes all of log.LstdFlags
62 log.SetFlags(log.Flags() &^ log.LstdFlags)
63
64 r, w, err := os.Pipe()
65 if err != nil {
66 panic(err)
67 }
68 os.Stderr = w
69 go lineLog(r, C.ANDROID_LOG_ERROR)
70
71 r, w, err = os.Pipe()
72 if err != nil {
73 panic(err)
74 }
75 os.Stdout = w
76 go lineLog(r, C.ANDROID_LOG_INFO)
77 }
OLDNEW
« no previous file with comments | « third_party/go/src/golang.org/x/mobile/app/loop_android.go ('k') | third_party/go/src/golang.org/x/mobile/app/x11.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698