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

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

Issue 619943002: complete overhaul of webtry work partition between jail and host (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix formatting in continue_install.sh" Created 6 years, 2 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
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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 filepath.Join(cwd, "templates/footercommon.html"), 193 filepath.Join(cwd, "templates/footercommon.html"),
194 ) 194 )
195 if err != nil { 195 if err != nil {
196 panic(err) 196 panic(err)
197 } 197 }
198 198
199 // The git command returns output of the format: 199 // The git command returns output of the format:
200 // 200 //
201 // f672cead70404080a991ebfb86c38316a4589b23 2014-04-27 19:21:51 +0000 201 // f672cead70404080a991ebfb86c38316a4589b23 2014-04-27 19:21:51 +0000
202 // 202 //
203 » logOutput, err := doCmd(`git log --format=%H%x20%ai HEAD^..HEAD`, true) 203 » logOutput, err := doCmd(`git log --format=%H%x20%ai HEAD^..HEAD`)
204 if err != nil { 204 if err != nil {
205 panic(err) 205 panic(err)
206 } 206 }
207 logInfo := strings.Split(logOutput, " ") 207 logInfo := strings.Split(logOutput, " ")
208 gitHash = logInfo[0] 208 gitHash = logInfo[0]
209 gitInfo = logInfo[1] + " " + logInfo[2] + " " + logInfo[0][0:6] 209 gitInfo = logInfo[1] + " " + logInfo[2] + " " + logInfo[0][0:6]
210 210
211 // Connect to MySQL server. First, get the password from the metadata se rver. 211 // Connect to MySQL server. First, get the password from the metadata se rver.
212 // See https://developers.google.com/compute/docs/metadata#custom. 212 // See https://developers.google.com/compute/docs/metadata#custom.
213 req, err := http.NewRequest("GET", "http://metadata/computeMetadata/v1/i nstance/attributes/password", nil) 213 req, err := http.NewRequest("GET", "http://metadata/computeMetadata/v1/i nstance/attributes/password", nil)
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 } 387 }
388 388
389 // response is serialized to JSON as a response to POSTs. 389 // response is serialized to JSON as a response to POSTs.
390 type response struct { 390 type response struct {
391 Message string `json:"message"` 391 Message string `json:"message"`
392 StdOut string `json:"stdout"` 392 StdOut string `json:"stdout"`
393 Img string `json:"img"` 393 Img string `json:"img"`
394 Hash string `json:"hash"` 394 Hash string `json:"hash"`
395 } 395 }
396 396
397 // doCmd executes the given command line string in either the out/Debug 397 // doCmd executes the given command line string; the command being
398 // directory or the inout directory. Returns the stdout and stderr. 398 // run is expected to not care what its current working directory is.
399 func doCmd(commandLine string, moveToDebug bool) (string, error) { 399 // Returns the stdout and stderr.
400 func doCmd(commandLine string) (string, error) {
400 log.Printf("Command: %q\n", commandLine) 401 log.Printf("Command: %q\n", commandLine)
401 programAndArgs := strings.SplitN(commandLine, " ", 2) 402 programAndArgs := strings.SplitN(commandLine, " ", 2)
402 program := programAndArgs[0] 403 program := programAndArgs[0]
403 args := []string{} 404 args := []string{}
404 if len(programAndArgs) > 1 { 405 if len(programAndArgs) > 1 {
405 args = strings.Split(programAndArgs[1], " ") 406 args = strings.Split(programAndArgs[1], " ")
406 } 407 }
407 cmd := exec.Command(program, args...) 408 cmd := exec.Command(program, args...)
408 abs, err := filepath.Abs("../../out/Debug")
409 if err != nil {
410 return "", fmt.Errorf("Failed to find absolute path to Debug dir ectory.")
411 }
412 if moveToDebug {
413 cmd.Dir = abs
414 } else if !*useChroot { // Don't set cmd.Dir when using chroot.
415 abs, err := filepath.Abs("../../../inout")
416 if err != nil {
417 return "", fmt.Errorf("Failed to find absolute path to i nout directory.")
418 }
419 cmd.Dir = abs
420 }
421 log.Printf("Run in directory: %q\n", cmd.Dir)
422 message, err := cmd.CombinedOutput() 409 message, err := cmd.CombinedOutput()
423 log.Printf("StdOut + StdErr: %s\n", string(message)) 410 log.Printf("StdOut + StdErr: %s\n", string(message))
424 if err != nil { 411 if err != nil {
425 log.Printf("Exit status: %s\n", err.Error()) 412 log.Printf("Exit status: %s\n", err.Error())
426 return string(message), fmt.Errorf("Failed to run command.") 413 return string(message), fmt.Errorf("Failed to run command.")
427 } 414 }
428 return string(message), nil 415 return string(message), nil
429 } 416 }
430 417
431 // reportError formats an HTTP error response and also logs the detailed error m essage. 418 // reportError formats an HTTP error response and also logs the detailed error m essage.
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 if err != nil { 809 if err != nil {
823 reportTryError(w, r, err, "Failed to write the code to c ompile.", hash) 810 reportTryError(w, r, err, "Failed to write the code to c ompile.", hash)
824 return 811 return
825 } 812 }
826 writeToDatabase(hash, request.Code, request.Name, request.Source ) 813 writeToDatabase(hash, request.Code, request.Name, request.Source )
827 err = expandGyp(hash) 814 err = expandGyp(hash)
828 if err != nil { 815 if err != nil {
829 reportTryError(w, r, err, "Failed to write the gyp file. ", hash) 816 reportTryError(w, r, err, "Failed to write the gyp file. ", hash)
830 return 817 return
831 } 818 }
832 » » message, err := doCmd(fmt.Sprintf(RUN_GYP, hash), true) 819 » » //cmd := hash + " --out " + hash + ".png"
jcgregorio 2014/10/01 16:39:50 commented out code?
humper 2014/10/01 17:02:44 Whoops! jumped the gun and failed to add support
820 » » //if request.Source > 0 {
821 » » » //cmd += fmt.Sprintf(" --source image-%d.png", request. Source)
822 » » //}
823 » » cmd := "scripts/fiddle_wrapper " + hash
824 » » if *useChroot {
825 » » » cmd = "schroot -c webtry --directory=/ -- /skia_build/sk ia/experimental/webtry/" + cmd
826 » » }
827
828 » » message, err := doCmd(cmd)
833 if err != nil { 829 if err != nil {
834 » » » message = cleanCompileOutput(message, hash) 830 » » » reportTryError(w, r, err, "Failed to run the code:\n"+me ssage, hash)
835 » » » reportTryError(w, r, err, message, hash)
836 » » » return
837 » » }
838 » » linkMessage, err := doCmd(fmt.Sprintf(RUN_NINJA, hash), true)
839 » » if err != nil {
840 » » » linkMessage = cleanCompileOutput(linkMessage, hash)
841 » » » reportTryError(w, r, err, linkMessage, hash)
842 » » » return
843 » » }
844 » » message += linkMessage
845 » » cmd := hash + " --out " + hash + ".png"
846 » » if request.Source > 0 {
847 » » » cmd += fmt.Sprintf(" --source image-%d.png", request.So urce)
848 » » }
849 » » if *useChroot {
850 » » » cmd = "schroot -c webtry --directory=/inout -- /inout/Re lease/" + cmd
851 » » } else {
852 » » » abs, err := filepath.Abs("../../../inout/Release")
853 » » » if err != nil {
854 » » » » reportTryError(w, r, err, "Failed to find execut able directory.", hash)
855 » » » » return
856 » » » }
857 » » » cmd = abs + "/" + cmd
858 » » }
859
860 » » execMessage, err := doCmd(cmd, false)
861 » » if err != nil {
862 » » » reportTryError(w, r, err, "Failed to run the code:\n"+ex ecMessage, hash)
863 return 831 return
864 } 832 }
865 png, err := ioutil.ReadFile("../../../inout/" + hash + ".png") 833 png, err := ioutil.ReadFile("../../../inout/" + hash + ".png")
866 if err != nil { 834 if err != nil {
867 reportTryError(w, r, err, "Failed to open the generated PNG.", hash) 835 reportTryError(w, r, err, "Failed to open the generated PNG.", hash)
868 return 836 return
869 } 837 }
870 838
871 m := response{ 839 m := response{
872 Message: message, 840 Message: message,
873 StdOut: execMessage,
874 Img: base64.StdEncoding.EncodeToString([]byte(png)), 841 Img: base64.StdEncoding.EncodeToString([]byte(png)),
875 Hash: hash, 842 Hash: hash,
876 } 843 }
877 resp, err := json.Marshal(m) 844 resp, err := json.Marshal(m)
878 if err != nil { 845 if err != nil {
879 reportTryError(w, r, err, "Failed to serialize a respons e.", hash) 846 reportTryError(w, r, err, "Failed to serialize a respons e.", hash)
880 return 847 return
881 } 848 }
882 w.Header().Set("Content-Type", "application/json") 849 w.Header().Set("Content-Type", "application/json")
883 w.Write(resp) 850 w.Write(resp)
(...skipping 10 matching lines...) Expand all
894 http.HandleFunc("/sources/", autogzip.HandleFunc(sourcesHandler)) 861 http.HandleFunc("/sources/", autogzip.HandleFunc(sourcesHandler))
895 862
896 // Resources are served directly 863 // Resources are served directly
897 // TODO add support for caching/etags/gzip 864 // TODO add support for caching/etags/gzip
898 http.Handle("/res/", autogzip.Handle(http.FileServer(http.Dir("./")))) 865 http.Handle("/res/", autogzip.Handle(http.FileServer(http.Dir("./"))))
899 866
900 // TODO Break out /c/ as it's own handler. 867 // TODO Break out /c/ as it's own handler.
901 http.HandleFunc("/", autogzip.HandleFunc(mainHandler)) 868 http.HandleFunc("/", autogzip.HandleFunc(mainHandler))
902 log.Fatal(http.ListenAndServe(*port, nil)) 869 log.Fatal(http.ListenAndServe(*port, nil))
903 } 870 }
OLDNEW
« experimental/webtry/setup/webtry_setup.sh ('K') | « experimental/webtry/templates/template.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698