MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/buildpacks / writeBuildAndRunScript

Function writeBuildAndRunScript

pkg/devmode/devmode.go:89–116  ·  view source on GitHub ↗

writeBuildAndRunScript writes the contents of a file that builds code and then runs the resulting program

(ctx *gcp.Context, sl *libcnb.Layer, cfg Config)

Source from the content-addressed store, hash-verified

87
88// writeBuildAndRunScript writes the contents of a file that builds code and then runs the resulting program
89func writeBuildAndRunScript(ctx *gcp.Context, sl *libcnb.Layer, cfg Config) error {
90 sl.Launch = true
91 binDir := filepath.Join(sl.Path, "bin")
92 if err := ctx.MkdirAll(binDir, 0755); err != nil {
93 return err
94 }
95
96 var cmd []string
97 if cfg.BuildCmd != nil {
98 cmd = append(cmd, strings.Join(cfg.BuildCmd, " "))
99 }
100 if cfg.RunCmd != nil {
101 cmd = append(cmd, strings.Join(cfg.RunCmd, " "))
102 }
103
104 c := fmt.Sprintf("#!/bin/sh\n%s", strings.Join(cmd, " && "))
105 br := filepath.Join(binDir, buildAndRun)
106 if err := ctx.WriteFile(br, []byte(c), os.FileMode(0755)); err != nil {
107 return err
108 }
109
110 c = fmt.Sprintf("#!/bin/sh\nwatchexec -r -e %s %s", strings.Join(cfg.Ext, ","), br)
111 wr := filepath.Join(binDir, WatchAndRun)
112 if err := ctx.WriteFile(wr, []byte(c), os.FileMode(0755)); err != nil {
113 return err
114 }
115 return nil
116}
117
118// installFileWatcher installs the `watchexec` file watcher.
119func installFileWatcher(ctx *gcp.Context) error {

Callers 2

AddFileWatcherProcessFunction · 0.85
TestWriteAndRunScriptsFunction · 0.85

Calls 2

MkdirAllMethod · 0.80
WriteFileMethod · 0.80

Tested by 1

TestWriteAndRunScriptsFunction · 0.68