Skip to content

Commit

Permalink
Fix duplicate definitions when adding registries
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanzab committed Mar 24, 2016
1 parent 99dfd89 commit 0ac24a6
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
22 changes: 17 additions & 5 deletions gl_generator/registry/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Brendan Zabarauskas and the gl-rs developers
// Copyright 2015-2016 Brendan Zabarauskas and the gl-rs developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,9 +15,9 @@
extern crate khronos_api;

use std::borrow::Cow;
use std::collections::BTreeSet;
use std::collections::HashMap;
use std::collections::{BTreeSet, HashMap, HashSet};
use std::fmt;
use std::hash::{Hash, Hasher};
use std::io;
use std::ops::Add;

Expand Down Expand Up @@ -57,6 +57,12 @@ pub struct Enum {
pub ty: Cow<'static, str>,
}

impl Hash for Enum {
fn hash<H: Hasher>(&self, state: &mut H) {
self.ident.hash(state);
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Binding {
pub ident: String,
Expand All @@ -72,6 +78,12 @@ pub struct Cmd {
pub glx: Option<GlxOpcode>,
}

impl Hash for Cmd {
fn hash<H: Hasher>(&self, state: &mut H) {
self.proto.ident.hash(state);
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct GlxOpcode {
pub opcode: String,
Expand All @@ -81,8 +93,8 @@ pub struct GlxOpcode {
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Registry {
pub api: Api,
pub enums: Vec<Enum>,
pub cmds: Vec<Cmd>,
pub enums: HashSet<Enum>,
pub cmds: HashSet<Cmd>,
pub aliases: HashMap<String, Vec<String>>,
}

Expand Down
11 changes: 11 additions & 0 deletions gl_tests/test_add_registries/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
# we don't include some metadata to avoid accidental publishes
name = "test_add_registries"
version = "0.0.0"
build = "build.rs"

[lib]
path = "lib.rs"

[build-dependencies]
gl_generator = { path = "../../gl_generator" }
32 changes: 32 additions & 0 deletions gl_tests/test_add_registries/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2016 Brendan Zabarauskas and the gl-rs developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

extern crate gl_generator;

use gl_generator::*;
use std::env;
use std::fs::File;
use std::path::*;

fn main() {
let dest = env::var("OUT_DIR").unwrap();
let mut file = File::create(&Path::new(&dest).join("test_add_registries.rs")).unwrap();

let registry0 = Registry::new(Api::Gl, (3, 2), Profile::Core, Fallbacks::All, []);
let registry1 = Registry::new(Api::Gl, (3, 2), Profile::Core, Fallbacks::All, []);

(registry0 + registry1)
.write_bindings(GlobalGenerator, &mut file)
.unwrap();
}
17 changes: 17 additions & 0 deletions gl_tests/test_add_registries/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2016 Brendan Zabarauskas and the gl-rs developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod gl {
include!(concat!(env!("OUT_DIR"), "/test_add_registries.rs"));
}

0 comments on commit 0ac24a6

Please sign in to comment.