@@ -329,15 +329,20 @@ func compileArchive(
329329 // If we have cgo, generate separate C and go files, and compile the
330330 // C files.
331331 var objFiles []string
332+ var goSrcsMapping []pathPair
332333 if compilingWithCgo {
333334 var srcDir string
334335 if coverMode != "" && cgoGoSrcsForNogoPath != "" {
335336 // If the package uses Cgo, compile .s and .S files with cgo2, not the Go assembler.
336337 // Otherwise: the .s/.S files will be compiled with the Go assembler later
337- srcDir , goSrcs , objFiles , err = cgo2 (goenv , goSrcs , cgoSrcs , cSrcs , cxxSrcs , objcSrcs , objcxxSrcs , sSrcs , hSrcs , packagePath , packageName , cc , cppFlags , cFlags , cxxFlags , objcFlags , objcxxFlags , ldFlags , cgoExportHPath , "" )
338+ srcDir , goSrcsMapping , objFiles , err = cgo2 (goenv , goSrcs , cgoSrcs , cSrcs , cxxSrcs , objcSrcs , objcxxSrcs , sSrcs , hSrcs , packagePath , packageName , cc , cppFlags , cFlags , cxxFlags , objcFlags , objcxxFlags , ldFlags , cgoExportHPath , "" )
338339 if err != nil {
339340 return err
340341 }
342+ goSrcs = make ([]string , len (goSrcsMapping ))
343+ for i , v := range goSrcsMapping {
344+ goSrcs [i ] = v .workingPath
345+ }
341346 // Also run cgo on original source files, not coverage instrumented, if using nogo.
342347 // The compilation outputs are only used to run cgo, but the generated sources are
343348 // passed to the separate nogo action via cgoGoSrcsForNogoPath.
@@ -348,10 +353,14 @@ func compileArchive(
348353 } else {
349354 // If the package uses Cgo, compile .s and .S files with cgo2, not the Go assembler.
350355 // Otherwise: the .s/.S files will be compiled with the Go assembler later
351- srcDir , goSrcs , objFiles , err = cgo2 (goenv , goSrcs , cgoSrcs , cSrcs , cxxSrcs , objcSrcs , objcxxSrcs , sSrcs , hSrcs , packagePath , packageName , cc , cppFlags , cFlags , cxxFlags , objcFlags , objcxxFlags , ldFlags , cgoExportHPath , cgoGoSrcsForNogoPath )
356+ srcDir , goSrcsMapping , objFiles , err = cgo2 (goenv , goSrcs , cgoSrcs , cSrcs , cxxSrcs , objcSrcs , objcxxSrcs , sSrcs , hSrcs , packagePath , packageName , cc , cppFlags , cFlags , cxxFlags , objcFlags , objcxxFlags , ldFlags , cgoExportHPath , cgoGoSrcsForNogoPath )
352357 if err != nil {
353358 return err
354359 }
360+ goSrcs = make ([]string , len (goSrcsMapping ))
361+ for i , v := range goSrcsMapping {
362+ goSrcs [i ] = v .workingPath
363+ }
355364 }
356365 gcFlags = append (gcFlags , createTrimPath (gcFlags , srcDir ))
357366 } else {
@@ -421,7 +430,7 @@ func compileArchive(
421430 }
422431
423432 // Compile the filtered .go files.
424- if err := compileGo (goenv , goSrcs , packagePath , importcfgPath , embedcfgPath , asmHdrPath , symabisPath , gcFlags , pgoprofile , outLinkObj , outInterfacePath , coverageCfg ); err != nil {
433+ if err := compileGo (goenv , goSrcs , packagePath , importcfgPath , embedcfgPath , asmHdrPath , symabisPath , gcFlags , goSrcsMapping , pgoprofile , outLinkObj , outInterfacePath , coverageCfg ); err != nil {
425434 return err
426435 }
427436
@@ -508,7 +517,7 @@ func checkImportsAndBuildCfg(goenv *env, importPath string, srcs archiveSrcs, de
508517 return importcfgPath , nil
509518}
510519
511- func compileGo (goenv * env , srcs []string , packagePath , importcfgPath , embedcfgPath , asmHdrPath , symabisPath string , gcFlags []string , pgoprofile , outLinkobjPath , outInterfacePath , coverageCfg string ) error {
520+ func compileGo (goenv * env , srcs []string , packagePath , importcfgPath , embedcfgPath , asmHdrPath , symabisPath string , gcFlags []string , paths [] pathPair , pgoprofile , outLinkobjPath , outInterfacePath , coverageCfg string ) error {
512521 args := goenv .goTool ("compile" )
513522 args = append (args , "-p" , packagePath , "-importcfg" , importcfgPath , "-pack" )
514523 if embedcfgPath != "" {
@@ -532,7 +541,7 @@ func compileGo(goenv *env, srcs []string, packagePath, importcfgPath, embedcfgPa
532541 args = append (args , "--" )
533542 args = append (args , srcs ... )
534543 absArgs (args , []string {"-I" , "-o" , "-trimpath" , "-importcfg" })
535- return goenv .runCommand (args )
544+ return goenv .runCommandAndReplacePaths (args , paths )
536545}
537546
538547func appendToArchive (goenv * env , pack , outPath string , objFiles []string ) error {
0 commit comments