Skip to content

Commit e5ba17f

Browse files
committed
feat: add pkg to backend init
1 parent ef55666 commit e5ba17f

File tree

1 file changed

+45
-63
lines changed

1 file changed

+45
-63
lines changed

cargo-dist/src/init.rs

Lines changed: 45 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use serde::Deserialize;
88
use crate::{
99
config::{
1010
self, CiStyle, CompressionImpl, Config, DistMetadata, HostingStyle, InstallPathStrategy,
11-
InstallerStyle, PublishStyle, ZipStyle,
11+
InstallerStyle, MacPkgConfig, PublishStyle, ZipStyle,
1212
},
1313
do_generate,
1414
errors::{DistError, DistResult},
@@ -665,7 +665,6 @@ fn get_new_dist_metadata(
665665
InstallerStyle::Npm,
666666
InstallerStyle::Homebrew,
667667
InstallerStyle::Msi,
668-
InstallerStyle::Pkg,
669668
]
670669
} else {
671670
eprintln!("{notice} no CI backends enabled, most installers have been hidden");
@@ -782,66 +781,6 @@ fn get_new_dist_metadata(
782781
}
783782
}
784783

785-
// Special handling of the pkg installer
786-
if meta
787-
.installers
788-
.as_deref()
789-
.unwrap_or_default()
790-
.contains(&InstallerStyle::Pkg)
791-
{
792-
let pkg_is_new = !orig_meta
793-
.installers
794-
.as_deref()
795-
.unwrap_or_default()
796-
.contains(&InstallerStyle::Pkg);
797-
798-
if pkg_is_new && orig_meta.mac_pkg_config.is_none() {
799-
let prompt = r#"you've enabled a Mac .pkg installer. This requires a unique bundle ID;
800-
please enter one now. This is in reverse-domain name format.
801-
For more information, consult the Apple documentation:
802-
https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html#//apple_ref/doc/uid/10000123i-CH101-SW1"#;
803-
let default = "".to_string();
804-
805-
let identifier: String = if args.yes {
806-
default
807-
} else {
808-
let res = Input::with_theme(&theme)
809-
.with_prompt(prompt)
810-
.allow_empty(true)
811-
.interact_text()?;
812-
eprintln!();
813-
res
814-
};
815-
let identifier = identifier.trim();
816-
if identifier.is_empty() {
817-
return Err(DistError::MacPkgBundleIdentifierMissing {});
818-
}
819-
820-
let prompt = r#"Please enter the installation prefix this .pkg should use."#;
821-
let prefix = if args.yes {
822-
None
823-
} else {
824-
let res: String = Input::with_theme(&theme)
825-
.with_prompt(prompt)
826-
.allow_empty(true)
827-
.interact_text()?;
828-
eprintln!();
829-
830-
let trimmed = res.trim();
831-
if trimmed.is_empty() {
832-
None
833-
} else {
834-
Some(trimmed.to_owned())
835-
}
836-
};
837-
838-
meta.mac_pkg_config = Some(config::MacPkgConfig {
839-
identifier: identifier.to_owned(),
840-
install_location: prefix,
841-
})
842-
}
843-
}
844-
845784
meta.publish_jobs = if publish_jobs.is_empty() {
846785
None
847786
} else {
@@ -1034,14 +973,14 @@ fn apply_dist_to_metadata(metadata: &mut toml_edit::Item, meta: &DistMetadata) {
1034973
github_release,
1035974
package_libraries,
1036975
install_libraries,
976+
mac_pkg_config,
1037977
// These settings are complex enough that we don't support editing them in init
1038978
extra_artifacts: _,
1039979
github_custom_runners: _,
1040980
github_custom_job_permissions: _,
1041981
bin_aliases: _,
1042982
system_dependencies: _,
1043983
github_build_setup: _,
1044-
mac_pkg_config: _,
1045984
} = &meta;
1046985

1047986
// Forcibly inline the default install_path if not specified,
@@ -1083,6 +1022,13 @@ fn apply_dist_to_metadata(metadata: &mut toml_edit::Item, meta: &DistMetadata) {
10831022
installers.as_ref(),
10841023
);
10851024

1025+
apply_optional_mac_pkg(
1026+
table,
1027+
"mac-pkg-config",
1028+
"\n# Configuration for the Mac .pkg installer\n",
1029+
mac_pkg_config.as_ref(),
1030+
);
1031+
10861032
apply_optional_value(
10871033
table,
10881034
"tap",
@@ -1494,3 +1440,39 @@ where
14941440
table.remove(key);
14951441
}
14961442
}
1443+
1444+
/// Similar to [`apply_optional_value`][] but specialized to `MacPkgConfig`, since we're not able to work with structs dynamically
1445+
fn apply_optional_mac_pkg(
1446+
table: &mut toml_edit::Table,
1447+
key: &str,
1448+
desc: &str,
1449+
val: Option<&MacPkgConfig>,
1450+
) {
1451+
if let Some(mac_pkg_config) = val {
1452+
let MacPkgConfig {
1453+
identifier,
1454+
install_location,
1455+
} = mac_pkg_config;
1456+
1457+
let new_item = &mut table[key];
1458+
let mut new_table = toml_edit::table();
1459+
if let Some(new_table) = new_table.as_table_mut() {
1460+
apply_optional_value(
1461+
new_table,
1462+
"identifier",
1463+
"# A unique identifier, in tld.domain.package format\n",
1464+
Some(identifier),
1465+
);
1466+
apply_optional_value(
1467+
new_table,
1468+
"install-location",
1469+
"# The location to which the software should be installed\n",
1470+
install_location.as_ref(),
1471+
);
1472+
new_table.decor_mut().set_prefix(desc);
1473+
}
1474+
new_item.or_insert(new_table);
1475+
} else {
1476+
table.remove(key);
1477+
}
1478+
}

0 commit comments

Comments
 (0)