Skip to content

Commit 35d36db

Browse files
committed
---
yaml --- r: 83867 b: refs/heads/try c: 399a425 h: refs/heads/master i: 83865: 861ce60 83863: 8a133bf v: v3
1 parent f2e1e02 commit 35d36db

File tree

8 files changed

+132
-44
lines changed

8 files changed

+132
-44
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 0e4d1fc8cae42e15e00f71d9f439b01bb25a86ae
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6c08cc2db4f98e9f07ae7d50338396c4123c2f0a
5-
refs/heads/try: 7bad4167654ef846155bae7165fd0ffcc24fcbbe
5+
refs/heads/try: 399a42575a3a5392277e4034812ce32c4f491929
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/librustc/lib/llvm.rs

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515

1616
use std::c_str::ToCStr;
1717
use std::hashmap::HashMap;
18-
use std::libc::{c_uint, c_ushort, c_void, free};
19-
use std::str::raw::from_c_str;
18+
use std::libc::{c_uint, c_ushort};
2019
use std::option;
2120

2221
use middle::trans::type_::Type;
@@ -1667,7 +1666,6 @@ pub mod llvm {
16671666
-> ValueRef;
16681667

16691668
pub fn LLVMDICompositeTypeSetTypeArray(CompositeType: ValueRef, TypeArray: ValueRef);
1670-
pub fn LLVMTypeToString(Type: TypeRef) -> *c_char;
16711669

16721670
pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
16731671

@@ -1791,15 +1789,68 @@ impl TypeNames {
17911789
self.named_types.find_equiv(&s).map(|x| Type::from_ref(*x))
17921790
}
17931791

1794-
pub fn type_to_str(&self, ty: Type) -> ~str {
1792+
// We have a depth count, because we seem to make infinite types.
1793+
pub fn type_to_str_depth(&self, ty: Type, depth: int) -> ~str {
1794+
match self.find_name(&ty) {
1795+
option::Some(name) => return name.to_owned(),
1796+
None => ()
1797+
}
1798+
1799+
if depth == 0 {
1800+
return ~"###";
1801+
}
1802+
17951803
unsafe {
1796-
let s = llvm::LLVMTypeToString(ty.to_ref());
1797-
let ret = from_c_str(s);
1798-
free(s as *c_void);
1799-
ret
1804+
let kind = ty.kind();
1805+
1806+
match kind {
1807+
Void => ~"Void",
1808+
Half => ~"Half",
1809+
Float => ~"Float",
1810+
Double => ~"Double",
1811+
X86_FP80 => ~"X86_FP80",
1812+
FP128 => ~"FP128",
1813+
PPC_FP128 => ~"PPC_FP128",
1814+
Label => ~"Label",
1815+
Vector => ~"Vector",
1816+
Metadata => ~"Metadata",
1817+
X86_MMX => ~"X86_MMAX",
1818+
Integer => {
1819+
format!("i{}", llvm::LLVMGetIntTypeWidth(ty.to_ref()) as int)
1820+
}
1821+
Function => {
1822+
let out_ty = ty.return_type();
1823+
let args = ty.func_params();
1824+
let args =
1825+
args.map(|&ty| self.type_to_str_depth(ty, depth-1)).connect(", ");
1826+
let out_ty = self.type_to_str_depth(out_ty, depth-1);
1827+
format!("fn({}) -> {}", args, out_ty)
1828+
}
1829+
Struct => {
1830+
let tys = ty.field_types();
1831+
let tys = tys.map(|&ty| self.type_to_str_depth(ty, depth-1)).connect(", ");
1832+
format!("\\{{}\\}", tys)
1833+
}
1834+
Array => {
1835+
let el_ty = ty.element_type();
1836+
let el_ty = self.type_to_str_depth(el_ty, depth-1);
1837+
let len = ty.array_length();
1838+
format!("[{} x {}]", el_ty, len)
1839+
}
1840+
Pointer => {
1841+
let el_ty = ty.element_type();
1842+
let el_ty = self.type_to_str_depth(el_ty, depth-1);
1843+
format!("*{}", el_ty)
1844+
}
1845+
_ => fail2!("Unknown Type Kind ({})", kind as uint)
1846+
}
18001847
}
18011848
}
18021849

1850+
pub fn type_to_str(&self, ty: Type) -> ~str {
1851+
self.type_to_str_depth(ty, 30)
1852+
}
1853+
18031854
pub fn types_to_str(&self, tys: &[Type]) -> ~str {
18041855
let strs = tys.map(|t| self.type_to_str(*t));
18051856
format!("[{}]", strs.connect(","))

branches/try/src/librustpkg/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,11 @@ impl RustcFlags {
210210
}
211211

212212
/// Returns true if any of the flags given are incompatible with the cmd
213-
pub fn flags_ok_for_cmd(flags: &RustcFlags,
213+
pub fn flags_forbidden_for_cmd(flags: &RustcFlags,
214214
cfgs: &[~str],
215215
cmd: &str, user_supplied_opt_level: bool) -> bool {
216216
let complain = |s| {
217-
println!("The {} option can only be used with the build command:
217+
println!("The {} option can only be used with the `build` command:
218218
rustpkg [options..] build {} [package-ID]", s, s);
219219
};
220220

branches/try/src/librustpkg/exit_codes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@
99
// except according to those terms.
1010

1111
pub static COPY_FAILED_CODE: int = 65;
12+
pub static BAD_FLAG_CODE: int = 67;
13+
pub static NONEXISTENT_PACKAGE_CODE: int = 68;
14+

branches/try/src/librustpkg/rustpkg.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use package_source::PkgSrc;
5050
use target::{WhatToBuild, Everything, is_lib, is_main, is_test, is_bench, Tests};
5151
// use workcache_support::{discover_outputs, digest_only_date};
5252
use workcache_support::digest_only_date;
53-
use exit_codes::COPY_FAILED_CODE;
53+
use exit_codes::{COPY_FAILED_CODE, BAD_FLAG_CODE};
5454

5555
pub mod api;
5656
mod conditions;
@@ -701,7 +701,7 @@ pub fn main_args(args: &[~str]) -> int {
701701
return 1;
702702
}
703703
};
704-
let mut help = matches.opt_present("h") ||
704+
let help = matches.opt_present("h") ||
705705
matches.opt_present("help");
706706
let no_link = matches.opt_present("no-link");
707707
let no_trans = matches.opt_present("no-trans");
@@ -798,8 +798,11 @@ pub fn main_args(args: &[~str]) -> int {
798798
return 0;
799799
}
800800
Some(cmd) => {
801-
help |= context::flags_ok_for_cmd(&rustc_flags, cfgs, *cmd, user_supplied_opt_level);
802-
if help {
801+
let bad_option = context::flags_forbidden_for_cmd(&rustc_flags,
802+
cfgs,
803+
*cmd,
804+
user_supplied_opt_level);
805+
if help || bad_option {
803806
match *cmd {
804807
~"build" => usage::build(),
805808
~"clean" => usage::clean(),
@@ -814,7 +817,12 @@ pub fn main_args(args: &[~str]) -> int {
814817
~"unprefer" => usage::unprefer(),
815818
_ => usage::general()
816819
};
817-
return 0;
820+
if bad_option {
821+
return BAD_FLAG_CODE;
822+
}
823+
else {
824+
return 0;
825+
}
818826
} else {
819827
cmd
820828
}

branches/try/src/librustpkg/tests.rs

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use syntax::diagnostic;
3636
use target::*;
3737
use package_source::PkgSrc;
3838
use source_control::{CheckedOutSources, DirToUse, safe_git_clone};
39+
use exit_codes::{BAD_FLAG_CODE, COPY_FAILED_CODE};
3940
use util::datestamp;
4041

4142
fn fake_ctxt(sysroot: Path, workspace: &Path) -> BuildContext {
@@ -244,14 +245,26 @@ fn rustpkg_exec() -> Path {
244245
fn command_line_test(args: &[~str], cwd: &Path) -> ProcessOutput {
245246
match command_line_test_with_env(args, cwd, None) {
246247
Success(r) => r,
247-
_ => fail2!("Command line test failed")
248+
Fail(error) => fail2!("Command line test failed with error {}", error)
248249
}
249250
}
250251

251252
fn command_line_test_partial(args: &[~str], cwd: &Path) -> ProcessResult {
252253
command_line_test_with_env(args, cwd, None)
253254
}
254255

256+
fn command_line_test_expect_fail(args: &[~str],
257+
cwd: &Path,
258+
env: Option<~[(~str, ~str)]>,
259+
expected_exitcode: int) {
260+
match command_line_test_with_env(args, cwd, env) {
261+
Success(_) => fail2!("Should have failed with {}, but it succeeded", expected_exitcode),
262+
Fail(error) if error == expected_exitcode => (), // ok
263+
Fail(other) => fail2!("Expected to fail with {}, but failed with {} instead",
264+
expected_exitcode, other)
265+
}
266+
}
267+
255268
enum ProcessResult {
256269
Success(ProcessOutput),
257270
Fail(int) // exit code
@@ -1448,11 +1461,11 @@ fn compile_flag_fail() {
14481461
let p_id = PkgId::new("foo");
14491462
let workspace = create_local_package(&p_id);
14501463
let workspace = workspace.path();
1451-
command_line_test([test_sysroot().to_str(),
1464+
command_line_test_expect_fail([test_sysroot().to_str(),
14521465
~"install",
14531466
~"--no-link",
14541467
~"foo"],
1455-
workspace);
1468+
workspace, None, BAD_FLAG_CODE);
14561469
assert!(!built_executable_exists(workspace, "foo"));
14571470
assert!(!object_file_exists(workspace, "foo"));
14581471
}
@@ -1488,14 +1501,11 @@ fn notrans_flag_fail() {
14881501
let flags_to_test = [~"--no-trans", ~"--parse-only",
14891502
~"--pretty", ~"-S"];
14901503
for flag in flags_to_test.iter() {
1491-
command_line_test([test_sysroot().to_str(),
1504+
command_line_test_expect_fail([test_sysroot().to_str(),
14921505
~"install",
14931506
flag.clone(),
14941507
~"foo"],
1495-
workspace);
1496-
// Ideally we'd test that rustpkg actually fails, but
1497-
// since task failure doesn't set the exit code properly,
1498-
// we can't tell
1508+
workspace, None, BAD_FLAG_CODE);
14991509
assert!(!built_executable_exists(workspace, "foo"));
15001510
assert!(!object_file_exists(workspace, "foo"));
15011511
assert!(!lib_exists(workspace, &Path("foo"), NoVersion));
@@ -1522,11 +1532,11 @@ fn dash_S_fail() {
15221532
let p_id = PkgId::new("foo");
15231533
let workspace = create_local_package(&p_id);
15241534
let workspace = workspace.path();
1525-
command_line_test([test_sysroot().to_str(),
1535+
command_line_test_expect_fail([test_sysroot().to_str(),
15261536
~"install",
15271537
~"-S",
15281538
~"foo"],
1529-
workspace);
1539+
workspace, None, BAD_FLAG_CODE);
15301540
assert!(!built_executable_exists(workspace, "foo"));
15311541
assert!(!object_file_exists(workspace, "foo"));
15321542
assert!(!assembly_file_exists(workspace, "foo"));
@@ -1587,11 +1597,13 @@ fn test_emit_llvm_S_fail() {
15871597
let p_id = PkgId::new("foo");
15881598
let workspace = create_local_package(&p_id);
15891599
let workspace = workspace.path();
1590-
command_line_test([test_sysroot().to_str(),
1600+
command_line_test_expect_fail([test_sysroot().to_str(),
15911601
~"install",
15921602
~"-S", ~"--emit-llvm",
15931603
~"foo"],
1594-
workspace);
1604+
workspace,
1605+
None,
1606+
BAD_FLAG_CODE);
15951607
assert!(!built_executable_exists(workspace, "foo"));
15961608
assert!(!object_file_exists(workspace, "foo"));
15971609
assert!(!llvm_assembly_file_exists(workspace, "foo"));
@@ -1620,11 +1632,13 @@ fn test_emit_llvm_fail() {
16201632
let p_id = PkgId::new("foo");
16211633
let workspace = create_local_package(&p_id);
16221634
let workspace = workspace.path();
1623-
command_line_test([test_sysroot().to_str(),
1635+
command_line_test_expect_fail([test_sysroot().to_str(),
16241636
~"install",
16251637
~"--emit-llvm",
16261638
~"foo"],
1627-
workspace);
1639+
workspace,
1640+
None,
1641+
BAD_FLAG_CODE);
16281642
assert!(!built_executable_exists(workspace, "foo"));
16291643
assert!(!object_file_exists(workspace, "foo"));
16301644
assert!(!llvm_bitcode_file_exists(workspace, "foo"));
@@ -1665,11 +1679,10 @@ fn test_build_install_flags_fail() {
16651679
~[~"--target", host_triple()],
16661680
~[~"--target-cpu", ~"generic"],
16671681
~[~"-Z", ~"--time-passes"]];
1682+
let cwd = os::getcwd();
16681683
for flag in forbidden.iter() {
1669-
let output = command_line_test_output([test_sysroot().to_str(),
1670-
~"list"] + *flag);
1671-
assert!(output.len() > 1);
1672-
assert!(output[1].find_str("can only be used with").is_some());
1684+
command_line_test_expect_fail([test_sysroot().to_str(),
1685+
~"list"] + *flag, &cwd, None, BAD_FLAG_CODE);
16731686
}
16741687
}
16751688

@@ -1686,6 +1699,7 @@ fn test_optimized_build() {
16861699
assert!(built_executable_exists(workspace, "foo"));
16871700
}
16881701

1702+
#[test]
16891703
fn pkgid_pointing_to_subdir() {
16901704
// The actual repo is mocki.8713187.xyz/mozilla/some_repo
16911705
// rustpkg should recognize that and treat the part after some_repo/ as a subdir
@@ -1717,6 +1731,7 @@ fn pkgid_pointing_to_subdir() {
17171731
assert_executable_exists(workspace, "testpkg");
17181732
}
17191733
1734+
#[test]
17201735
fn test_recursive_deps() {
17211736
let a_id = PkgId::new("a");
17221737
let b_id = PkgId::new("b");
@@ -1762,6 +1777,7 @@ fn test_install_to_rust_path() {
17621777
assert!(!executable_exists(second_workspace, "foo"));
17631778
}
17641779
1780+
#[test]
17651781
fn test_target_specific_build_dir() {
17661782
let p_id = PkgId::new("foo");
17671783
let workspace = create_local_package(&p_id);
@@ -1870,8 +1886,9 @@ fn correct_package_name_with_rust_path_hack() {
18701886
let rust_path = Some(~[(~"RUST_PATH", format!("{}:{}", dest_workspace.to_str(),
18711887
foo_workspace.push_many(["src", "foo-0.1"]).to_str()))]);
18721888
// bar doesn't exist, but we want to make sure rustpkg doesn't think foo is bar
1873-
command_line_test_with_env([~"install", ~"--rust-path-hack", ~"bar"],
1874-
dest_workspace, rust_path);
1889+
command_line_test_expect_fail([~"install", ~"--rust-path-hack", ~"bar"],
1890+
// FIXME #3408: Should be NONEXISTENT_PACKAGE_CODE
1891+
dest_workspace, rust_path, COPY_FAILED_CODE);
18751892
assert!(!executable_exists(dest_workspace, "bar"));
18761893
assert!(!lib_exists(dest_workspace, &bar_id.path.clone(), bar_id.version.clone()));
18771894
assert!(!executable_exists(dest_workspace, "foo"));
@@ -2050,6 +2067,23 @@ fn test_7402() {
20502067
assert_executable_exists(dest_workspace, "foo");
20512068
}
20522069
2070+
#[test]
2071+
fn test_compile_error() {
2072+
let foo_id = PkgId::new("foo");
2073+
let foo_workspace = create_local_package(&foo_id);
2074+
let foo_workspace = foo_workspace.path();
2075+
let main_crate = foo_workspace.push_many(["src", "foo-0.1", "main.rs"]);
2076+
// Write something bogus
2077+
writeFile(&main_crate, "pub fn main() { if 42 != ~\"the answer\" { fail!(); } }");
2078+
let result = command_line_test_partial([~"build", ~"foo"], foo_workspace);
2079+
match result {
2080+
Success(*) => fail2!("Failed by succeeding!"), // should be a compile error
2081+
Fail(status) => {
2082+
debug2!("Failed with status {:?}... that's good, right?", status);
2083+
}
2084+
}
2085+
}
2086+
20532087
/// Returns true if p exists and is executable
20542088
fn is_executable(p: &Path) -> bool {
20552089
use std::libc::consts::os::posix88::{S_IXUSR};

branches/try/src/rustllvm/RustWrapper.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -803,10 +803,3 @@ extern "C" void LLVMDICompositeTypeSetTypeArray(
803803
{
804804
unwrapDI<DICompositeType>(CompositeType).setTypeArray(unwrapDI<DIArray>(TypeArray));
805805
}
806-
807-
extern "C" char *LLVMTypeToString(LLVMTypeRef Type) {
808-
std::string s;
809-
llvm::raw_string_ostream os(s);
810-
unwrap<llvm::Type>(Type)->print(os);
811-
return strdup(os.str().data());
812-
}

branches/try/src/rustllvm/rustllvm.def.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,4 +628,3 @@ LLVMRustSetNormalizedTarget
628628
LLVMRustAddAlwaysInlinePass
629629
LLVMAddReturnAttribute
630630
LLVMRemoveReturnAttribute
631-
LLVMTypeToString

0 commit comments

Comments
 (0)