github.com/metux/go-metabuild@v0.0.0-20240118143255-d9ed5ab697f9/engine/autoconf/probe/main.go (about) 1 // This package contains the actual probes for auto configuration 2 package probe 3 4 import ( 5 "github.com/metux/go-metabuild/spec" 6 "github.com/metux/go-metabuild/spec/check" 7 ) 8 9 type Key = spec.Key 10 type Check = spec.Check 11 12 func mkProbe(chk Check) ProbeInterface { 13 switch Key(chk.Type()) { 14 case check.KeyCHeader: 15 return MakeProbeCHeader(chk) 16 case check.KeyCFunction: 17 return MakeProbeCFunction(chk) 18 case check.KeyCType: 19 return MakeProbeCType(chk) 20 case check.KeyPkgConfig: 21 return MakeProbePkgConfig(chk) 22 case check.KeyCCompiler: 23 return MakeProbeCCompiler(chk) 24 case check.KeyCXXCompiler: 25 return MakeProbeCXXCompiler(chk) 26 case check.KeyTargetDistro: 27 return MakeProbeTargetDistro(chk) 28 case check.KeyGitDescribe: 29 return MakeGitDescribe(chk) 30 case check.KeyI18nLinguas: 31 return MakeI18nLinguas(chk) 32 } 33 return nil 34 } 35 36 // FIXME: store error in cache ? 37 func Probe(chk Check) bool { 38 probe := mkProbe(chk) 39 if probe == nil { 40 panic("unsupported check: " + chk.Type()) 41 } 42 43 chk.Logf("checking: %s", chk) 44 45 // check for cached value ? 46 if cached, cacheval := chk.Cached(); cached { 47 chk.Logf("cached: %t", cacheval) 48 return cacheval 49 } 50 51 if err := probe.Probe(); err != nil { 52 chk.Logf("check failed: %s\n", err) 53 chk.Done(false) 54 return false 55 } 56 57 chk.Done(true) 58 return true 59 }