...
 
Commits (4)
...@@ -27,6 +27,18 @@ stable:test: ...@@ -27,6 +27,18 @@ stable:test:
# image: "rustlang/rust:nightly" # image: "rustlang/rust:nightly"
# <<: *cargo_test # <<: *cargo_test
# Configure and run rustfmt on nightly
# Exits and build fails on bad format
rustfmt:
image: "rustlang/rust:nightly"
stage: lint
variables:
CFG_RELEASE_CHANNEL: "nightly"
script:
- rustc --version && cargo --version
- cargo install rustfmt-nightly --force
- cargo fmt --all -- --write-mode=diff
# Configure and run clippy on nightly # Configure and run clippy on nightly
clippy: clippy:
image: "rustlang/rust:nightly" image: "rustlang/rust:nightly"
......
unstable_features = true
indent_style = "Visual"
verbose = false
max_width = 100
comment_width = 100
wrap_comments = true
tab_spaces = 4
hard_tabs = false
newline_style = "Unix"
write_mode = "Overwrite"
condense_wildcard_suffixes = false
format_strings = true
# normalize_comments = true
reorder_imports = true
reorder_imported_names = true
reorder_imports_in_group = true
...@@ -24,24 +24,25 @@ use std::thread; ...@@ -24,24 +24,25 @@ use std::thread;
use std::time::Duration; use std::time::Duration;
use structopt::StructOpt; use structopt::StructOpt;
#[cfg_attr(rustfmt, rustfmt_skip)]
#[derive(StructOpt, Debug)] #[derive(StructOpt, Debug)]
#[structopt(name = "rsvg-bench", about = "Benchmarking utility for librsvg.")] #[structopt(name = "rsvg-bench", about = "Benchmarking utility for librsvg.")]
struct Opt { struct Opt {
#[structopt(short = "s", #[structopt(short = "s",
long = "sleep", long = "sleep",
help = "Number of seconds to sleep before starting to process SVGs", help = "Number of seconds to sleep before starting to process SVGs",
default_value = "0")] default_value = "0")]
sleep_secs: usize, sleep_secs: usize,
#[structopt(short = "p", #[structopt(short = "p",
long = "num-parse", long = "num-parse",
help = "Number of times to parse each file", help = "Number of times to parse each file",
default_value = "100")] default_value = "100")]
num_parse: usize, num_parse: usize,
#[structopt(short = "r", #[structopt(short = "r",
long = "num-render", long = "num-render",
help = "Number of times to render each file", help = "Number of times to render each file",
default_value = "100")] default_value = "100")]
num_render: usize, num_render: usize,
...@@ -49,20 +50,17 @@ struct Opt { ...@@ -49,20 +50,17 @@ struct Opt {
help = "Render to a GdkPixbuf instead of a Cairo image surface")] help = "Render to a GdkPixbuf instead of a Cairo image surface")]
render_to_pixbuf: bool, render_to_pixbuf: bool,
#[structopt(help = "Input files or directories", #[structopt(help = "Input files or directories", parse(from_os_str))]
parse(from_os_str))] inputs: Vec<PathBuf>,
inputs: Vec<PathBuf>
} }
#[derive(Debug, Fail)] #[derive(Debug, Fail)]
enum ProcessingError { enum ProcessingError {
#[fail(display = "Cairo error: {:?}", status)] #[fail(display = "Cairo error: {:?}", status)]
CairoError { CairoError { status: cairo::Status },
status: cairo::Status
},
#[fail(display = "Rendering error")] #[fail(display = "Rendering error")]
RenderingError RenderingError,
} }
impl From<cairo::Status> for ProcessingError { impl From<cairo::Status> for ProcessingError {
...@@ -106,7 +104,7 @@ fn process_file<P: AsRef<Path>>(opt: &Opt, path: P) -> Result<(), Error> { ...@@ -106,7 +104,7 @@ fn process_file<P: AsRef<Path>>(opt: &Opt, path: P) -> Result<(), Error> {
assert!(opt.num_parse > 0); assert!(opt.num_parse > 0);
for _ in 0 .. opt.num_parse - 1 { for _ in 0..opt.num_parse - 1 {
// FIXME: this exercises the rsvg_handle_write() / rsvg_handle_close() path. // FIXME: this exercises the rsvg_handle_write() / rsvg_handle_close() path.
// Should we provide an option to use a GInputStream? // Should we provide an option to use a GInputStream?
let _ = rsvg::Handle::new_from_data(bytes)?; let _ = rsvg::Handle::new_from_data(bytes)?;
...@@ -114,7 +112,7 @@ fn process_file<P: AsRef<Path>>(opt: &Opt, path: P) -> Result<(), Error> { ...@@ -114,7 +112,7 @@ fn process_file<P: AsRef<Path>>(opt: &Opt, path: P) -> Result<(), Error> {
let handle = rsvg::Handle::new_from_data(bytes)?; let handle = rsvg::Handle::new_from_data(bytes)?;
for _ in 0 .. opt.num_render { for _ in 0..opt.num_render {
if opt.render_to_pixbuf { if opt.render_to_pixbuf {
render_to_pixbuf(&handle)?; render_to_pixbuf(&handle)?;
} else { } else {
...@@ -127,15 +125,13 @@ fn process_file<P: AsRef<Path>>(opt: &Opt, path: P) -> Result<(), Error> { ...@@ -127,15 +125,13 @@ fn process_file<P: AsRef<Path>>(opt: &Opt, path: P) -> Result<(), Error> {
fn render_to_pixbuf(handle: &rsvg::Handle) -> Result<(), ProcessingError> { fn render_to_pixbuf(handle: &rsvg::Handle) -> Result<(), ProcessingError> {
handle.get_pixbuf() handle.get_pixbuf()
.ok_or_else(|| ProcessingError::RenderingError) .ok_or_else(|| ProcessingError::RenderingError)
.map(|_| ()) .map(|_| ())
} }
fn render_to_cairo(handle: &rsvg::Handle) -> Result<(), ProcessingError> { fn render_to_cairo(handle: &rsvg::Handle) -> Result<(), ProcessingError> {
let dim = handle.get_dimensions(); let dim = handle.get_dimensions();
let surface = cairo::ImageSurface::create(cairo::Format::ARgb32, let surface = cairo::ImageSurface::create(cairo::Format::ARgb32, dim.width, dim.height)?;
dim.width,
dim.height)?;
let cr = cairo::Context::new(&surface); let cr = cairo::Context::new(&surface);
...@@ -144,7 +140,6 @@ fn render_to_cairo(handle: &rsvg::Handle) -> Result<(), ProcessingError> { ...@@ -144,7 +140,6 @@ fn render_to_cairo(handle: &rsvg::Handle) -> Result<(), ProcessingError> {
} else { } else {
Err(ProcessingError::RenderingError) Err(ProcessingError::RenderingError)
} }
} }
fn sleep(secs: usize) { fn sleep(secs: usize) {
...@@ -162,7 +157,8 @@ fn print_options(opt: &Opt) { ...@@ -162,7 +157,8 @@ fn print_options(opt: &Opt) {
"Cairo image surface" "Cairo image surface"
}); });
} }
println!("Sleeping for {} seconds before processing SVGs...", opt.sleep_secs); println!("Sleeping for {} seconds before processing SVGs...",
opt.sleep_secs);
} }
fn run(opt: &Opt) -> Result<(), Error> { fn run(opt: &Opt) -> Result<(), Error> {
......