Text file src/cmd/go/testdata/script/build_overlay_cgo.txt

     1  [short] skip
     2  [!cgo] skip
     3  
     4  # Test building cgo packages in overlays.
     5  
     6  cd m
     7  
     8  go build -overlay overlay.json -o main_cgo_replace$GOEXE ./cgo_hello_replace
     9  exec ./main_cgo_replace$GOEXE
    10  stdout '^hello cgo\r?\n'
    11  
    12  go build -overlay overlay.json -o main_cgo_quote$GOEXE ./cgo_hello_quote
    13  exec ./main_cgo_quote$GOEXE
    14  stdout '^hello cgo\r?\n'
    15  
    16  go build -overlay overlay.json -o main_cgo_angle$GOEXE ./cgo_hello_angle
    17  exec ./main_cgo_angle$GOEXE
    18  stdout '^hello cgo\r?\n'
    19  
    20  go list -compiled -overlay overlay.json -f '{{range .CompiledGoFiles}}{{. | printf "%s\n"}}{{end}}' ./cgo_hello_replace
    21  cp stdout compiled_cgo_sources.txt
    22  go run ../print_line_comments.go compiled_cgo_sources.txt
    23  stdout $GOPATH[/\\]src[/\\]m[/\\]cgo_hello_replace[/\\]cgo_hello_replace.go
    24  ! stdout $GOPATH[/\\]src[/\\]m[/\\]overlay[/\\]hello.c
    25  
    26  -- m/go.mod --
    27  // TODO(matloob): how do overlays work with go.mod (especially if mod=readonly)
    28  module m
    29  
    30  go 1.16
    31  
    32  -- m/overlay.json --
    33  {
    34  	"Replace": {
    35  		"printpath/main.go": "overlay/printpath.go",
    36  		"printpath/other.go": "overlay2/printpath2.go",
    37  		"call_asm/asm_gc.s": "overlay/asm_gc.s",
    38  		"call_asm/asm_gccgo.s": "overlay/asm_gccgo.s",
    39  		"test_cache/main.go": "overlay/test_cache.go",
    40  		"cgo_hello_replace/cgo_header.h": "overlay/cgo_head.h",
    41  		"cgo_hello_replace/hello.c": "overlay/hello.c",
    42  		"cgo_hello_quote/cgo_hello.go": "overlay/cgo_hello_quote.go",
    43  		"cgo_hello_quote/cgo_header.h": "overlay/cgo_head.h",
    44  		"cgo_hello_angle/cgo_hello.go": "overlay/cgo_hello_angle.go",
    45  		"cgo_hello_angle/cgo_header.h": "overlay/cgo_head.h"
    46  	}
    47  }
    48  -- m/cgo_hello_replace/cgo_hello_replace.go --
    49  package main
    50  
    51  // #include "cgo_header.h"
    52  import "C"
    53  
    54  func main() {
    55  	C.say_hello()
    56  }
    57  -- m/cgo_hello_replace/cgo_header.h --
    58   // Test that this header is replaced with one that has the proper declaration.
    59  void say_goodbye();
    60  
    61  -- m/cgo_hello_replace/hello.c --
    62  #include <stdio.h>
    63  
    64  void say_goodbye() { puts("goodbye cgo\n"); fflush(stdout); }
    65  
    66  -- m/overlay/cgo_hello_quote.go --
    67  package main
    68  
    69  // #include "cgo_header.h"
    70  import "C"
    71  
    72  func main() {
    73  	C.say_hello()
    74  }
    75  -- m/overlay/cgo_hello_angle.go --
    76  package main
    77  
    78  // #include <cgo_header.h>
    79  import "C"
    80  
    81  func main() {
    82  	C.say_hello()
    83  }
    84  -- m/overlay/cgo_head.h --
    85  void say_hello();
    86  -- m/overlay/hello.c --
    87  #include <stdio.h>
    88  
    89  void say_hello() { puts("hello cgo\n"); fflush(stdout); }
    90  -- m/cgo_hello_quote/hello.c --
    91  #include <stdio.h>
    92  
    93  void say_hello() { puts("hello cgo\n"); fflush(stdout); }
    94  -- m/cgo_hello_angle/hello.c --
    95  #include <stdio.h>
    96  
    97  void say_hello() { puts("hello cgo\n"); fflush(stdout); }
    98  
    99  -- print_line_comments.go --
   100  package main
   101  
   102  import (
   103  	"fmt"
   104  	"io/ioutil"
   105  	"log"
   106  	"os"
   107  	"strings"
   108  )
   109  
   110  func main() {
   111  	compiledGoFilesArg := os.Args[1]
   112  	b, err := ioutil.ReadFile(compiledGoFilesArg)
   113  	if err != nil {
   114  		log.Fatal(err)
   115  	}
   116  	compiledGoFiles := strings.Split(strings.TrimSpace(string(b)), "\n")
   117  	for _, f := range compiledGoFiles {
   118  		b, err := ioutil.ReadFile(f)
   119  		if err != nil {
   120  			log.Fatal(err)
   121  		}
   122  		for _, line := range strings.Split(string(b), "\n") {
   123  			if strings.HasPrefix(line, "#line") || strings.HasPrefix(line, "//line") {
   124  				fmt.Println(line)
   125  			}
   126  		}
   127  	}
   128  }
   129  

View as plain text