@@ -70,8 +70,7 @@ type flags struct {
7070 Extract struct {
7171 OutputDir string `kong:"help='Output directory path to use for extracted debug information files.',default='out'"`
7272
73- Paths []string `kong:"required,arg,name='path',help='Paths to extract debug information.',type:'path'"`
74- CompressDWARFSections bool `kong:"default=false,help:'Compress debuginfo files DWARF sections before uploading.'"`
73+ Paths []string `kong:"required,arg,name='path',help='Paths to extract debug information.',type:'path'"`
7574 } `cmd:"" help:"Extract debug information."`
7675
7776 Buildid struct {
@@ -93,19 +92,7 @@ func main() {
9392 }
9493}
9594
96- type uploadInfo struct {
97- buildID string
98- path string
99- reader io.ReadSeeker
100- size int64
101- }
102-
10395func run (kongCtx * kong.Context , flags flags ) error {
104- opts := []elfwriter.Option {}
105- if flags .Extract .CompressDWARFSections {
106- opts = append (opts , elfwriter .WithCompressDWARFSections ())
107- }
108-
10996 var g grun.Group
11097 ctx , cancel := context .WithCancel (context .Background ())
11198 switch kongCtx .Command () {
@@ -198,12 +185,12 @@ func run(kongCtx *kong.Context, flags flags) error {
198185 return fmt .Errorf ("check if upload should be initiated for %q with Build ID %q: %w" , flags .Upload .Path , buildID , err )
199186 }
200187 if ! shouldInitiate .ShouldInitiateUpload {
201- fmt .Fprintf (os .Stdout , "Skipping upload of %q with Build ID %q as the store instructed not to: %s\n " , flags .Upload .Path , buildID , shouldInitiate .Reason )
188+ fmt .Fprintf (os .Stdout , "Skipping upload of %q with Build ID %q as the store instructed not to: %s\n " , flags .Upload .Path , buildID , shouldInitiate .GetReason () )
202189 return nil
203190 }
204191
205192 if flags .Upload .NoInitiate {
206- fmt .Fprintf (os .Stdout , "Not initiating upload of %q with Build ID %q as requested, but would have requested that next, because: %s\n " , flags .Upload .Path , buildID , shouldInitiate .Reason )
193+ fmt .Fprintf (os .Stdout , "Not initiating upload of %q with Build ID %q as requested, but would have requested that next, because: %s\n " , flags .Upload .Path , buildID , shouldInitiate .GetReason () )
207194 return nil
208195 }
209196
@@ -228,32 +215,32 @@ func run(kongCtx *kong.Context, flags flags) error {
228215 }
229216
230217 if flags .LogLevel == LogLevelDebug {
231- fmt .Fprintf (os .Stdout , "Upload instructions\n BuildID: %s\n UploadID: %s\n UploadStrategy: %s\n SignedURL: %s\n Type: %s\n " , initiationResp .UploadInstructions . BuildId , initiationResp .UploadInstructions . UploadId , initiationResp .UploadInstructions . UploadStrategy .String (), initiationResp .UploadInstructions . SignedUrl , initiationResp .UploadInstructions . Type )
218+ fmt .Fprintf (os .Stdout , "Upload instructions\n BuildID: %s\n UploadID: %s\n UploadStrategy: %s\n SignedURL: %s\n Type: %s\n " , initiationResp .GetUploadInstructions (). GetBuildId () , initiationResp .GetUploadInstructions (). GetUploadId () , initiationResp .GetUploadInstructions (). GetUploadStrategy () .String (), initiationResp .GetUploadInstructions (). GetSignedUrl () , initiationResp .GetUploadInstructions (). GetType () )
232219 }
233220
234221 switch initiationResp .UploadInstructions .UploadStrategy {
235222 case debuginfopb .UploadInstructions_UPLOAD_STRATEGY_GRPC :
236223 if flags .LogLevel == LogLevelDebug {
237224 fmt .Fprintf (os .Stdout , "Performing a gRPC upload for %q with Build ID %q." , flags .Upload .Path , buildID )
238225 }
239- _ , err = grpcUploadClient .Upload (ctx , initiationResp .UploadInstructions , reader )
226+ _ , err = grpcUploadClient .Upload (ctx , initiationResp .GetUploadInstructions () , reader )
240227 case debuginfopb .UploadInstructions_UPLOAD_STRATEGY_SIGNED_URL :
241228 if flags .LogLevel == LogLevelDebug {
242229 fmt .Fprintf (os .Stdout , "Performing a signed URL upload for %q with Build ID %q." , flags .Upload .Path , buildID )
243230 }
244- err = uploadViaSignedURL (ctx , initiationResp .UploadInstructions . SignedUrl , reader )
231+ err = uploadViaSignedURL (ctx , initiationResp .GetUploadInstructions (). GetSignedUrl () , reader )
245232 case debuginfopb .UploadInstructions_UPLOAD_STRATEGY_UNSPECIFIED :
246233 err = errors .New ("no upload strategy specified" )
247234 default :
248- err = fmt .Errorf ("unknown upload strategy: %v" , initiationResp .UploadInstructions . UploadStrategy )
235+ err = fmt .Errorf ("unknown upload strategy: %v" , initiationResp .GetUploadInstructions (). GetUploadStrategy () )
249236 }
250237 if err != nil {
251238 return fmt .Errorf ("upload %q with Build ID %q: %w" , flags .Upload .Path , buildID , err )
252239 }
253240
254241 _ , err = debuginfoClient .MarkUploadFinished (ctx , & debuginfopb.MarkUploadFinishedRequest {
255242 BuildId : buildID ,
256- UploadId : initiationResp .UploadInstructions . UploadId ,
243+ UploadId : initiationResp .GetUploadInstructions (). GetUploadId () ,
257244 Type : debuginfoTypeStringToPb (flags .Upload .Type ),
258245 })
259246 if err != nil {
@@ -475,7 +462,7 @@ func grpcConn(reg prometheus.Registerer, flags flags) (*grpc.ClientConn, error)
475462 }))
476463 }
477464
478- return grpc .Dial (flags .Upload .StoreAddress , opts ... )
465+ return grpc .NewClient (flags .Upload .StoreAddress , opts ... )
479466}
480467
481468type perRequestBearerToken struct {
@@ -547,17 +534,17 @@ func getSectionData(elfFile *elf.File, sectionName string) ([]byte, error) {
547534 }
548535 data , err := section .Data ()
549536 if err != nil {
550- return nil , fmt .Errorf ("failed to read data from section %s: %v " , sectionName , err )
537+ return nil , fmt .Errorf ("failed to read data from section %s: %w " , sectionName , err )
551538 }
552539 return data , nil
553540}
554541
555542// getBuildIDFromNotes returns the build ID from an ELF notes section data.
556543func getBuildIDFromNotes (notes []byte ) (string , error ) {
557544 // 0x3 is the "Build ID" type. Not sure where this is standardized.
558- buildID , found , err := getNoteHexString (notes , "GNU" , 0x3 )
545+ buildID , found , err := getNoteHexString (notes , "GNU" , 0x3 ) //nolint:mnd
559546 if err != nil {
560- return "" , fmt .Errorf ("could not determine BuildID: %v " , err )
547+ return "" , fmt .Errorf ("could not determine BuildID: %w " , err )
561548 }
562549 if ! found {
563550 return "" , ErrNoBuildID
@@ -567,8 +554,7 @@ func getBuildIDFromNotes(notes []byte) (string, error) {
567554
568555// getNoteHexString returns the hex string contents of an ELF note from a note section, as described
569556// in the ELF standard in Figure 2-3.
570- func getNoteHexString (sectionBytes []byte , name string , noteType uint32 ) (
571- noteHexString string , found bool , err error ) {
557+ func getNoteHexString (sectionBytes []byte , name string , noteType uint32 ) (string , bool , error ) {
572558 // The data stored inside ELF notes is made of one or multiple structs, containing the
573559 // following fields:
574560 // - namesz // 32-bit, size of "name"
@@ -579,23 +565,23 @@ func getNoteHexString(sectionBytes []byte, name string, noteType uint32) (
579565 // Because of this structure, the information of the build id starts at the 17th byte.
580566
581567 // Null terminated string
582- nameBytes := append ([]byte (name ), 0x0 )
583- noteTypeBytes := make ([]byte , 4 )
568+ nameBytes := append ([]byte (name ), 0x0 ) //nolint:mnd
569+ noteTypeBytes := make ([]byte , 4 ) //nolint:mnd
584570
585571 binary .LittleEndian .PutUint32 (noteTypeBytes , noteType )
586- noteHeader := append (noteTypeBytes , nameBytes ... ) //nolint:gocritic
572+ noteHeader := append (noteTypeBytes , nameBytes ... ) //nolint:gocritic,makezero
587573
588574 // Try to find the note in the section
589575 idx := bytes .Index (sectionBytes , noteHeader )
590576 if idx == - 1 {
591577 return "" , false , nil
592578 }
593- if idx < 4 { // there needs to be room for descsz
579+ if idx < 4 { //nolint:mnd there needs to be room for descsz
594580 return "" , false , errors .New ("could not read note data size" )
595581 }
596582
597583 idxDataStart := idx + len (noteHeader )
598- idxDataStart += (4 - (idxDataStart & 3 )) & 3 // data is 32bit-aligned, round up
584+ idxDataStart += (4 - (idxDataStart & 3 )) & 3 //nolint:mnd data is 32bit-aligned, round up
599585
600586 // read descsz and compute the last index of the note data
601587 dataSize := binary .LittleEndian .Uint32 (sectionBytes [idx - 4 : idx ])
0 commit comments