Skip to content

Commit

Permalink
Update, improve build on Mac OS X
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Jun 17, 2024
1 parent c0f1769 commit b87ca89
Show file tree
Hide file tree
Showing 19 changed files with 562 additions and 260 deletions.
735 changes: 509 additions & 226 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pyo3 = []

[dependencies]
pyo3 = { workspace = true }
gettext-rs = { version = "0.7", optional = true }
gettext-rs = { workspace = true, optional = true }
log = { workspace = true }
breezy-osutils = { path = "crates/osutils", version = ">=3.3.4" }
chrono = { workspace = true }
Expand All @@ -61,3 +61,5 @@ chrono = { version = "0.4", default-features = false, features = ["std", "clock"
url = "2"
log = "0.4"
whoami = { version = "1", default-features = false }
# Work around broken build on Mac OS X (https://github.com/Koka/gettext-rs/issues/114)
gettext-rs = { git = "https://github.com/dennisschagt/gettext-rs", branch = "update-gettext-22.5" }
3 changes: 2 additions & 1 deletion crates/bazaar-py/src/chk_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ fn common_prefix_pair(py: Python, key: &[u8], key2: &[u8]) -> Py<PyBytes> {
}

#[pyfunction]
fn common_prefix_many(py: Python, keys: Vec<&[u8]>) -> Option<Py<PyBytes>> {
fn common_prefix_many(py: Python, keys: Vec<Vec<u8>>) -> Option<Py<PyBytes>> {
let keys = keys.iter().map(|x| x.as_slice()).collect::<Vec<&[u8]>>();
bazaar::chk_map::common_prefix_many(keys.into_iter())
.as_ref()
.map(|v| PyBytes::new(py, v).into_py(py))
Expand Down
9 changes: 6 additions & 3 deletions crates/bazaar-py/src/dirstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,15 @@ fn fields_per_entry(num_present_parents: usize) -> usize {
}

#[pyfunction]
fn get_ghosts_line(py: Python, ghost_ids: Vec<&[u8]>) -> PyResult<PyObject> {
fn get_ghosts_line(py: Python, ghost_ids: Vec<Vec<u8>>) -> PyResult<PyObject> {
let ghost_ids = ghost_ids.iter().map(|x| x.as_slice()).collect::<Vec<&[u8]>>();
let bs = bazaar::dirstate::get_ghosts_line(ghost_ids.as_slice());
Ok(PyBytes::new(py, bs.as_slice()).to_object(py))
}

#[pyfunction]
fn get_parents_line(py: Python, parent_ids: Vec<&[u8]>) -> PyResult<PyObject> {
fn get_parents_line(py: Python, parent_ids: Vec<Vec<u8>>) -> PyResult<PyObject> {
let parent_ids = parent_ids.iter().map(|x| x.as_slice()).collect::<Vec<&[u8]>>();
let bs = bazaar::dirstate::get_parents_line(parent_ids.as_slice());
Ok(PyBytes::new(py, bs.as_slice()).to_object(py))
}
Expand Down Expand Up @@ -415,7 +417,8 @@ fn inv_entry_to_details(
}

#[pyfunction]
fn get_output_lines(py: Python, lines: Vec<&[u8]>) -> Vec<PyObject> {
fn get_output_lines(py: Python, lines: Vec<Vec<u8>>) -> Vec<PyObject> {
let lines = lines.iter().map(|x| x.as_slice()).collect::<Vec<&[u8]>>();
bazaar::dirstate::get_output_lines(lines)
.into_iter()
.map(|x| PyBytes::new(py, x.as_slice()).to_object(py))
Expand Down
4 changes: 3 additions & 1 deletion crates/bazaar-py/src/groupcompress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use pyo3::prelude::*;
use pyo3::types::PyBytes;
use pyo3::wrap_pyfunction;
use std::convert::TryInto;
use std::borrow::Cow;

#[pyfunction]
fn encode_base128_int(py: Python, value: u128) -> PyResult<&PyBytes> {
Expand Down Expand Up @@ -99,10 +100,11 @@ impl LinesDeltaIndex {
fn make_delta<'a>(
&'a self,
py: Python,
source: Vec<std::borrow::Cow<'a, [u8]>>,
source: Vec<Vec<u8>>,
bytes_length: usize,
soft: Option<bool>,
) -> (Vec<Py<PyBytes>>, Vec<bool>) {
let source = source.iter().map(|x| Cow::Borrowed(x.as_slice())).collect::<Vec<Cow<'_, [u8]>>>();
let (delta, index) = self.0.make_delta(source.as_slice(), bytes_length, soft);
(
delta
Expand Down
9 changes: 6 additions & 3 deletions crates/bazaar-py/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,8 @@ impl Inventory {
.map_err(|e| inventory_err_to_py_err(e, py))
}

fn path2id_segments(&self, names: Vec<&str>) -> Option<FileId> {
fn path2id_segments(&self, names: Vec<String>) -> Option<FileId> {
let names = names.iter().map(|x| x.as_str()).collect::<Vec<&str>>();
self.0.path2id_segments(names.as_slice()).cloned()
}

Expand All @@ -1207,7 +1208,8 @@ impl Inventory {
) -> PyResult<(Option<PyObject>, Option<Vec<String>>, Option<Vec<String>>)> {
let ret = if let Ok(relpath) = relpath.extract::<&str>(py) {
self.0.get_entry_by_path_partial(relpath)
} else if let Ok(segments) = relpath.extract::<Vec<&str>>(py) {
} else if let Ok(segments) = relpath.extract::<Vec<String>>(py) {
let segments = segments.iter().map(|x| x.as_str()).collect::<Vec<&str>>();
self.0
.get_entry_by_path_segments_partial(segments.as_slice())
} else {
Expand All @@ -1231,7 +1233,8 @@ impl Inventory {
.0
.get_entry_by_path(relpath)
.map(|entry| entry_to_py(py, entry.clone()).unwrap()))
} else if let Ok(segments) = relpath.extract::<Vec<&str>>(py) {
} else if let Ok(segments) = relpath.extract::<Vec<String>>(py) {
let segments = segments.iter().map(|x| x.as_str()).collect::<Vec<&str>>();
Ok(self
.0
.get_entry_by_path_segments(segments.as_slice())
Expand Down
2 changes: 1 addition & 1 deletion crates/bazaar/src/hashcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl HashCache {
} else {
self.miss_count += 1;

match SFlag::from_bits_truncate(file_fp.mode) {
match SFlag::from_bits_truncate(((file_fp.mode) >> 16) as u16) {
SFlag::S_IFREG => {
let filters: Box<dyn ContentFilter> =
if let Some(filter_provider) = self.filter_provider.as_ref() {
Expand Down
2 changes: 1 addition & 1 deletion crates/bazaar/src/versionedfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl pyo3::ToPyObject for Key {
#[cfg(feature = "pyo3")]
impl pyo3::FromPyObject<'_> for Key {
fn extract(ob: &pyo3::PyAny) -> pyo3::PyResult<Self> {
match ob.get_type().name().unwrap() {
match ob.get_type().name().unwrap().as_ref() {
"tuple" | "StaticTuple" => {}
_ => {
return Err(pyo3::exceptions::PyTypeError::new_err(
Expand Down
2 changes: 1 addition & 1 deletion crates/cmd-py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ crate-type = ["cdylib"]
pyo3 = { workspace = true, features = ["extension-module"]}
pyo3-filelike = { workspace = true }
breezy = { path = "../..", features = ["pyo3"] }
gettext-rs = "0.7"
gettext-rs = { workspace = true }
log = { workspace = true, features=["std"]}
9 changes: 6 additions & 3 deletions crates/cmd-py/src/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ struct DynamicHelpTopic(std::sync::Arc<breezy::help::DynamicHelpTopic>);

#[pymethods]
impl DynamicHelpTopic {
fn get_help_text(&self, additional_see_also: Option<Vec<&str>>, plain: Option<bool>) -> String {
fn get_help_text(&self, additional_see_also: Option<Vec<String>>, plain: Option<bool>) -> String {
let additional_see_also = additional_see_also.as_ref().map(|x| x.iter().map(|x| x.as_str()).collect::<Vec<&str>>());
self.0
.get_help_text(additional_see_also.as_deref(), plain.unwrap_or(true))
}
Expand Down Expand Up @@ -45,7 +46,8 @@ impl StaticHelpTopic {
self.0.name.to_string()
}

fn get_help_text(&self, additional_see_also: Option<Vec<&str>>, plain: Option<bool>) -> String {
fn get_help_text(&self, additional_see_also: Option<Vec<String>>, plain: Option<bool>) -> String {
let additional_see_also = additional_see_also.as_ref().map(|x| x.iter().map(|x| x.as_str()).collect::<Vec<&str>>());
self.0
.get_help_text(additional_see_also.as_deref(), plain.unwrap_or(true))
}
Expand Down Expand Up @@ -179,7 +181,8 @@ impl HelpTopicRegistry {
}

#[pyfunction]
fn _format_see_also(topics: Vec<&str>) -> String {
fn _format_see_also(topics: Vec<String>) -> String {
let topics = topics.iter().map(|x| x.as_str()).collect::<Vec<&str>>();
breezy::help::format_see_also(topics.as_slice())
}

Expand Down
15 changes: 9 additions & 6 deletions crates/cmd-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,14 @@ fn help_as_plain_text(text: &str) -> PyResult<String> {
}

#[pyfunction]
fn format_see_also(see_also: Option<Vec<&str>>) -> PyResult<String> {
if see_also.is_none() {
return Ok("".to_string());
fn format_see_also(see_also: Option<Vec<String>>) -> PyResult<String> {
match see_also {
None => Ok("".to_string()),
Some(see_also) => {
let see_also = see_also.iter().map(|x| x.as_str()).collect::<Vec<&str>>();
Ok(breezy::help::format_see_also(see_also.as_slice()))
}
}

Ok(breezy::help::format_see_also(see_also.unwrap().as_slice()))
}

mod help;
Expand All @@ -431,7 +433,8 @@ impl TreeBuilder {
TreeBuilder(breezy::treebuilder::TreeBuilder::new())
}

fn build(&mut self, recipe: Vec<&str>) -> PyResult<()> {
fn build(&mut self, recipe: Vec<String>) -> PyResult<()> {
let recipe = recipe.iter().map(|x| x.as_str()).collect::<Vec<&str>>();
self.0
.build(recipe.as_slice())
.map_err(|e| PyRuntimeError::new_err(format!("Failed to build tree: {:?}", e)))
Expand Down
2 changes: 1 addition & 1 deletion crates/graph-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ struct MergeSorter {
fn branch_tip_is_null(py: Python, branch_tip: PyObject) -> bool {
if let Ok(branch_tip) = branch_tip.extract::<&[u8]>(py) {
branch_tip == b"null:"
} else if let Ok((branch_tip,)) = branch_tip.extract::<(&[u8],)>(py) {
} else if let Ok((branch_tip,)) = branch_tip.extract::<(Vec<u8>,)>(py) {
branch_tip == b"null:"
} else {
false
Expand Down
4 changes: 2 additions & 2 deletions crates/osutils-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ fn unpack_highres_date(date: &str) -> PyResult<(f64, i32)> {

#[pyfunction]
#[cfg(unix)]
fn get_umask() -> PyResult<u32> {
fn get_umask() -> PyResult<nix::sys::stat::mode_t> {
Ok(breezy_osutils::get_umask().bits())
}

Expand Down Expand Up @@ -804,7 +804,7 @@ fn win32_abspath(path: PathBuf) -> PyResult<PathBuf> {

#[cfg(unix)]
#[pyfunction]
fn kind_from_mode(mode: u32) -> &'static str {
fn kind_from_mode(mode: nix::sys::stat::mode_t) -> &'static str {
use nix::sys::stat::SFlag;
breezy_osutils::file::kind_from_mode(SFlag::from_bits_truncate(mode))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/osutils/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub fn link_or_copy<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dest: Q) -> std::io:
}
}

#[cfg(any(target_os = "windows", target_env = "cygwin", target_os = "macos"))]
#[cfg(any(target_os = "windows", target_env = "cygwin"))]
pub fn link_or_copy<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dest: Q) -> io::Result<()> {
std::fs::copy(src.as_ref(), dest.as_ref())?;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/osutils/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub fn inaccessible_normalized_filename(path: &Path) -> Option<(PathBuf, bool)>
/// So return the normalized path, and a flag indicating if the file
/// can be accessed by that path.
#[cfg(target_os = "macos")]
pub fn normalized_filename(path: &Path) -> (PathBuf, bool) {
pub fn normalized_filename(path: &Path) -> Option<(PathBuf, bool)> {
accessible_normalized_filename(path)
}

Expand Down
7 changes: 4 additions & 3 deletions crates/transport-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn default_perms() -> Permissions {
let mask = umask(Mode::empty());
umask(mask);
let mode = 0o666 & !mask.bits();
Permissions::from_mode(mode)
Permissions::from_mode(mode.into())
}

#[pyclass]
Expand Down Expand Up @@ -310,7 +310,8 @@ impl Transport {
.map_err(|e| map_transport_err_to_py_err(e, None, Some(path)))
}

fn has_any(&self, py: Python, paths: Vec<&str>) -> PyResult<bool> {
fn has_any(&self, py: Python, paths: Vec<String>) -> PyResult<bool> {
let paths = paths.iter().map(|x| x.as_str()).collect::<Vec<&str>>();
py.allow_threads(|| self.0.has_any(paths.as_slice()))
.map_err(|e| map_transport_err_to_py_err(e, None, None))
}
Expand Down Expand Up @@ -364,7 +365,7 @@ impl Transport {
.map_err(|e| map_transport_err_to_py_err(e, None, Some(path)))?;
Ok(PyStat {
st_size: stat.size,
st_mode: stat.mode,
st_mode: stat.mode.into(),
st_mtime: stat.mtime,
}
.into_py(py))
Expand Down
6 changes: 3 additions & 3 deletions crates/transport/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ impl From<breezy_urlutils::Error> for Error {

pub struct Stat {
pub size: usize,
pub mode: u32,
pub mode: nix::sys::stat::mode_t,
pub mtime: Option<f64>,
}

impl From<Metadata> for Stat {
fn from(metadata: Metadata) -> Self {
Stat {
size: metadata.len() as usize,
mode: metadata.permissions().mode(),
mode: (metadata.permissions().mode() >> 16) as u16,
mtime: metadata.modified().map_or(None, |t| {
Some(t.duration_since(UNIX_EPOCH).unwrap().as_secs_f64())
}),
Expand Down Expand Up @@ -415,7 +415,7 @@ pub trait Transport: std::fmt::Debug + 'static + Send + Sync {
// create target directory with the same rwx bits as source
// use umask to ensure bits other than rwx are ignored
let stat = self.stat(from_relpath)?;
target.mkdir(".", Some(Permissions::from_mode(stat.mode)))?;
target.mkdir(".", Some(Permissions::from_mode(stat.mode.into())))?;
source.copy_tree_to_transport(target.as_ref())?;
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/transport/src/pyo3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl Transport for PyTransport {
};

Ok(Stat {
mode: stat_result.getattr(py, "st_mode")?.extract::<u32>(py)?,
mode: stat_result.getattr(py, "st_mode")?.extract::<nix::sys::stat::mode_t>(py)?,
size: stat_result.getattr(py, "st_size")?.extract::<usize>(py)?,
mtime,
})
Expand Down
3 changes: 2 additions & 1 deletion crates/urlutils-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ fn join_segment_parameters_raw(url: &str, args: &PyTuple) -> PyResult<String> {
}

#[pyfunction]
fn join_segment_parameters(url: &str, parameters: HashMap<&str, &str>) -> PyResult<String> {
fn join_segment_parameters(url: &str, parameters: HashMap<String, String>) -> PyResult<String> {
let parameters = parameters.iter().map(|(k, v)| (k.as_str(), v.as_str())).collect::<HashMap<&str, &str>>();
breezy_urlutils::join_segment_parameters(url, &parameters).map_err(map_urlutils_error_to_pyerr)
}

Expand Down

0 comments on commit b87ca89

Please sign in to comment.