Skip to content

Commit ee59aac

Browse files
committed
Merge remote-tracking branch 'remotes/origin/master' into remove-str-trailing-nulls
2 parents cab6d46 + 6f6dce7 commit ee59aac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1740
-1109
lines changed

doc/rust.md

+22-8
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ There are several kinds of view item:
744744
##### Extern mod declarations
745745

746746
~~~~~~~~ {.ebnf .gram}
747-
extern_mod_decl : "extern" "mod" ident [ '(' link_attrs ')' ] ? ;
747+
extern_mod_decl : "extern" "mod" ident [ '(' link_attrs ')' ] ? [ '=' string_lit ] ? ;
748748
link_attrs : link_attr [ ',' link_attrs ] + ;
749749
link_attr : ident '=' literal ;
750750
~~~~~~~~
@@ -755,20 +755,34 @@ as the `ident` provided in the `extern_mod_decl`.
755755

756756
The external crate is resolved to a specific `soname` at compile time,
757757
and a runtime linkage requirement to that `soname` is passed to the linker for
758-
loading at runtime. The `soname` is resolved at compile time by scanning the
759-
compiler's library path and matching the `link_attrs` provided in the
760-
`use_decl` against any `#link` attributes that were declared on the external
761-
crate when it was compiled. If no `link_attrs` are provided, a default `name`
762-
attribute is assumed, equal to the `ident` given in the `use_decl`.
763-
764-
Three examples of `extern mod` declarations:
758+
loading at runtime.
759+
The `soname` is resolved at compile time by scanning the compiler's library path
760+
and matching the `link_attrs` provided in the `use_decl` against any `#link` attributes that
761+
were declared on the external crate when it was compiled.
762+
If no `link_attrs` are provided,
763+
a default `name` attribute is assumed,
764+
equal to the `ident` given in the `use_decl`.
765+
766+
Optionally, an identifier in an `extern mod` declaration may be followed by an equals sign,
767+
then a string literal denoting a relative path on the filesystem.
768+
This path should exist in one of the directories in the Rust path,
769+
which by default contains the `.rust` subdirectory of the current directory and each of its parents,
770+
as well as any directories in the colon-separated (or semicolon-separated on Windows)
771+
list of paths that is the `RUST_PATH` environment variable.
772+
The meaning of `extern mod a = "b/c/d";`, supposing that `/a` is in the RUST_PATH,
773+
is that the name `a` should be taken as a reference to the crate whose absolute location is
774+
`/a/b/c/d`.
775+
776+
Four examples of `extern mod` declarations:
765777

766778
~~~~~~~~{.xfail-test}
767779
extern mod pcre (uuid = "54aba0f8-a7b1-4beb-92f1-4cf625264841");
768780
769781
extern mod extra; // equivalent to: extern mod extra ( name = "extra" );
770782
771783
extern mod rustextra (name = "extra"); // linking to 'extra' under another name
784+
785+
extern mod complicated_mod = "some-file/in/the-rust/path";
772786
~~~~~~~~
773787

774788
##### Use declarations

mk/install.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ endef
199199
$(foreach target,$(CFG_TARGET_TRIPLES), \
200200
$(if $(findstring $(target),"arm-linux-androideabi"), \
201201
$(if $(findstring adb,$(CFG_ADB)), \
202-
$(if $(findstring device,$(shell adb devices 2>/dev/null | grep -E '^[_A-Za-z0-9-]+[[:blank:]]+device')), \
202+
$(if $(findstring device,$(shell $(CFG_ADB) devices 2>/dev/null | grep -E '^[_A-Za-z0-9-]+[[:blank:]]+device')), \
203203
$(info install: install-runtime-target for $(target) enabled \
204204
$(info install: android device attached) \
205205
$(eval $(call DEF_ADB_DEVICE_STATUS, true))), \

mk/tests.mk

+4-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ endef
123123
$(foreach target,$(CFG_TARGET_TRIPLES), \
124124
$(if $(findstring $(target),"arm-linux-androideabi"), \
125125
$(if $(findstring adb,$(CFG_ADB)), \
126-
$(if $(findstring device,$(shell adb devices 2>/dev/null | grep -E '^[_A-Za-z0-9-]+[[:blank:]]+device')), \
126+
$(if $(findstring device,$(shell $(CFG_ADB) devices 2>/dev/null | grep -E '^[_A-Za-z0-9-]+[[:blank:]]+device')), \
127127
$(info check: $(target) test enabled \
128128
$(info check: android device attached) \
129129
$(eval $(call DEF_ADB_DEVICE_STATUS, true))), \
@@ -348,7 +348,9 @@ $(3)/stage$(1)/test/rustpkgtest-$(2)$$(X_$(2)): \
348348
$$(RUSTPKG_LIB) $$(RUSTPKG_INPUTS) \
349349
$$(SREQ$(1)_T_$(2)_H_$(3)) \
350350
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBSYNTAX_$(2)) \
351-
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC_$(2))
351+
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC_$(2)) \
352+
$$(TBIN$(1)_T_$(2)_H_$(3))/rustpkg$$(X_$(2)) \
353+
$$(TBIN$(1)_T_$(2)_H_$(3))/rustc$$(X_$(2))
352354
@$$(call E, compile_and_link: $$@)
353355
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
354356

src/libextra/time.rs

-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ impl Ord for Timespec {
5757
self.sec < other.sec ||
5858
(self.sec == other.sec && self.nsec < other.nsec)
5959
}
60-
fn le(&self, other: &Timespec) -> bool { !other.lt(self) }
61-
fn ge(&self, other: &Timespec) -> bool { !self.lt(other) }
62-
fn gt(&self, other: &Timespec) -> bool { !self.le(other) }
6360
}
6461

6562
/**

src/librustc/back/link.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use lib::llvm::llvm;
1616
use lib::llvm::ModuleRef;
1717
use lib;
1818
use metadata::common::LinkMeta;
19-
use metadata::{encoder, csearch, cstore};
19+
use metadata::{encoder, csearch, cstore, filesearch};
2020
use middle::trans::context::CrateContext;
2121
use middle::trans::common::gensym_name;
2222
use middle::ty;
@@ -500,35 +500,40 @@ pub fn build_link_meta(sess: Session,
500500
struct ProvidedMetas {
501501
name: Option<@str>,
502502
vers: Option<@str>,
503+
pkg_id: Option<@str>,
503504
cmh_items: ~[@ast::MetaItem]
504505
}
505506

506507
fn provided_link_metas(sess: Session, c: &ast::Crate) ->
507508
ProvidedMetas {
508509
let mut name = None;
509510
let mut vers = None;
511+
let mut pkg_id = None;
510512
let mut cmh_items = ~[];
511513
let linkage_metas = attr::find_linkage_metas(c.attrs);
512514
attr::require_unique_names(sess.diagnostic(), linkage_metas);
513515
for meta in linkage_metas.iter() {
514516
match meta.name_str_pair() {
515517
Some((n, value)) if "name" == n => name = Some(value),
516518
Some((n, value)) if "vers" == n => vers = Some(value),
519+
Some((n, value)) if "package_id" == n => pkg_id = Some(value),
517520
_ => cmh_items.push(*meta)
518521
}
519522
}
520523

521524
ProvidedMetas {
522525
name: name,
523526
vers: vers,
527+
pkg_id: pkg_id,
524528
cmh_items: cmh_items
525529
}
526530
}
527531

528532
// This calculates CMH as defined above
529533
fn crate_meta_extras_hash(symbol_hasher: &mut hash::State,
530534
cmh_items: ~[@ast::MetaItem],
531-
dep_hashes: ~[@str]) -> @str {
535+
dep_hashes: ~[@str],
536+
pkg_id: Option<@str>) -> @str {
532537
fn len_and_str(s: &str) -> ~str {
533538
fmt!("%u_%s", s.len(), s)
534539
}
@@ -566,7 +571,10 @@ pub fn build_link_meta(sess: Session,
566571
write_string(symbol_hasher, len_and_str(*dh));
567572
}
568573

569-
// tjc: allocation is unfortunate; need to change std::hash
574+
for p in pkg_id.iter() {
575+
write_string(symbol_hasher, len_and_str(*p));
576+
}
577+
570578
return truncated_hash_result(symbol_hasher).to_managed();
571579
}
572580

@@ -608,18 +616,20 @@ pub fn build_link_meta(sess: Session,
608616
let ProvidedMetas {
609617
name: opt_name,
610618
vers: opt_vers,
619+
pkg_id: opt_pkg_id,
611620
cmh_items: cmh_items
612621
} = provided_link_metas(sess, c);
613622
let name = crate_meta_name(sess, output, opt_name);
614623
let vers = crate_meta_vers(sess, opt_vers);
615624
let dep_hashes = cstore::get_dep_hashes(sess.cstore);
616625
let extras_hash =
617626
crate_meta_extras_hash(symbol_hasher, cmh_items,
618-
dep_hashes);
627+
dep_hashes, opt_pkg_id);
619628

620629
LinkMeta {
621630
name: name,
622631
vers: vers,
632+
package_id: opt_pkg_id,
623633
extras_hash: extras_hash
624634
}
625635
}
@@ -942,6 +952,11 @@ pub fn link_args(sess: Session,
942952
args.push(~"-L" + path.to_str());
943953
}
944954

955+
let rustpath = filesearch::rust_path();
956+
for path in rustpath.iter() {
957+
args.push(~"-L" + path.to_str());
958+
}
959+
945960
// The names of the extern libraries
946961
let used_libs = cstore::get_used_libraries(cstore);
947962
for l in used_libs.iter() { args.push(~"-l" + *l); }

src/librustc/back/rpath.rs

+13-113
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ use metadata::cstore;
1414
use metadata::filesearch;
1515

1616
use std::hashmap::HashSet;
17-
use std::num;
18-
use std::os;
19-
use std::util;
20-
use std::vec;
17+
use std::{num, os, path, uint, util, vec};
2118

2219
fn not_win32(os: session::os) -> bool {
2320
os != session::os_win32
@@ -122,42 +119,7 @@ pub fn get_rpath_relative_to_output(os: session::os,
122119
session::os_win32 => util::unreachable()
123120
};
124121

125-
Path(prefix).push_rel(&get_relative_to(&os::make_absolute(output),
126-
&os::make_absolute(lib)))
127-
}
128-
129-
// Find the relative path from one file to another
130-
pub fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
131-
assert!(abs1.is_absolute);
132-
assert!(abs2.is_absolute);
133-
let abs1 = abs1.normalize();
134-
let abs2 = abs2.normalize();
135-
debug!("finding relative path from %s to %s",
136-
abs1.to_str(), abs2.to_str());
137-
let split1: &[~str] = abs1.components;
138-
let split2: &[~str] = abs2.components;
139-
let len1 = split1.len();
140-
let len2 = split2.len();
141-
assert!(len1 > 0);
142-
assert!(len2 > 0);
143-
144-
let max_common_path = num::min(len1, len2) - 1;
145-
let mut start_idx = 0;
146-
while start_idx < max_common_path
147-
&& split1[start_idx] == split2[start_idx] {
148-
start_idx += 1;
149-
}
150-
151-
let mut path = ~[];
152-
for _ in range(start_idx, len1 - 1) { path.push(~".."); };
153-
154-
path.push_all(split2.slice(start_idx, len2 - 1));
155-
156-
return if !path.is_empty() {
157-
Path("").push_many(path)
158-
} else {
159-
Path(".")
160-
}
122+
Path(prefix).push_rel(&os::make_absolute(output).get_relative_to(&os::make_absolute(lib)))
161123
}
162124

163125
fn get_absolute_rpaths(libs: &[Path]) -> ~[Path] {
@@ -168,6 +130,7 @@ pub fn get_absolute_rpath(lib: &Path) -> Path {
168130
os::make_absolute(lib).dir_path()
169131
}
170132

133+
#[cfg(stage0)]
171134
pub fn get_install_prefix_rpath(target_triple: &str) -> Path {
172135
let install_prefix = env!("CFG_PREFIX");
173136

@@ -179,6 +142,14 @@ pub fn get_install_prefix_rpath(target_triple: &str) -> Path {
179142
os::make_absolute(&Path(install_prefix).push_rel(&tlib))
180143
}
181144

145+
#[cfg(not(stage0))]
146+
pub fn get_install_prefix_rpath(target_triple: &str) -> Path {
147+
let install_prefix = env!("CFG_PREFIX");
148+
149+
let tlib = filesearch::relative_target_lib_path(target_triple);
150+
os::make_absolute(&Path(install_prefix).push_rel(&tlib))
151+
}
152+
182153
pub fn minimize_rpaths(rpaths: &[Path]) -> ~[Path] {
183154
let mut set = HashSet::new();
184155
let mut minimized = ~[];
@@ -199,8 +170,7 @@ mod test {
199170
#[cfg(test)]
200171
#[cfg(test)]
201172
use back::rpath::{get_absolute_rpath, get_install_prefix_rpath};
202-
use back::rpath::{get_relative_to, get_rpath_relative_to_output};
203-
use back::rpath::{minimize_rpaths, rpaths_to_flags};
173+
use back::rpath::{minimize_rpaths, rpaths_to_flags, get_rpath_relative_to_output};
204174
use driver::session;
205175

206176
#[test]
@@ -244,78 +214,9 @@ mod test {
244214
assert_eq!(res, ~[Path("1a"), Path("2"), Path("4a"), Path("3")]);
245215
}
246216
247-
#[test]
248-
fn test_relative_to1() {
249-
let p1 = Path("/usr/bin/rustc");
250-
let p2 = Path("/usr/lib/mylib");
251-
let res = get_relative_to(&p1, &p2);
252-
assert_eq!(res, Path("../lib"));
253-
}
254-
255-
#[test]
256-
fn test_relative_to2() {
257-
let p1 = Path("/usr/bin/rustc");
258-
let p2 = Path("/usr/bin/../lib/mylib");
259-
let res = get_relative_to(&p1, &p2);
260-
assert_eq!(res, Path("../lib"));
261-
}
262-
263-
#[test]
264-
fn test_relative_to3() {
265-
let p1 = Path("/usr/bin/whatever/rustc");
266-
let p2 = Path("/usr/lib/whatever/mylib");
267-
let res = get_relative_to(&p1, &p2);
268-
assert_eq!(res, Path("../../lib/whatever"));
269-
}
270-
271-
#[test]
272-
fn test_relative_to4() {
273-
let p1 = Path("/usr/bin/whatever/../rustc");
274-
let p2 = Path("/usr/lib/whatever/mylib");
275-
let res = get_relative_to(&p1, &p2);
276-
assert_eq!(res, Path("../lib/whatever"));
277-
}
278-
279-
#[test]
280-
fn test_relative_to5() {
281-
let p1 = Path("/usr/bin/whatever/../rustc");
282-
let p2 = Path("/usr/lib/whatever/../mylib");
283-
let res = get_relative_to(&p1, &p2);
284-
assert_eq!(res, Path("../lib"));
285-
}
286-
287-
#[test]
288-
fn test_relative_to6() {
289-
let p1 = Path("/1");
290-
let p2 = Path("/2/3");
291-
let res = get_relative_to(&p1, &p2);
292-
assert_eq!(res, Path("2"));
293-
}
294-
295-
#[test]
296-
fn test_relative_to7() {
297-
let p1 = Path("/1/2");
298-
let p2 = Path("/3");
299-
let res = get_relative_to(&p1, &p2);
300-
assert_eq!(res, Path(".."));
301-
}
302-
303-
#[test]
304-
fn test_relative_to8() {
305-
let p1 = Path("/home/brian/Dev/rust/build/").push_rel(
306-
&Path("stage2/lib/rustc/i686-unknown-linux-gnu/lib/librustc.so"));
307-
let p2 = Path("/home/brian/Dev/rust/build/stage2/bin/..").push_rel(
308-
&Path("lib/rustc/i686-unknown-linux-gnu/lib/libstd.so"));
309-
let res = get_relative_to(&p1, &p2);
310-
debug!("test_relative_tu8: %s vs. %s",
311-
res.to_str(),
312-
Path(".").to_str());
313-
assert_eq!(res, Path("."));
314-
}
315-
316217
#[test]
317218
#[cfg(target_os = "linux")]
318-
#[cfg(target_os = "andorid")]
219+
#[cfg(target_os = "android")]
319220
fn test_rpath_relative() {
320221
let o = session::os_linux;
321222
let res = get_rpath_relative_to_output(o,
@@ -335,7 +236,6 @@ mod test {
335236
#[test]
336237
#[cfg(target_os = "macos")]
337238
fn test_rpath_relative() {
338-
// this is why refinements would be nice
339239
let o = session::os_macos;
340240
let res = get_rpath_relative_to_output(o,
341241
&Path("bin/rustc"),

0 commit comments

Comments
 (0)