go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/vpython/wheels/verify.go (about)

     1  // Copyright 2024 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package wheels
    16  
    17  import (
    18  	"os"
    19  	"strings"
    20  
    21  	"go.chromium.org/luci/cipd/client/cipd/template"
    22  
    23  	"go.chromium.org/luci/vpython/api/vpython"
    24  	"go.chromium.org/luci/vpython/common"
    25  )
    26  
    27  // Verify the spec for all VerifyPep425Tag listed in the spec. This will ensure
    28  // all packages existed for these platforms.
    29  //
    30  // TODO: Maybe implement it inside a derivation after we executing cipd binary
    31  // directly.
    32  func Verify(spec *vpython.Spec) error {
    33  	for _, t := range spec.VerifyPep425Tag {
    34  		ef, err := ensureFileFromVPythonSpec(spec, []*vpython.PEP425Tag{t})
    35  		if err != nil {
    36  			return err
    37  		}
    38  		ef.VerifyPlatforms = []template.Platform{PlatformForPEP425Tag(t)}
    39  		var efs strings.Builder
    40  		if err := ef.Serialize(&efs); err != nil {
    41  			return err
    42  		}
    43  
    44  		cmd := common.CIPDCommand("ensure-file-verify", "-ensure-file", "-")
    45  		cmd.Stdin = strings.NewReader(efs.String())
    46  		cmd.Stdout = os.Stdout
    47  		cmd.Stderr = os.Stderr
    48  		if err := cmd.Run(); err != nil {
    49  			return err
    50  		}
    51  	}
    52  	return nil
    53  }