Skip to content

Commit

Permalink
feat: use index map for env (#1251)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Dec 10, 2024
1 parent 70d8524 commit c24de58
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/packaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fn copy_license_files(
// if a file was copied from the recipe dir, and the work dir, we should
// issue a warning
for file in copied_files_recipe_dir {
if copied_files_work_dir.contains(&file) {
if copied_files_work_dir.contains(file) {
let warn_str = format!("License file from source directory was overwritten by license file from recipe folder ({})", file.display());
tracing::warn!(warn_str);
output.record_warning(&warn_str);
Expand Down
20 changes: 20 additions & 0 deletions src/recipe/custom_yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,26 @@ where
}
}

impl<K, V> TryConvertNode<IndexMap<K, V>> for RenderedNode
where
K: Ord + Display + Hash,
RenderedScalarNode: TryConvertNode<K>,
RenderedNode: TryConvertNode<V>,
{
fn try_convert(&self, name: &str) -> Result<IndexMap<K, V>, Vec<PartialParsingError>> {
self.as_mapping()
.ok_or_else(|| {
_partialerror!(
*self.span(),
ErrorKind::ExpectedMapping,
help = format!("expected a mapping for `{name}`")
)
})
.map_err(|e| vec![e])
.and_then(|m| m.try_convert(name))
}
}

impl<K, V> TryConvertNode<IndexMap<K, V>> for RenderedMappingNode
where
K: Ord + Display + Hash,
Expand Down
13 changes: 7 additions & 6 deletions src/recipe/parser/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ use crate::{
},
recipe::error::{ErrorKind, PartialParsingError},
};
use indexmap::IndexMap;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::{borrow::Cow, collections::BTreeMap, path::PathBuf};
use std::{borrow::Cow, path::PathBuf};

/// Defines the script to run to build the package.
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct Script {
/// The interpreter to use for the script.
pub interpreter: Option<String>,
/// Environment variables to set in the build environment.
pub env: BTreeMap<String, String>,
pub env: IndexMap<String, String>,
/// Environment variables to leak into the build environment from the host system that
/// contain sensitive information. Use with care because this might make recipes no
/// longer reproducible on other machines.
Expand Down Expand Up @@ -48,8 +49,8 @@ impl Serialize for Script {
Object {
#[serde(skip_serializing_if = "Option::is_none")]
interpreter: Option<&'a String>,
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
env: &'a BTreeMap<String, String>,
#[serde(skip_serializing_if = "IndexMap::is_empty")]
env: &'a IndexMap<String, String>,
#[serde(skip_serializing_if = "Vec::is_empty")]
secrets: &'a Vec<String>,
#[serde(skip_serializing_if = "Option::is_none", flatten)]
Expand Down Expand Up @@ -114,7 +115,7 @@ impl<'de> Deserialize<'de> for Script {
#[serde(default)]
interpreter: Option<String>,
#[serde(default)]
env: BTreeMap<String, String>,
env: IndexMap<String, String>,
#[serde(default)]
secrets: Vec<String>,
#[serde(default, flatten)]
Expand Down Expand Up @@ -164,7 +165,7 @@ impl Script {
}

/// Get the environment variables to set in the build environment.
pub fn env(&self) -> &BTreeMap<String, String> {
pub fn env(&self) -> &IndexMap<String, String> {
&self.env
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ expression: yaml_serde
- script:
interpreter: bash
env:
BAZ: QUX
FOO: BAR
BAZ: QUX
secrets:
- ABC
- DEF
Expand Down
1 change: 1 addition & 0 deletions src/variant_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ impl Stage1Render {
Ok(sorted_indices)
}

#[allow(clippy::type_complexity)]
pub fn into_sorted_outputs(
self,
) -> Result<Vec<((Node, Recipe), BTreeMap<NormalizedKey, String>)>, VariantError> {
Expand Down

0 comments on commit c24de58

Please sign in to comment.