]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass-fulldeps/compiler-calls.rs
Account for --remap-path-prefix in save-analysis
[rust.git] / src / test / run-pass-fulldeps / compiler-calls.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Test that the CompilerCalls interface to the compiler works.
12
13 // ignore-cross-compile
14
15 #![feature(rustc_private, path)]
16 #![feature(core)]
17
18 extern crate getopts;
19 extern crate rustc;
20 extern crate rustc_driver;
21 extern crate rustc_codegen_utils;
22 extern crate syntax;
23 extern crate rustc_errors as errors;
24 extern crate rustc_metadata;
25
26 use rustc::session::Session;
27 use rustc::session::config::{self, Input};
28 use rustc_driver::{driver, CompilerCalls, Compilation};
29 use rustc_codegen_utils::codegen_backend::CodegenBackend;
30 use rustc_metadata::cstore::CStore;
31 use syntax::ast;
32
33 use std::path::PathBuf;
34
35 struct TestCalls<'a> {
36     count: &'a mut u32
37 }
38
39 impl<'a> CompilerCalls<'a> for TestCalls<'a> {
40     fn early_callback(&mut self,
41                       _: &getopts::Matches,
42                       _: &config::Options,
43                       _: &ast::CrateConfig,
44                       _: &errors::registry::Registry,
45                       _: config::ErrorOutputType)
46                       -> Compilation {
47         *self.count *= 2;
48         Compilation::Continue
49     }
50
51     fn late_callback(&mut self,
52                      _: &CodegenBackend,
53                      _: &getopts::Matches,
54                      _: &Session,
55                      _: &CStore,
56                      _: &Input,
57                      _: &Option<PathBuf>,
58                      _: &Option<PathBuf>)
59                      -> Compilation {
60         *self.count *= 3;
61         Compilation::Stop
62     }
63
64     fn some_input(&mut self, input: Input, input_path: Option<PathBuf>)
65                   -> (Input, Option<PathBuf>) {
66         *self.count *= 5;
67         (input, input_path)
68     }
69
70     fn no_input(&mut self,
71                 _: &getopts::Matches,
72                 _: &config::Options,
73                 _: &ast::CrateConfig,
74                 _: &Option<PathBuf>,
75                 _: &Option<PathBuf>,
76                 _: &errors::registry::Registry)
77                 -> Option<(Input, Option<PathBuf>)> {
78         panic!("This shouldn't happen");
79     }
80
81     fn build_controller(self: Box<Self>,
82                         _: &Session,
83                         _: &getopts::Matches)
84                         -> driver::CompileController<'a> {
85         panic!("This shouldn't be called");
86     }
87 }
88
89
90 fn main() {
91     let mut count = 1;
92     {
93         let tc = TestCalls { count: &mut count };
94         // we should never get use this filename, but lets make sure they are valid args.
95         let args = vec!["compiler-calls".to_string(), "foo.rs".to_string()];
96         rustc_driver::run_compiler(&args, Box::new(tc), None, None);
97     }
98     assert_eq!(count, 30);
99 }