Skip to content

Commit b0eabb3

Browse files
committed
fix: ignore vendor when explicitly required
1 parent 97bb76c commit b0eabb3

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

tool/instrument/inst_func.go

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func (rp *RuleProcessor) restoreAst(filePath string, root *dst.File) (string, er
6868
return arg == filePath
6969
})
7070
if err != nil {
71+
err = errc.Adhere(err, "filePath", filePath)
7172
err = errc.Adhere(err, "compileArgs", strings.Join(rp.compileArgs, " "))
7273
err = errc.Adhere(err, "newArg", newFile)
7374
return "", err

tool/preprocess/preprocess.go

+17-4
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,23 @@ func (dp *DepProcessor) init() error {
258258
util.Log("Found sources %v", dp.sources)
259259

260260
// Check if the build mode
261-
// FIXME: vendor directory name can be anything, but we assume it's "vendor"
262-
// for now
263-
vendor := filepath.Join(dp.getGoModDir(), VendorDir)
264-
dp.vendorBuild = util.PathExists(vendor)
261+
ignoreVendor := false
262+
for _, arg := range dp.goBuildCmd {
263+
// -mod=mod and -mod=readonly tells the go command to ignore the vendor
264+
// directory. We should not use the vendor directory in this case.
265+
if strings.HasPrefix(arg, "-mod=mod") ||
266+
strings.HasPrefix(arg, "-mod=readonly") {
267+
dp.vendorBuild = false
268+
ignoreVendor = true
269+
break
270+
}
271+
}
272+
if !ignoreVendor {
273+
// FIXME: vendor directory name can be anything, but we assume it's "vendor"
274+
// for now
275+
vendor := filepath.Join(dp.getGoModDir(), VendorDir)
276+
dp.vendorBuild = util.PathExists(vendor)
277+
}
265278
util.Log("Vendor build: %v", dp.vendorBuild)
266279

267280
// Register signal handler to catch up SIGINT/SIGTERM interrupt signals and

tool/preprocess/setup.go

+4
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ func (dp *DepProcessor) initRules() (err error) {
294294

295295
// Write to ${GOMOD.DIR}/otel_rules/otel_setup_inst.go
296296
initTarget := dp.generatedOf(filepath.Join(OtelRules, OtelSetupInst))
297+
err = os.MkdirAll(filepath.Dir(initTarget), 0777)
298+
if err != nil {
299+
return err
300+
}
297301
_, err = util.WriteFile(initTarget, c)
298302
if err != nil {
299303
return err

0 commit comments

Comments
 (0)