Skip to content

Commit 437d887

Browse files
committed
add --workspace-path
1 parent 098551f commit 437d887

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/main.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ enum SubCommand {
5454
Build {
5555
/// Path to mount to the docker image
5656
mount_directory: Option<String>,
57+
/// Path to mount to the workspace root
58+
workspace_directory: Option<String>,
5759
/// Which binary file to build (applies to repositories with multiple programs)
5860
#[clap(long)]
5961
library_name: Option<String>,
@@ -106,6 +108,10 @@ enum SubCommand {
106108
/// This should be the directory that contains the workspace Cargo.toml and the Cargo.lock file
107109
#[clap(long, default_value = "")]
108110
mount_path: String,
111+
/// Relative path to the specific program workspace directory in the source code repository from which to build the program
112+
/// This should be the directory that contains the program's workspace Cargo.toml and the Cargo.lock file, if different from repo's workspace
113+
#[clap(long, default_value = "")]
114+
workspace_path: String,
109115
/// The HTTPS URL of the repo to clone
110116
repo_url: String,
111117
/// Optional commit hash to checkout
@@ -156,12 +162,14 @@ async fn main() -> anyhow::Result<()> {
156162
SubCommand::Build {
157163
// mount directory
158164
mount_directory,
165+
workspace_directory,
159166
library_name,
160167
base_image,
161168
bpf: bpf_flag,
162169
cargo_args,
163170
} => build(
164171
mount_directory,
172+
workspace_directory,
165173
library_name,
166174
base_image,
167175
bpf_flag,
@@ -200,6 +208,7 @@ async fn main() -> anyhow::Result<()> {
200208
SubCommand::VerifyFromRepo {
201209
remote,
202210
mount_path,
211+
workspace_path,
203212
repo_url,
204213
commit_hash,
205214
program_id,
@@ -212,6 +221,7 @@ async fn main() -> anyhow::Result<()> {
212221
verify_from_repo(
213222
remote,
214223
mount_path,
224+
workspace_path,
215225
args.url,
216226
repo_url,
217227
commit_hash,
@@ -331,6 +341,7 @@ pub fn get_docker_resource_limits() -> Option<(String, String)> {
331341

332342
pub fn build(
333343
mount_directory: Option<String>,
344+
workspace_root: Option<String>,
334345
library_name: Option<String>,
335346
base_image: Option<String>,
336347
bpf_flag: bool,
@@ -346,6 +357,9 @@ pub fn build(
346357
);
347358
println!("Mounting path: {}", mount_path);
348359

360+
let workspace_path = workspace_root.unwrap_or(mount_path.clone());
361+
println!("Workspace path: {}", workspace_path);
362+
349363
let lockfile = format!("{}/Cargo.lock", mount_path);
350364
if !std::path::Path::new(&lockfile).exists() {
351365
println!("Mount directory must contain a Cargo.lock file");
@@ -516,7 +530,7 @@ pub fn build(
516530
if let Some(program_name) = library_name {
517531
let executable_path = std::process::Command::new("find")
518532
.args([
519-
&format!("{}/target/deploy", mount_path),
533+
&format!("{}/target/deploy", workspace_path),
520534
"-name",
521535
&format!("{}.so", program_name),
522536
])
@@ -644,6 +658,7 @@ pub fn verify_from_image(
644658
pub async fn verify_from_repo(
645659
remote: bool,
646660
relative_mount_path: String,
661+
relative_workspace_path: String,
647662
connection_url: Option<String>,
648663
repo_url: String,
649664
commit_hash: Option<String>,
@@ -774,8 +789,13 @@ pub async fn verify_from_repo(
774789
};
775790
println!("Verifying program: {}", library_name);
776791

792+
// Get the absolute build path to the solana program directory to build inside docker
793+
let workspace_path = PathBuf::from(verify_tmp_root_path.clone()).join(relative_workspace_path);
794+
println!("Workspace path: {:?}", workspace_path);
795+
777796
let result = build_and_verify_repo(
778797
mount_path.to_str().unwrap().to_string(),
798+
workspace_path.to_str().unwrap().to_string(),
779799
base_image,
780800
bpf_flag,
781801
library_name,
@@ -810,6 +830,7 @@ pub async fn verify_from_repo(
810830
#[allow(clippy::too_many_arguments)]
811831
pub fn build_and_verify_repo(
812832
mount_path: String,
833+
workspace_path: String,
813834
base_image: Option<String>,
814835
bpf_flag: bool,
815836
library_name: String,
@@ -822,6 +843,7 @@ pub fn build_and_verify_repo(
822843
let executable_filename = format!("{}.so", &library_name);
823844
build(
824845
Some(mount_path.clone()),
846+
Some(workspace_path.clone()),
825847
Some(library_name),
826848
base_image,
827849
bpf_flag,
@@ -832,7 +854,7 @@ pub fn build_and_verify_repo(
832854
// Get the hash of the build
833855
let executable_path = std::process::Command::new("find")
834856
.args([
835-
&format!("{}/target/deploy", mount_path),
857+
&format!("{}/target/deploy", workspace_path),
836858
"-name",
837859
executable_filename.as_str(),
838860
])

0 commit comments

Comments
 (0)