Skip to content

Commit

Permalink
Merge pull request #2808 from hi-rustin/rustin-dist
Browse files Browse the repository at this point in the history
Make all dist functions and structs crate-private and cleanup unused functions
  • Loading branch information
kinnison authored Jul 18, 2021
2 parents 626b7a8 + 4f37c11 commit 457d643
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 128 deletions.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::env;

include!("src/dist/triple.rs");

pub fn from_build() -> Result<PartialTargetTriple, String> {
fn from_build() -> Result<PartialTargetTriple, String> {
let triple = if let Ok(triple) = env::var("RUSTUP_OVERRIDE_BUILD_TRIPLE") {
triple
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl Display for PgpPublicKey {
pub const UNIX_FALLBACK_SETTINGS: &str = "/etc/rustup/settings.toml";

pub struct Cfg {
pub profile_override: Option<dist::Profile>,
profile_override: Option<dist::Profile>,
pub rustup_dir: PathBuf,
pub settings_file: SettingsFile,
pub fallback_settings: Option<FallbackSettings>,
Expand Down Expand Up @@ -376,7 +376,7 @@ impl Cfg {
&self.pgp_keys
}

pub fn set_profile_override(&mut self, profile: dist::Profile) {
pub(crate) fn set_profile_override(&mut self, profile: dist::Profile) {
self.profile_override = Some(profile);
}

Expand Down Expand Up @@ -429,7 +429,7 @@ impl Cfg {
// if there is no profile in the settings file. The last variant happens when
// a user upgrades from a version of Rustup without profiles to a version of
// Rustup with profiles.
pub fn get_profile(&self) -> Result<dist::Profile> {
pub(crate) fn get_profile(&self) -> Result<dist::Profile> {
if let Some(p) = self.profile_override {
return Ok(p);
}
Expand Down Expand Up @@ -986,7 +986,7 @@ impl Cfg {
})
}

pub fn get_default_host_triple(&self) -> Result<dist::TargetTriple> {
pub(crate) fn get_default_host_triple(&self) -> Result<dist::TargetTriple> {
Ok(self
.settings_file
.with(|s| {
Expand Down
30 changes: 15 additions & 15 deletions src/dist/component/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Components {
})
.collect())
}
pub fn add<'a>(&self, name: &str, tx: Transaction<'a>) -> ComponentBuilder<'a> {
pub(crate) fn add<'a>(&self, name: &str, tx: Transaction<'a>) -> ComponentBuilder<'a> {
ComponentBuilder {
components: self.clone(),
name: name.to_owned(),
Expand All @@ -85,40 +85,40 @@ impl Components {
let result = self.list()?;
Ok(result.into_iter().find(|c| (c.name() == name)))
}
pub fn prefix(&self) -> InstallPrefix {
pub(crate) fn prefix(&self) -> InstallPrefix {
self.prefix.clone()
}
}

pub struct ComponentBuilder<'a> {
pub(crate) struct ComponentBuilder<'a> {
components: Components,
name: String,
parts: Vec<ComponentPart>,
tx: Transaction<'a>,
}

impl<'a> ComponentBuilder<'a> {
pub fn copy_file(&mut self, path: PathBuf, src: &Path) -> Result<()> {
pub(crate) fn copy_file(&mut self, path: PathBuf, src: &Path) -> Result<()> {
self.parts
.push(ComponentPart("file".to_owned(), path.clone()));
self.tx.copy_file(&self.name, path, src)
}
pub fn copy_dir(&mut self, path: PathBuf, src: &Path) -> Result<()> {
pub(crate) fn copy_dir(&mut self, path: PathBuf, src: &Path) -> Result<()> {
self.parts
.push(ComponentPart("dir".to_owned(), path.clone()));
self.tx.copy_dir(&self.name, path, src)
}
pub fn move_file(&mut self, path: PathBuf, src: &Path) -> Result<()> {
pub(crate) fn move_file(&mut self, path: PathBuf, src: &Path) -> Result<()> {
self.parts
.push(ComponentPart("file".to_owned(), path.clone()));
self.tx.move_file(&self.name, path, src)
}
pub fn move_dir(&mut self, path: PathBuf, src: &Path) -> Result<()> {
pub(crate) fn move_dir(&mut self, path: PathBuf, src: &Path) -> Result<()> {
self.parts
.push(ComponentPart("dir".to_owned(), path.clone()));
self.tx.move_dir(&self.name, path, src)
}
pub fn finish(mut self) -> Result<Transaction<'a>> {
pub(crate) fn finish(mut self) -> Result<Transaction<'a>> {
// Write component manifest
let path = self.components.rel_component_manifest(&self.name);
let abs_path = self.components.prefix.abs_path(&path);
Expand Down Expand Up @@ -146,10 +146,10 @@ impl<'a> ComponentBuilder<'a> {
pub struct ComponentPart(pub String, pub PathBuf);

impl ComponentPart {
pub fn encode(&self) -> String {
pub(crate) fn encode(&self) -> String {
format!("{}:{}", &self.0, &self.1.to_string_lossy())
}
pub fn decode(line: &str) -> Option<Self> {
pub(crate) fn decode(line: &str) -> Option<Self> {
line.find(':')
.map(|pos| Self(line[0..pos].to_owned(), PathBuf::from(&line[(pos + 1)..])))
}
Expand All @@ -162,21 +162,21 @@ pub struct Component {
}

impl Component {
pub fn manifest_name(&self) -> String {
pub(crate) fn manifest_name(&self) -> String {
format!("manifest-{}", &self.name)
}
pub fn manifest_file(&self) -> PathBuf {
pub(crate) fn manifest_file(&self) -> PathBuf {
self.components.prefix.manifest_file(&self.manifest_name())
}
pub fn rel_manifest_file(&self) -> PathBuf {
pub(crate) fn rel_manifest_file(&self) -> PathBuf {
self.components
.prefix
.rel_manifest_file(&self.manifest_name())
}
pub fn name(&self) -> &str {
pub(crate) fn name(&self) -> &str {
&self.name
}
pub fn parts(&self) -> Result<Vec<ComponentPart>> {
pub(crate) fn parts(&self) -> Result<Vec<ComponentPart>> {
let mut result = Vec::new();
for line in utils::read_file("component", &self.manifest_file())?.lines() {
result.push(
Expand Down
12 changes: 6 additions & 6 deletions src/dist/component/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use crate::utils::notifications::Notification;
use crate::utils::utils;

/// The current metadata revision used by rust-installer
pub const INSTALLER_VERSION: &str = "3";
pub const VERSION_FILE: &str = "rust-installer-version";
pub(crate) const INSTALLER_VERSION: &str = "3";
pub(crate) const VERSION_FILE: &str = "rust-installer-version";

pub trait Package: fmt::Debug {
fn contains(&self, component: &str, short_name: Option<&str>) -> bool;
Expand Down Expand Up @@ -136,7 +136,7 @@ impl Package for DirectoryPackage {
}

#[derive(Debug)]
pub struct TarPackage<'a>(DirectoryPackage, temp::Dir<'a>);
pub(crate) struct TarPackage<'a>(DirectoryPackage, temp::Dir<'a>);

impl<'a> TarPackage<'a> {
pub(crate) fn new<R: Read>(
Expand Down Expand Up @@ -548,7 +548,7 @@ impl<'a> Package for TarPackage<'a> {
}

#[derive(Debug)]
pub struct TarGzPackage<'a>(TarPackage<'a>);
pub(crate) struct TarGzPackage<'a>(TarPackage<'a>);

impl<'a> TarGzPackage<'a> {
pub(crate) fn new<R: Read>(
Expand Down Expand Up @@ -584,7 +584,7 @@ impl<'a> Package for TarGzPackage<'a> {
}

#[derive(Debug)]
pub struct TarXzPackage<'a>(TarPackage<'a>);
pub(crate) struct TarXzPackage<'a>(TarPackage<'a>);

impl<'a> TarXzPackage<'a> {
pub(crate) fn new<R: Read>(
Expand Down Expand Up @@ -620,7 +620,7 @@ impl<'a> Package for TarXzPackage<'a> {
}

#[derive(Debug)]
pub struct TarZStdPackage<'a>(TarPackage<'a>);
pub(crate) struct TarZStdPackage<'a>(TarPackage<'a>);

impl<'a> TarZStdPackage<'a> {
pub(crate) fn new<R: Read>(
Expand Down
11 changes: 8 additions & 3 deletions src/dist/component/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ impl<'a> Transaction<'a> {
}

/// Move a file to a relative path of the install prefix.
pub fn move_file(&mut self, component: &str, relpath: PathBuf, src: &Path) -> Result<()> {
pub(crate) fn move_file(
&mut self,
component: &str,
relpath: PathBuf,
src: &Path,
) -> Result<()> {
assert!(relpath.is_relative());
let item =
ChangedItem::move_file(&self.prefix, component, relpath, src, self.notify_handler())?;
Expand All @@ -157,15 +162,15 @@ impl<'a> Transaction<'a> {
}

/// Recursively move a directory to a relative path of the install prefix.
pub fn move_dir(&mut self, component: &str, relpath: PathBuf, src: &Path) -> Result<()> {
pub(crate) fn move_dir(&mut self, component: &str, relpath: PathBuf, src: &Path) -> Result<()> {
assert!(relpath.is_relative());
let item =
ChangedItem::move_dir(&self.prefix, component, relpath, src, self.notify_handler())?;
self.change(item);
Ok(())
}

pub fn temp(&self) -> &'a temp::Cfg {
pub(crate) fn temp(&self) -> &'a temp::Cfg {
self.temp_cfg
}
pub(crate) fn notify_handler(&self) -> &'a dyn Fn(Notification<'_>) {
Expand Down
14 changes: 7 additions & 7 deletions src/dist/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use super::manifest::Component;
use crate::errors::*;
use crate::utils::toml_utils::*;

pub const SUPPORTED_CONFIG_VERSIONS: [&str; 1] = ["1"];
pub const DEFAULT_CONFIG_VERSION: &str = "1";
pub(crate) const SUPPORTED_CONFIG_VERSIONS: [&str; 1] = ["1"];
pub(crate) const DEFAULT_CONFIG_VERSION: &str = "1";

#[derive(Clone, Debug)]
pub struct Config {
Expand All @@ -14,7 +14,7 @@ pub struct Config {
}

impl Config {
pub fn from_toml(mut table: toml::value::Table, path: &str) -> Result<Self> {
pub(crate) fn from_toml(mut table: toml::value::Table, path: &str) -> Result<Self> {
let config_version = get_string(&mut table, "config_version", path)?;
if !SUPPORTED_CONFIG_VERSIONS.contains(&&*config_version) {
bail!(RustupError::UnsupportedVersion(config_version));
Expand All @@ -29,7 +29,7 @@ impl Config {
components,
})
}
pub fn into_toml(self) -> toml::value::Table {
pub(crate) fn into_toml(self) -> toml::value::Table {
let mut result = toml::value::Table::new();
result.insert(
"config_version".to_owned(),
Expand All @@ -42,12 +42,12 @@ impl Config {
result
}

pub fn parse(data: &str) -> Result<Self> {
pub(crate) fn parse(data: &str) -> Result<Self> {
let value = toml::from_str(data).context("error parsing manifest")?;
Self::from_toml(value, "")
}

pub fn stringify(self) -> String {
pub(crate) fn stringify(self) -> String {
toml::Value::Table(self.into_toml()).to_string()
}

Expand All @@ -72,7 +72,7 @@ impl Config {
result
}

pub fn new() -> Self {
pub(crate) fn new() -> Self {
Default::default()
}
}
Expand Down
Loading

0 comments on commit 457d643

Please sign in to comment.