Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -y option to samply setup to autosign #353

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions samply/src/mac/codesign_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ const ENTITLEMENTS_XML: &str = r#"<?xml version="1.0" encoding="UTF-8"?>
</plist>
"#;

pub fn codesign_setup() {
print!(
r#"
pub fn codesign_setup(skip_prompt: bool) {
if !skip_prompt {
print!(
r#"
On macOS, attaching to an existing process is only allowed to binaries with
the com.apple.security.cs.debugger entitlement. The samply binary will be
signed with this entitlement for your local machine only. The following command
Expand All @@ -27,14 +28,15 @@ entitlements.xml contains:

Press any key to continue, or Ctrl-C to cancel.
"#,
env::current_exe().unwrap().display(),
ENTITLEMENTS_XML
);
env::current_exe().unwrap().display(),
ENTITLEMENTS_XML
);

let mut input = String::new();
std::io::stdin()
.read_line(&mut input)
.expect("Failed to read input?");
let mut input = String::new();
std::io::stdin()
.read_line(&mut input)
.expect("Failed to read input?");
}

let mut entitlements_file = tempfile::Builder::new()
.prefix("samply_entitlements")
Expand Down
13 changes: 10 additions & 3 deletions samply/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ enum Action {

/// Codesign the samply binary on macOS to allow attaching to processes.
#[cfg(target_os = "macos")]
Setup,
Setup(SetupArgs),
}

#[derive(Debug, Args)]
Expand Down Expand Up @@ -333,6 +333,13 @@ struct SymbolArgs {
simpleperf_binary_cache: Option<PathBuf>,
}

#[derive(Debug, Args, Clone)]
pub struct SetupArgs {
/// Don't wait for confirmation to codesign.
#[arg(short = 'y', long)]
yes: bool,
}

#[derive(Debug, Args, Clone)]
pub struct ProfileCreationArgs {
/// Set a custom name for the recorded profile.
Expand Down Expand Up @@ -491,8 +498,8 @@ fn main() {
}

#[cfg(target_os = "macos")]
Action::Setup => {
mac::codesign_setup::codesign_setup();
Action::Setup(SetupArgs { yes }) => {
mac::codesign_setup::codesign_setup(yes);
}
}
}
Expand Down