1+ #! /usr/bin/env bash
2+ 
3+ set  -euo pipefail
4+ 
5+ #  Check for required arguments
6+ if  [[ $#  -lt  2 ]];  then 
7+     echo  " Usage: $0  <package> <target>" >&2 
8+     echo  " Example: $0  hyperlight-host debug" >&2 
9+     exit  1
10+ fi 
11+ 
12+ PACKAGE=" $1 " 
13+ TARGET=" $2 " 
14+ 
15+ #  Convert target for cargo profile
16+ PROFILE=$( [ " $TARGET " =  " debug" &&  echo  " dev" ||  echo  " $TARGET " ) 
17+ 
18+ #  Required features needed so the rust packages can compile
19+ if  [[ " $PACKAGE " ==  " hyperlight-host" ;  then 
20+     REQUIRED_FEATURES=(" kvm" " mshv3" 
21+ elif  [[ " $PACKAGE " ==  " hyperlight-guest-bin" ;  then 
22+     REQUIRED_FEATURES=(" printf" 
23+ else  
24+     REQUIRED_FEATURES=()
25+ fi 
26+ 
27+ #  Get all features for the package (excluding default and required features)
28+ #  Always exclude "default", and exclude any required features using jq
29+ features=$( cargo metadata --format-version 1 --no-deps |  jq -r --arg pkg " $PACKAGE " ' .packages[] | select(.name == $pkg) | .features | keys[] | select(. != "default" and (IN($ARGS.positional[])|not))' " ${REQUIRED_FEATURES[@]} " ||  true) 
30+ 
31+ #  Convert required features array to comma-separated string for cargo
32+ if  [[ ${# REQUIRED_FEATURES[@]}  -gt  0 ]];  then 
33+     required_features_str=$( IFS=,;  echo  " ${REQUIRED_FEATURES[*]} " ) 
34+ else 
35+     required_features_str=" " 
36+ fi 
37+ 
38+ #  Test with minimal features
39+ if  [[ ${# REQUIRED_FEATURES[@]}  -gt  0 ]];  then 
40+     echo  " Testing $PACKAGE  with required features only ($required_features_str )..." 
41+     (set -x;  cargo clippy -p " $PACKAGE " " $required_features_str " " $PROFILE " 
42+ else 
43+     echo  " Testing $PACKAGE  with no features..." 
44+     (set -x;  cargo clippy -p " $PACKAGE " " $PROFILE " 
45+ fi 
46+ 
47+ echo  " Testing $PACKAGE  with default features..." 
48+ (set -x;  cargo clippy -p " $PACKAGE " " $PROFILE " 
49+ 
50+ #  Test each additional feature individually
51+ for  feature  in  $features ;  do 
52+     if  [[ ${# REQUIRED_FEATURES[@]}  -gt  0 ]];  then 
53+         echo  " Testing $PACKAGE  with feature: $required_features_str ,$feature " 
54+         (set -x;  cargo clippy -p " $PACKAGE " " $required_features_str ,$feature " " $PROFILE " 
55+     else 
56+         echo  " Testing $PACKAGE  with feature: $feature " 
57+         (set -x;  cargo clippy -p " $PACKAGE " " $feature " " $PROFILE " 
58+     fi 
59+ done 
60+ 
61+ #  Test all features together
62+ if  [[ -n  " $features " ;  then 
63+     all_features=$( echo $features  |  tr ' \n' ' ,' |  sed ' s/,$//' ) 
64+     if  [[ ${# REQUIRED_FEATURES[@]}  -gt  0 ]];  then 
65+         echo  " Testing $PACKAGE  with all features: $required_features_str ,$all_features " 
66+         (set -x;  cargo clippy -p " $PACKAGE " " $required_features_str ,$all_features " " $PROFILE " 
67+     else 
68+         echo  " Testing $PACKAGE  with all features: $all_features " 
69+         (set -x;  cargo clippy -p " $PACKAGE " " $all_features " " $PROFILE " 
70+     fi 
71+ fi 
0 commit comments