Skip to content

include_bytes! now registers the file included #24423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/libsyntax/ext/source_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
return DummyResult::expr(sp);
}
Ok(..) => {
// Add this input file to the code map to make it available as
// dependency information, but don't enter it's contents
let filename = format!("{}", file.display());
cx.codemap().new_filemap(filename, "".to_string());

base::MacEager::expr(cx.expr_lit(sp, ast::LitBinary(Rc::new(bytes))))
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/test/run-make/include_bytes_deps/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-include ../tools.mk

# FIXME: ignore freebsd/windows
# on windows `rustc --dep-info` produces Makefile dependency with
# windows native paths (e.g. `c:\path\to\libfoo.a`)
# but msys make seems to fail to recognize such paths, so test fails.
ifneq ($(shell uname),FreeBSD)
ifndef IS_WINDOWS
all:
$(RUSTC) --emit dep-info main.rs
grep "input.txt" $(TMPDIR)/main.d
grep "input.bin" $(TMPDIR)/main.d
else
all:

endif

else
all:

endif
1 change: 1 addition & 0 deletions src/test/run-make/include_bytes_deps/input.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello world!
1 change: 1 addition & 0 deletions src/test/run-make/include_bytes_deps/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello world!
17 changes: 17 additions & 0 deletions src/test/run-make/include_bytes_deps/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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.

pub fn main() {
const INPUT_TXT: &'static str = include_str!("input.txt");
const INPUT_BIN: &'static [u8] = include_bytes!("input.bin");

println!("{}", INPUT_TXT);
println!("{:?}", INPUT_BIN);
}