Move validate_crate_name to rustc_metadata
This commit is contained in:
@@ -2219,6 +2219,7 @@ dependencies = [
|
|||||||
"rustc 0.0.0",
|
"rustc 0.0.0",
|
||||||
"rustc_data_structures 0.0.0",
|
"rustc_data_structures 0.0.0",
|
||||||
"rustc_incremental 0.0.0",
|
"rustc_incremental 0.0.0",
|
||||||
|
"rustc_metadata_utils 0.0.0",
|
||||||
"rustc_mir 0.0.0",
|
"rustc_mir 0.0.0",
|
||||||
"rustc_target 0.0.0",
|
"rustc_target 0.0.0",
|
||||||
"syntax 0.0.0",
|
"syntax 0.0.0",
|
||||||
@@ -2352,6 +2353,7 @@ dependencies = [
|
|||||||
"rustc 0.0.0",
|
"rustc 0.0.0",
|
||||||
"rustc_data_structures 0.0.0",
|
"rustc_data_structures 0.0.0",
|
||||||
"rustc_errors 0.0.0",
|
"rustc_errors 0.0.0",
|
||||||
|
"rustc_metadata_utils 0.0.0",
|
||||||
"rustc_target 0.0.0",
|
"rustc_target 0.0.0",
|
||||||
"serialize 0.0.0",
|
"serialize 0.0.0",
|
||||||
"syntax 0.0.0",
|
"syntax 0.0.0",
|
||||||
@@ -2359,6 +2361,14 @@ dependencies = [
|
|||||||
"syntax_pos 0.0.0",
|
"syntax_pos 0.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc_metadata_utils"
|
||||||
|
version = "0.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"rustc 0.0.0",
|
||||||
|
"syntax_pos 0.0.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc_mir"
|
name = "rustc_mir"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
|
|||||||
@@ -260,33 +260,6 @@ pub trait CrateStore {
|
|||||||
|
|
||||||
pub type CrateStoreDyn = dyn CrateStore + sync::Sync;
|
pub type CrateStoreDyn = dyn CrateStore + sync::Sync;
|
||||||
|
|
||||||
// FIXME: find a better place for this?
|
|
||||||
pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
|
|
||||||
let mut err_count = 0;
|
|
||||||
{
|
|
||||||
let mut say = |s: &str| {
|
|
||||||
match (sp, sess) {
|
|
||||||
(_, None) => bug!("{}", s),
|
|
||||||
(Some(sp), Some(sess)) => sess.span_err(sp, s),
|
|
||||||
(None, Some(sess)) => sess.err(s),
|
|
||||||
}
|
|
||||||
err_count += 1;
|
|
||||||
};
|
|
||||||
if s.is_empty() {
|
|
||||||
say("crate name must not be empty");
|
|
||||||
}
|
|
||||||
for c in s.chars() {
|
|
||||||
if c.is_alphanumeric() { continue }
|
|
||||||
if c == '_' { continue }
|
|
||||||
say(&format!("invalid character `{}` in crate name: `{}`", c, s));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err_count > 0 {
|
|
||||||
sess.unwrap().abort_if_errors();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A dummy crate store that does not support any non-local crates,
|
/// A dummy crate store that does not support any non-local crates,
|
||||||
/// for test purposes.
|
/// for test purposes.
|
||||||
pub struct DummyCrateStore;
|
pub struct DummyCrateStore;
|
||||||
|
|||||||
@@ -20,3 +20,4 @@ rustc_target = { path = "../librustc_target" }
|
|||||||
rustc_data_structures = { path = "../librustc_data_structures" }
|
rustc_data_structures = { path = "../librustc_data_structures" }
|
||||||
rustc_mir = { path = "../librustc_mir" }
|
rustc_mir = { path = "../librustc_mir" }
|
||||||
rustc_incremental = { path = "../librustc_incremental" }
|
rustc_incremental = { path = "../librustc_incremental" }
|
||||||
|
rustc_metadata_utils = { path = "../librustc_metadata_utils" }
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ extern crate rustc_incremental;
|
|||||||
extern crate syntax;
|
extern crate syntax;
|
||||||
extern crate syntax_pos;
|
extern crate syntax_pos;
|
||||||
#[macro_use] extern crate rustc_data_structures;
|
#[macro_use] extern crate rustc_data_structures;
|
||||||
|
extern crate rustc_metadata_utils;
|
||||||
|
|
||||||
use rustc::ty::TyCtxt;
|
use rustc::ty::TyCtxt;
|
||||||
|
|
||||||
|
|||||||
@@ -10,11 +10,12 @@
|
|||||||
|
|
||||||
use rustc::session::config::{self, OutputFilenames, Input, OutputType};
|
use rustc::session::config::{self, OutputFilenames, Input, OutputType};
|
||||||
use rustc::session::Session;
|
use rustc::session::Session;
|
||||||
use rustc::middle::cstore::{self, LinkMeta};
|
use rustc::middle::cstore::LinkMeta;
|
||||||
use rustc::hir::svh::Svh;
|
use rustc::hir::svh::Svh;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use syntax::{ast, attr};
|
use syntax::{ast, attr};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
|
use rustc_metadata_utils::validate_crate_name;
|
||||||
|
|
||||||
pub fn out_filename(sess: &Session,
|
pub fn out_filename(sess: &Session,
|
||||||
crate_type: config::CrateType,
|
crate_type: config::CrateType,
|
||||||
@@ -61,7 +62,7 @@ pub fn find_crate_name(sess: Option<&Session>,
|
|||||||
attrs: &[ast::Attribute],
|
attrs: &[ast::Attribute],
|
||||||
input: &Input) -> String {
|
input: &Input) -> String {
|
||||||
let validate = |s: String, span: Option<Span>| {
|
let validate = |s: String, span: Option<Span>| {
|
||||||
cstore::validate_crate_name(sess, &s, span);
|
validate_crate_name(sess, &s, span);
|
||||||
s
|
s
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -20,3 +20,4 @@ serialize = { path = "../libserialize" }
|
|||||||
syntax = { path = "../libsyntax" }
|
syntax = { path = "../libsyntax" }
|
||||||
syntax_ext = { path = "../libsyntax_ext" }
|
syntax_ext = { path = "../libsyntax_ext" }
|
||||||
syntax_pos = { path = "../libsyntax_pos" }
|
syntax_pos = { path = "../libsyntax_pos" }
|
||||||
|
rustc_metadata_utils = { path = "../librustc_metadata_utils" }
|
||||||
|
|||||||
@@ -25,11 +25,13 @@ use rustc::session::config::{Sanitizer, self};
|
|||||||
use rustc_target::spec::{PanicStrategy, TargetTriple};
|
use rustc_target::spec::{PanicStrategy, TargetTriple};
|
||||||
use rustc::session::search_paths::PathKind;
|
use rustc::session::search_paths::PathKind;
|
||||||
use rustc::middle;
|
use rustc::middle;
|
||||||
use rustc::middle::cstore::{validate_crate_name, ExternCrate, ExternCrateSource};
|
use rustc::middle::cstore::{ExternCrate, ExternCrateSource};
|
||||||
use rustc::util::common::record_time;
|
use rustc::util::common::record_time;
|
||||||
use rustc::util::nodemap::FxHashSet;
|
use rustc::util::nodemap::FxHashSet;
|
||||||
use rustc::hir::map::Definitions;
|
use rustc::hir::map::Definitions;
|
||||||
|
|
||||||
|
use rustc_metadata_utils::validate_crate_name;
|
||||||
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::{cmp, fs};
|
use std::{cmp, fs};
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ extern crate serialize as rustc_serialize; // used by deriving
|
|||||||
extern crate rustc_errors as errors;
|
extern crate rustc_errors as errors;
|
||||||
extern crate syntax_ext;
|
extern crate syntax_ext;
|
||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
|
extern crate rustc_metadata_utils;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rustc;
|
extern crate rustc;
|
||||||
|
|||||||
13
src/librustc_metadata_utils/Cargo.toml
Normal file
13
src/librustc_metadata_utils/Cargo.toml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
[package]
|
||||||
|
authors = ["The Rust Project Developers"]
|
||||||
|
name = "rustc_metadata_utils"
|
||||||
|
version = "0.0.0"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "rustc_metadata_utils"
|
||||||
|
path = "lib.rs"
|
||||||
|
crate-type = ["dylib"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
rustc = { path = "../librustc" }
|
||||||
|
syntax_pos = { path = "../libsyntax_pos" }
|
||||||
42
src/librustc_metadata_utils/lib.rs
Normal file
42
src/librustc_metadata_utils/lib.rs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
// Copyright 2018 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.
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate rustc;
|
||||||
|
extern crate syntax_pos;
|
||||||
|
|
||||||
|
use rustc::session::Session;
|
||||||
|
use syntax_pos::Span;
|
||||||
|
|
||||||
|
pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
|
||||||
|
let mut err_count = 0;
|
||||||
|
{
|
||||||
|
let mut say = |s: &str| {
|
||||||
|
match (sp, sess) {
|
||||||
|
(_, None) => bug!("{}", s),
|
||||||
|
(Some(sp), Some(sess)) => sess.span_err(sp, s),
|
||||||
|
(None, Some(sess)) => sess.err(s),
|
||||||
|
}
|
||||||
|
err_count += 1;
|
||||||
|
};
|
||||||
|
if s.is_empty() {
|
||||||
|
say("crate name must not be empty");
|
||||||
|
}
|
||||||
|
for c in s.chars() {
|
||||||
|
if c.is_alphanumeric() { continue }
|
||||||
|
if c == '_' { continue }
|
||||||
|
say(&format!("invalid character `{}` in crate name: `{}`", c, s));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err_count > 0 {
|
||||||
|
sess.unwrap().abort_if_errors();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user