1- use std:: process:: Command ;
1+ use std:: { path :: Path , process:: Command } ;
22
33use anyhow:: Context as _;
44use clap:: Parser ;
@@ -15,12 +15,24 @@ pub struct Options {
1515 pub release : bool ,
1616}
1717
18+ /// Set the ORYX_BIN_PATH env var based on build option
19+ fn set_ebpf_build_base_dir ( build_type : & str ) {
20+ let path = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) )
21+ . join ( format ! ( "../target/bpfel-unknown-none/{build_type}/oryx" ) )
22+ . to_path_buf ( ) ;
23+ std:: env:: set_var ( "ORYX_BIN_PATH" , & path) ;
24+ }
25+
1826/// Build the project
1927fn build_project ( opts : & Options ) -> Result < ( ) , anyhow:: Error > {
2028 let mut args = vec ! [ "build" ] ;
2129 if opts. release {
22- args. push ( "--release" )
30+ args. push ( "--release" ) ;
31+ set_ebpf_build_base_dir ( "release" ) ;
32+ } else {
33+ set_ebpf_build_base_dir ( "debug" ) ;
2334 }
35+
2436 let status = Command :: new ( "cargo" )
2537 . args ( & args)
2638 . status ( )
@@ -40,3 +52,23 @@ pub fn build(opts: Options) -> Result<(), anyhow::Error> {
4052 build_project ( & opts) . context ( "Error while building userspace application" ) ?;
4153 Ok ( ( ) )
4254}
55+
56+
57+ /// Run linter on the project with ORYX_BIN_DIR env var set
58+ pub fn lint ( ) -> Result < ( ) , anyhow:: Error > {
59+ set_ebpf_build_base_dir ( "debug" ) ;
60+ let status = Command :: new ( "cargo" )
61+ . args ( [
62+ "clippy" ,
63+ "--workspace" ,
64+ "--all-features" ,
65+ "--" ,
66+ "-D" ,
67+ "warnings" ,
68+ ] )
69+ . status ( )
70+ . expect ( "failed to build userspace" ) ;
71+
72+ assert ! ( status. success( ) ) ;
73+ Ok ( ( ) )
74+ }
0 commit comments