File tree Expand file tree Collapse file tree 1 file changed +28
-6
lines changed Expand file tree Collapse file tree 1 file changed +28
-6
lines changed Original file line number Diff line number Diff line change 1
- use std:: { io:: stdout, path:: PathBuf } ;
1
+ use std:: { fs , io:: stdout, path:: PathBuf , str :: FromStr } ;
2
2
3
3
use anyhow:: { bail, Context , Result } ;
4
4
use argp:: FromArgs ;
@@ -74,12 +74,34 @@ pub fn run(args: Args) -> Result<()> {
74
74
)
75
75
} ;
76
76
if let Some ( u) = u {
77
- let Some ( object) =
78
- project_config. objects . iter_mut ( ) . find ( |obj| obj. name ( ) == u)
79
- else {
77
+ let unit_path =
78
+ PathBuf :: from_str ( u) . ok ( ) . and_then ( |p| fs:: canonicalize ( p) . ok ( ) ) ;
79
+
80
+ let Some ( object) = project_config. objects . iter_mut ( ) . find_map ( |obj| {
81
+ if obj. name . as_deref ( ) == Some ( u) {
82
+ resolve_paths ( obj) ;
83
+ return Some ( obj) ;
84
+ }
85
+
86
+ let Some ( up) = unit_path. as_deref ( ) else {
87
+ return None ;
88
+ } ;
89
+
90
+ resolve_paths ( obj) ;
91
+
92
+ if [ & obj. base_path , & obj. target_path ]
93
+ . into_iter ( )
94
+ . filter_map ( |p| p. as_ref ( ) . and_then ( |p| p. canonicalize ( ) . ok ( ) ) )
95
+ . any ( |p| p == up)
96
+ {
97
+ return Some ( obj) ;
98
+ }
99
+
100
+ None
101
+ } ) else {
80
102
bail ! ( "Unit not found: {}" , u)
81
103
} ;
82
- resolve_paths ( object ) ;
104
+
83
105
object
84
106
} else {
85
107
let mut idx = None ;
@@ -92,7 +114,7 @@ pub fn run(args: Args) -> Result<()> {
92
114
. as_deref ( )
93
115
. map ( |o| obj:: elf:: has_function ( o, & args. symbol ) )
94
116
. transpose ( ) ?
95
- . unwrap_or_default ( )
117
+ . unwrap_or ( false )
96
118
{
97
119
idx = Some ( i) ;
98
120
count += 1 ;
You can’t perform that action at this time.
0 commit comments