Merge branch 'orphans' into 'master'
tests: Check for orphaned layout files See merge request World/Phosh/squeekboard!574
This commit is contained in:
		@ -32,7 +32,7 @@ build_meson:
 | 
			
		||||
  script:
 | 
			
		||||
    - mv debian/control-newer debian/control
 | 
			
		||||
    - apt-get -y build-dep .
 | 
			
		||||
    - meson . _build/ -Ddepdatadir=/usr/share --werror
 | 
			
		||||
    - meson . _build/ -Ddepdatadir=/usr/share -Dfind_orphans=true --werror
 | 
			
		||||
    - ninja -C _build install
 | 
			
		||||
  except:
 | 
			
		||||
    variables:
 | 
			
		||||
 | 
			
		||||
@ -16,6 +16,10 @@ path = "@path@/src/bin/test_layout.rs"
 | 
			
		||||
name = "test_layout"
 | 
			
		||||
path = "@path@/examples/test_layout.rs"
 | 
			
		||||
 | 
			
		||||
[[example]]
 | 
			
		||||
name = "find_orphan_layouts"
 | 
			
		||||
path = "@path@/examples/find_orphan_layouts.rs"
 | 
			
		||||
 | 
			
		||||
[features]
 | 
			
		||||
glib_v0_14 = []
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										53
									
								
								examples/find_orphan_layouts.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								examples/find_orphan_layouts.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,53 @@
 | 
			
		||||
/*! Tests if any layout files are not in use */
 | 
			
		||||
 | 
			
		||||
extern crate rs;
 | 
			
		||||
 | 
			
		||||
use rs::resources;
 | 
			
		||||
use std::env;
 | 
			
		||||
use std::error::Error;
 | 
			
		||||
use std::ffi::OsStr;
 | 
			
		||||
use std::fs;
 | 
			
		||||
use std::path::{Path, PathBuf};
 | 
			
		||||
 | 
			
		||||
enum Orphans {
 | 
			
		||||
    None,
 | 
			
		||||
    Present,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn check(base: &Path, dir: &Path) -> Result<Orphans, Box<dyn Error>> {
 | 
			
		||||
    let mut orphans = Orphans::None;
 | 
			
		||||
    for entry in fs::read_dir(dir)? {
 | 
			
		||||
        let entry = entry?;
 | 
			
		||||
        let path = entry.path();
 | 
			
		||||
 | 
			
		||||
        if entry.file_type()?.is_dir() {
 | 
			
		||||
            check(base, &path)?;
 | 
			
		||||
        } else {
 | 
			
		||||
            if Some(OsStr::new("yaml")) == path.extension() {
 | 
			
		||||
                let resource_path = path
 | 
			
		||||
                    .strip_prefix(base).unwrap()
 | 
			
		||||
                    .with_extension("");
 | 
			
		||||
                let resource_path = resource_path
 | 
			
		||||
                    .to_str().unwrap();
 | 
			
		||||
                let resource_path = resource_path
 | 
			
		||||
                    .strip_prefix('/').unwrap_or(resource_path);
 | 
			
		||||
                if let None = resources::get_keyboard(resource_path) {
 | 
			
		||||
                    println!("Data not registered in the resources file: {:?}", path);
 | 
			
		||||
                    orphans = Orphans::Present;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    Ok(orphans)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn main() -> () {
 | 
			
		||||
    let path = env::args().nth(1).expect("Provide a path");
 | 
			
		||||
    let path = PathBuf::from(path);
 | 
			
		||||
 | 
			
		||||
    match check(&path, &path) {
 | 
			
		||||
        Err(e) => panic!("{:?}", e),
 | 
			
		||||
        Ok(Orphans::Present) => panic!("Unregistered files present. Check the tutorial in doc/tutorial.md"),
 | 
			
		||||
        _ => {},
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -7,6 +7,10 @@ option('tests',
 | 
			
		||||
       type: 'boolean', value: true,
 | 
			
		||||
       description: 'Whether to compile unit tests')
 | 
			
		||||
 | 
			
		||||
option('find_orphans',
 | 
			
		||||
       type: 'boolean', value: false,
 | 
			
		||||
       description: 'Check if all present layout files are included in resources.')
 | 
			
		||||
 | 
			
		||||
option('newer',
 | 
			
		||||
       type: 'boolean', value: false,
 | 
			
		||||
       description: 'Build with dependencies newer than those of Byzantium')
 | 
			
		||||
 | 
			
		||||
@ -39,7 +39,7 @@ mod outputs;
 | 
			
		||||
mod panel;
 | 
			
		||||
mod popover;
 | 
			
		||||
mod receiver;
 | 
			
		||||
mod resources;
 | 
			
		||||
pub mod resources;
 | 
			
		||||
mod state;
 | 
			
		||||
mod style;
 | 
			
		||||
mod submission;
 | 
			
		||||
 | 
			
		||||
@ -127,3 +127,14 @@ foreach layout : [
 | 
			
		||||
endforeach
 | 
			
		||||
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
if get_option('find_orphans')
 | 
			
		||||
    test('test_find_orphans',
 | 
			
		||||
        cargo_script,
 | 
			
		||||
        args: ['run'] + cargo_build_flags
 | 
			
		||||
            + ['--example', 'find_orphan_layouts',
 | 
			
		||||
                '--', meson.source_root() + '/data/keyboards/'],
 | 
			
		||||
        timeout: timeout,
 | 
			
		||||
        workdir: meson.build_root(),
 | 
			
		||||
    )
 | 
			
		||||
endif
 | 
			
		||||
		Reference in New Issue
	
	Block a user