@@ -25,10 +25,17 @@ pub fn run<P: AsRef<Path>>(
2525 package : & BenchmarkPackage ,
2626 profile_dir : P ,
2727) -> anyhow:: Result < ( TempDir , PathBuf ) > {
28- // 1. Copy the whole module to a build directory
28+ // 1. Copy the whole git repository to a build directory
2929 let target_dir = TempDir :: new ( ) ?;
3030 std:: fs:: create_dir_all ( & target_dir) . context ( "Failed to create target directory" ) ?;
31- utils:: copy_dir_recursively ( & package. module . dir , & target_dir) ?;
31+
32+ let git_root = if let Ok ( git_dir) = utils:: get_parent_git_repo_path ( & package. module . dir ) {
33+ git_dir
34+ } else {
35+ warn ! ( "Could not find git repository root. Falling back to module directory as root" ) ;
36+ PathBuf :: from ( & package. module . dir )
37+ } ;
38+ utils:: copy_dir_recursively ( & git_root, & target_dir) ?;
3239
3340 // Create a new go-runner.metadata file in the root of the project
3441 //
@@ -58,12 +65,11 @@ pub fn run<P: AsRef<Path>>(
5865 . test_files ( )
5966 . with_context ( || anyhow:: anyhow!( "No test files found for package: {}" , package. name) ) ?;
6067
61- // Calculate the relative path from module root to package directory
68+ // Calculate the relative path from git root to package directory
6269 let package_dir = Path :: new ( & package. dir ) ;
63- let module_dir = Path :: new ( & package. module . dir ) ;
64- let relative_package_path = package_dir. strip_prefix ( module_dir) . context ( format ! (
65- "Package dir {:?} is not within module dir {:?}" ,
66- package. dir, package. module. dir
70+ let relative_package_path = package_dir. strip_prefix ( & git_root) . context ( format ! (
71+ "Package dir {:?} is not within git root {:?}" ,
72+ package. dir, git_root
6773 ) ) ?;
6874 debug ! ( "Relative package path: {relative_package_path:?}" ) ;
6975
@@ -87,8 +93,16 @@ pub fn run<P: AsRef<Path>>(
8793 }
8894 patcher:: patch_imports ( & target_dir) ?;
8995
90- // 3. Install codspeed-go dependency at the module level (once for the whole module)
91- patcher:: install_codspeed_dependency ( & target_dir) ?;
96+ // 3. Install codspeed-go dependency at the package module level
97+ // Find the module directory by getting the relative path from git root
98+ let module_dir = Path :: new ( & package. module . dir )
99+ . strip_prefix ( & git_root)
100+ . map ( |relative_module_path| target_dir. path ( ) . join ( relative_module_path) )
101+ . unwrap_or_else ( |_| {
102+ // Fall back to target_dir if we can't calculate relative path
103+ target_dir. path ( ) . to_path_buf ( )
104+ } ) ;
105+ patcher:: install_codspeed_dependency ( & module_dir) ?;
92106
93107 // 3. Handle test files differently based on whether they're external or internal tests
94108 let codspeed_dir = target_dir
0 commit comments