Skip to content

Commit ec8d7a4

Browse files
fix: don't get target_aid when NoEmbed
Signed-off-by: Andrew Lilley Brinker <[email protected]>
1 parent 5fac943 commit ec8d7a4

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

omnibor/src/embed.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
pub(crate) mod auto_embed;
55
pub(crate) mod embed_provider;
66

7-
use crate::{error::InputManifestError, hash_algorithm::HashAlgorithm};
7+
use crate::{error::InputManifestError, hash_algorithm::HashAlgorithm, util::sealed::Sealed};
88
use std::{marker::PhantomData, path::Path};
99

1010
pub use crate::embed::embed_provider::EmbedProvider;
@@ -13,7 +13,7 @@ pub use crate::embed::embed_provider::EmbedProvider;
1313
use crate::embed::auto_embed::embed_manifest_in_target;
1414

1515
/// Defines how embedding should be handled in target artifacts.
16-
pub trait Embed<H>
16+
pub trait Embed<H>: Sealed
1717
where
1818
H: HashAlgorithm,
1919
{
@@ -26,12 +26,19 @@ where
2626
target_path: &Path,
2727
embed_provider: EmbedProvider<H>,
2828
) -> Option<Result<(), InputManifestError>>;
29+
30+
/// Indicates if the embedder will attempt to embed.
31+
fn will_embed(&self) -> bool {
32+
true
33+
}
2934
}
3035

3136
/// Do not embed in the target file.
3237
#[derive(Debug, Copy, Clone)]
3338
pub struct NoEmbed;
3439

40+
impl Sealed for NoEmbed {}
41+
3542
impl<H: HashAlgorithm> Embed<H> for NoEmbed {
3643
// Do nothing, as we're not actually embedding.
3744
fn try_embed(
@@ -41,13 +48,20 @@ impl<H: HashAlgorithm> Embed<H> for NoEmbed {
4148
) -> Option<Result<(), InputManifestError>> {
4249
None
4350
}
51+
52+
fn will_embed(&self) -> bool {
53+
false
54+
}
4455
}
4556

4657
#[cfg(feature = "infer-filetypes")]
4758
/// Automatically infer the filetype of the target file, and attempt to embed.
4859
#[derive(Debug, Copy, Clone)]
4960
pub struct AutoEmbed;
5061

62+
#[cfg(feature = "infer-filetypes")]
63+
impl Sealed for AutoEmbed {}
64+
5165
#[cfg(feature = "infer-filetypes")]
5266
impl<H: HashAlgorithm> Embed<H> for AutoEmbed {
5367
fn try_embed(
@@ -83,6 +97,13 @@ where
8397
}
8498
}
8599

100+
impl<H, F> Sealed for CustomEmbed<H, F>
101+
where
102+
H: HashAlgorithm,
103+
F: Fn(&Path, EmbedProvider<H>) -> Result<(), InputManifestError>,
104+
{
105+
}
106+
86107
impl<H, F> Embed<H> for CustomEmbed<H, F>
87108
where
88109
H: HashAlgorithm,

omnibor/src/input_manifest/input_manifest_builder.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,19 @@ where
112112
S2: Storage<H2>,
113113
{
114114
// Get the Artifact ID of the target.
115-
let target_aid =
116-
ArtifactId::new(manifest_builder.storage.get_hash_provider(), target)?;
115+
let target_aid = if embed.will_embed() {
116+
Some(ArtifactId::new(
117+
manifest_builder.storage.get_hash_provider(),
118+
target,
119+
)?)
120+
} else {
121+
None
122+
};
117123

118124
// Construct a new input manifest.
119125
let manifest = InputManifest::with_relations(
120126
manifest_builder.relations.iter().cloned(),
121-
Some(target_aid),
127+
target_aid,
122128
);
123129

124130
// Get the Artifact ID of the manifest.

0 commit comments

Comments
 (0)