MCPcopy Create free account
hub / github.com/golang/mobile / writeGoMod

Function writeGoMod

cmd/gomobile/bind.go:321–348  ·  view source on GitHub ↗

writeGoMod writes go.mod file at dir when Go modules are used.

(dir, targetPlatform, targetArch string)

Source from the content-addressed store, hash-verified

319
320// writeGoMod writes go.mod file at dir when Go modules are used.
321func writeGoMod(dir, targetPlatform, targetArch string) error {
322 m, err := areGoModulesUsed()
323 if err != nil {
324 return err
325 }
326 // If Go modules are not used, go.mod should not be created because the dependencies might not be compatible with Go modules.
327 if !m {
328 return nil
329 }
330
331 return writeFile(filepath.Join(dir, "go.mod"), func(w io.Writer) error {
332 f, err := getModuleVersions(targetPlatform, targetArch, ".")
333 if err != nil {
334 return err
335 }
336 if f == nil {
337 return nil
338 }
339 bs, err := f.Format()
340 if err != nil {
341 return err
342 }
343 if _, err := w.Write(bs); err != nil {
344 return err
345 }
346 return nil
347 })
348}
349
350var (
351 areGoModulesUsedResult struct {

Callers 2

buildAndroidSOFunction · 0.85
goAppleBindFunction · 0.85

Calls 4

areGoModulesUsedFunction · 0.85
writeFileFunction · 0.85
getModuleVersionsFunction · 0.85
WriteMethod · 0.45

Tested by

no test coverage detected