#2: support building with very old apt
This commit is contained in:
parent
7a55e2678b
commit
46aa9ed07f
@ -24,3 +24,7 @@ libc = "0.2"
|
||||
[dev-dependencies]
|
||||
boolinator = "2"
|
||||
itertools = "0.7"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
ye-olde-apt = []
|
||||
|
@ -21,6 +21,12 @@ While the code in this crate is available under a permissive MIT license,
|
||||
`libapt-pkg-dev` must be installed. The [`gcc`](https://crates.io/crates/gcc)
|
||||
crate is used to try and find a native compiler.
|
||||
|
||||
The `ye-olde-apt` feature provides support for `apt <1.2` (Ubuntu 14.04 (Trusty),
|
||||
Debian 7 (Jessie) (2015)). This works by just deleting methods which are not
|
||||
available in that version. See
|
||||
[#2](https://github.com/FauxFaux/apt-pkg-native-rs/issues/2#issuecomment-351180818).
|
||||
|
||||
|
||||
### Thread safety
|
||||
|
||||
It is intended that the crate should be usable from multiple threads.
|
||||
|
@ -80,11 +80,13 @@ extern "C" {
|
||||
// ver_iter access
|
||||
const char *ver_iter_version(PVerIterator *iterator);
|
||||
const char *ver_iter_section(PVerIterator *iterator);
|
||||
const char *ver_iter_arch(PVerIterator *iterator);
|
||||
|
||||
#ifndef YE_OLDE_APT
|
||||
const char *ver_iter_source_package(PVerIterator *iterator);
|
||||
const char *ver_iter_source_version(PVerIterator *iterator);
|
||||
const char *ver_iter_arch(PVerIterator *iterator);
|
||||
int32_t ver_iter_priority(PVerIterator *iterator);
|
||||
|
||||
#endif
|
||||
|
||||
// ver_file_iter creation and deletion
|
||||
PVerFileIterator *ver_iter_ver_file_iter(PVerIterator *iterator);
|
||||
@ -227,6 +229,8 @@ const char *ver_iter_section(PVerIterator *wrapper) {
|
||||
return wrapper->iterator.Section();
|
||||
}
|
||||
|
||||
#ifndef YE_OLDE_APT
|
||||
|
||||
const char *ver_iter_source_package(PVerIterator *wrapper) {
|
||||
return wrapper->iterator.SourcePkgName();
|
||||
}
|
||||
@ -235,16 +239,19 @@ const char *ver_iter_source_version(PVerIterator *wrapper) {
|
||||
return wrapper->iterator.SourceVerStr();
|
||||
}
|
||||
|
||||
const char *ver_iter_arch(PVerIterator *wrapper) {
|
||||
return wrapper->iterator.Arch();
|
||||
}
|
||||
|
||||
int32_t ver_iter_priority(PVerIterator *wrapper) {
|
||||
// The priority is a "short", which is roughly a (signed) int16_t;
|
||||
// going bigger just in case
|
||||
return wrapper->cache->cache_file->GetPolicy()->GetPriority(wrapper->iterator);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
const char *ver_iter_arch(PVerIterator *wrapper) {
|
||||
return wrapper->iterator.Arch();
|
||||
}
|
||||
|
||||
|
||||
PVerFileIterator *ver_iter_ver_file_iter(PVerIterator *wrapper) {
|
||||
PVerFileIterator *new_wrapper = new PVerFileIterator();
|
||||
new_wrapper->iterator = wrapper->iterator.FileList();
|
||||
|
16
build.rs
16
build.rs
@ -5,9 +5,15 @@ const SRC: &str = "apt-pkg-c/lib.cpp";
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed={}", SRC);
|
||||
|
||||
gcc::Build::new()
|
||||
.file(SRC)
|
||||
.cpp(true)
|
||||
.flag("-std=gnu++11")
|
||||
.compile("libapt-pkg-c.a");
|
||||
let mut build = gcc::Build::new();
|
||||
build.file(SRC);
|
||||
build.cpp(true);
|
||||
build.flag("-std=gnu++11");
|
||||
|
||||
#[cfg(feature="ye-olde-apt")]
|
||||
{
|
||||
build.define("YE_OLDE_APT", "1");
|
||||
}
|
||||
|
||||
build.compile("libapt-pkg-c.a");
|
||||
}
|
||||
|
@ -67,9 +67,15 @@ extern "C" {
|
||||
|
||||
pub fn ver_iter_version(iterator: PVerIterator) -> *mut c_char;
|
||||
pub fn ver_iter_section(iterator: PVerIterator) -> *mut c_char;
|
||||
|
||||
#[cfg(not(feature="ye-olde-apt"))]
|
||||
pub fn ver_iter_source_package(iterator: PVerIterator) -> *mut c_char;
|
||||
|
||||
#[cfg(not(feature="ye-olde-apt"))]
|
||||
pub fn ver_iter_source_version(iterator: PVerIterator) -> *mut c_char;
|
||||
pub fn ver_iter_arch(iterator: PVerIterator) -> *mut c_char;
|
||||
|
||||
#[cfg(not(feature="ye-olde-apt"))]
|
||||
pub fn ver_iter_priority(iterator: PVerIterator) -> i32;
|
||||
|
||||
pub fn ver_iter_ver_file_iter(iterator: PVerIterator) -> PVerFileIterator;
|
||||
|
@ -238,6 +238,7 @@ impl<'c> VerView<'c> {
|
||||
unsafe { make_owned_ascii_string(raw::ver_iter_section(self.ptr)) }
|
||||
}
|
||||
|
||||
#[cfg(not(feature="ye-olde-apt"))]
|
||||
pub fn source_package(&self) -> String {
|
||||
unsafe {
|
||||
make_owned_ascii_string(raw::ver_iter_source_package(self.ptr))
|
||||
@ -245,6 +246,7 @@ impl<'c> VerView<'c> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature="ye-olde-apt"))]
|
||||
pub fn source_version(&self) -> String {
|
||||
unsafe {
|
||||
make_owned_ascii_string(raw::ver_iter_source_version(self.ptr))
|
||||
@ -252,6 +254,7 @@ impl<'c> VerView<'c> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature="ye-olde-apt"))]
|
||||
pub fn priority(&self) -> i32 {
|
||||
unsafe { raw::ver_iter_priority(self.ptr) }
|
||||
}
|
||||
|
@ -41,8 +41,12 @@ pub struct Version {
|
||||
pub version: String,
|
||||
pub arch: String,
|
||||
pub section: Option<String>,
|
||||
|
||||
#[cfg(not(feature="ye-olde-apt"))]
|
||||
pub source_package: String,
|
||||
#[cfg(not(feature="ye-olde-apt"))]
|
||||
pub source_version: String,
|
||||
#[cfg(not(feature="ye-olde-apt"))]
|
||||
pub priority: i32,
|
||||
}
|
||||
|
||||
@ -53,8 +57,11 @@ impl Version {
|
||||
version: view.version(),
|
||||
arch: view.arch(),
|
||||
section: view.section(),
|
||||
#[cfg(not(feature="ye-olde-apt"))]
|
||||
source_package: view.source_package(),
|
||||
#[cfg(not(feature="ye-olde-apt"))]
|
||||
source_version: view.source_version(),
|
||||
#[cfg(not(feature="ye-olde-apt"))]
|
||||
priority: view.priority(),
|
||||
}
|
||||
}
|
||||
@ -66,13 +73,16 @@ impl fmt::Display for Version {
|
||||
if let Some(ref section) = self.section {
|
||||
write!(f, " in {}", section)?;
|
||||
}
|
||||
#[cfg(not(feature="ye-olde-apt"))]
|
||||
write!(
|
||||
f,
|
||||
" from {}:{} at {}",
|
||||
self.source_package,
|
||||
self.source_version,
|
||||
self.priority,
|
||||
)
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user