-
-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(proguard): Replace
MappingRef
with ProguardMapping
The new `ProguardMapping` type directly references the `ByteView` of the Proguard file, rather than simply storing the path to the file. This change will enable us to replace `ChunkedMapping` with `Chunked<ProguardMapping>`. ref #2196
- Loading branch information
1 parent
2790aa1
commit 543e79e
Showing
6 changed files
with
95 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use symbolic::common::ByteView; | ||
use thiserror::Error; | ||
use uuid::Uuid; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum ProguardMappingError { | ||
#[error("Proguard mapping does not contain line information")] | ||
MissingLineInfo, | ||
} | ||
|
||
pub struct ProguardMapping<'a> { | ||
bytes: ByteView<'a>, | ||
uuid: Uuid, | ||
} | ||
|
||
impl<'a> ProguardMapping<'a> { | ||
/// Get the length of the mapping in bytes. | ||
pub fn len(&self) -> usize { | ||
self.bytes.len() | ||
} | ||
|
||
/// Get the UUID of the mapping. | ||
pub fn uuid(&self) -> Uuid { | ||
self.uuid | ||
} | ||
|
||
/// Force the UUID of the mapping to a specific value, rather | ||
/// than the UUID which is derived from the proguard crate. | ||
pub fn force_uuid(&mut self, uuid: Uuid) { | ||
self.uuid = uuid; | ||
} | ||
|
||
/// Create a new `ProguardMapping` from a `ByteView`. | ||
/// Not public because we want to ensure that the `ByteView` contains line | ||
/// information, and this method does not check for that. To create a | ||
/// `ProguardMapping` externally, use the `TryFrom<ByteView>` implementation. | ||
fn new(bytes: ByteView<'a>, uuid: Uuid) -> Self { | ||
Self { bytes, uuid } | ||
} | ||
} | ||
|
||
impl<'a> TryFrom<ByteView<'a>> for ProguardMapping<'a> { | ||
type Error = ProguardMappingError; | ||
|
||
/// Try to create a `ProguardMapping` from a `ByteView`. | ||
/// The method returns an error if the mapping does not contain | ||
/// line information. | ||
fn try_from(value: ByteView<'a>) -> Result<Self, Self::Error> { | ||
let mapping = ::proguard::ProguardMapping::new(&value); | ||
|
||
if !mapping.has_line_info() { | ||
return Err(ProguardMappingError::MissingLineInfo); | ||
} | ||
|
||
let uuid = mapping.uuid(); | ||
Ok(ProguardMapping::new(value, uuid)) | ||
} | ||
} | ||
|
||
impl AsRef<[u8]> for ProguardMapping<'_> { | ||
fn as_ref(&self) -> &[u8] { | ||
self.bytes.as_ref() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
mod mapping; | ||
mod upload; | ||
|
||
pub use self::mapping::ProguardMapping; | ||
pub use self::upload::chunk_upload; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/integration/_cases/upload_proguard/upload_proguard-no-upload.trycmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/integration/_cases/upload_proguard/upload_proguard.trycmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters