File tree Expand file tree Collapse file tree 5 files changed +78
-0
lines changed
Expand file tree Collapse file tree 5 files changed +78
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
33github.com/inconshreveable/mousetrap v1.1.0 /go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw =
44github.com/russross/blackfriday/v2 v2.1.0 /go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM =
55github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s =
6+ github.com/spf13/cobra v1.10.1 /go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0 =
67github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY =
8+ github.com/spf13/pflag v1.0.9 /go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg =
79gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 /go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0 =
810gopkg.in/yaml.v3 v3.0.1 /go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM =
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ func main() {
2929 rootCmd .AddCommand (CheckStaticCommand ())
3030 rootCmd .AddCommand (CheckByProductCommand ())
3131 rootCmd .AddCommand (CheckDevCommand ())
32+ rootCmd .AddCommand (CheckDebugCommand ())
3233
3334 if err := rootCmd .Execute (); err != nil {
3435 fmt .Println (err )
@@ -117,3 +118,14 @@ func CheckDevCommand() *cobra.Command {
117118 },
118119 }
119120}
121+
122+ func CheckDebugCommand () * cobra.Command {
123+ return & cobra.Command {
124+ Use : "debug <PACKAGE>" ,
125+ Short : "Check and verify the package is a debug package" ,
126+ Args : cobra .ExactArgs (1 ),
127+ RunE : func (cmd * cobra.Command , args []string ) error {
128+ return checkers .CheckDebugPackage (args [0 ])
129+ },
130+ }
131+ }
Original file line number Diff line number Diff line change 1+ package checkers
2+
3+ import (
4+ "fmt"
5+
6+ "github.com/chainguard-dev/cg-tw/package-type-check/pkg/utils"
7+ )
8+
9+ func CheckDebugPackage (pkg string ) error {
10+ fmt .Printf ("Checking if package %s is a valid debug package\n " , pkg )
11+
12+ // Check 1: Package name contains debug indicators
13+ hasDebugName := utils .HasDebugPackageName (pkg )
14+ if ! hasDebugName {
15+ return fmt .Errorf ("FAIL [1/2]: Debug package [%s] does not contain '-dbg' or '-debug' in its name.\n " +
16+ "Debug packages should have '-dbg' or '-debug' in their name" , pkg )
17+ }
18+ fmt .Printf ("PASS [1/2]: Debug package [%s] has debug indicator in name\n " , pkg )
19+
20+ // Check 2: Package contains .debug files in /usr/lib/debug
21+ debugFiles , err := utils .GetDebugSymbolFiles (pkg )
22+ if err != nil {
23+ return err
24+ }
25+ if len (debugFiles ) == 0 {
26+ return fmt .Errorf ("FAIL [2/2]: Debug package [%s] does not contain any .debug files in /usr/lib/debug/.\n " +
27+ "Debug packages must contain debug symbol files" , pkg )
28+ }
29+ fmt .Printf ("PASS [2/2]: Debug package [%s] contains %d debug symbol files\n " , pkg , len (debugFiles ))
30+
31+ return nil
32+ }
Original file line number Diff line number Diff line change @@ -204,3 +204,25 @@ func HasHeaderFiles(pkg string) (bool, error) {
204204 }
205205 return false , nil
206206}
207+
208+ // HasDebugPackageName checks if package name contains debug indicators
209+ func HasDebugPackageName (pkg string ) bool {
210+ return strings .Contains (pkg , "-dbg" ) || strings .Contains (pkg , "-debug" )
211+ }
212+
213+ // GetDebugSymbolFiles finds .debug files in /usr/lib/debug for a package
214+ func GetDebugSymbolFiles (pkg string ) ([]string , error ) {
215+ files , err := GetPackageFiles (pkg )
216+ if err != nil {
217+ return nil , err
218+ }
219+
220+ var debugFiles []string
221+ for _ , file := range files {
222+ if strings .HasPrefix (file , "usr/lib/debug/" ) && strings .HasSuffix (file , ".debug" ) {
223+ debugFiles = append (debugFiles , file )
224+ }
225+ }
226+
227+ return debugFiles , nil
228+ }
Original file line number Diff line number Diff line change 1+ name : Debug Package Check
2+
3+ needs :
4+ packages :
5+ - package-type-check
6+
7+ pipeline :
8+ - name : Check if the package is a Debug Package
9+ runs : |
10+ package-type-check debug "${{context.name}}"
You can’t perform that action at this time.
0 commit comments