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

Side by Side Diff: experimental/webtry/webtry.go

Issue 578013003: fixes to linux build for webtry (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix linux run; don't try to mix SK_DEBUG with a release build! Created 6 years, 3 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
« no previous file with comments | « experimental/webtry/templates/template.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 package main 1 package main
2 2
3 import ( 3 import (
4 "bytes" 4 "bytes"
5 "crypto/md5" 5 "crypto/md5"
6 "database/sql" 6 "database/sql"
7 "encoding/base64" 7 "encoding/base64"
8 "encoding/binary" 8 "encoding/binary"
9 "encoding/json" 9 "encoding/json"
10 "flag" 10 "flag"
(...skipping 18 matching lines...) Expand all
29 ) 29 )
30 30
31 import ( 31 import (
32 "github.com/fiorix/go-web/autogzip" 32 "github.com/fiorix/go-web/autogzip"
33 _ "github.com/go-sql-driver/mysql" 33 _ "github.com/go-sql-driver/mysql"
34 _ "github.com/mattn/go-sqlite3" 34 _ "github.com/mattn/go-sqlite3"
35 "github.com/rcrowley/go-metrics" 35 "github.com/rcrowley/go-metrics"
36 ) 36 )
37 37
38 const ( 38 const (
39 » RUN_GYP = `../../experimental/webtry/gyp_for_webtry %s` 39 » RUN_GYP = `../../experimental/webtry/gyp_for_webtry %s -Dskia_gpu=0`
40 » RUN_NINJA = `ninja -C ../../../inout/Release %s` 40 » RUN_NINJA = `ninja -C ../../../inout/Release %s`
41 41
42 DEFAULT_SAMPLE = `void draw(SkCanvas* canvas) { 42 DEFAULT_SAMPLE = `void draw(SkCanvas* canvas) {
43 SkPaint p; 43 SkPaint p;
44 p.setColor(SK_ColorRED); 44 p.setColor(SK_ColorRED);
45 p.setAntiAlias(true); 45 p.setAntiAlias(true);
46 p.setStyle(SkPaint::kStroke_Style); 46 p.setStyle(SkPaint::kStroke_Style);
47 p.setStrokeWidth(10); 47 p.setStrokeWidth(10);
48 48
49 canvas->drawLine(20, 20, 100, 100, p); 49 canvas->drawLine(20, 20, 100, 100, p);
50 }` 50 }`
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 } 337 }
338 338
339 // userCode is used in template expansion. 339 // userCode is used in template expansion.
340 type userCode struct { 340 type userCode struct {
341 Code string 341 Code string
342 Hash string 342 Hash string
343 Source int 343 Source int
344 Titlebar Titlebar 344 Titlebar Titlebar
345 } 345 }
346 346
347 // writeTemplate creates a given output file and writes the template 347 // writeTemplate creates a given output file and writes the template
348 // result there. 348 // result there.
349 func writeTemplate(filename string, t *template.Template, context interface{}) e rror { 349 func writeTemplate(filename string, t *template.Template, context interface{}) e rror {
350 f, err := os.Create(filename) 350 f, err := os.Create(filename)
351 if err != nil { 351 if err != nil {
352 return err 352 return err
353 } 353 }
354 defer f.Close() 354 defer f.Close()
355 » return t.Execute( f, context ) 355 » return t.Execute(f, context)
356 } 356 }
357 357
358 // expandToFile expands the template and writes the result to the file. 358 // expandToFile expands the template and writes the result to the file.
359 func expandToFile(filename string, code string, t *template.Template) error { 359 func expandToFile(filename string, code string, t *template.Template) error {
360 » return writeTemplate( filename, t, userCode{Code: code, Titlebar: Titleb ar{GitHash: gitHash, GitInfo: gitInfo}} ) 360 » return writeTemplate(filename, t, userCode{Code: code, Titlebar: Titleba r{GitHash: gitHash, GitInfo: gitInfo}})
361 } 361 }
362 362
363 // expandCode expands the template into a file and calculates the MD5 hash. 363 // expandCode expands the template into a file and calculates the MD5 hash.
364 func expandCode(code string, source int) (string, error) { 364 func expandCode(code string, source int) (string, error) {
365 h := md5.New() 365 h := md5.New()
366 h.Write([]byte(code)) 366 h.Write([]byte(code))
367 binary.Write(h, binary.LittleEndian, int64(source)) 367 binary.Write(h, binary.LittleEndian, int64(source))
368 hash := fmt.Sprintf("%x", h.Sum(nil)) 368 hash := fmt.Sprintf("%x", h.Sum(nil))
369 // At this point we are running in skia/experimental/webtry, making cach e a 369 // At this point we are running in skia/experimental/webtry, making cach e a
370 // peer directory to skia. 370 // peer directory to skia.
371 // TODO(jcgregorio) Make all relative directories into flags. 371 // TODO(jcgregorio) Make all relative directories into flags.
372 err := expandToFile(fmt.Sprintf("../../../cache/src/%s.cpp", hash), code , codeTemplate) 372 err := expandToFile(fmt.Sprintf("../../../cache/src/%s.cpp", hash), code , codeTemplate)
373 return hash, err 373 return hash, err
374 } 374 }
375 375
376 // expandGyp produces the GYP file needed to build the code 376 // expandGyp produces the GYP file needed to build the code
377 func expandGyp(hash string) (error) { 377 func expandGyp(hash string) error {
378 » return writeTemplate(fmt.Sprintf("../../../cache/%s.gyp", hash), gypTemp late, struct {Hash string}{hash} ) 378 » return writeTemplate(fmt.Sprintf("../../../cache/%s.gyp", hash), gypTemp late, struct{ Hash string }{hash})
379 } 379 }
380 380
381 // response is serialized to JSON as a response to POSTs. 381 // response is serialized to JSON as a response to POSTs.
382 type response struct { 382 type response struct {
383 Message string `json:"message"` 383 Message string `json:"message"`
384 StdOut string `json:"stdout"` 384 StdOut string `json:"stdout"`
385 Img string `json:"img"` 385 Img string `json:"img"`
386 Hash string `json:"hash"` 386 Hash string `json:"hash"`
387 } 387 }
388 388
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 http.HandleFunc("/sources/", autogzip.HandleFunc(sourcesHandler)) 886 http.HandleFunc("/sources/", autogzip.HandleFunc(sourcesHandler))
887 887
888 // Resources are served directly 888 // Resources are served directly
889 // TODO add support for caching/etags/gzip 889 // TODO add support for caching/etags/gzip
890 http.Handle("/res/", autogzip.Handle(http.FileServer(http.Dir("./")))) 890 http.Handle("/res/", autogzip.Handle(http.FileServer(http.Dir("./"))))
891 891
892 // TODO Break out /c/ as it's own handler. 892 // TODO Break out /c/ as it's own handler.
893 http.HandleFunc("/", autogzip.HandleFunc(mainHandler)) 893 http.HandleFunc("/", autogzip.HandleFunc(mainHandler))
894 log.Fatal(http.ListenAndServe(*port, nil)) 894 log.Fatal(http.ListenAndServe(*port, nil))
895 } 895 }
OLDNEW
« no previous file with comments | « experimental/webtry/templates/template.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698