Skip to content

Commit

Permalink
Remove dsyms/associate API usage (#1886)
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem committed Jan 29, 2024
1 parent be94aa6 commit 9721ea0
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 206 deletions.
96 changes: 0 additions & 96 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@ use uuid::Uuid;

use crate::config::{Auth, Config};
use crate::constants::{ARCH, EXT, PLATFORM, RELEASE_REGISTRY_LATEST_URL, VERSION};
use crate::utils::android::AndroidManifest;
use crate::utils::file_upload::UploadContext;
use crate::utils::http::{self, is_absolute_url, parse_link_header};
use crate::utils::progress::ProgressBar;
use crate::utils::retry::{get_default_backoff, DurationAsMilliseconds};
use crate::utils::sourcemaps::get_sourcemap_reference_from_headers;
use crate::utils::ui::{capitalize_string, make_byte_progress_bar};
use crate::utils::xcode::InfoPlist;

// Based on https://docs.rs/percent-encoding/1.0.1/src/percent_encoding/lib.rs.html#104
// WHATWG Spec: https://url.spec.whatwg.org/#percent-encoded-bytes
Expand Down Expand Up @@ -1356,50 +1354,6 @@ impl Api {
}
}

/// Associate apple debug symbols with a build
pub fn associate_apple_dsyms(
&self,
org: &str,
project: &str,
info_plist: &InfoPlist,
checksums: Vec<String>,
) -> ApiResult<Option<AssociateDsymsResponse>> {
self.associate_dsyms(
org,
project,
&AssociateDsyms {
platform: "apple".to_string(),
checksums,
name: info_plist.name().to_string(),
app_id: info_plist.bundle_id().to_string(),
version: info_plist.version().to_string(),
build: Some(info_plist.build().to_string()),
},
)
}

/// Associate proguard mappings with an android app
pub fn associate_android_proguard_mappings(
&self,
org: &str,
project: &str,
manifest: &AndroidManifest,
checksums: Vec<String>,
) -> ApiResult<Option<AssociateDsymsResponse>> {
self.associate_dsyms(
org,
project,
&AssociateDsyms {
platform: "android".to_string(),
checksums,
name: manifest.name(),
app_id: manifest.package().to_string(),
version: manifest.version_name().to_string(),
build: Some(manifest.version_code().to_string()),
},
)
}

pub fn associate_proguard_mappings(
&self,
org: &str,
Expand Down Expand Up @@ -1430,39 +1384,6 @@ impl Api {
}
}

/// Associate arbitrary debug symbols with a build
pub fn associate_dsyms(
&self,
org: &str,
project: &str,
data: &AssociateDsyms,
) -> ApiResult<Option<AssociateDsymsResponse>> {
// in case we have no checksums to send up the server does not actually
// let us associate anything. This generally makes sense but means that
// from the client side we need to deal with this separately. In this
// case we just pretend we did a request that did nothing.
if data.checksums.is_empty() {
return Ok(Some(AssociateDsymsResponse {
associated_dsyms: vec![],
}));
}

let path = format!(
"/projects/{}/{}/files/dsyms/associate/",
PathArg(org),
PathArg(project)
);
let resp = self
.request(Method::Post, &path)?
.with_json_body(data)?
.send()?;
if resp.status() == 404 {
Ok(None)
} else {
resp.convert()
}
}

/// Triggers reprocessing for a project
pub fn trigger_reprocessing(&self, org: &str, project: &str) -> ApiResult<bool> {
let path = format!(
Expand Down Expand Up @@ -2486,17 +2407,6 @@ impl DebugInfoFile {
}
}

#[derive(Debug, Serialize)]
pub struct AssociateDsyms {
pub platform: String,
pub checksums: Vec<String>,
pub name: String,
#[serde(rename = "appId")]
pub app_id: String,
pub version: String,
pub build: Option<String>,
}

#[derive(Debug, Serialize)]
pub struct AssociateProguard {
pub release_name: String,
Expand Down Expand Up @@ -2585,12 +2495,6 @@ impl IssueFilter {
}
}

#[derive(Deserialize)]
pub struct AssociateDsymsResponse {
#[serde(rename = "associatedDsymFiles")]
pub associated_dsyms: Vec<DebugInfoFile>,
}

#[derive(Deserialize, Debug)]
pub struct Organization {
pub id: String,
Expand Down
33 changes: 2 additions & 31 deletions src/commands/debug_files/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use crate::constants::DEFAULT_MAX_WAIT;
use crate::utils::args::ArgExt;
use crate::utils::dif::{DifType, ObjectDifFeatures};
use crate::utils::dif_upload::{DifFormat, DifUpload};
use crate::utils::progress::{ProgressBar, ProgressStyle};
use crate::utils::system::QuietExit;
use crate::utils::xcode::{InfoPlist, MayDetach};

Expand Down Expand Up @@ -304,7 +303,8 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
}

// Try to resolve the Info.plist either by path or from Xcode
let info_plist = match matches.get_one::<String>("info_plist") {
// TODO: maybe remove this completely?
let _info_plist = match matches.get_one::<String>("info_plist") {
Some(path) => Some(InfoPlist::from_path(path)?),
None => InfoPlist::discover_from_env()?,
};
Expand All @@ -324,35 +324,6 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
let (uploaded, has_processing_errors) = upload.upload()?;
let api = Api::current();

// Associate the dSYMs with the Info.plist data, if available
if let Some(ref info_plist) = info_plist {
let progress_style = ProgressStyle::default_spinner()
.template("{spinner} Associating dSYMs with {msg}...");

let pb = ProgressBar::new_spinner();
pb.enable_steady_tick(100);
pb.set_style(progress_style);
pb.set_message(&info_plist.to_string());

let checksums = uploaded.iter().map(|dif| dif.checksum.clone()).collect();
let response = api.associate_apple_dsyms(&org, &project, info_plist, checksums)?;
pb.finish_and_clear();

if let Some(association) = response {
if association.associated_dsyms.is_empty() {
println!("{} No new debug symbols to associate.", style(">").dim());
} else {
println!(
"{} Associated {} debug symbols with the build.",
style(">").dim(),
style(association.associated_dsyms.len()).yellow()
);
}
} else {
info!("Server does not support dSYM associations. Ignoring.");
}
}

// Trigger reprocessing only if requested by user
if matches.get_flag("no_reprocessing") {
println!("{} skipped reprocessing", style(">").dim());
Expand Down
15 changes: 3 additions & 12 deletions src/commands/upload_proguard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use uuid::Uuid;
use crate::api::Api;
use crate::api::AssociateProguard;
use crate::config::Config;
use crate::utils::android::{dump_proguard_uuids_as_properties, AndroidManifest};
use crate::utils::android::dump_proguard_uuids_as_properties;
use crate::utils::args::ArgExt;
use crate::utils::fs::{get_sha1_checksum, TempFile};
use crate::utils::system::QuietExit;
Expand Down Expand Up @@ -106,6 +106,7 @@ pub fn make_command(command: Command) -> Command {
.long("android-manifest")
.value_name("PATH")
.conflicts_with("app_id")
.hide(true)
.help("Read version and version code from an Android manifest file."),
)
.arg(
Expand Down Expand Up @@ -152,12 +153,6 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
let mut mappings = vec![];
let mut all_checksums = vec![];

let android_manifest = if let Some(path) = matches.get_one::<String>("android_manifest") {
Some(AndroidManifest::from_path(path)?)
} else {
None
};

let forced_uuid = matches.get_one::<Uuid>("uuid");
if forced_uuid.is_some() && paths.len() != 1 {
bail!(
Expand Down Expand Up @@ -261,12 +256,8 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
}
}

// update the uuids
if let Some(android_manifest) = android_manifest {
api.associate_android_proguard_mappings(&org, &project, &android_manifest, all_checksums)?;

// if values are given associate
} else if let Some(app_id) = matches.get_one::<String>("app_id") {
if let Some(app_id) = matches.get_one::<String>("app_id") {
let version = matches.get_one::<String>("version").unwrap().to_owned();
let build: Option<String> = matches.get_one::<String>("version_code").cloned();

Expand Down
66 changes: 0 additions & 66 deletions src/utils/android.rs
Original file line number Diff line number Diff line change
@@ -1,78 +1,12 @@
use std::collections::HashMap;
use std::fmt;
use std::fs;
use std::io;
use std::path::Path;

use anyhow::{format_err, Result};
use elementtree::Element;
use itertools::Itertools;
use uuid::Uuid;

pub struct AndroidManifest {
root: Element,
}

const ANDROID_NS: &str = "http://schemas.android.com/apk/res/android";

impl AndroidManifest {
pub fn from_path<P: AsRef<Path>>(path: P) -> Result<AndroidManifest> {
let f = fs::File::open(path.as_ref())?;
let root = Element::from_reader(f)?;
Ok(AndroidManifest { root })
}

/// Returns the package ID
pub fn package(&self) -> &str {
self.root.get_attr("package").unwrap_or("unknown")
}

/// Returns a name
pub fn name(&self) -> String {
// fallback name is the package reformatted
self.root
.get_attr("package")
.unwrap_or("unknown")
.rsplit('.')
.next()
.unwrap()
.chars()
.enumerate()
.map(|(idx, c)| {
if idx == 0 {
c.to_uppercase().to_string()
} else {
c.to_lowercase().to_string()
}
})
.collect()
}

/// Returns the internal version code for this manifest
pub fn version_code(&self) -> &str {
self.root
.get_attr((ANDROID_NS, "versionCode"))
.unwrap_or("0")
}

/// Returns the human readable version number of the manifest
pub fn version_name(&self) -> &str {
self.root
.get_attr((ANDROID_NS, "versionName"))
.unwrap_or("0.0")
}
}

impl fmt::Debug for AndroidManifest {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("AndroidManifest")
.field("package", &self.package())
.field("version_code", &self.version_code())
.field("version_name", &self.version_name())
.finish()
}
}

pub fn dump_proguard_uuids_as_properties<P: AsRef<Path>>(p: P, uuids: &[Uuid]) -> Result<()> {
let mut props = match fs::File::open(p.as_ref()) {
Ok(f) => java_properties::read(f).unwrap_or_else(|_| HashMap::new()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Options:
upload (this also automatically disables reprocessing). This
is useful if you just want to verify the mapping files and
write the proguard UUIDs into a properties file.
--android-manifest <PATH> Read version and version code from an Android manifest file.
--write-properties <PATH> Write the UUIDs for the processed mapping files into the given
properties file.
--require-one Requires at least one file to upload or the command will error.
Expand Down

0 comments on commit 9721ea0

Please sign in to comment.