| OLD | NEW |
| 1 package common | 1 package common |
| 2 | 2 |
| 3 import ( | 3 import ( |
| 4 "fmt" | 4 "fmt" |
| 5 "os" | 5 "os" |
| 6 "path/filepath" | 6 "path/filepath" |
| 7 | 7 |
| 8 "github.com/skia-dev/glog" | 8 "github.com/skia-dev/glog" |
| 9 "go.skia.org/infra/fuzzer/go/config" | 9 "go.skia.org/infra/fuzzer/go/config" |
| 10 "go.skia.org/infra/go/exec" | 10 "go.skia.org/infra/go/exec" |
| 11 ) | 11 ) |
| 12 | 12 |
| 13 // BuildClangHarness builds the test harness for parsing skp files using clang.
If any step fails, it returns an error. | 13 // BuildClangHarness builds the test harness for parsing skp files using clang.
If any step fails, |
| 14 // it returns an error. |
| 14 func BuildClangHarness(buildType string, isClean bool) error { | 15 func BuildClangHarness(buildType string, isClean bool) error { |
| 16 glog.Infof("Building %s clang harness", buildType) |
| 15 buildVars := []string{ | 17 buildVars := []string{ |
| 16 fmt.Sprintf("CC=%s", config.Common.ClangPath), | 18 fmt.Sprintf("CC=%s", config.Common.ClangPath), |
| 17 fmt.Sprintf("CXX=%s", config.Common.ClangPlusPlusPath), | 19 fmt.Sprintf("CXX=%s", config.Common.ClangPlusPlusPath), |
| 18 } | 20 } |
| 19 return buildHarness(buildType, isClean, buildVars) | 21 return buildHarness(buildType, isClean, buildVars) |
| 20 } | 22 } |
| 21 | 23 |
| 22 // BuildFuzzingHarness builds the test harness for parsing skp files using afl-i
nstrumented clang. If any step fails, it returns an error. | 24 // BuildASANHarness builds the test harness for parsing skp files using clang an
d AddressSanitizer. |
| 25 // If any step fails, it returns an error. |
| 26 func BuildASANHarness(buildType string, isClean bool) error { |
| 27 » glog.Infof("Building %s ASAN harness", buildType) |
| 28 » buildVars := []string{ |
| 29 » » fmt.Sprintf("CC=%s", config.Common.ClangPath), |
| 30 » » fmt.Sprintf("CXX=%s", config.Common.ClangPlusPlusPath), |
| 31 » » "CXXFLAGS=-O1 -g -fsanitize=address -fno-omit-frame-pointer", |
| 32 » » "LDFLAGS=-g -fsanitize=address", |
| 33 » » ASAN_OPTIONS, |
| 34 » } |
| 35 » return buildHarness(buildType, isClean, buildVars) |
| 36 } |
| 37 |
| 38 // BuildFuzzingHarness builds the test harness for parsing skp files using afl-i
nstrumented clang. |
| 39 // If any step fails, it returns an error. |
| 23 func BuildFuzzingHarness(buildType string, isClean bool) error { | 40 func BuildFuzzingHarness(buildType string, isClean bool) error { |
| 41 glog.Infof("Building %s fuzzing harness", buildType) |
| 24 buildVars := []string{ | 42 buildVars := []string{ |
| 25 fmt.Sprintf("CC=%s", filepath.Join(config.Generator.AflRoot, "af
l-clang")), | 43 fmt.Sprintf("CC=%s", filepath.Join(config.Generator.AflRoot, "af
l-clang")), |
| 26 fmt.Sprintf("CXX=%s", filepath.Join(config.Generator.AflRoot, "a
fl-clang++")), | 44 fmt.Sprintf("CXX=%s", filepath.Join(config.Generator.AflRoot, "a
fl-clang++")), |
| 27 } | 45 } |
| 28 | 46 |
| 29 return buildHarness(buildType, isClean, buildVars) | 47 return buildHarness(buildType, isClean, buildVars) |
| 30 } | 48 } |
| 31 | 49 |
| 32 // buildHarness builds the test harness for parsing skp (and other) files. | 50 // buildHarness builds the test harness for parsing skp (and other) files. |
| 33 // First it creates a hard link for the gyp and cpp files. The gyp file is linke
d into Skia's gyp folder and the cpp file is linked into SKIA_ROOT/../fuzzer_cac
he/src, which is where the gyp file is configured to point. | 51 // First it creates a hard link for the gyp and cpp files. The gyp file is linke
d into Skia's gyp folder and the cpp file is linked into SKIA_ROOT/../fuzzer_cac
he/src, which is where the gyp file is configured to point. |
| 34 // Then it activates Skia's gyp command, which creates the build (ninja) files. | 52 // Then it activates Skia's gyp command, which creates the build (ninja) files. |
| 35 // Finally, it runs those build files. | 53 // Finally, it runs those build files. |
| 36 // If any step fails in unexpected ways, it returns an error. | 54 // If any step fails in unexpected ways, it returns an error. |
| 37 func buildHarness(buildType string, isClean bool, buildVars []string) error { | 55 func buildHarness(buildType string, isClean bool, buildVars []string) error { |
| 38 glog.Infof("Building %s fuzzing harness", buildType) | |
| 39 | |
| 40 // clean previous build if specified | 56 // clean previous build if specified |
| 41 buildLocation := filepath.Join("out", buildType) | 57 buildLocation := filepath.Join("out", buildType) |
| 42 if isClean { | 58 if isClean { |
| 43 if err := os.RemoveAll(filepath.Join(config.Generator.SkiaRoot,
buildLocation)); err != nil { | 59 if err := os.RemoveAll(filepath.Join(config.Generator.SkiaRoot,
buildLocation)); err != nil { |
| 44 return fmt.Errorf("Could not clear out %s before buildin
g: %s", filepath.Join(config.Generator.SkiaRoot, buildLocation), err) | 60 return fmt.Errorf("Could not clear out %s before buildin
g: %s", filepath.Join(config.Generator.SkiaRoot, buildLocation), err) |
| 45 } | 61 } |
| 46 } | 62 } |
| 47 | 63 |
| 48 gypCmd := &exec.Command{ | 64 gypCmd := &exec.Command{ |
| 49 Name: "./gyp_skia", | 65 Name: "./gyp_skia", |
| 50 Dir: config.Generator.SkiaRoot, | 66 Dir: config.Generator.SkiaRoot, |
| 51 » » LogStdout: false, | 67 » » LogStdout: config.Common.VerboseBuilds, |
| 52 » » LogStderr: false, | 68 » » LogStderr: config.Common.VerboseBuilds, |
| 53 Env: append(buildVars, "GYP_DEFINES=skia_clang_build=1"), | 69 Env: append(buildVars, "GYP_DEFINES=skia_clang_build=1"), |
| 54 } | 70 } |
| 55 | 71 |
| 56 // run gyp | 72 // run gyp |
| 57 if err := exec.Run(gypCmd); err != nil { | 73 if err := exec.Run(gypCmd); err != nil { |
| 58 return fmt.Errorf("Failed gyp: %s", err) | 74 return fmt.Errorf("Failed gyp: %s", err) |
| 59 } | 75 } |
| 60 | 76 |
| 61 ninjaPath := filepath.Join(config.Common.DepotToolsPath, "ninja") | 77 ninjaPath := filepath.Join(config.Common.DepotToolsPath, "ninja") |
| 62 | 78 |
| 63 ninjaCmd := &exec.Command{ | 79 ninjaCmd := &exec.Command{ |
| 64 Name: ninjaPath, | 80 Name: ninjaPath, |
| 65 Args: []string{"-C", buildLocation, "fuzz"}, | 81 Args: []string{"-C", buildLocation, "fuzz"}, |
| 66 » » LogStdout: true, | 82 » » LogStdout: config.Common.VerboseBuilds, |
| 67 LogStderr: true, | 83 LogStderr: true, |
| 68 InheritPath: true, | 84 InheritPath: true, |
| 69 Dir: config.Generator.SkiaRoot, | 85 Dir: config.Generator.SkiaRoot, |
| 70 Env: buildVars, | 86 Env: buildVars, |
| 71 } | 87 } |
| 72 | 88 |
| 73 // run ninja | 89 // run ninja |
| 74 return exec.Run(ninjaCmd) | 90 return exec.Run(ninjaCmd) |
| 75 } | 91 } |
| OLD | NEW |