...

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

Documentation: cmd/go/testdata/script

     1# This is a test that -trimpath trims the paths of every directory
     2# of Cgo dependencies in the module, and trims file paths included
     3# through the __FILE__ macro using --file-prefix-map.
     4
     5[!cgo] skip
     6[short] skip 'links and runs binaries'
     7
     8# Test in main module.
     9go run -trimpath -mod=vendor ./main
    10stdout '(\\_\\_|/_)[\\/]m[\\/]c[\\/]bar.h'
    11
    12# Test in vendored module.
    13go run -trimpath -mod=vendor v.com/main
    14stdout '(\\_\\_|/_)[\\/]vendor[\\/]v.com[\\/]c[\\/]bar.h'
    15
    16# Test in GOPATH mode.
    17env GO111MODULE=off
    18go run -trimpath ./main
    19stdout '(\\_\\_|/_)[\\/]GOPATH[\\/]src[\\/]c[\\/]bar.h'
    20
    21-- go.mod --
    22module m
    23
    24require v.com v1.0.0
    25-- go.sum --
    26v.com v1.0.0 h1:xxx
    27v.com v1.0.0/go.mod h1:xxx
    28-- vendor/modules.txt --
    29# v.com v1.0.0
    30## explicit; go 1.20
    31v.com/main
    32-- vendor/v.com/main/main.go --
    33package main
    34
    35// #cgo CFLAGS: -I../c
    36// #include "stdio.h"
    37// void printfile();
    38import "C"
    39
    40func main() {
    41    C.printfile()
    42    C.fflush(C.stdout)
    43}
    44-- vendor/v.com/main/foo.c --
    45#include "bar.h"
    46-- vendor/v.com/c/bar.h --
    47#include "stdio.h"
    48
    49void printfile() {
    50    printf("%s\n", __FILE__);
    51}
    52-- main/main.go --
    53package main
    54
    55// #cgo CFLAGS: -I../c
    56// #include "stdio.h"
    57// void printfile();
    58import "C"
    59
    60func main() {
    61    C.printfile()
    62    C.fflush(C.stdout)
    63}
    64-- main/foo.c --
    65#include "bar.h"
    66-- c/bar.h --
    67#include "stdio.h"
    68
    69void printfile() {
    70    printf("%s\n", __FILE__);
    71}

View as plain text