From 250b4459c95e5921a993cd061cfe7857c4f62296 Mon Sep 17 00:00:00 2001 From: Sean Griffin <sean@seantheprogrammer.com> Date: Thu, 6 Oct 2016 12:20:59 -0400 Subject: [PATCH] Remove `embed_migrations!` temporarily Unfortunately it will be impossible to write this macro using the Macros 1.1 API. While this is an important feature that I want to keep, I more importantly want to keep the main repository working on stable. It will have to live as a separate crate, and possibly have an API change to work around build scripts. --- .travis.yml | 2 +- CHANGELOG.md | 5 + diesel_codegen_old/Cargo.toml | 22 --- diesel_codegen_old/README.md | 182 -------------------- diesel_codegen_old/src/lib.rs | 12 -- diesel_codegen_syntex/Cargo.toml | 11 +- diesel_codegen_syntex/build.rs | 88 +++++----- diesel_codegen_syntex/src/lib.in.rs | 1 - diesel_codegen_syntex/src/lib.rs | 16 -- diesel_codegen_syntex/src/migrations.rs | 190 --------------------- diesel_codegen_syntex/src/util.rs | 2 - diesel_tests/Cargo.toml | 14 +- diesel_tests/build.rs | 1 - diesel_tests/tests/lib.rs | 4 +- diesel_tests/tests/schema.rs | 14 +- examples/getting_started_step_1/Cargo.toml | 1 - examples/getting_started_step_1/src/lib.rs | 3 +- examples/getting_started_step_2/Cargo.toml | 1 - examples/getting_started_step_2/src/lib.rs | 3 +- examples/getting_started_step_3/Cargo.toml | 1 - examples/getting_started_step_3/src/lib.rs | 3 +- examples/getting_started_step_4/Cargo.toml | 3 +- examples/getting_started_step_4/src/lib.rs | 3 +- 23 files changed, 70 insertions(+), 512 deletions(-) delete mode 100644 diesel_codegen_old/Cargo.toml delete mode 100644 diesel_codegen_old/README.md delete mode 100644 diesel_codegen_old/src/lib.rs delete mode 100644 diesel_codegen_syntex/src/migrations.rs diff --git a/.travis.yml b/.travis.yml index 962670158339..2c2fe8842923 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ dist: trusty rust: - stable - beta - - nightly-2016-09-29 + - nightly cache: cargo addons: postgresql: '9.4' diff --git a/CHANGELOG.md b/CHANGELOG.md index 71e794a479fb..000f4251890f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,11 @@ for Rust libraries in [RFC #1105](https://github.com/rust-lang/rfcs/blob/master/ [bash completion]: https://github.com/diesel-rs/diesel/blob/b1a0d9901f0f2a8c8d530ccba8173b57f332b891/diesel_cli/README.md#bash-completion +### Removed + +* `embed_migrations!` has been removed, as it is incompatible with the Macros + 1.1 API. It will be released as a separate crate in the coming weeks. + ### Changed * Structs annotated with `#[has_many]` or `#[belongs_to]` now require diff --git a/diesel_codegen_old/Cargo.toml b/diesel_codegen_old/Cargo.toml deleted file mode 100644 index f6952095229c..000000000000 --- a/diesel_codegen_old/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "diesel_codegen_old" -version = "0.7.2" -authors = ["Sean Griffin <sean@seantheprogrammer.com>"] -license = "MIT OR Apache-2.0" -description = "Annotations to remove boilerplate from Diesel" -documentation = "https://github.com/diesel-rs/diesel/blob/master/diesel_codegen" -homepage = "http://diesel.rs" -repository = "https://github.com/diesel-rs/diesel/tree/master/diesel_codegen" -keywords = ["orm", "database", "postgres", "sql", "codegen"] - -[dependencies] -diesel_codegen_syntex = { path = "../diesel_codegen_syntex", default-features = false } - -[features] -default = ["postgres", "dotenv"] -dotenv = ["diesel_codegen_syntex/dotenv"] -postgres = ["diesel_codegen_syntex/postgres"] -sqlite = ["diesel_codegen_syntex/sqlite"] - -[lib] -plugin = true diff --git a/diesel_codegen_old/README.md b/diesel_codegen_old/README.md deleted file mode 100644 index d1d9e7a77b58..000000000000 --- a/diesel_codegen_old/README.md +++ /dev/null @@ -1,182 +0,0 @@ -Diesel Codegen -============ - -Provides various macros and annotations for -[Diesel](http://docs.diesel.rs/diesel/index.html) to reduce the amount of -boilerplate needing to be written. It can be used through `rustc_plugin`, or -`syntex` on stable. - -Using on nightly ----------------- - -Make sure you're using nightly-2016-08-18, we don't test against earlier or -later versions. We update our supported nightly version to the latest nightly -once every 6 weeks, coinciding with Rust releases. - -Add this line to your dependencies section in `Cargo.toml` - -```toml -diesel_codegen = { version = "0.7.0", features = ["postgres"] } -``` - -Then you'll need to add two lines to the root of your crate. - -```rust -#![feature(custom_derive, custom_attribute, plugin)] -#![plugin(diesel_codegen)] -``` - -After that, you'll be good to go. - -Using on stable ---------------- - -On stable, you'll need to use [`syntex`](https://crates.io/crates/syntex) to -build any modules using our annotations. Add the following to your -build-dependencies. - -```toml -diesel_codegen_syntex = { version = "0.7.0", features = ["postgres"] } -syntex = "0.38.0" -``` - -You'll need to move any code using annotations into a different file. - -`src/schema.rs` - -```rust -include!(concat!(env!("OUT_DIR"), "/schema.rs")); -``` - -`src/schema.in.rs` - -```rust -#[derive(Queryable)] -pub struct User { - id -> i32, - name -> String, -} -``` - -Then create a `build.rs` with the following: - -```rust -extern crate syntex; -extern crate diesel_codegen_syntex as diesel_codegen; - -use std::env; -use std::path::Path; - -pub fn main() { - let out_dir = env::var_os("OUT_DIR").unwrap(); - let mut registry = syntex::Registry::new(); - diesel_codegen::register(&mut registry); - - let src = Path::new("src/schema.in.rs"); - let dst = Path::new(&out_dir).join("schema.rs"); - - registry.expand("", &src, &dst).unwrap(); -} -``` - -Note that compiler errors will be reported in the generated file, not the source -file. For that reason, it's often easier to develop with nightly rust, and -deploy or test on stable. You can see an example of how to do this by looking at -[Diesel's tests](https://github.com/diesel-rs/diesel/tree/master/diesel_tests). - -Struct annotations ------------------- - -### `#[derive(Queryable)]` - -Adds an implementation of the [`Queryable`][queryable] trait to the annotated -item. At this time it only supports structs with named fields. Enums and tuple -structs are not supported. - -### `#[derive(Insertable)]` - -Adds an implementation of the [`Insertable`][insertable] trait to the annotated -item, targeting the given table. Can only annotate structs and tuple structs. -Enums are not supported. See [field annotations][#field-annotations] for -additional configurations. - -Structs which derive `Insertable` must have a table name annotation like so: -`#[table_name = "something"]` - -### `#[derive(AsChangeset)]` - -Adds an implementation of the [`AsChangeset`][as_changeset] trait to the -annotated item, targeting the given table. at this time, it only supports -structs with named fields. Tuple structs and enums are not supported. See [field -annotations][#field-annotations] for additional configurations. - -Structs which derive `AsChangeset` must have a table name annotation like so: -`#[table_name = "something"]` - -Any fields which are of the type `Option` will be skipped when their value is -`None`. This makes it easy to support APIs where you may not want to update all -of the fields of a record on every request. - -If you'd like `None` to change a field to `NULL`, instead of skipping it, you -can pass the `treat_none_as_null` option like so: -`#[changeset_options(treat_none_as_null = "true")]` - -If the struct has a field for the primary key, an additional function, -`save_changes<T: Queryable<..>>(&self, connection: &Connection) -> -QueryResult<T>`, will be added to the model. This will persist any changes made, -and return the resulting record. It is intended to be a shorthand for filtering -by the primary key. - -[queryable]: http://docs.diesel.rs/diesel/query_source/trait.Queryable.html -[insertable]: http://docs.diesel.rs/diesel/trait.Insertable.html -[as_changeset]: http://docs.diesel.rs/diesel/query_builder/trait.AsChangeset.html - -Field annotations ------------------ - -### `#[column_name="value"]` - -Any field can be annotated with `column_name=` to have it map to a column with a -different name. This is required for all fields of tuple structs. - -Macros ---------------------- - -### `infer_schema!("database_url")` - -Queries the database for the names of all tables, and calls -`infer_table_from_schema!` for each one. We recommend using with the -[`dotenv`](https://github.com/slapresta/rust-dotenv) crate, and invoking this as -`infer_schema!(dotenv!("DATABASE_URL"))` - -### `infer_table_from_schema!("database_url", "table_name")` - -Establishes a database connection at compile time, loads the schema information -about a table's columns, and invokes -[`table`](http://docs.diesel.rs/diesel/macro.table!.html) for you -automatically. We recommend using with the -[`dotenv`](https://github.com/slapresta/rust-dotenv) crate, and invoking this as -`infer_table_from_schema!(dotenv!("DATABASE_URL"), "table_name")` - -At this time, the schema inference macros do not support types from third party -crates, and having any columns with a type not already supported will result in -a compiler error (please open an issue if this happens unexpectedly for a type -listed in [our -docs](http://docs.diesel.rs/diesel/types/index.html#structs).) - -### `embed_migrations!()` - -This macro will read your migrations at compile time, and embed a module you can -use to execute them at runtime without the migration files being present on the -file system. This is useful if you would like to use Diesel's migration -infrastructure, but want to ship a single executable file (such as for embedded -applications). It can also be used to apply migrations to an in memory database -(Diesel does this for its own test suite). - -You can optionally pass the path to the migrations directory to this macro. When -left unspecified, Diesel Codegen will search for the migrations directory in the -same way that Diesel CLI does. If specified, the path should be relative to the -directory where the macro was invoked (similar to -[`include_str!`][include-str]). - -[include-str]: https://doc.rust-lang.org/nightly/std/macro.include_str!.html diff --git a/diesel_codegen_old/src/lib.rs b/diesel_codegen_old/src/lib.rs deleted file mode 100644 index 298073a9171d..000000000000 --- a/diesel_codegen_old/src/lib.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![feature(rustc_private, plugin_registrar)] - -extern crate diesel_codegen_syntex; -extern crate syntax; -extern crate rustc_plugin; - -use diesel_codegen_syntex::*; - -#[plugin_registrar] -pub fn register(reg: &mut rustc_plugin::Registry) { - reg.register_macro("embed_migrations", migrations::expand_embed_migrations); -} diff --git a/diesel_codegen_syntex/Cargo.toml b/diesel_codegen_syntex/Cargo.toml index b5dfc521b13a..e2e78c15d9d8 100644 --- a/diesel_codegen_syntex/Cargo.toml +++ b/diesel_codegen_syntex/Cargo.toml @@ -11,12 +11,12 @@ repository = "https://github.com/diesel-rs/diesel/tree/master/diesel_codegen" keywords = ["orm", "database", "postgres", "sql", "codegen"] [build-dependencies] -syntex = { version = "0.44.0", optional = true } -syntex_syntax = { version = "0.44.0", optional = true } +syntex = { version = "0.44.0" } +syntex_syntax = { version = "0.44.0" } [dependencies] -syntex = { version = "0.44.0", optional = true } -syntex_syntax = { version = "0.44.0", optional = true } +syntex = { version = "0.44.0" } +syntex_syntax = { version = "0.44.0" } diesel = { version = "0.7.0", default-features = false } diesel_codegen_shared = { path = "../diesel_codegen_shared", default-features = false } @@ -24,8 +24,7 @@ diesel_codegen_shared = { path = "../diesel_codegen_shared", default-features = tempdir = "0.3.4" [features] -default = ["with-syntex", "postgres", "dotenv"] +default = ["postgres", "dotenv"] dotenv = ["diesel_codegen_shared/dotenv"] -with-syntex = ["syntex", "syntex_syntax"] postgres = ["diesel/postgres", "diesel_codegen_shared/postgres"] sqlite = ["diesel/sqlite", "diesel_codegen_shared/sqlite"] diff --git a/diesel_codegen_syntex/build.rs b/diesel_codegen_syntex/build.rs index d336831b10ae..5a27f077c360 100644 --- a/diesel_codegen_syntex/build.rs +++ b/diesel_codegen_syntex/build.rs @@ -1,58 +1,46 @@ -#[cfg(feature = "with-syntex")] -mod inner { - extern crate syntex; - extern crate syntex_syntax as syntax; - - use std::env; - use std::path::Path; - use std::thread; - - use self::syntax::codemap::Span; - use self::syntax::ext::base::{self, ExtCtxt}; - use self::syntax::tokenstream::TokenTree; - - pub fn main() { - with_extra_stack(move || { - let out_dir = env::var_os("OUT_DIR").unwrap(); - let mut registry = syntex::Registry::new(); - - macro_rules! register_quote_macro { - ($macro_name: ident, $name: ident) => { - fn $name<'cx>( - cx: &'cx mut ExtCtxt, - sp: Span, - tts: &[TokenTree], - ) -> Box<base::MacResult + 'cx> { - syntax::ext::quote::$name(cx, sp, tts) - } - - registry.add_macro(stringify!($macro_name), $name); - } - } +extern crate syntex; +extern crate syntex_syntax as syntax; - register_quote_macro!(quote_ty, expand_quote_ty); - register_quote_macro!(quote_item, expand_quote_item); - register_quote_macro!(quote_tokens, expand_quote_tokens); - register_quote_macro!(quote_expr, expand_quote_expr); +use std::env; +use std::path::Path; +use std::thread; - let src = Path::new("src/lib.in.rs"); - let dst = Path::new(&out_dir).join("lib.rs"); +use self::syntax::codemap::Span; +use self::syntax::ext::base::{self, ExtCtxt}; +use self::syntax::tokenstream::TokenTree; - registry.expand("", &src, &dst).unwrap(); - }); - } +fn main() { + with_extra_stack(move || { + let out_dir = env::var_os("OUT_DIR").unwrap(); + let mut registry = syntex::Registry::new(); + + macro_rules! register_quote_macro { + ($macro_name: ident, $name: ident) => { + fn $name<'cx>( + cx: &'cx mut ExtCtxt, + sp: Span, + tts: &[TokenTree], + ) -> Box<base::MacResult + 'cx> { + syntax::ext::quote::$name(cx, sp, tts) + } - fn with_extra_stack<F: FnOnce() + Send + 'static>(f: F) { - env::set_var("RUST_MIN_STACK", "16777216"); // 16MB - thread::spawn(f).join().unwrap(); - } -} + registry.add_macro(stringify!($macro_name), $name); + } + } + + register_quote_macro!(quote_ty, expand_quote_ty); + register_quote_macro!(quote_item, expand_quote_item); + register_quote_macro!(quote_tokens, expand_quote_tokens); + register_quote_macro!(quote_expr, expand_quote_expr); -#[cfg(not(feature = "with-syntex"))] -mod inner { - pub fn main() {} + let src = Path::new("src/lib.in.rs"); + let dst = Path::new(&out_dir).join("lib.rs"); + + registry.expand("", &src, &dst).unwrap(); + }); } -fn main() { - inner::main(); +fn with_extra_stack<F: FnOnce() + Send + 'static>(f: F) { + env::set_var("RUST_MIN_STACK", "16777216"); // 16MB + thread::spawn(f).join().unwrap(); } diff --git a/diesel_codegen_syntex/src/lib.in.rs b/diesel_codegen_syntex/src/lib.in.rs index 3ae49f9f5dab..dfc9614c2104 100644 --- a/diesel_codegen_syntex/src/lib.in.rs +++ b/diesel_codegen_syntex/src/lib.in.rs @@ -2,7 +2,6 @@ pub mod associations; mod attr; pub mod identifiable; pub mod insertable; -pub mod migrations; mod model; pub mod queryable; pub mod schema_inference; diff --git a/diesel_codegen_syntex/src/lib.rs b/diesel_codegen_syntex/src/lib.rs index 76baa3f5084b..85ca2fd39e8d 100644 --- a/diesel_codegen_syntex/src/lib.rs +++ b/diesel_codegen_syntex/src/lib.rs @@ -1,30 +1,15 @@ -#![cfg_attr(not(feature = "with-syntex"), feature(rustc_private, quote))] #![deny(warnings)] #[macro_use] extern crate diesel; extern crate diesel_codegen_shared; -#[cfg(feature = "with-syntex")] extern crate syntex; - -#[cfg(feature = "with-syntex")] extern crate syntex_syntax as syntax; -#[cfg(not(feature = "with-syntex"))] -extern crate syntax; - -#[cfg(not(feature = "with-syntex"))] -extern crate rustc_plugin; - -#[cfg(feature = "with-syntex")] include!(concat!(env!("OUT_DIR"), "/lib.rs")); -#[cfg(not(feature = "with-syntex"))] -include!("lib.in.rs"); - mod util; -#[cfg(feature = "with-syntex")] pub fn register(reg: &mut syntex::Registry) { reg.add_attr("feature(custom_derive)"); reg.add_attr("feature(custom_attribute)"); @@ -34,7 +19,6 @@ pub fn register(reg: &mut syntex::Registry) { reg.add_decorator("derive_Identifiable", identifiable::expand_derive_identifiable); reg.add_decorator("derive_Insertable", insertable::expand_derive_insertable); reg.add_decorator("derive_Queryable", queryable::expand_derive_queryable); - reg.add_macro("embed_migrations", migrations::expand_embed_migrations); reg.add_macro("infer_table_from_schema", schema_inference::expand_load_table); reg.add_macro("infer_schema", schema_inference::expand_infer_schema); diff --git a/diesel_codegen_syntex/src/migrations.rs b/diesel_codegen_syntex/src/migrations.rs deleted file mode 100644 index 52896fe773a1..000000000000 --- a/diesel_codegen_syntex/src/migrations.rs +++ /dev/null @@ -1,190 +0,0 @@ -use diesel::migrations::search_for_migrations_directory; -use std::error::Error; -use std::path::{Path, PathBuf}; -use syntax::ast; -use syntax::codemap::Span; -use syntax::ext::base::*; -use syntax::util::small_vector::SmallVector; -use syntax::ptr::P; -use syntax::ext::build::AstBuilder; -use syntax::tokenstream; - -pub fn expand_embed_migrations<'cx>( - cx: &'cx mut ExtCtxt, - sp: Span, - tts: &[tokenstream::TokenTree] -) -> Box<MacResult+'cx> { - let migrations_expr = migrations_directory_from_args(cx, sp, tts) - .and_then(|d| migration_literals_from_path(cx, sp, &d)); - let migrations_expr = match migrations_expr { - Err(e) => { - cx.span_err(sp, &format!("Error reading migrations: {}", e)); - return DummyResult::expr(sp); - } - Ok(v) => v, - }; - - let item = quote_item!(cx, mod embedded_migrations { - extern crate diesel; - - use self::diesel::migrations::*; - use self::diesel::connection::SimpleConnection; - use std::io; - - struct EmbeddedMigration { - version: &'static str, - up_sql: &'static str, - } - - impl Migration for EmbeddedMigration { - fn version(&self) -> &str { - self.version - } - - fn run(&self, conn: &SimpleConnection) -> Result<(), RunMigrationsError> { - conn.batch_execute(self.up_sql).map_err(Into::into) - } - - fn revert(&self, _conn: &SimpleConnection) -> Result<(), RunMigrationsError> { - unreachable!() - } - } - - const ALL_MIGRATIONS: &'static [&'static Migration] = $migrations_expr; - - pub fn run<C: MigrationConnection>(conn: &C) -> Result<(), RunMigrationsError> { - run_with_output(conn, &mut io::sink()) - } - - pub fn run_with_output<C: MigrationConnection>(conn: &C, out: &mut io::Write) - -> Result<(), RunMigrationsError> - { - run_migrations(conn, ALL_MIGRATIONS.iter().map(|v| *v), out) - } - }).unwrap(); - MacEager::items(SmallVector::one(item)) -} - -fn migrations_directory_from_args( - cx: &mut ExtCtxt, - sp: Span, - tts: &[tokenstream::TokenTree], -) -> Result<PathBuf, Box<Error>> { - let callsite_file = cx.codemap().span_to_filename(sp); - let relative_path_to_migrations = if tts.is_empty() { - None - } else { - match get_single_str_from_tts(cx, sp, tts, "embed_migrations!") { - None => return Err("Usage error".into()), - value => value, - } - }; - let callsite_path = Path::new(&callsite_file); - let migrations_path = relative_path_to_migrations.as_ref().map(Path::new); - resolve_migrations_directory(callsite_path, migrations_path) -} - -fn resolve_migrations_directory( - callsite: &Path, - relative_path_to_migrations: Option<&Path>, -) -> Result<PathBuf, Box<Error>> { - let callsite_dir = callsite.parent().unwrap(); - - let result = match relative_path_to_migrations { - Some(dir) => callsite_dir.join(dir), - None => try!(search_for_migrations_directory(&callsite_dir)), - }; - - result.canonicalize().map_err(Into::into) -} - -fn migration_literals_from_path( - cx: &ExtCtxt, - sp: Span, - path: &Path, -) -> Result<P<ast::Expr>, Box<Error>> { - use diesel::migrations::migration_paths_in_directory; - - let exprs = try!(migration_paths_in_directory(&path)).into_iter() - .map(|e| migration_literal_from_path(cx, &e.path())) - .collect(); - Ok(cx.expr_vec_slice(sp, try!(exprs))) -} - -fn migration_literal_from_path( - cx: &ExtCtxt, - path: &Path, -) -> Result<P<ast::Expr>, Box<Error>> { - use diesel::migrations::version_from_path; - - let version = try!(version_from_path(path)); - let sql_file = path.join("up.sql"); - let sql_file_path = sql_file.to_string_lossy(); - - Ok(quote_expr!(cx, &EmbeddedMigration { - version: $version, - up_sql: include_str!($sql_file_path), - })) -} - -#[cfg(test)] -mod tests { - extern crate tempdir; - - use self::tempdir::TempDir; - use std::fs; - use std::path::Path; - use super::resolve_migrations_directory; - - #[test] - fn migrations_directory_resolved_relative_to_callsite_dir() { - let tempdir = TempDir::new("diesel").unwrap(); - fs::create_dir_all(tempdir.path().join("foo/special_migrations")).unwrap(); - let callsite = tempdir.path().join("foo/bar.rs"); - let relative_path = Some(Path::new("special_migrations")); - - assert_eq!( - tempdir.path().join("foo/special_migrations").canonicalize().ok(), - resolve_migrations_directory(&callsite, relative_path).ok() - ); - } - - #[test] - fn migrations_directory_canonicalizes_result() { - let tempdir = TempDir::new("diesel").unwrap(); - fs::create_dir_all(tempdir.path().join("foo/migrations/bar")).unwrap(); - fs::create_dir_all(tempdir.path().join("foo/bar")).unwrap(); - let callsite = tempdir.path().join("foo/bar/baz.rs"); - let relative_path = Some(Path::new("../migrations/bar")); - - assert_eq!( - tempdir.path().join("foo/migrations/bar").canonicalize().ok(), - resolve_migrations_directory(&callsite, relative_path).ok() - ); - } - - #[test] - fn migrations_directory_defaults_to_searching_migrations_path() { - let tempdir = TempDir::new("diesel").unwrap(); - fs::create_dir_all(tempdir.path().join("foo/migrations")).unwrap(); - fs::create_dir_all(tempdir.path().join("foo/bar")).unwrap(); - let callsite = tempdir.path().join("foo/bar/baz.rs"); - - assert_eq!( - tempdir.path().join("foo/migrations").canonicalize().ok(), - resolve_migrations_directory(&callsite, None).ok() - ); - } - - #[test] - fn migrations_directory_allows_no_parent_dir_for_callsite() { - let tempdir = TempDir::new("diesel").unwrap(); - fs::create_dir_all(tempdir.path().join("special_migrations")).unwrap(); - let callsite = tempdir.path().join("bar.rs"); - let relative_path = Some(Path::new("special_migrations")); - assert_eq!( - tempdir.path().join("special_migrations").canonicalize().ok(), - resolve_migrations_directory(&callsite, relative_path).ok() - ); - } -} diff --git a/diesel_codegen_syntex/src/util.rs b/diesel_codegen_syntex/src/util.rs index 82089c928c30..da26b8d8549a 100644 --- a/diesel_codegen_syntex/src/util.rs +++ b/diesel_codegen_syntex/src/util.rs @@ -66,7 +66,6 @@ pub fn ident_value_of_attr_with_name( .and_then(|a| single_arg_value_of_attr(cx, &a, name)) } -#[cfg(feature = "with-syntex")] const KNOWN_ATTRIBUTES: &'static [&'static str] = &[ "belongs_to", "changeset_options", @@ -75,7 +74,6 @@ const KNOWN_ATTRIBUTES: &'static [&'static str] = &[ "table_name", ]; -#[cfg(feature = "with-syntex")] pub fn strip_attributes(krate: ast::Crate) -> ast::Crate { use syntax::fold; diff --git a/diesel_tests/Cargo.toml b/diesel_tests/Cargo.toml index 31b9a6e4c14b..785343402770 100644 --- a/diesel_tests/Cargo.toml +++ b/diesel_tests/Cargo.toml @@ -8,30 +8,28 @@ build = "build.rs" [build-dependencies] syntex = { version = "0.44.0", optional = true } diesel_codegen_syntex = { path = "../diesel_codegen_syntex", optional = true } -dotenv_codegen = { version = "0.9.0", optional = true } diesel = { path = "../diesel", default-features = false } -dotenv = { git = "https://github.com/slapresta/rust-dotenv.git" } +dotenv = "0.8.0" [dependencies] assert_matches = "1.0.1" chrono = { version = "^0.2.17" } diesel = { path = "../diesel", default-features = false, features = ["quickcheck", "chrono", "uuid"] } diesel_codegen = { version = "0.7.2", optional = true } -diesel_codegen_old = { path = "../diesel_codegen_old", default-features = false, features = ["dotenv"], optional = true } -dotenv_macros = { version = "0.9.0", optional = true } +dotenv = "0.8.0" quickcheck = { version = "0.3.1", features = ["unstable"] } uuid = { version = ">=0.2.0, <0.4.0" } [features] default = ["with-syntex"] -unstable = ["diesel/unstable", "dotenv_macros", "diesel_codegen", "diesel_codegen_old"] -with-syntex = ["syntex", "dotenv_codegen", "diesel_codegen_syntex"] +unstable = ["diesel/unstable", "diesel_codegen"] +with-syntex = ["syntex", "diesel_codegen_syntex"] postgres = ["diesel/postgres"] sqlite = ["diesel/sqlite"] stable_postgres = ["with-syntex", "postgres", "diesel_codegen_syntex/postgres"] stable_sqlite = ["with-syntex", "sqlite", "diesel_codegen_syntex/sqlite"] -unstable_postgres = ["unstable", "postgres", "diesel_codegen/postgres", "diesel_codegen_old/postgres"] -unstable_sqlite = ["unstable", "sqlite", "diesel_codegen/sqlite", "diesel_codegen_old/sqlite"] +unstable_postgres = ["unstable", "postgres", "diesel_codegen/postgres"] +unstable_sqlite = ["unstable", "sqlite", "diesel_codegen/sqlite"] [[test]] name = "integration_tests" diff --git a/diesel_tests/build.rs b/diesel_tests/build.rs index 6bb26bcb9e5d..06f38937becb 100644 --- a/diesel_tests/build.rs +++ b/diesel_tests/build.rs @@ -2,7 +2,6 @@ mod inner { extern crate syntex; extern crate diesel_codegen_syntex as diesel_codegen; - extern crate dotenv_codegen; use std::env; use std::path::Path; diff --git a/diesel_tests/tests/lib.rs b/diesel_tests/tests/lib.rs index b7fe18f8c2c3..4764174f9c5a 100644 --- a/diesel_tests/tests/lib.rs +++ b/diesel_tests/tests/lib.rs @@ -1,11 +1,11 @@ -#![cfg_attr(feature = "unstable", feature(plugin, rustc_macro))] -#![cfg_attr(feature = "unstable", plugin(diesel_codegen_old, dotenv_macros))] +#![cfg_attr(feature = "unstable", feature(rustc_macro))] extern crate quickcheck; #[macro_use] extern crate assert_matches; #[macro_use] extern crate diesel; #[cfg(feature = "unstable")] #[macro_use] extern crate diesel_codegen; +extern crate dotenv; #[cfg(feature = "unstable")] include!("lib.in.rs"); diff --git a/diesel_tests/tests/schema.rs b/diesel_tests/tests/schema.rs index 5bb593da45fa..a11dcd05ecbb 100644 --- a/diesel_tests/tests/schema.rs +++ b/diesel_tests/tests/schema.rs @@ -1,4 +1,6 @@ use diesel::*; +use dotenv::dotenv; +use std::env; infer_schema!("dotenv:DATABASE_URL"); @@ -122,18 +124,18 @@ pub fn connection() -> TestConnection { #[cfg(feature = "postgres")] pub fn connection_without_transaction() -> TestConnection { - let connection_url = dotenv!("DATABASE_URL", - "DATABASE_URL must be set in order to run tests"); + dotenv().ok(); + let connection_url = env::var("DATABASE_URL") + .expect("DATABASE_URL must be set in order to run tests"); ::diesel::pg::PgConnection::establish(&connection_url).unwrap() } -#[cfg(feature = "sqlite")] -embed_migrations!("../../migrations/sqlite"); - #[cfg(feature = "sqlite")] pub fn connection_without_transaction() -> TestConnection { + use std::io; let connection = ::diesel::sqlite::SqliteConnection::establish(":memory:").unwrap(); - embedded_migrations::run(&connection).unwrap(); + let migrations_dir = migrations::find_migrations_directory().unwrap().join("sqlite"); + migrations::run_pending_migrations_in_directory(&connection, &migrations_dir, &mut io::sink()).unwrap(); connection } diff --git a/examples/getting_started_step_1/Cargo.toml b/examples/getting_started_step_1/Cargo.toml index 59fe11c27e4e..f4408215a458 100644 --- a/examples/getting_started_step_1/Cargo.toml +++ b/examples/getting_started_step_1/Cargo.toml @@ -6,5 +6,4 @@ authors = ["Sean Griffin <sean@seantheprogrammer.com>"] [dependencies] diesel = "0.7.1" diesel_codegen = { version = "0.7.2", features = ["postgres"] } -diesel_codegen_old = { path = "../../diesel_codegen_old", features = ["postgres"] } dotenv = "0.8.0" diff --git a/examples/getting_started_step_1/src/lib.rs b/examples/getting_started_step_1/src/lib.rs index 2329edc10bce..034759147014 100644 --- a/examples/getting_started_step_1/src/lib.rs +++ b/examples/getting_started_step_1/src/lib.rs @@ -1,5 +1,4 @@ -#![feature(plugin, rustc_macro)] -#![plugin(diesel_codegen_old)] +#![feature(rustc_macro)] #[macro_use] extern crate diesel; #[macro_use] extern crate diesel_codegen; diff --git a/examples/getting_started_step_2/Cargo.toml b/examples/getting_started_step_2/Cargo.toml index 59fe11c27e4e..f4408215a458 100644 --- a/examples/getting_started_step_2/Cargo.toml +++ b/examples/getting_started_step_2/Cargo.toml @@ -6,5 +6,4 @@ authors = ["Sean Griffin <sean@seantheprogrammer.com>"] [dependencies] diesel = "0.7.1" diesel_codegen = { version = "0.7.2", features = ["postgres"] } -diesel_codegen_old = { path = "../../diesel_codegen_old", features = ["postgres"] } dotenv = "0.8.0" diff --git a/examples/getting_started_step_2/src/lib.rs b/examples/getting_started_step_2/src/lib.rs index 72012466307e..4e0b61058358 100644 --- a/examples/getting_started_step_2/src/lib.rs +++ b/examples/getting_started_step_2/src/lib.rs @@ -1,5 +1,4 @@ -#![feature(plugin, rustc_macro)] -#![plugin(diesel_codegen_old)] +#![feature(rustc_macro)] #[macro_use] extern crate diesel; #[macro_use] extern crate diesel_codegen; diff --git a/examples/getting_started_step_3/Cargo.toml b/examples/getting_started_step_3/Cargo.toml index 59fe11c27e4e..f4408215a458 100644 --- a/examples/getting_started_step_3/Cargo.toml +++ b/examples/getting_started_step_3/Cargo.toml @@ -6,5 +6,4 @@ authors = ["Sean Griffin <sean@seantheprogrammer.com>"] [dependencies] diesel = "0.7.1" diesel_codegen = { version = "0.7.2", features = ["postgres"] } -diesel_codegen_old = { path = "../../diesel_codegen_old", features = ["postgres"] } dotenv = "0.8.0" diff --git a/examples/getting_started_step_3/src/lib.rs b/examples/getting_started_step_3/src/lib.rs index 72012466307e..4e0b61058358 100644 --- a/examples/getting_started_step_3/src/lib.rs +++ b/examples/getting_started_step_3/src/lib.rs @@ -1,5 +1,4 @@ -#![feature(plugin, rustc_macro)] -#![plugin(diesel_codegen_old)] +#![feature(rustc_macro)] #[macro_use] extern crate diesel; #[macro_use] extern crate diesel_codegen; diff --git a/examples/getting_started_step_4/Cargo.toml b/examples/getting_started_step_4/Cargo.toml index 97de85aa4781..3572fb8b4b89 100644 --- a/examples/getting_started_step_4/Cargo.toml +++ b/examples/getting_started_step_4/Cargo.toml @@ -11,10 +11,9 @@ diesel_codegen_syntex = { version = "0.7.2", features = ["postgres"], optional = [dependencies] diesel = "0.7.1" diesel_codegen = { version = "0.7.2", features = ["postgres"], optional = true } -diesel_codegen_old = { path = "../../diesel_codegen_old", features = ["postgres"], optional = true } dotenv = "0.8.0" [features] default = ["nightly"] with-syntex = ["syntex", "diesel_codegen_syntex"] -nightly = ["diesel/unstable", "diesel_codegen", "diesel_codegen_old"] +nightly = ["diesel/unstable", "diesel_codegen"] diff --git a/examples/getting_started_step_4/src/lib.rs b/examples/getting_started_step_4/src/lib.rs index bf67dfc276ae..d758055dd3d5 100644 --- a/examples/getting_started_step_4/src/lib.rs +++ b/examples/getting_started_step_4/src/lib.rs @@ -1,5 +1,4 @@ -#![cfg_attr(feature = "nightly", feature(plugin, rustc_macro))] -#![cfg_attr(feature = "nightly", plugin(diesel_codegen_old))] +#![cfg_attr(feature = "nightly", feature(rustc_macro))] #[macro_use] extern crate diesel; #[cfg(feature = "nightly")]