Skip to content

Commit 46aa9ed

Browse files
committed
#2: support building with very old apt
1 parent 7a55e26 commit 46aa9ed

File tree

7 files changed

+54
-12
lines changed

7 files changed

+54
-12
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ libc = "0.2"
2424
[dev-dependencies]
2525
boolinator = "2"
2626
itertools = "0.7"
27+
28+
[features]
29+
default = []
30+
ye-olde-apt = []

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ While the code in this crate is available under a permissive MIT license,
2121
`libapt-pkg-dev` must be installed. The [`gcc`](https://crates.io/crates/gcc)
2222
crate is used to try and find a native compiler.
2323

24+
The `ye-olde-apt` feature provides support for `apt <1.2` (Ubuntu 14.04 (Trusty),
25+
Debian 7 (Jessie) (2015)). This works by just deleting methods which are not
26+
available in that version. See
27+
[#2](https://github.com/FauxFaux/apt-pkg-native-rs/issues/2#issuecomment-351180818).
28+
29+
2430
### Thread safety
2531

2632
It is intended that the crate should be usable from multiple threads.

apt-pkg-c/lib.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ extern "C" {
8080
// ver_iter access
8181
const char *ver_iter_version(PVerIterator *iterator);
8282
const char *ver_iter_section(PVerIterator *iterator);
83+
const char *ver_iter_arch(PVerIterator *iterator);
84+
85+
#ifndef YE_OLDE_APT
8386
const char *ver_iter_source_package(PVerIterator *iterator);
8487
const char *ver_iter_source_version(PVerIterator *iterator);
85-
const char *ver_iter_arch(PVerIterator *iterator);
8688
int32_t ver_iter_priority(PVerIterator *iterator);
87-
89+
#endif
8890

8991
// ver_file_iter creation and deletion
9092
PVerFileIterator *ver_iter_ver_file_iter(PVerIterator *iterator);
@@ -227,6 +229,8 @@ const char *ver_iter_section(PVerIterator *wrapper) {
227229
return wrapper->iterator.Section();
228230
}
229231

232+
#ifndef YE_OLDE_APT
233+
230234
const char *ver_iter_source_package(PVerIterator *wrapper) {
231235
return wrapper->iterator.SourcePkgName();
232236
}
@@ -235,16 +239,19 @@ const char *ver_iter_source_version(PVerIterator *wrapper) {
235239
return wrapper->iterator.SourceVerStr();
236240
}
237241

238-
const char *ver_iter_arch(PVerIterator *wrapper) {
239-
return wrapper->iterator.Arch();
240-
}
241-
242242
int32_t ver_iter_priority(PVerIterator *wrapper) {
243243
// The priority is a "short", which is roughly a (signed) int16_t;
244244
// going bigger just in case
245245
return wrapper->cache->cache_file->GetPolicy()->GetPriority(wrapper->iterator);
246246
}
247247

248+
#endif
249+
250+
const char *ver_iter_arch(PVerIterator *wrapper) {
251+
return wrapper->iterator.Arch();
252+
}
253+
254+
248255
PVerFileIterator *ver_iter_ver_file_iter(PVerIterator *wrapper) {
249256
PVerFileIterator *new_wrapper = new PVerFileIterator();
250257
new_wrapper->iterator = wrapper->iterator.FileList();

build.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ const SRC: &str = "apt-pkg-c/lib.cpp";
55
fn main() {
66
println!("cargo:rerun-if-changed={}", SRC);
77

8-
gcc::Build::new()
9-
.file(SRC)
10-
.cpp(true)
11-
.flag("-std=gnu++11")
12-
.compile("libapt-pkg-c.a");
8+
let mut build = gcc::Build::new();
9+
build.file(SRC);
10+
build.cpp(true);
11+
build.flag("-std=gnu++11");
12+
13+
#[cfg(feature="ye-olde-apt")]
14+
{
15+
build.define("YE_OLDE_APT", "1");
16+
}
17+
18+
build.compile("libapt-pkg-c.a");
1319
}

src/raw.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,15 @@ extern "C" {
6767

6868
pub fn ver_iter_version(iterator: PVerIterator) -> *mut c_char;
6969
pub fn ver_iter_section(iterator: PVerIterator) -> *mut c_char;
70+
71+
#[cfg(not(feature="ye-olde-apt"))]
7072
pub fn ver_iter_source_package(iterator: PVerIterator) -> *mut c_char;
73+
74+
#[cfg(not(feature="ye-olde-apt"))]
7175
pub fn ver_iter_source_version(iterator: PVerIterator) -> *mut c_char;
7276
pub fn ver_iter_arch(iterator: PVerIterator) -> *mut c_char;
77+
78+
#[cfg(not(feature="ye-olde-apt"))]
7379
pub fn ver_iter_priority(iterator: PVerIterator) -> i32;
7480

7581
pub fn ver_iter_ver_file_iter(iterator: PVerIterator) -> PVerFileIterator;

src/sane.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,20 +238,23 @@ impl<'c> VerView<'c> {
238238
unsafe { make_owned_ascii_string(raw::ver_iter_section(self.ptr)) }
239239
}
240240

241+
#[cfg(not(feature="ye-olde-apt"))]
241242
pub fn source_package(&self) -> String {
242243
unsafe {
243244
make_owned_ascii_string(raw::ver_iter_source_package(self.ptr))
244245
.expect("versions always have a source package")
245246
}
246247
}
247248

249+
#[cfg(not(feature="ye-olde-apt"))]
248250
pub fn source_version(&self) -> String {
249251
unsafe {
250252
make_owned_ascii_string(raw::ver_iter_source_version(self.ptr))
251253
.expect("versions always have a source_version")
252254
}
253255
}
254256

257+
#[cfg(not(feature="ye-olde-apt"))]
255258
pub fn priority(&self) -> i32 {
256259
unsafe { raw::ver_iter_priority(self.ptr) }
257260
}

src/simple.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ pub struct Version {
4141
pub version: String,
4242
pub arch: String,
4343
pub section: Option<String>,
44+
45+
#[cfg(not(feature="ye-olde-apt"))]
4446
pub source_package: String,
47+
#[cfg(not(feature="ye-olde-apt"))]
4548
pub source_version: String,
49+
#[cfg(not(feature="ye-olde-apt"))]
4650
pub priority: i32,
4751
}
4852

@@ -53,8 +57,11 @@ impl Version {
5357
version: view.version(),
5458
arch: view.arch(),
5559
section: view.section(),
60+
#[cfg(not(feature="ye-olde-apt"))]
5661
source_package: view.source_package(),
62+
#[cfg(not(feature="ye-olde-apt"))]
5763
source_version: view.source_version(),
64+
#[cfg(not(feature="ye-olde-apt"))]
5865
priority: view.priority(),
5966
}
6067
}
@@ -66,13 +73,16 @@ impl fmt::Display for Version {
6673
if let Some(ref section) = self.section {
6774
write!(f, " in {}", section)?;
6875
}
76+
#[cfg(not(feature="ye-olde-apt"))]
6977
write!(
7078
f,
7179
" from {}:{} at {}",
7280
self.source_package,
7381
self.source_version,
7482
self.priority,
75-
)
83+
)?;
84+
85+
Ok(())
7686
}
7787
}
7888

0 commit comments

Comments
 (0)