##// END OF EJS Templates
packaging: support building WiX installers with PyOxidizer...
packaging: support building WiX installers with PyOxidizer We initially implemented PyOxidizer support for Inno installers. That did most of the heavy work of integrating PyOxidizer into the packaging system. Implementing WiX installer support was pretty straightforward. Aspects of this patch look very similar to Inno's. The main difference is the handling of the Visual C++ Redistributable Runtime files. The WiX installer was formerly using merge modules to install the VC++ 9.0 runtime because this feature is supported by the WiX installer (it isn't easily available to Inno installers). Our strategy for the runtime files is to install the vcruntime140.dll file next to hg.exe just like any other file. While we could leverage WiX's functionality for invoking a VCRedist installer, I don't want to deal with the complexity at this juncture. So, we let run_pyoxidizer() copy vcruntime140.dll into the staging directory (like it does for Inno) and our dynamic WiX XML generator picks it up as a regular file and installs it. We did, however, have to teach mercurial.wxs how to conditionally use the merge modules. But this was rather straightforward. Comparing the file layout of the WiX installers before and after: * Various lib/*.{pyd, dll} files no longer exist * python27.dll was replaced by python37.dll * vcruntime140.dll was added All these changes are expected due to the transition to Python 3 and to PyOxidizer, which embeded the .pyd and .dll files in hg.exe. Differential Revision: https://phab.mercurial-scm.org/D8477

File last commit:

r44740:aa0fc32e default
r45260:c9517d9d default
Show More
utils.rs
168 lines | 3.9 KiB | application/rls-services+xml | RustLexer
Raphaël Gomès
rust-docstrings: add missing module docstrings...
r42996 // utils module
//
// Copyright 2019 Raphaël Gomès <rgomes@octobus.net>
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
//! Contains useful functions, traits, structs, etc. for use in core.
Raphaël Gomès
rust-utils: add `Escaped` trait...
r44740 use crate::utils::hg_path::HgPath;
use std::{io::Write, ops::Deref};
Raphaël Gomès
rust: switch hg-core and hg-cpython to rust 2018 edition...
r42828 pub mod files;
Raphaël Gomès
rust-hgpath: add HgPath and HgPathBuf structs to encapsulate handling of paths...
r43226 pub mod hg_path;
Raphaël Gomès
rust-pathauditor: add Rust implementation of the `pathauditor`...
r44737 pub mod path_auditor;
Raphaël Gomès
rust: switch hg-core and hg-cpython to rust 2018 edition...
r42828
Raphaël Gomès
rust-utils: add util to find a slice in another slice...
r44538 /// Useful until rust/issues/56345 is stable
///
/// # Examples
///
/// ```
/// use crate::hg::utils::find_slice_in_slice;
///
/// let haystack = b"This is the haystack".to_vec();
/// assert_eq!(find_slice_in_slice(&haystack, b"the"), Some(8));
/// assert_eq!(find_slice_in_slice(&haystack, b"not here"), None);
/// ```
pub fn find_slice_in_slice<T>(slice: &[T], needle: &[T]) -> Option<usize>
where
for<'a> &'a [T]: PartialEq,
{
slice
.windows(needle.len())
.position(|window| window == needle)
}
Raphaël Gomès
rust-utils: add docstrings and doctests for utils.rs...
r42829 /// Replaces the `from` slice with the `to` slice inside the `buf` slice.
///
/// # Examples
///
/// ```
/// use crate::hg::utils::replace_slice;
/// let mut line = b"I hate writing tests!".to_vec();
/// replace_slice(&mut line, b"hate", b"love");
/// assert_eq!(
/// line,
/// b"I love writing tests!".to_vec()
Yuya Nishihara
rust: apply more formatting fixes...
r43109 /// );
Raphaël Gomès
rust-utils: add docstrings and doctests for utils.rs...
r42829 /// ```
Raphaël Gomès
rust: switch hg-core and hg-cpython to rust 2018 edition...
r42828 pub fn replace_slice<T>(buf: &mut [T], from: &[T], to: &[T])
where
T: Clone + PartialEq,
{
Raphaël Gomès
rust-utils: remove buggy assertion...
r42830 if buf.len() < from.len() || from.len() != to.len() {
Raphaël Gomès
rust: switch hg-core and hg-cpython to rust 2018 edition...
r42828 return;
}
for i in 0..=buf.len() - from.len() {
if buf[i..].starts_with(from) {
buf[i..(i + from.len())].clone_from_slice(to);
}
}
}
pub trait SliceExt {
Raphaël Gomès
rust-utils: add docstrings and doctests for utils.rs...
r42829 fn trim_end(&self) -> &Self;
fn trim_start(&self) -> &Self;
Raphaël Gomès
rust: switch hg-core and hg-cpython to rust 2018 edition...
r42828 fn trim(&self) -> &Self;
Valentin Gatien-Baron
rustfilepatterns: refactor the pattern of removing a prefix from a &[u8]...
r43129 fn drop_prefix(&self, needle: &Self) -> Option<&Self>;
Raphaël Gomès
rust: switch hg-core and hg-cpython to rust 2018 edition...
r42828 }
fn is_not_whitespace(c: &u8) -> bool {
!(*c as char).is_whitespace()
}
impl SliceExt for [u8] {
fn trim_end(&self) -> &[u8] {
if let Some(last) = self.iter().rposition(is_not_whitespace) {
&self[..last + 1]
} else {
&[]
}
}
Raphaël Gomès
rust-utils: add docstrings and doctests for utils.rs...
r42829 fn trim_start(&self) -> &[u8] {
if let Some(first) = self.iter().position(is_not_whitespace) {
&self[first..]
} else {
&[]
}
}
/// ```
/// use hg::utils::SliceExt;
/// assert_eq!(
/// b" to trim ".trim(),
/// b"to trim"
/// );
/// assert_eq!(
/// b"to trim ".trim(),
/// b"to trim"
/// );
/// assert_eq!(
/// b" to trim".trim(),
/// b"to trim"
/// );
/// ```
fn trim(&self) -> &[u8] {
self.trim_start().trim_end()
}
Valentin Gatien-Baron
rustfilepatterns: refactor the pattern of removing a prefix from a &[u8]...
r43129
fn drop_prefix(&self, needle: &Self) -> Option<&Self> {
if self.starts_with(needle) {
Some(&self[needle.len()..])
} else {
None
}
}
Raphaël Gomès
rust: switch hg-core and hg-cpython to rust 2018 edition...
r42828 }
Raphaël Gomès
rust-utils: add `Escaped` trait...
r44740
pub trait Escaped {
/// Return bytes escaped for display to the user
fn escaped_bytes(&self) -> Vec<u8>;
}
impl Escaped for u8 {
fn escaped_bytes(&self) -> Vec<u8> {
let mut acc = vec![];
match self {
c @ b'\'' | c @ b'\\' => {
acc.push(b'\\');
acc.push(*c);
}
b'\t' => {
acc.extend(br"\\t");
}
b'\n' => {
acc.extend(br"\\n");
}
b'\r' => {
acc.extend(br"\\r");
}
c if (*c < b' ' || *c >= 127) => {
write!(acc, "\\x{:x}", self).unwrap();
}
c => {
acc.push(*c);
}
}
acc
}
}
impl<'a, T: Escaped> Escaped for &'a [T] {
fn escaped_bytes(&self) -> Vec<u8> {
self.iter().flat_map(|item| item.escaped_bytes()).collect()
}
}
impl<T: Escaped> Escaped for Vec<T> {
fn escaped_bytes(&self) -> Vec<u8> {
self.deref().escaped_bytes()
}
}
impl<'a> Escaped for &'a HgPath {
fn escaped_bytes(&self) -> Vec<u8> {
self.as_bytes().escaped_bytes()
}
}