Skip to content

Commit 9da6065

Browse files
committed
Ensure that we are *actually* able to compile without PG
While the tests were passing previously, we didn't actually build if you compiled without libpq installed on your system. This corrects those issues, and the failures that resulted from it. There are several places where I'm legitimately unsure how the code compiled before this change. I've had to do some janky things to codegen to make it actually work, as there's an issue where cfg attrs aren't properly applied inside of `include!`. This is why the dummy version has to exist, and why it warns instead of errors. It might make sense to just define the macro as a no-op in the future.
1 parent d9f733f commit 9da6065

30 files changed

Lines changed: 95 additions & 62 deletions

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ matrix:
4343
allow_failures:
4444
- rust: nightly
4545
after_success:
46-
- "(cd diesel && travis-cargo --only stable doc-upload -- --features \"postgres sqlite\")"
46+
- "(cd diesel && travis-cargo --only stable doc-upload)"
4747
branches:
4848
only:
4949
- master

diesel_codegen/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ syntex_syntax = { version = "^0.26.0", optional = true }
1717
[dependencies]
1818
syntex = { version = "^0.26.0", optional = true }
1919
syntex_syntax = { version = "^0.26.0", optional = true }
20-
diesel = { git = "https://github.com/sgrif/diesel.git" }
20+
diesel = { path = "../diesel", default-features = false }
2121

2222
[features]
23-
default = ["with-syntex"]
23+
default = ["with-syntex", "postgres"]
2424
nightly = []
2525
with-syntex = ["syntex", "syntex_syntax"]
26+
postgres = ["diesel/postgres"]
2627

2728
[lib]
2829
name = "diesel_codegen"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use syntax::ast;
2+
use syntax::codemap::Span;
3+
use syntax::ext::base::*;
4+
5+
pub fn expand_load_table<'cx>(
6+
cx: &'cx mut ExtCtxt,
7+
sp: Span,
8+
_tts: &[ast::TokenTree]
9+
) -> Box<MacResult+'cx> {
10+
cx.span_warn(sp, "load_table_from_schema! is only supported on PostgreSQL");
11+
DummyResult::any(sp)
12+
}
13+
14+
pub fn expand_infer_schema<'cx>(
15+
cx: &'cx mut ExtCtxt,
16+
sp: Span,
17+
_tts: &[ast::TokenTree]
18+
) -> Box<MacResult+'cx> {
19+
cx.span_warn(sp, "infer_schema! is only supported on PostgreSQL");
20+
DummyResult::any(sp)
21+
}

diesel_codegen/src/lib.in.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@ mod attr;
33
mod insertable;
44
mod model;
55
mod queryable;
6+
#[cfg(feature = "postgres")]
67
mod schema_inference;
8+
#[cfg(not(feature = "postgres"))]
9+
#[path="dummy_schema_inference.rs"]
10+
mod schema_inference;
11+
712
mod update;

diesel_tests/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ build = "build.rs"
99
syntex = { version = "^0.26.0", optional = true }
1010
diesel_codegen = { path = "../diesel_codegen", default-features = false }
1111
dotenv_codegen = { git = "https://github.com/slapresta/rust-dotenv.git", optional = true }
12-
diesel = { path = "../diesel" }
12+
diesel = { path = "../diesel", default-features = false }
1313
dotenv = { git = "https://github.com/slapresta/rust-dotenv.git" }
1414

1515
[dependencies]
@@ -26,7 +26,7 @@ quickcheck = { git = "https://github.com/BurntSushi/quickcheck.git" }
2626
default = ["syntex", "diesel_codegen/with-syntex", "dotenv_codegen"]
2727
unstable = ["compiletest_rs", "diesel_codegen/nightly", "diesel/unstable",
2828
"quickcheck/unstable", "dotenv_macros"]
29-
postgres = ["diesel/postgres"]
29+
postgres = ["diesel/postgres", "diesel_codegen/postgres"]
3030
sqlite = ["diesel/sqlite"]
3131

3232
[[test]]

diesel_tests/build.rs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,33 @@ mod inner {
2525
pub fn main() {}
2626
}
2727

28-
extern crate diesel;
29-
extern crate dotenv;
30-
use diesel::*;
31-
use diesel::pg::PgConnection;
32-
use dotenv::dotenv;
33-
use std::io;
28+
#[cfg(feature = "postgres")]
29+
mod outer {
30+
extern crate diesel;
31+
extern crate dotenv;
32+
use self::diesel::*;
33+
use self::diesel::pg::PgConnection;
34+
use self::dotenv::dotenv;
35+
use std::io;
36+
37+
pub fn main() {
38+
dotenv().ok();
39+
let database_url = ::std::env::var("DATABASE_URL")
40+
.expect("DATABASE_URL must be set to run tests");
41+
let connection = PgConnection::establish(&database_url).unwrap();
42+
let migrations_dir = migrations::find_migrations_directory().unwrap().join("postgresql");
43+
migrations::run_pending_migrations_in_directory(&connection, &migrations_dir, &mut io::sink()).unwrap();
44+
::inner::main();
45+
}
46+
}
47+
48+
#[cfg(not(feature = "postgres"))]
49+
mod outer {
50+
pub fn main() {
51+
::inner::main();
52+
}
53+
}
3454

3555
fn main() {
36-
dotenv().ok();
37-
let database_url = ::std::env::var("DATABASE_URL")
38-
.expect("DATABASE_URL must be set to run tests");
39-
let connection = PgConnection::establish(&database_url).unwrap();
40-
let migrations_dir = migrations::find_migrations_directory().unwrap().join("postgresql");
41-
migrations::run_pending_migrations_in_directory(&connection, &migrations_dir, &mut io::sink()).unwrap();
42-
inner::main();
56+
outer::main();
4357
}

diesel_tests/tests/annotations.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ mod associations_can_have_nullable_foreign_keys {
9494

9595
table! {
9696
foos{
97-
id -> Serial,
97+
id -> Integer,
9898
}
9999
}
100100

101101
table! {
102102
bars {
103-
id -> Serial,
103+
id -> Integer,
104104
foo_id -> Nullable<Integer>,
105105
}
106106
}

diesel_tests/tests/compile-fail/global/cannot_mix_aggregate_and_non_aggregate_selects.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use diesel::expression::count;
66

77
table! {
88
users {
9-
id -> Serial,
9+
id -> Integer,
1010
}
1111
}
1212

diesel_tests/tests/compile-fail/global/cannot_pass_aggregate_to_where.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use diesel::expression::count;
66

77
table! {
88
users {
9-
id -> Serial,
9+
id -> Integer,
1010
}
1111
}
1212

diesel_tests/tests/compile-fail/global/expressions_can_only_be_compared_for_equality_to_expressions_of_same_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use diesel::*;
55

66
table! {
77
users {
8-
id -> Serial,
8+
id -> Integer,
99
name -> VarChar,
1010
}
1111
}

0 commit comments

Comments
 (0)