]> git.lizzy.rs Git - rust.git/commitdiff
Change --crate-type metadata to --emit=metadata
authorNick Cameron <ncameron@mozilla.com>
Fri, 23 Dec 2016 06:39:20 +0000 (19:39 +1300)
committerNick Cameron <ncameron@mozilla.com>
Thu, 29 Dec 2016 00:24:45 +0000 (13:24 +1300)
18 files changed:
src/librustc/middle/dependency_format.rs
src/librustc/middle/reachable.rs
src/librustc/middle/weak_lang_items.rs
src/librustc/session/config.rs
src/librustc_driver/driver.rs
src/librustc_driver/lib.rs
src/librustc_metadata/creader.rs
src/librustc_trans/back/link.rs
src/librustc_trans/back/lto.rs
src/librustc_trans/back/symbol_export.rs
src/librustc_trans/back/write.rs
src/librustc_trans/base.rs
src/test/compile-fail/auxiliary/rmeta_meta.rs
src/test/compile-fail/rmeta-lib-pass.rs
src/test/compile-fail/rmeta-pass.rs
src/test/compile-fail/rmeta.rs
src/test/compile-fail/rmeta_meta_main.rs
src/test/run-pass/auxiliary/rmeta_rmeta.rs

index 075b3d7a8e90c9e2588bac8f87a5d7dc0f175e75..662b5a2e2e21edc4170d835b73fd4ed4ac840048 100644 (file)
@@ -103,6 +103,10 @@ pub fn calculate(sess: &session::Session) {
 
 fn calculate_type(sess: &session::Session,
                   ty: config::CrateType) -> DependencyList {
+    if sess.opts.output_types.contains_key(&config::OutputType::Metadata) {
+        return Vec::new();
+    }
+
     match ty {
         // If the global prefer_dynamic switch is turned off, first attempt
         // static linkage (this can fail).
@@ -114,7 +118,7 @@ fn calculate_type(sess: &session::Session,
 
         // No linkage happens with rlibs, we just needed the metadata (which we
         // got long ago), so don't bother with anything.
-        config::CrateTypeRlib | config::CrateTypeMetadata => return Vec::new(),
+        config::CrateTypeRlib => return Vec::new(),
 
         // Staticlibs and cdylibs must have all static dependencies. If any fail
         // to be found, we generate some nice pretty errors.
index ee841afc02169e96d0d5cf15eb1197a2f6ca650c..765d93742d8fbc4f521b629bfb5f29094bd8b2cb 100644 (file)
@@ -139,7 +139,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
     fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> ReachableContext<'a, 'tcx> {
         let any_library = tcx.sess.crate_types.borrow().iter().any(|ty| {
             *ty == config::CrateTypeRlib || *ty == config::CrateTypeDylib ||
-            *ty == config::CrateTypeProcMacro || *ty == config::CrateTypeMetadata
+            *ty == config::CrateTypeProcMacro
         });
         ReachableContext {
             tcx: tcx,
index c6df1497e681dd3ac3c4587d0c7d45e772ff3c29..acb506878e6b65eb94f45d772dab26fe388ec647 100644 (file)
@@ -75,8 +75,7 @@ fn verify(sess: &Session, items: &lang_items::LanguageItems) {
             config::CrateTypeCdylib |
             config::CrateTypeExecutable |
             config::CrateTypeStaticlib => true,
-            config::CrateTypeRlib |
-            config::CrateTypeMetadata => false,
+            config::CrateTypeRlib => false,
         }
     });
     if !needs_check {
index a78482171a0de501abaa1d0f40ffd6292e995807..c1927379534821c360c8e76c227a46170202d519 100644 (file)
@@ -73,6 +73,7 @@ pub enum OutputType {
     Bitcode,
     Assembly,
     LlvmAssembly,
+    Metadata,
     Object,
     Exe,
     DepInfo,
@@ -86,7 +87,8 @@ fn is_compatible_with_codegen_units_and_single_output_file(&self) -> bool {
             OutputType::Bitcode |
             OutputType::Assembly |
             OutputType::LlvmAssembly |
-            OutputType::Object => false,
+            OutputType::Object |
+            OutputType::Metadata => false,
         }
     }
 
@@ -96,6 +98,7 @@ fn shorthand(&self) -> &'static str {
             OutputType::Assembly => "asm",
             OutputType::LlvmAssembly => "llvm-ir",
             OutputType::Object => "obj",
+            OutputType::Metadata => "metadata",
             OutputType::Exe => "link",
             OutputType::DepInfo => "dep-info",
         }
@@ -107,6 +110,7 @@ pub fn extension(&self) -> &'static str {
             OutputType::Assembly => "s",
             OutputType::LlvmAssembly => "ll",
             OutputType::Object => "o",
+            OutputType::Metadata => "rmeta",
             OutputType::DepInfo => "d",
             OutputType::Exe => "",
         }
@@ -482,7 +486,6 @@ pub enum CrateType {
     CrateTypeStaticlib,
     CrateTypeCdylib,
     CrateTypeProcMacro,
-    CrateTypeMetadata,
 }
 
 #[derive(Clone, Hash)]
@@ -1159,12 +1162,12 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
                              assumed.", "[KIND=]NAME"),
         opt::multi_s("", "crate-type", "Comma separated list of types of crates
                                     for the compiler to emit",
-                   "[bin|lib|rlib|dylib|cdylib|staticlib|metadata]"),
+                   "[bin|lib|rlib|dylib|cdylib|staticlib]"),
         opt::opt_s("", "crate-name", "Specify the name of the crate being built",
                "NAME"),
         opt::multi_s("", "emit", "Comma separated list of types of output for \
                               the compiler to emit",
-                 "[asm|llvm-bc|llvm-ir|obj|link|dep-info]"),
+                 "[asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info]"),
         opt::multi_s("", "print", "Comma separated list of compiler information to \
                                print on stdout", &print_opts.join("|")),
         opt::flagmulti_s("g",  "",  "Equivalent to -C debuginfo=2"),
@@ -1327,6 +1330,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
                     "llvm-ir" => OutputType::LlvmAssembly,
                     "llvm-bc" => OutputType::Bitcode,
                     "obj" => OutputType::Object,
+                    "metadata" => OutputType::Metadata,
                     "link" => OutputType::Exe,
                     "dep-info" => OutputType::DepInfo,
                     part => {
@@ -1553,7 +1557,6 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
                 "cdylib"    => CrateTypeCdylib,
                 "bin"       => CrateTypeExecutable,
                 "proc-macro" => CrateTypeProcMacro,
-                "metadata"  => CrateTypeMetadata,
                 _ => {
                     return Err(format!("unknown crate type: `{}`",
                                        part));
@@ -1638,7 +1641,6 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
             CrateTypeStaticlib => "staticlib".fmt(f),
             CrateTypeCdylib => "cdylib".fmt(f),
             CrateTypeProcMacro => "proc-macro".fmt(f),
-            CrateTypeMetadata => "metadata".fmt(f),
         }
     }
 }
index 8da9a23f4faad2d5b949592641fafe752a91b279..291f0e0d50d8fa4ea83421224d030e2ff741ad36 100644 (file)
@@ -1182,9 +1182,6 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c
                          Some(ref n) if *n == "rlib" => {
                              Some(config::CrateTypeRlib)
                          }
-                         Some(ref n) if *n == "metadata" => {
-                             Some(config::CrateTypeMetadata)
-                         }
                          Some(ref n) if *n == "dylib" => {
                              Some(config::CrateTypeDylib)
                          }
index f84622c2f028553a547113d7f0b2ef6a40c499b0..5ceec9edda3d07a5aaef494ac70e3b864b7018e1 100644 (file)
@@ -493,7 +493,8 @@ fn build_controller(&mut self,
             control.after_hir_lowering.stop = Compilation::Stop;
         }
 
-        if !sess.opts.output_types.keys().any(|&i| i == OutputType::Exe) {
+        if !sess.opts.output_types.keys().any(|&i| i == OutputType::Exe ||
+                                                   i == OutputType::Metadata) {
             control.after_llvm.stop = Compilation::Stop;
         }
 
index a9af4118c5957f7266fe05bfdf6252fe58192696..724c164b3b41af747310df2a02c2917b6fb30310 100644 (file)
@@ -799,8 +799,7 @@ fn inject_allocator_crate(&mut self) {
                 config::CrateTypeProcMacro |
                 config::CrateTypeCdylib |
                 config::CrateTypeStaticlib => need_lib_alloc = true,
-                config::CrateTypeRlib |
-                config::CrateTypeMetadata => {}
+                config::CrateTypeRlib => {}
             }
         }
         if !need_lib_alloc && !need_exe_alloc { return }
index 648dc4c24c9a658c79426f2b53d2f5c707ca7f6a..58fe1e8e1c27eea6f41f9304287fd8eec13e3160 100644 (file)
@@ -191,7 +191,8 @@ pub fn link_binary(sess: &Session,
     let mut out_filenames = Vec::new();
     for &crate_type in sess.crate_types.borrow().iter() {
         // Ignore executable crates if we have -Z no-trans, as they will error.
-        if sess.opts.debugging_opts.no_trans &&
+        if (sess.opts.debugging_opts.no_trans ||
+            sess.opts.output_types.contains_key(&OutputType::Metadata)) &&
            crate_type == config::CrateTypeExecutable {
             continue;
         }
@@ -200,15 +201,16 @@ pub fn link_binary(sess: &Session,
            bug!("invalid output type `{:?}` for target os `{}`",
                 crate_type, sess.opts.target_triple);
         }
-        let out_file = link_binary_output(sess, trans, crate_type, outputs,
-                                          crate_name);
+        let out_file = link_binary_output(sess, trans, crate_type, outputs, crate_name);
         out_filenames.push(out_file);
     }
 
     // Remove the temporary object file and metadata if we aren't saving temps
     if !sess.opts.cg.save_temps {
-        for obj in object_filenames(trans, outputs) {
-            remove(sess, &obj);
+        if !sess.opts.output_types.contains_key(&OutputType::Metadata) {
+            for obj in object_filenames(trans, outputs) {
+                remove(sess, &obj);
+            }
         }
         remove(sess, &outputs.with_extension("metadata.o"));
     }
@@ -259,13 +261,15 @@ pub fn filename_for_input(sess: &Session,
                           crate_name: &str,
                           outputs: &OutputFilenames) -> PathBuf {
     let libname = format!("{}{}", crate_name, sess.opts.cg.extra_filename);
+
+    if outputs.outputs.contains_key(&OutputType::Metadata) {
+        return outputs.out_directory.join(&format!("lib{}.rmeta", libname));
+    }
+
     match crate_type {
         config::CrateTypeRlib => {
             outputs.out_directory.join(&format!("lib{}.rlib", libname))
         }
-        config::CrateTypeMetadata => {
-            outputs.out_directory.join(&format!("lib{}.rmeta", libname))
-        }
         config::CrateTypeCdylib |
         config::CrateTypeProcMacro |
         config::CrateTypeDylib => {
@@ -351,20 +355,21 @@ fn link_binary_output(sess: &Session,
         Err(err) => sess.fatal(&format!("couldn't create a temp dir: {}", err)),
     };
 
-    match crate_type {
-        config::CrateTypeRlib => {
-            link_rlib(sess, Some(trans), &objects, &out_filename,
-                      tmpdir.path()).build();
-        }
-        config::CrateTypeStaticlib => {
-            link_staticlib(sess, &objects, &out_filename, tmpdir.path());
-        }
-        config::CrateTypeMetadata => {
-            emit_metadata(sess, trans, &out_filename);
-        }
-        _ => {
-            link_natively(sess, crate_type, &objects, &out_filename, trans,
-                          outputs, tmpdir.path());
+    if outputs.outputs.contains_key(&OutputType::Metadata) {
+        emit_metadata(sess, trans, &out_filename);
+    } else {
+        match crate_type {
+            config::CrateTypeRlib => {
+                link_rlib(sess, Some(trans), &objects, &out_filename,
+                          tmpdir.path()).build();
+            }
+            config::CrateTypeStaticlib => {
+                link_staticlib(sess, &objects, &out_filename, tmpdir.path());
+            }
+            _ => {
+                link_natively(sess, crate_type, &objects, &out_filename, trans,
+                              outputs, tmpdir.path());
+            }
         }
     }
 
index f137bfff034d0e37c7cc9af7afd364a86d42064b..0ef3f351a2a4bffdb58292beb058e482a73416cc 100644 (file)
@@ -34,7 +34,6 @@ pub fn crate_type_allows_lto(crate_type: config::CrateType) -> bool {
 
         config::CrateTypeDylib     |
         config::CrateTypeRlib      |
-        config::CrateTypeMetadata  |
         config::CrateTypeProcMacro => false,
     }
 }
index eef464eb7f4dc61098e64884dd9f9a70ae1ac756..5f16291892387fb6b2622895a4979b37625b0618 100644 (file)
@@ -149,7 +149,6 @@ pub fn crate_export_threshold(crate_type: config::CrateType)
         config::CrateTypeProcMacro  |
         config::CrateTypeCdylib     => SymbolExportLevel::C,
         config::CrateTypeRlib       |
-        config::CrateTypeMetadata   |
         config::CrateTypeDylib      => SymbolExportLevel::Rust,
     }
 }
index de8814f143e04f62b4c07b046a7c5ac0039b01f7..fb485a7f0f5a223ee6de2b61af485e8a0ed5a25f 100644 (file)
@@ -701,8 +701,8 @@ pub fn run_passes(sess: &Session,
 
     for output_type in output_types.keys() {
         match *output_type {
-            OutputType::Bitcode => { modules_config.emit_bc = true; },
-            OutputType::LlvmAssembly => { modules_config.emit_ir = true; },
+            OutputType::Bitcode => { modules_config.emit_bc = true; }
+            OutputType::LlvmAssembly => { modules_config.emit_ir = true; }
             OutputType::Assembly => {
                 modules_config.emit_asm = true;
                 // If we're not using the LLVM assembler, this function
@@ -711,8 +711,9 @@ pub fn run_passes(sess: &Session,
                 if !sess.opts.output_types.contains_key(&OutputType::Assembly) {
                     metadata_config.emit_obj = true;
                 }
-            },
-            OutputType::Object => { modules_config.emit_obj = true; },
+            }
+            OutputType::Object => { modules_config.emit_obj = true; }
+            OutputType::Metadata => { metadata_config.emit_obj = true; }
             OutputType::Exe => {
                 modules_config.emit_obj = true;
                 metadata_config.emit_obj = true;
@@ -853,6 +854,7 @@ pub fn run_passes(sess: &Session,
                 user_wants_objects = true;
                 copy_if_one_unit(OutputType::Object, true);
             }
+            OutputType::Metadata |
             OutputType::Exe |
             OutputType::DepInfo => {}
         }
index 76bb1c56af3818aa155be237b4bb5da7292aded4..47b76658bdd1481689e5c960e8c7862004c232df 100644 (file)
@@ -807,8 +807,7 @@ enum MetadataKind {
             config::CrateTypeStaticlib |
             config::CrateTypeCdylib => MetadataKind::None,
 
-            config::CrateTypeRlib |
-            config::CrateTypeMetadata => MetadataKind::Uncompressed,
+            config::CrateTypeRlib => MetadataKind::Uncompressed,
 
             config::CrateTypeDylib |
             config::CrateTypeProcMacro => MetadataKind::Compressed,
@@ -1191,7 +1190,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
 
     // Skip crate items and just output metadata in -Z no-trans mode.
     if tcx.sess.opts.debugging_opts.no_trans ||
-       tcx.sess.crate_types.borrow().iter().all(|ct| ct == &config::CrateTypeMetadata) {
+       tcx.sess.opts.output_types.contains_key(&config::OutputType::Metadata) {
         let linker_info = LinkerInfo::new(&shared_ccx, &ExportedSymbols::empty());
         return CrateTranslation {
             modules: modules,
index 7bd1a96f452d83a53c47aaeb4cbe7a397c08b466..4207fc2373b1749ad49c929fe83655c1778cf4a2 100644 (file)
@@ -9,8 +9,9 @@
 // except according to those terms.
 
 // no-prefer-dynamic
+// compile-flags: --emit=metadata
 
-#![crate_type="metadata"]
+#![crate_type="rlib"]
 
 pub struct Foo {
     pub field: i32,
index f2ac37a2ce9f597925d07daa1bde884abc3ca770..dde559b018cde55ecbc1f7fdac6f8cefc68e5262 100644 (file)
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// compile-flags: --emit=metadata
 // aux-build:rmeta_rlib.rs
 // no-prefer-dynamic
 // must-compile-successfully
@@ -15,8 +16,6 @@
 // Check that building a metadata crate works with a dependent, rlib crate.
 // This is a cfail test since there is no executable to run.
 
-#![crate_type="metadata"]
-
 extern crate rmeta_rlib;
 use rmeta_rlib::Foo;
 
index 2c0b6f77c1e08114d0239f36fac1192e5f71d86f..5b24da79a7e63a953d6eebadc9f997e3319a962a 100644 (file)
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// compile-flags: --emit=metadata
 // aux-build:rmeta_meta.rs
 // no-prefer-dynamic
 // must-compile-successfully
@@ -16,8 +17,6 @@
 // crate.
 // This is a cfail test since there is no executable to run.
 
-#![crate_type="metadata"]
-
 extern crate rmeta_meta;
 use rmeta_meta::Foo;
 
index 455574bbb9dde58912e0f721fc2138730ab3c8ca..edcf98d99647654b66eb4d6c47f7b82e5b8d8ef3 100644 (file)
@@ -9,11 +9,10 @@
 // except according to those terms.
 
 // no-prefer-dynamic
+// compile-flags: --emit=metadata
 
 // Check that building a metadata crate finds an error.
 
-#![crate_type="metadata"]
-
 fn main() {
     let _ = Foo; //~ ERROR unresolved value `Foo`
 }
index 1c922c281397a8f45102c2d64a909a2819b05000..ffeb5bc3b858f26261364c70dc2059af9f25349f 100644 (file)
@@ -8,13 +8,13 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// compile-flags: --emit=metadata
 // aux-build:rmeta_meta.rs
 // no-prefer-dynamic
 
 // Check that building a metadata crate finds an error with a dependent,
 // metadata-only crate.
 
-#![crate_type="metadata"]
 
 extern crate rmeta_meta;
 use rmeta_meta::Foo;
index 394845b66f3d3a105694589464d879349d60096a..c3cfe89ee5c3e9cca6b80d7a3721a682bc9e301d 100644 (file)
@@ -9,8 +9,9 @@
 // except according to those terms.
 
 // no-prefer-dynamic
+// compile-flags: --emit=metadata
 
-#![crate_type="metadata"]
+#![crate_type="rlib"]
 #![crate_name="rmeta_aux"]
 
 pub struct Foo {