about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-07-08 13:31:41 +0000
committerbors <bors@rust-lang.org>2014-07-08 13:31:41 +0000
commitbfe4ddfdea45533c98657701509bb7185fd96cba (patch)
tree019280c736bb5cab19f2413bb874506c30b8eda2
parente2e237afc1f9887699414c33332faa1efaba41ce (diff)
parent2c26a00f91ab76a25316dc51befea03188b545d4 (diff)
downloadrust-bfe4ddfdea45533c98657701509bb7185fd96cba.tar.gz
rust-bfe4ddfdea45533c98657701509bb7185fd96cba.zip
auto merge of #15518 : alexcrichton/rust/fix-some-crate-names, r=sfackler
The output file was only being renamed based off #[crate_name], not #[crate_id]
or --crate-name. Both of these behaviors have been restored now.
-rw-r--r--src/librustc/driver/driver.rs19
-rw-r--r--src/librustc/lint/builtin.rs2
-rw-r--r--src/test/run-make/crate-name-priority/Makefile13
-rw-r--r--src/test/run-make/crate-name-priority/foo.rs11
-rw-r--r--src/test/run-make/crate-name-priority/foo1.rs14
5 files changed, 54 insertions, 5 deletions
diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs
index 16605c06017..7e34ff2dbbd 100644
--- a/src/librustc/driver/driver.rs
+++ b/src/librustc/driver/driver.rs
@@ -903,10 +903,21 @@ pub fn build_output_filenames(input: &Input,
             };
 
             // If a crate name is present, we use it as the link name
-           let stem = match attr::find_crate_name(attrs) {
-                None => input.filestem(),
-                Some(name) => name.get().to_string(),
-            };
+            let stem = sess.opts.crate_name.clone().or_else(|| {
+                attr::find_crate_name(attrs).map(|n| n.get().to_string())
+            }).or_else(|| {
+                // NB: this clause can be removed once #[crate_id] is no longer
+                // deprecated.
+                //
+                // Also note that this will be warned about later so we don't
+                // warn about it here.
+                use syntax::crateid::CrateId;
+                attrs.iter().find(|at| at.check_name("crate_id"))
+                     .and_then(|at| at.value_str())
+                     .and_then(|s| from_str::<CrateId>(s.get()))
+                     .map(|id| id.name)
+            }).unwrap_or(input.filestem());
+
             OutputFilenames {
                 out_directory: dirpath,
                 out_filestem: stem,
diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs
index 0ab3d50cfbc..7b8026e32e0 100644
--- a/src/librustc/lint/builtin.rs
+++ b/src/librustc/lint/builtin.rs
@@ -575,12 +575,12 @@ impl LintPass for UnusedAttribute {
         ];
 
         static CRATE_ATTRS: &'static [&'static str] = &[
+            "crate_name",
             "crate_type",
             "feature",
             "no_start",
             "no_main",
             "no_std",
-            "crate_id",
             "desc",
             "comment",
             "license",
diff --git a/src/test/run-make/crate-name-priority/Makefile b/src/test/run-make/crate-name-priority/Makefile
new file mode 100644
index 00000000000..250602710f5
--- /dev/null
+++ b/src/test/run-make/crate-name-priority/Makefile
@@ -0,0 +1,13 @@
+-include ../tools.mk
+
+all:
+	$(RUSTC) foo.rs
+	rm $(TMPDIR)/$(call BIN,foo)
+	$(RUSTC) foo.rs --crate-name bar
+	rm $(TMPDIR)/$(call BIN,bar)
+	$(RUSTC) foo1.rs
+	rm $(TMPDIR)/$(call BIN,foo)
+	$(RUSTC) foo1.rs --crate-name bar
+	rm $(TMPDIR)/$(call BIN,bar)
+	$(RUSTC) foo1.rs --crate-name bar -o $(TMPDIR)/bar1
+	rm $(TMPDIR)/$(call BIN,bar1)
diff --git a/src/test/run-make/crate-name-priority/foo.rs b/src/test/run-make/crate-name-priority/foo.rs
new file mode 100644
index 00000000000..8ae3d072362
--- /dev/null
+++ b/src/test/run-make/crate-name-priority/foo.rs
@@ -0,0 +1,11 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {}
diff --git a/src/test/run-make/crate-name-priority/foo1.rs b/src/test/run-make/crate-name-priority/foo1.rs
new file mode 100644
index 00000000000..0f02f100572
--- /dev/null
+++ b/src/test/run-make/crate-name-priority/foo1.rs
@@ -0,0 +1,14 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_name = "foo"]
+
+fn main() {}
+