From db16ca7c839c6dcc5a3103b5e0b37239dd21e450 Mon Sep 17 00:00:00 2001 From: David LeGare Date: Fri, 5 May 2017 20:35:07 -0500 Subject: [PATCH 01/28] Update documention in windows::ffi --- src/libstd/sys/windows/ext/ffi.rs | 42 +++++++++++++++++++++++++++---- src/libstd/sys/windows/ext/mod.rs | 10 +++++--- src/libstd/sys_common/wtf8.rs | 1 + 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/libstd/sys/windows/ext/ffi.rs b/src/libstd/sys/windows/ext/ffi.rs index 253787546c1dc..cb13595fcd6d8 100644 --- a/src/libstd/sys/windows/ext/ffi.rs +++ b/src/libstd/sys/windows/ext/ffi.rs @@ -26,8 +26,22 @@ pub trait OsStringExt { /// Creates an `OsString` from a potentially ill-formed UTF-16 slice of /// 16-bit code units. /// - /// This is lossless: calling `.encode_wide()` on the resulting string + /// This is lossless: calling [`encode_wide()`] on the resulting string /// will always return the original code units. + /// + /// # Examples + /// + /// ``` + /// use std::ffi::OsString; + /// use std::os::windows::prelude::*; + /// + /// // UTF-16 encoding for "Unicode". + /// let source = [0x0055, 0x006E, 0x0069, 0x0063, 0x006F, 0x0064, 0x0065]; + /// + /// let string = OsString::from_wide(&source[..]); + /// ``` + /// + /// [`encode_wide()`]: ./trait.OsStrExt.html#tymethod.encode_wide #[stable(feature = "rust1", since = "1.0.0")] fn from_wide(wide: &[u16]) -> Self; } @@ -42,11 +56,29 @@ impl OsStringExt for OsString { /// Windows-specific extensions to `OsStr`. #[stable(feature = "rust1", since = "1.0.0")] pub trait OsStrExt { - /// Re-encodes an `OsStr` as a wide character sequence, - /// i.e. potentially ill-formed UTF-16. + /// Re-encodes an `OsStr` as a wide character sequence, i.e. potentially + /// ill-formed UTF-16. + /// + /// This is lossless: calling [`OsString::from_wide()`] and then + /// `encode_wide()` on the result will yield the original code units. + /// Note that the encoding does not add a final null terminator. + /// + /// # Examples + /// + /// ``` + /// use std::ffi::OsString; + /// use std::os::windows::prelude::*; + /// + /// // UTF-16 encoding for "Unicode". + /// let source = [0x0055, 0x006E, 0x0069, 0x0063, 0x006F, 0x0064, 0x0065]; + /// + /// let string = OsString::from_wide(&source[..]); + /// + /// let result: Vec = string.encode_wide().collect(); + /// assert_eq!(&source[..], &result[..]); + /// ``` /// - /// This is lossless. Note that the encoding does not include a final - /// null. + /// [`OsString::from_wide()`]: ./trait.OsStringExt.html#tymethod.from_wide #[stable(feature = "rust1", since = "1.0.0")] fn encode_wide(&self) -> EncodeWide; } diff --git a/src/libstd/sys/windows/ext/mod.rs b/src/libstd/sys/windows/ext/mod.rs index f12e50cc92317..e07acad5e46c4 100644 --- a/src/libstd/sys/windows/ext/mod.rs +++ b/src/libstd/sys/windows/ext/mod.rs @@ -8,11 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Experimental extensions to `std` for Windows. +//! Platform-specific extensions to `std` for Windows. //! -//! For now, this module is limited to extracting handles, file -//! descriptors, and sockets, but its functionality will grow over -//! time. +//! Provides access to platform-level information for Windows, and exposes +//! Windows-specific idioms that would otherwise be inappropriate as part +//! the core `std` library. These extensions allow developers to use +//! `std` types and idioms with Windows in a way that the noraml +//! platform-agnostic idioms would not normally support. #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libstd/sys_common/wtf8.rs b/src/libstd/sys_common/wtf8.rs index 79aaf34ce2e0f..df5e4ef1d886e 100644 --- a/src/libstd/sys_common/wtf8.rs +++ b/src/libstd/sys_common/wtf8.rs @@ -750,6 +750,7 @@ impl<'a> Iterator for Wtf8CodePoints<'a> { } } +/// Generates a wide character sequence for potentially ill-formed UTF-16. #[stable(feature = "rust1", since = "1.0.0")] #[derive(Clone)] pub struct EncodeWide<'a> { From e406cd1ec9abb77236318db30e362e4654411a1a Mon Sep 17 00:00:00 2001 From: David LeGare Date: Fri, 5 May 2017 20:35:35 -0500 Subject: [PATCH 02/28] Update documentation in windows::ffi --- src/libstd/sys/windows/ext/fs.rs | 112 +++++++++++++++++++++++++------ 1 file changed, 91 insertions(+), 21 deletions(-) diff --git a/src/libstd/sys/windows/ext/fs.rs b/src/libstd/sys/windows/ext/fs.rs index c63dd8a47ca4f..ea322b9822a9c 100644 --- a/src/libstd/sys/windows/ext/fs.rs +++ b/src/libstd/sys/windows/ext/fs.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Windows-specific extensions for the primitives in `std::fs` +//! Windows-specific extensions for the primitives in the `std::fs` module. #![stable(feature = "rust1", since = "1.0.0")] @@ -35,6 +35,25 @@ pub trait FileExt { /// Note that similar to `File::read`, it is not an error to return with a /// short read. When returning from such a short read, the file pointer is /// still updated. + /// + /// # Examples + /// + /// ``` + /// use std::io; + /// use std::io::prelude::*; + /// use std::fs::File; + /// use std::os::windows::prelude::*; + /// + /// # fn foo() -> io::Result<()> { + /// let mut file = File::open("foo.txt")?; + /// let mut buffer = [0; 10]; + /// + /// // Read 10 bytes, starting 72 bytes from the + /// // start of the file. + /// file.seek_read(&mut buffer[..], 72)?; + /// # Ok(()) + /// # } + /// ``` #[stable(feature = "file_offset", since = "1.15.0")] fn seek_read(&self, buf: &mut [u8], offset: u64) -> io::Result; @@ -52,6 +71,23 @@ pub trait FileExt { /// Note that similar to `File::write`, it is not an error to return a /// short write. When returning from such a short write, the file pointer /// is still updated. + /// + /// # Examples + /// + /// ``` + /// use std::io::prelude::*; + /// use std::fs::File; + /// use std::os::windows::prelude::*; + /// + /// # fn foo() -> std::io::Result<()> { + /// let mut buffer = File::create("foo.txt")?; + /// + /// // Write a byte string starting 72 bytes from + /// // the start of the file. + /// buffer.write(b"some bytes", offset)?; + /// # Ok(()) + /// # } + /// ``` #[stable(feature = "file_offset", since = "1.15.0")] fn seek_write(&self, buf: &[u8], offset: u64) -> io::Result; } @@ -70,13 +106,13 @@ impl FileExt for fs::File { /// Windows-specific extensions to `OpenOptions` #[stable(feature = "open_options_ext", since = "1.10.0")] pub trait OpenOptionsExt { - /// Overrides the `dwDesiredAccess` argument to the call to `CreateFile` + /// Overrides the `dwDesiredAccess` argument to the call to [`CreateFile`] /// with the specified value. /// /// This will override the `read`, `write`, and `append` flags on the /// `OpenOptions` structure. This method provides fine-grained control over /// the permissions to read, write and append data, attributes (like hidden - /// and system) and extended attributes. + /// and system), and extended attributes. /// /// # Examples /// @@ -88,16 +124,20 @@ pub trait OpenOptionsExt { /// // to call `stat()` on the file /// let file = OpenOptions::new().access_mode(0).open("foo.txt"); /// ``` + /// + /// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx #[stable(feature = "open_options_ext", since = "1.10.0")] fn access_mode(&mut self, access: u32) -> &mut Self; - /// Overrides the `dwShareMode` argument to the call to `CreateFile` with + /// Overrides the `dwShareMode` argument to the call to [`CreateFile`] with /// the specified value. /// /// By default `share_mode` is set to - /// `FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE`. Specifying - /// less permissions denies others to read from, write to and/or delete the - /// file while it is open. + /// `FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE`. This allows + /// other processes to to read, write, and delete/rename the same file + /// while it is open. Removing any of the flags will prevent other + /// processes from performing the corresponding operation until the file + /// handle is closed. /// /// # Examples /// @@ -106,42 +146,46 @@ pub trait OpenOptionsExt { /// use std::os::windows::fs::OpenOptionsExt; /// /// // Do not allow others to read or modify this file while we have it open - /// // for writing + /// // for writing. /// let file = OpenOptions::new().write(true) /// .share_mode(0) /// .open("foo.txt"); /// ``` + /// + /// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx #[stable(feature = "open_options_ext", since = "1.10.0")] fn share_mode(&mut self, val: u32) -> &mut Self; /// Sets extra flags for the `dwFileFlags` argument to the call to - /// `CreateFile2` (or combines it with `attributes` and `security_qos_flags` - /// to set the `dwFlagsAndAttributes` for `CreateFile`). + /// [`CreateFile2`] to the specified value (or combines it with + /// `attributes` and `security_qos_flags` to set the `dwFlagsAndAttributes` + /// for [`CreateFile`]). /// - /// Custom flags can only set flags, not remove flags set by Rusts options. - /// This options overwrites any previously set custom flags. + /// Custom flags can only set flags, not remove flags set by Rust's options. + /// This option overwrites any previously set custom flags. /// /// # Examples /// - /// ```rust,ignore + /// ```ignore /// extern crate winapi; /// use std::fs::OpenOptions; /// use std::os::windows::fs::OpenOptionsExt; /// /// let mut options = OpenOptions::new(); /// options.create(true).write(true); - /// if cfg!(windows) { - /// options.custom_flags(winapi::FILE_FLAG_DELETE_ON_CLOSE); - /// } + /// options.custom_flags(winapi::FILE_FLAG_DELETE_ON_CLOSE); /// let file = options.open("foo.txt"); /// ``` + /// + /// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx + /// [`CreateFile2`]: https://msdn.microsoft.com/en-us/library/windows/desktop/hh449422.aspx #[stable(feature = "open_options_ext", since = "1.10.0")] fn custom_flags(&mut self, flags: u32) -> &mut Self; - /// Sets the `dwFileAttributes` argument to the call to `CreateFile2` to + /// Sets the `dwFileAttributes` argument to the call to [`CreateFile2`] to /// the specified value (or combines it with `custom_flags` and /// `security_qos_flags` to set the `dwFlagsAndAttributes` for - /// `CreateFile`). + /// [`CreateFile`]). /// /// If a _new_ file is created because it does not yet exist and ///`.create(true)` or `.create_new(true)` are specified, the new file is @@ -155,7 +199,7 @@ pub trait OpenOptionsExt { /// /// # Examples /// - /// ```rust,ignore + /// ```ignore /// extern crate winapi; /// use std::fs::OpenOptions; /// use std::os::windows::fs::OpenOptionsExt; @@ -164,12 +208,38 @@ pub trait OpenOptionsExt { /// .attributes(winapi::FILE_ATTRIBUTE_HIDDEN) /// .open("foo.txt"); /// ``` + /// + /// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx + /// [`CreateFile2`]: https://msdn.microsoft.com/en-us/library/windows/desktop/hh449422.aspx #[stable(feature = "open_options_ext", since = "1.10.0")] fn attributes(&mut self, val: u32) -> &mut Self; - /// Sets the `dwSecurityQosFlags` argument to the call to `CreateFile2` to + /// Sets the `dwSecurityQosFlags` argument to the call to [`CreateFile2`] to /// the specified value (or combines it with `custom_flags` and `attributes` - /// to set the `dwFlagsAndAttributes` for `CreateFile`). + /// to set the `dwFlagsAndAttributes` for [`CreateFile`]). + /// + /// By default, `security_qos_flags` is set to `SECURITY_ANONYMOUS`. For + /// information about possible values, see [Impersonation Levels] on the + /// Windows Dev Center site. + /// + /// # Examples + /// + /// ```ignore + /// use std::fs::OpenOptions; + /// use std::os::windows::fs::OpenOptionsExt; + /// + /// let options = OpenOptions::new(); + /// options.write(true).create(true); + /// + /// // Sets the flag value to `SecurityIdentification`. + /// options.security_qos_flags(1); + /// + /// let file = options.open("foo.txt"); + /// ``` + /// + /// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx + /// [`CreateFile2`]: https://msdn.microsoft.com/en-us/library/windows/desktop/hh449422.aspx + /// [Impersonation Levels]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa379572.aspx #[stable(feature = "open_options_ext", since = "1.10.0")] fn security_qos_flags(&mut self, flags: u32) -> &mut OpenOptions; } From 76128b32ccaed5576331ec10e8bdf2c5919978d5 Mon Sep 17 00:00:00 2001 From: David LeGare Date: Sat, 6 May 2017 23:05:47 -0500 Subject: [PATCH 03/28] Update documentation in windows::fs --- src/libstd/sys/windows/ext/fs.rs | 137 ++++++++++++++++++++++++++++--- 1 file changed, 127 insertions(+), 10 deletions(-) diff --git a/src/libstd/sys/windows/ext/fs.rs b/src/libstd/sys/windows/ext/fs.rs index e2e405db276bb..d49c884cb9f8a 100644 --- a/src/libstd/sys/windows/ext/fs.rs +++ b/src/libstd/sys/windows/ext/fs.rs @@ -18,7 +18,9 @@ use path::Path; use sys; use sys_common::{AsInnerMut, AsInner}; -/// Windows-specific extensions to `File` +/// Windows-specific extensions to [`File`]. +/// +/// [`File`]: ../../../fs/struct.File.html #[stable(feature = "file_offset", since = "1.15.0")] pub trait FileExt { /// Seeks to a given position and reads a number of bytes. @@ -103,7 +105,9 @@ impl FileExt for fs::File { } } -/// Windows-specific extensions to `OpenOptions` +/// Windows-specific extensions to [`OpenOptions`]. +/// +/// [`OpenOptions`]: ../../../fs/struct.OpenOptions.html #[stable(feature = "open_options_ext", since = "1.10.0")] pub trait OpenOptionsExt { /// Overrides the `dwDesiredAccess` argument to the call to [`CreateFile`] @@ -267,35 +271,134 @@ impl OpenOptionsExt for OpenOptions { } } -/// Extension methods for `fs::Metadata` to access the raw fields contained +/// Extension methods for [`fs::Metadata`] to access the raw fields contained /// within. +/// +/// The data members that this trait exposes correspond to the members +/// of the [`BY_HANDLE_FILE_INFORMATION`] structure. +/// +/// [`fs::Metadata`]: ../../../fs/struct.Metadata.html +/// [`BY_HANDLE_FILE_INFORMATION`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363788.aspx #[stable(feature = "metadata_ext", since = "1.1.0")] pub trait MetadataExt { /// Returns the value of the `dwFileAttributes` field of this metadata. /// /// This field contains the file system attribute information for a file - /// or directory. + /// or directory. For possible values and their descriptions, see + /// [File Attribute Constants] in the Windows Dev Center. + /// + /// # Examples + /// + /// ```ignore + /// use std::io; + /// use std::io::prelude::*; + /// use std::fs::File; + /// use std::os::windows::prelude::*; + /// + /// # fn foo() -> io::Result<()> { + /// let mut file = File::open("foo.txt")?; + /// let attributes = file.file_attributes(); + /// # } + /// ``` + /// + /// [File Attribute Constants]: https://msdn.microsoft.com/en-us/library/windows/desktop/gg258117.aspx #[stable(feature = "metadata_ext", since = "1.1.0")] fn file_attributes(&self) -> u32; /// Returns the value of the `ftCreationTime` field of this metadata. /// - /// The returned 64-bit value represents the number of 100-nanosecond - /// intervals since January 1, 1601 (UTC). + /// The returned 64-bit value is equivalent to a [`FILETIME`] struct, + /// which represents the number of 100-nanosecond intervals since + /// January 1, 1601 (UTC). The struct is automatically + /// converted to a `u64` value, as that is the recommended way + /// to use it. + /// + /// If the underlying filesystem does not support creation time, the + /// returned value is 0. + /// + /// # Examples + /// + /// ```ignore + /// use std::io; + /// use std::io::prelude::*; + /// use std::fs::File; + /// use std::os::windows::prelude::*; + /// + /// # fn foo() -> io::Result<()> { + /// let mut file = File::open("foo.txt")?; + /// let creation_time = file.creation_time(); + /// # } + /// ``` + /// + /// [`FILETIME`]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284.aspx #[stable(feature = "metadata_ext", since = "1.1.0")] fn creation_time(&self) -> u64; /// Returns the value of the `ftLastAccessTime` field of this metadata. /// - /// The returned 64-bit value represents the number of 100-nanosecond - /// intervals since January 1, 1601 (UTC). + /// The returned 64-bit value is equivalent to a [`FILETIME`] struct, + /// which represents the number of 100-nanosecond intervals since + /// January 1, 1601 (UTC). The struct is automatically + /// converted to a `u64` value, as that is the recommended way + /// to use it. + /// + /// For a file, the value specifies the last time that a file was read + /// from or written to. For a directory, the value specifies when + /// the directory was created. For both files and directories, the + /// specified date is correct, but the time of day is always set to + /// midnight. + /// + /// If the underlying filesystem does not support last access time, the + /// returned value is 0. + /// + /// # Examples + /// + /// ```ignore + /// use std::io; + /// use std::io::prelude::*; + /// use std::fs::File; + /// use std::os::windows::prelude::*; + /// + /// # fn foo() -> io::Result<()> { + /// let mut file = File::open("foo.txt")?; + /// let last_access_time = file.last_access_time(); + /// # } + /// ``` + /// + /// [`FILETIME`]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284.aspx #[stable(feature = "metadata_ext", since = "1.1.0")] fn last_access_time(&self) -> u64; /// Returns the value of the `ftLastWriteTime` field of this metadata. /// - /// The returned 64-bit value represents the number of 100-nanosecond - /// intervals since January 1, 1601 (UTC). + /// The returned 64-bit value is equivalent to a [`FILETIME`] struct, + /// which represents the number of 100-nanosecond intervals since + /// January 1, 1601 (UTC). The struct is automatically + /// converted to a `u64` value, as that is the recommended way + /// to use it. + /// + /// For a file, the value specifies the last time that a file was written + /// to. For a directory, the structure specifies when the directory was + /// created. + /// + /// If the underlying filesystem does not support the last write time + /// time, the returned value is 0. + /// + /// # Examples + /// + /// ```ignore + /// use std::io; + /// use std::io::prelude::*; + /// use std::fs::File; + /// use std::os::windows::prelude::*; + /// + /// # fn foo() -> io::Result<()> { + /// let mut file = File::open("foo.txt")?; + /// let last_write_time = file.last_write_time(); + /// # } + /// ``` + /// + /// [`FILETIME`]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284.aspx #[stable(feature = "metadata_ext", since = "1.1.0")] fn last_write_time(&self) -> u64; @@ -303,6 +406,20 @@ pub trait MetadataExt { /// metadata. /// /// The returned value does not have meaning for directories. + /// + /// # Examples + /// + /// ```ignore + /// use std::io; + /// use std::io::prelude::*; + /// use std::fs::File; + /// use std::os::windows::prelude::*; + /// + /// # fn foo() -> io::Result<()> { + /// let mut file = File::open("foo.txt")?; + /// let file_size = file.file_size(); + /// # } + /// ``` #[stable(feature = "metadata_ext", since = "1.1.0")] fn file_size(&self) -> u64; } From c350bc17eedc776eacf194472107ec82756b204a Mon Sep 17 00:00:00 2001 From: David LeGare Date: Sun, 7 May 2017 10:35:45 -0500 Subject: [PATCH 04/28] Fix documentation tests in windows::fs --- src/libstd/sys/windows/ext/fs.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libstd/sys/windows/ext/fs.rs b/src/libstd/sys/windows/ext/fs.rs index d49c884cb9f8a..c4ec75d32e4a5 100644 --- a/src/libstd/sys/windows/ext/fs.rs +++ b/src/libstd/sys/windows/ext/fs.rs @@ -42,7 +42,6 @@ pub trait FileExt { /// /// ``` /// use std::io; - /// use std::io::prelude::*; /// use std::fs::File; /// use std::os::windows::prelude::*; /// @@ -77,7 +76,6 @@ pub trait FileExt { /// # Examples /// /// ``` - /// use std::io::prelude::*; /// use std::fs::File; /// use std::os::windows::prelude::*; /// @@ -86,7 +84,7 @@ pub trait FileExt { /// /// // Write a byte string starting 72 bytes from /// // the start of the file. - /// buffer.write(b"some bytes", offset)?; + /// buffer.seek_write(b"some bytes", 72)?; /// # Ok(()) /// # } /// ``` From 5135cc854156ae149f6ad50a3b5bc36c7519e3e6 Mon Sep 17 00:00:00 2001 From: David LeGare Date: Tue, 9 May 2017 21:20:56 -0500 Subject: [PATCH 05/28] Fix tidy errors --- src/libstd/sys/windows/ext/fs.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libstd/sys/windows/ext/fs.rs b/src/libstd/sys/windows/ext/fs.rs index c4ec75d32e4a5..8b227573f9827 100644 --- a/src/libstd/sys/windows/ext/fs.rs +++ b/src/libstd/sys/windows/ext/fs.rs @@ -241,7 +241,8 @@ pub trait OpenOptionsExt { /// /// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx /// [`CreateFile2`]: https://msdn.microsoft.com/en-us/library/windows/desktop/hh449422.aspx - /// [Impersonation Levels]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa379572.aspx + /// [Impersonation Levels]: + /// https://msdn.microsoft.com/en-us/library/windows/desktop/aa379572.aspx #[stable(feature = "open_options_ext", since = "1.10.0")] fn security_qos_flags(&mut self, flags: u32) -> &mut OpenOptions; } @@ -276,7 +277,8 @@ impl OpenOptionsExt for OpenOptions { /// of the [`BY_HANDLE_FILE_INFORMATION`] structure. /// /// [`fs::Metadata`]: ../../../fs/struct.Metadata.html -/// [`BY_HANDLE_FILE_INFORMATION`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363788.aspx +/// [`BY_HANDLE_FILE_INFORMATION`]: +/// https://msdn.microsoft.com/en-us/library/windows/desktop/aa363788.aspx #[stable(feature = "metadata_ext", since = "1.1.0")] pub trait MetadataExt { /// Returns the value of the `dwFileAttributes` field of this metadata. @@ -299,7 +301,8 @@ pub trait MetadataExt { /// # } /// ``` /// - /// [File Attribute Constants]: https://msdn.microsoft.com/en-us/library/windows/desktop/gg258117.aspx + /// [File Attribute Constants]: + /// https://msdn.microsoft.com/en-us/library/windows/desktop/gg258117.aspx #[stable(feature = "metadata_ext", since = "1.1.0")] fn file_attributes(&self) -> u32; From e6cde9f2a4f5e4d9e20686f29344461eacae3eba Mon Sep 17 00:00:00 2001 From: Mike Lubinets Date: Thu, 11 May 2017 16:48:25 +0300 Subject: [PATCH 06/28] Number of filtered out tests in tests summary Closes #31905 --- src/libtest/lib.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 0d615db3deb47..ef048ac8ca355 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -542,6 +542,7 @@ struct ConsoleTestState { passed: usize, failed: usize, ignored: usize, + filtered_out: usize, measured: usize, metrics: MetricMap, failures: Vec<(TestDesc, Vec)>, @@ -570,6 +571,7 @@ impl ConsoleTestState { passed: 0, failed: 0, ignored: 0, + filtered_out: 0, measured: 0, metrics: MetricMap::new(), failures: Vec::new(), @@ -775,11 +777,12 @@ impl ConsoleTestState { } else { self.write_pretty("FAILED", term::color::RED)?; } - let s = format!(". {} passed; {} failed; {} ignored; {} measured\n\n", + let s = format!(". {} passed; {} failed; {} ignored; {} measured; {} filtered out\n\n", self.passed, self.failed, self.ignored, - self.measured); + self.measured, + self.filtered_out); self.write_plain(&s)?; return Ok(success); } @@ -875,6 +878,7 @@ pub fn run_tests_console(opts: &TestOpts, tests: Vec) -> io::Resu fn callback(event: &TestEvent, st: &mut ConsoleTestState) -> io::Result<()> { match (*event).clone() { TeFiltered(ref filtered_tests) => st.write_run_start(filtered_tests.len()), + TeFilteredOut(filtered_out) => Ok(st.filtered_out = filtered_out), TeWait(ref test, padding) => st.write_test_start(test, padding), TeTimeout(ref test) => st.write_timeout(test), TeResult(test, result, stdout) => { @@ -957,6 +961,7 @@ fn should_sort_failures_before_printing_them() { passed: 0, failed: 0, ignored: 0, + filtered_out: 0, measured: 0, max_name_len: 10, metrics: MetricMap::new(), @@ -1017,6 +1022,7 @@ pub enum TestEvent { TeWait(TestDesc, NamePadding), TeResult(TestDesc, TestResult, Vec), TeTimeout(TestDesc), + TeFilteredOut(usize), } pub type MonitorMsg = (TestDesc, TestResult, Vec); @@ -1028,11 +1034,16 @@ pub fn run_tests(opts: &TestOpts, tests: Vec, mut callback: F) use std::collections::HashMap; use std::sync::mpsc::RecvTimeoutError; + let tests_len = tests.len(); + let mut filtered_tests = filter_tests(opts, tests); if !opts.bench_benchmarks { filtered_tests = convert_benchmarks_to_tests(filtered_tests); } + let filtered_out = tests_len - filtered_tests.len(); + callback(TeFilteredOut(filtered_out))?; + let filtered_descs = filtered_tests.iter() .map(|t| t.desc.clone()) .collect(); From 94d2c43300148d5c0ea8c93cedb94151953dcf83 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 13 May 2017 08:21:24 -0500 Subject: [PATCH 07/28] add -Z pre-link-arg{,s} to rustc This commit adds two unstable flags to `rustc`: `-Z pre-link-arg` and `-Z pre-link-args`. These are the counterpart of the existing `-C link-arg{,s}` flags and can be used to pass extra arguments at the *beginning* of the linker invocation, before the Rust object files are passed. --- src/librustc/session/config.rs | 8 ++++++-- src/librustc_trans/back/link.rs | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 884a71f0d32d4..79bb20599ca1a 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -824,9 +824,9 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options, linker: Option = (None, parse_opt_string, [UNTRACKED], "system linker to link outputs with"), link_arg: Vec = (vec![], parse_string_push, [UNTRACKED], - "a single extra argument to pass to the linker (can be used several times)"), + "a single extra argument to append to the linker invocation (can be used several times)"), link_args: Option> = (None, parse_opt_list, [UNTRACKED], - "extra arguments to pass to the linker (space separated)"), + "extra arguments to append to the linker invocation (space separated)"), link_dead_code: bool = (false, parse_bool, [UNTRACKED], "don't let linker strip dead code (turning it on can be used for code coverage)"), lto: bool = (false, parse_bool, [TRACKED], @@ -1029,6 +1029,10 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "add a mapping target to the file path remapping config"), force_unstable_if_unmarked: bool = (false, parse_bool, [TRACKED], "force all crates to be `rustc_private` unstable"), + pre_link_arg: Vec = (vec![], parse_string_push, [UNTRACKED], + "a single extra argument to prepend the linker invocation (can be used several times)"), + pre_link_args: Option> = (None, parse_opt_list, [UNTRACKED], + "extra arguments to prepend to the linker invocation (space separated)"), } pub fn default_lib_output() -> CrateType { diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index e42e69d2a76e2..d1000a574b526 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -714,6 +714,10 @@ fn link_natively(sess: &Session, if let Some(args) = sess.target.target.options.pre_link_args.get(&flavor) { cmd.args(args); } + if let Some(ref args) = sess.opts.debugging_opts.pre_link_args { + cmd.args(args); + } + cmd.args(&sess.opts.debugging_opts.pre_link_arg); let pre_link_objects = if crate_type == config::CrateTypeExecutable { &sess.target.target.options.pre_link_objects_exe From 4f2f27014de578c26478848fc746182e22413540 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Mon, 15 May 2017 09:41:05 +0000 Subject: [PATCH 08/28] Fix regression on `include!(line!())`. --- src/libsyntax/ext/base.rs | 4 ++-- src/libsyntax/ext/source_util.rs | 6 +++--- src/test/compile-fail/issue-41776.rs | 13 +++++++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 src/test/compile-fail/issue-41776.rs diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index fda026fec64ef..1f279cc9c80cd 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -695,7 +695,7 @@ impl<'a> ExtCtxt<'a> { /// Returns span for the macro which originally caused the current expansion to happen. /// /// Stops backtracing at include! boundary. - pub fn expansion_cause(&self) -> Span { + pub fn expansion_cause(&self) -> Option { let mut ctxt = self.backtrace(); let mut last_macro = None; loop { @@ -711,7 +711,7 @@ impl<'a> ExtCtxt<'a> { break } } - last_macro.expect("missing expansion backtrace") + last_macro } pub fn struct_span_warn(&self, diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 22a5776315a0c..fc557a78dda0d 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -35,7 +35,7 @@ pub fn expand_line(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree]) -> Box { base::check_zero_tts(cx, sp, tts, "line!"); - let topmost = cx.expansion_cause(); + let topmost = cx.expansion_cause().unwrap_or(sp); let loc = cx.codemap().lookup_char_pos(topmost.lo); base::MacEager::expr(cx.expr_u32(topmost, loc.line as u32)) @@ -46,7 +46,7 @@ pub fn expand_column(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree]) -> Box { base::check_zero_tts(cx, sp, tts, "column!"); - let topmost = cx.expansion_cause(); + let topmost = cx.expansion_cause().unwrap_or(sp); let loc = cx.codemap().lookup_char_pos(topmost.lo); base::MacEager::expr(cx.expr_u32(topmost, loc.col.to_usize() as u32)) @@ -59,7 +59,7 @@ pub fn expand_file(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree]) -> Box { base::check_zero_tts(cx, sp, tts, "file!"); - let topmost = cx.expansion_cause(); + let topmost = cx.expansion_cause().unwrap_or(sp); let loc = cx.codemap().lookup_char_pos(topmost.lo); base::MacEager::expr(cx.expr_str(topmost, Symbol::intern(&loc.file.name))) } diff --git a/src/test/compile-fail/issue-41776.rs b/src/test/compile-fail/issue-41776.rs new file mode 100644 index 0000000000000..5f108e0a1ed81 --- /dev/null +++ b/src/test/compile-fail/issue-41776.rs @@ -0,0 +1,13 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + include!(line!()); //~ ERROR argument must be a string literal +} From 1b6a182cf1e400b63ae8692e3183beabe541ea6c Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 17 May 2017 15:14:30 +0200 Subject: [PATCH 09/28] Improve the error management when /proc is not mounted This PR does two things: * Triggers an error on GNU/Linux & Android when /proc/self/exe doesn't exist * Handle the error properly --- src/librustc/session/filesearch.rs | 11 ++++++++--- src/libstd/sys/unix/os.rs | 7 ++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/librustc/session/filesearch.rs b/src/librustc/session/filesearch.rs index 82c2425aead73..47b988a21b4c1 100644 --- a/src/librustc/session/filesearch.rs +++ b/src/librustc/session/filesearch.rs @@ -159,9 +159,14 @@ pub fn get_or_default_sysroot() -> PathBuf { }) } - match canonicalize(env::current_exe().ok()) { - Some(mut p) => { p.pop(); p.pop(); p } - None => bug!("can't determine value for sysroot") + match env::current_exe() { + Ok(exe) => { + match canonicalize(Some(exe)) { + Some(mut p) => { p.pop(); p.pop(); return p; }, + None => bug!("can't determine value for sysroot") + } + } + Err(ref e) => panic!(format!("failed to get current_exe: {}", e)) } } diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 36928696c4059..8e41fd009be67 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -253,7 +253,12 @@ pub fn current_exe() -> io::Result { #[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))] pub fn current_exe() -> io::Result { - ::fs::read_link("/proc/self/exe") + let selfexe = PathBuf::from("/proc/self/exe"); + if selfexe.exists() { + ::fs::read_link(selfexe) + } else { + Err(io::Error::new(io::ErrorKind::Other, "no /proc/self/exe available. Is /proc mounted?")) + } } #[cfg(any(target_os = "macos", target_os = "ios"))] From 307d8e5aa5f0c66881b1028fe1dc7f17e5ea317a Mon Sep 17 00:00:00 2001 From: Marco A L Barbosa Date: Fri, 12 May 2017 15:18:34 -0300 Subject: [PATCH 10/28] ci: allows shared scripts --- src/ci/docker/android-ndk.sh | 7 +- .../install-sdk.sh => android-sdk.sh} | 6 +- ...-emulator.sh => android-start-emulator.sh} | 0 src/ci/docker/arm-android/Dockerfile | 70 +++++++++---------- src/ci/docker/arm-android/install-ndk.sh | 35 ---------- src/ci/docker/armhf-gnu/Dockerfile | 6 +- src/ci/docker/cross/Dockerfile | 4 +- .../disabled/dist-aarch64-android/Dockerfile | 47 +++++++------ .../disabled/dist-armv7-android/Dockerfile | 49 +++++++------ .../disabled/dist-i686-android/Dockerfile | 49 +++++++------ .../disabled/dist-x86_64-android/Dockerfile | 47 +++++++------ src/ci/docker/dist-aarch64-linux/Dockerfile | 2 +- src/ci/docker/dist-android/Dockerfile | 44 ++++++------ src/ci/docker/dist-android/install-ndk.sh | 35 ---------- src/ci/docker/dist-arm-linux/Dockerfile | 2 +- src/ci/docker/dist-armhf-linux/Dockerfile | 2 +- src/ci/docker/dist-armv7-linux/Dockerfile | 2 +- src/ci/docker/dist-fuchsia/Dockerfile | 2 +- .../docker/dist-i586-gnu-i686-musl/Dockerfile | 2 +- src/ci/docker/dist-i686-freebsd/Dockerfile | 2 +- src/ci/docker/dist-i686-linux/Dockerfile | 16 ++--- src/ci/docker/dist-powerpc64-linux/Dockerfile | 4 +- .../docker/dist-powerpc64le-linux/Dockerfile | 2 +- src/ci/docker/dist-s390x-linux/Dockerfile | 4 +- src/ci/docker/dist-x86_64-freebsd/Dockerfile | 2 +- src/ci/docker/dist-x86_64-linux/Dockerfile | 16 ++--- src/ci/docker/dist-x86_64-musl/Dockerfile | 2 +- src/ci/docker/dist-x86_64-netbsd/Dockerfile | 2 +- src/ci/docker/dumb-init.sh | 15 ++++ src/ci/docker/emscripten/Dockerfile | 2 +- src/ci/docker/run.sh | 3 +- src/ci/docker/sccache.sh | 16 +++++ 32 files changed, 237 insertions(+), 260 deletions(-) rename src/ci/docker/{arm-android/install-sdk.sh => android-sdk.sh} (92%) rename src/ci/docker/{arm-android/start-emulator.sh => android-start-emulator.sh} (100%) delete mode 100644 src/ci/docker/arm-android/install-ndk.sh delete mode 100644 src/ci/docker/dist-android/install-ndk.sh create mode 100644 src/ci/docker/dumb-init.sh create mode 100644 src/ci/docker/sccache.sh diff --git a/src/ci/docker/android-ndk.sh b/src/ci/docker/android-ndk.sh index 4849f84300729..c3d83c087e52f 100644 --- a/src/ci/docker/android-ndk.sh +++ b/src/ci/docker/android-ndk.sh @@ -1,4 +1,3 @@ -#!/bin/sh # Copyright 2017 The Rust Project Developers. See the COPYRIGHT # file at the top-level directory of this distribution and at # http://rust-lang.org/COPYRIGHT. @@ -33,3 +32,9 @@ make_standalone_toolchain() { remove_ndk() { rm -rf /android/ndk/ndk } + +download_and_make_toolchain() { + download_ndk $1 && \ + make_standalone_toolchain $2 $3 && \ + remove_ndk +} diff --git a/src/ci/docker/arm-android/install-sdk.sh b/src/ci/docker/android-sdk.sh similarity index 92% rename from src/ci/docker/arm-android/install-sdk.sh rename to src/ci/docker/android-sdk.sh index 258fc47a7a692..7d8110efedec9 100644 --- a/src/ci/docker/arm-android/install-sdk.sh +++ b/src/ci/docker/android-sdk.sh @@ -1,4 +1,3 @@ -#!/bin/sh # Copyright 2017 The Rust Project Developers. See the COPYRIGHT # file at the top-level directory of this distribution and at # http://rust-lang.org/COPYRIGHT. @@ -47,3 +46,8 @@ create_avd() { --abi $abi } +download_and_create_avd() { + download_sdk $1 + download_sysimage $2 $3 + create_avd $2 $3 +} diff --git a/src/ci/docker/arm-android/start-emulator.sh b/src/ci/docker/android-start-emulator.sh similarity index 100% rename from src/ci/docker/arm-android/start-emulator.sh rename to src/ci/docker/android-start-emulator.sh diff --git a/src/ci/docker/arm-android/Dockerfile b/src/ci/docker/arm-android/Dockerfile index 93f15baf55e77..6fd3ed7c6a9e9 100644 --- a/src/ci/docker/arm-android/Dockerfile +++ b/src/ci/docker/arm-android/Dockerfile @@ -2,52 +2,44 @@ FROM ubuntu:16.04 RUN apt-get update && \ apt-get install -y --no-install-recommends \ + ca-certificates \ + cmake \ + curl \ + file \ g++ \ + git \ + libssl-dev \ make \ - file \ - curl \ - ca-certificates \ + pkg-config \ python2.7 \ - git \ - cmake \ - unzip \ sudo \ - xz-utils \ - libssl-dev \ - pkg-config - -RUN curl -OL https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb && \ - dpkg -i dumb-init_*.deb && \ - rm dumb-init_*.deb + unzip \ + xz-utils -RUN curl -o /usr/local/bin/sccache \ - https://s3.amazonaws.com/rust-lang-ci/rust-ci-mirror/2017-05-12-sccache-x86_64-unknown-linux-musl && \ - chmod +x /usr/local/bin/sccache +# dumb-init +COPY dumb-init.sh /scripts/ +RUN sh /scripts/dumb-init.sh -# Install NDK -COPY install-ndk.sh /tmp -RUN . /tmp/install-ndk.sh && \ - download_ndk android-ndk-r13b-linux-x86_64.zip && \ - make_standalone_toolchain arm 9 && \ - remove_ndk +# ndk +COPY android-ndk.sh /scripts/ +RUN . /scripts/android-ndk.sh && \ + download_and_make_toolchain android-ndk-r13b-linux-x86_64.zip arm 9 -# Install SDK +# sdk RUN dpkg --add-architecture i386 && \ apt-get update && \ apt-get install -y --no-install-recommends \ - openjdk-9-jre-headless \ - tzdata \ - libstdc++6:i386 \ libgl1-mesa-glx \ - libpulse0 + libpulse0 \ + libstdc++6:i386 \ + openjdk-9-jre-headless \ + tzdata -COPY install-sdk.sh /tmp -RUN . /tmp/install-sdk.sh && \ - download_sdk tools_r25.2.5-linux.zip && \ - download_sysimage armeabi-v7a 18 && \ - create_avd armeabi-v7a 18 +COPY android-sdk.sh /scripts/ +RUN . /scripts/android-sdk.sh && \ + download_and_create_avd tools_r25.2.5-linux.zip armeabi-v7a 18 -# Setup env +# env ENV PATH=$PATH:/android/sdk/tools ENV PATH=$PATH:/android/sdk/platform-tools @@ -57,8 +49,12 @@ ENV RUST_CONFIGURE_ARGS \ --target=$TARGETS \ --arm-linux-androideabi-ndk=/android/ndk/arm-9 -ENV SCRIPT python2.7 ../x.py test --target $TARGETS --verbose +ENV SCRIPT python2.7 ../x.py test --target $TARGETS + +# sccache +COPY sccache.sh /scripts/ +RUN sh /scripts/sccache.sh -# Entrypoint -COPY start-emulator.sh /android/ -ENTRYPOINT ["/usr/bin/dumb-init", "--", "/android/start-emulator.sh"] +# init +COPY android-start-emulator.sh /scripts/ +ENTRYPOINT ["/usr/bin/dumb-init", "--", "/scripts/android-start-emulator.sh"] diff --git a/src/ci/docker/arm-android/install-ndk.sh b/src/ci/docker/arm-android/install-ndk.sh deleted file mode 100644 index 8081872119983..0000000000000 --- a/src/ci/docker/arm-android/install-ndk.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh -# Copyright 2016 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 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. - -set -ex - -URL=https://dl.google.com/android/repository - -download_ndk() { - mkdir -p /android/ndk - cd /android/ndk - curl -O $URL/$1 - unzip -q $1 - rm $1 - mv android-ndk-* ndk -} - -make_standalone_toolchain() { - # See https://developer.android.com/ndk/guides/standalone_toolchain.html - python2.7 /android/ndk/ndk/build/tools/make_standalone_toolchain.py \ - --install-dir /android/ndk/$1-$2 \ - --arch $1 \ - --api $2 -} - -remove_ndk() { - rm -rf /android/ndk/ndk -} diff --git a/src/ci/docker/armhf-gnu/Dockerfile b/src/ci/docker/armhf-gnu/Dockerfile index 801de69a63d54..03e0b78ba89b3 100644 --- a/src/ci/docker/armhf-gnu/Dockerfile +++ b/src/ci/docker/armhf-gnu/Dockerfile @@ -31,7 +31,7 @@ WORKDIR /build # The `vexpress_config` config file was a previously generated config file for # the kernel. This file was generated by running `make vexpress_defconfig` # followed by `make menuconfig` and then enabling the IPv6 protocol page. -COPY vexpress_config /build/.config +COPY armhf-gnu/vexpress_config /build/.config RUN curl https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.4.42.tar.xz | \ tar xJf - && \ cd /build/linux-4.4.42 && \ @@ -63,11 +63,11 @@ RUN curl http://cdimage.ubuntu.com/ubuntu-base/releases/16.04/release/ubuntu-bas # Copy over our init script, which starts up our test server and also a few # other misc tasks. -COPY rcS rootfs/etc/init.d/rcS +COPY armhf-gnu/rcS rootfs/etc/init.d/rcS RUN chmod +x rootfs/etc/init.d/rcS # Helper to quickly fill the entropy pool in the kernel. -COPY addentropy.c /tmp/ +COPY armhf-gnu/addentropy.c /tmp/ RUN arm-linux-gnueabihf-gcc addentropy.c -o rootfs/addentropy -static # TODO: What is this?! diff --git a/src/ci/docker/cross/Dockerfile b/src/ci/docker/cross/Dockerfile index 30a699c3ba214..7759d91e1bb63 100644 --- a/src/ci/docker/cross/Dockerfile +++ b/src/ci/docker/cross/Dockerfile @@ -32,10 +32,10 @@ ENTRYPOINT ["/usr/bin/dumb-init", "--"] WORKDIR /tmp -COPY build-rumprun.sh /tmp/ +COPY cross/build-rumprun.sh /tmp/ RUN ./build-rumprun.sh -COPY build-arm-musl.sh /tmp/ +COPY cross/build-arm-musl.sh /tmp/ RUN ./build-arm-musl.sh # originally from diff --git a/src/ci/docker/disabled/dist-aarch64-android/Dockerfile b/src/ci/docker/disabled/dist-aarch64-android/Dockerfile index e15876edbd8db..5a966518759e4 100644 --- a/src/ci/docker/disabled/dist-aarch64-android/Dockerfile +++ b/src/ci/docker/disabled/dist-aarch64-android/Dockerfile @@ -2,36 +2,30 @@ FROM ubuntu:16.04 RUN apt-get update && \ apt-get install -y --no-install-recommends \ + ca-certificates \ + cmake \ + curl \ + file \ g++ \ + git \ + libssl-dev \ make \ - file \ - curl \ - ca-certificates \ + pkg-config \ python2.7 \ - git \ - cmake \ - unzip \ sudo \ - xz-utils \ - libssl-dev \ - pkg-config - -RUN curl -OL https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb && \ - dpkg -i dumb-init_*.deb && \ - rm dumb-init_*.deb - -RUN curl -o /usr/local/bin/sccache \ - https://s3.amazonaws.com/rust-lang-ci/rust-ci-mirror/2017-05-12-sccache-x86_64-unknown-linux-musl && \ - chmod +x /usr/local/bin/sccache + unzip \ + xz-utils -ENTRYPOINT ["/usr/bin/dumb-init", "--"] +# dumb-init +COPY dumb-init.sh /scripts/ +RUN sh /scripts/dumb-init.sh -COPY android-ndk.sh / -RUN . /android-ndk.sh && \ - download_ndk android-ndk-r13b-linux-x86_64.zip && \ - make_standalone_toolchain arm64 21 && \ - remove_ndk +# ndk +COPY android-ndk.sh /scripts/ +RUN . /scripts/android-ndk.sh && \ + download_and_make_toolchain android-ndk-r13b-linux-x86_64.zip arm64 21 +# env ENV PATH=$PATH:/android/ndk/arm64-21/bin ENV DEP_Z_ROOT=/android/ndk/arm64-21/sysroot/usr/ @@ -47,3 +41,10 @@ ENV RUST_CONFIGURE_ARGS \ --enable-cargo-openssl-static ENV SCRIPT python2.7 ../x.py dist --target $HOSTS --host $HOSTS + +# sccache +COPY sccache.sh /scripts/ +RUN sh /scripts/sccache.sh + +# init +ENTRYPOINT ["/usr/bin/dumb-init", "--"] diff --git a/src/ci/docker/disabled/dist-armv7-android/Dockerfile b/src/ci/docker/disabled/dist-armv7-android/Dockerfile index 0d81e404b5c0d..f92a28a794612 100644 --- a/src/ci/docker/disabled/dist-armv7-android/Dockerfile +++ b/src/ci/docker/disabled/dist-armv7-android/Dockerfile @@ -2,37 +2,36 @@ FROM ubuntu:16.04 RUN apt-get update && \ apt-get install -y --no-install-recommends \ + ca-certificates \ + cmake \ + curl \ + file \ g++ \ + git \ + libssl-dev \ make \ - file \ - curl \ - ca-certificates \ + pkg-config \ python2.7 \ - git \ - cmake \ - unzip \ sudo \ - xz-utils \ - libssl-dev \ - pkg-config - -RUN curl -OL https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb && \ - dpkg -i dumb-init_*.deb && \ - rm dumb-init_*.deb - -RUN curl -o /usr/local/bin/sccache \ - https://s3.amazonaws.com/rust-lang-ci/rust-ci-mirror/2017-05-12-sccache-x86_64-unknown-linux-musl && \ - chmod +x /usr/local/bin/sccache + unzip \ + xz-utils -ENTRYPOINT ["/usr/bin/dumb-init", "--"] +# dumb-init +COPY dumb-init.sh /scripts/ +RUN sh /scripts/dumb-init.sh -COPY android-ndk.sh / -RUN . /android-ndk.sh && \ +# ndk +COPY android-ndk.sh /scripts/ +RUN . /scripts/android-ndk.sh && \ download_ndk android-ndk-r13b-linux-x86_64.zip && \ make_standalone_toolchain arm 9 && \ make_standalone_toolchain arm 21 && \ remove_ndk +RUN chmod 777 /android/ndk && \ + ln -s /android/ndk/arm-21 /android/ndk/arm + +# env ENV PATH=$PATH:/android/ndk/arm-9/bin ENV DEP_Z_ROOT=/android/ndk/arm-9/sysroot/usr/ @@ -54,12 +53,16 @@ ENV RUST_CONFIGURE_ARGS \ # level 9), the default linker behavior is to generate an error, to allow the # build to finish we use --warn-unresolved-symbols. Note that the missing # symbols does not affect std, only the compiler (llvm) and cargo (openssl). -RUN chmod 777 /android/ndk && \ - ln -s /android/ndk/arm-21 /android/ndk/arm - ENV SCRIPT \ python2.7 ../x.py build src/llvm --host $HOSTS --target $HOSTS && \ (export RUSTFLAGS="\"-C link-arg=-Wl,--warn-unresolved-symbols\""; \ rm /android/ndk/arm && \ ln -s /android/ndk/arm-9 /android/ndk/arm && \ python2.7 ../x.py dist --host $HOSTS --target $HOSTS) + +# sccache +COPY sccache.sh /scripts/ +RUN sh /scripts/sccache.sh + +# init +ENTRYPOINT ["/usr/bin/dumb-init", "--"] diff --git a/src/ci/docker/disabled/dist-i686-android/Dockerfile b/src/ci/docker/disabled/dist-i686-android/Dockerfile index 37930639b8a69..c475c19ebde76 100644 --- a/src/ci/docker/disabled/dist-i686-android/Dockerfile +++ b/src/ci/docker/disabled/dist-i686-android/Dockerfile @@ -2,37 +2,36 @@ FROM ubuntu:16.04 RUN apt-get update && \ apt-get install -y --no-install-recommends \ + ca-certificates \ + cmake \ + curl \ + file \ g++ \ + git \ + libssl-dev \ make \ - file \ - curl \ - ca-certificates \ + pkg-config \ python2.7 \ - git \ - cmake \ - unzip \ sudo \ - xz-utils \ - libssl-dev \ - pkg-config - -RUN curl -OL https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb && \ - dpkg -i dumb-init_*.deb && \ - rm dumb-init_*.deb - -RUN curl -o /usr/local/bin/sccache \ - https://s3.amazonaws.com/rust-lang-ci/rust-ci-mirror/2017-05-12-sccache-x86_64-unknown-linux-musl && \ - chmod +x /usr/local/bin/sccache + unzip \ + xz-utils -ENTRYPOINT ["/usr/bin/dumb-init", "--"] +# dumb-init +COPY dumb-init.sh /scripts/ +RUN sh /scripts/dumb-init.sh -COPY android-ndk.sh / -RUN . /android-ndk.sh && \ +# ndk +COPY android-ndk.sh /scripts/ +RUN . /scripts/android-ndk.sh && \ download_ndk android-ndk-r13b-linux-x86_64.zip && \ make_standalone_toolchain x86 9 && \ make_standalone_toolchain x86 21 && \ remove_ndk +RUN chmod 777 /android/ndk && \ + ln -s /android/ndk/x86-21 /android/ndk/x86 + +# env ENV PATH=$PATH:/android/ndk/x86-9/bin ENV DEP_Z_ROOT=/android/ndk/x86-9/sysroot/usr/ @@ -54,12 +53,16 @@ ENV RUST_CONFIGURE_ARGS \ # level 9), the default linker behavior is to generate an error, to allow the # build to finish we use --warn-unresolved-symbols. Note that the missing # symbols does not affect std, only the compiler (llvm) and cargo (openssl). -RUN chmod 777 /android/ndk && \ - ln -s /android/ndk/x86-21 /android/ndk/x86 - ENV SCRIPT \ python2.7 ../x.py build src/llvm --host $HOSTS --target $HOSTS && \ (export RUSTFLAGS="\"-C link-arg=-Wl,--warn-unresolved-symbols\""; \ rm /android/ndk/x86 && \ ln -s /android/ndk/x86-9 /android/ndk/x86 && \ python2.7 ../x.py dist --host $HOSTS --target $HOSTS) + +# sccache +COPY sccache.sh /scripts/ +RUN sh /scripts/sccache.sh + +# init +ENTRYPOINT ["/usr/bin/dumb-init", "--"] diff --git a/src/ci/docker/disabled/dist-x86_64-android/Dockerfile b/src/ci/docker/disabled/dist-x86_64-android/Dockerfile index a642d8ed6ecc2..4f4f5fae18d18 100644 --- a/src/ci/docker/disabled/dist-x86_64-android/Dockerfile +++ b/src/ci/docker/disabled/dist-x86_64-android/Dockerfile @@ -2,36 +2,30 @@ FROM ubuntu:16.04 RUN apt-get update && \ apt-get install -y --no-install-recommends \ + ca-certificates \ + cmake \ + curl \ + file \ g++ \ + git \ + libssl-dev \ make \ - file \ - curl \ - ca-certificates \ + pkg-config \ python2.7 \ - git \ - cmake \ - unzip \ sudo \ - xz-utils \ - libssl-dev \ - pkg-config - -RUN curl -OL https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb && \ - dpkg -i dumb-init_*.deb && \ - rm dumb-init_*.deb - -RUN curl -o /usr/local/bin/sccache \ - https://s3.amazonaws.com/rust-lang-ci/rust-ci-mirror/2017-05-12-sccache-x86_64-unknown-linux-musl && \ - chmod +x /usr/local/bin/sccache + unzip \ + xz-utils -ENTRYPOINT ["/usr/bin/dumb-init", "--"] +# dumb-init +COPY dumb-init.sh /scripts/ +RUN sh /scripts/dumb-init.sh -COPY android-ndk.sh / -RUN . /android-ndk.sh && \ - download_ndk android-ndk-r13b-linux-x86_64.zip && \ - make_standalone_toolchain x86_64 21 && \ - remove_ndk +# ndk +COPY android-ndk.sh /scripts/ +RUN . /scripts/android-ndk.sh && \ + download_and_make_toolchain android-ndk-r13b-linux-x86_64.zip x86_64 21 +# env ENV PATH=$PATH:/android/ndk/x86_64-21/bin ENV DEP_Z_ROOT=/android/ndk/x86_64-21/sysroot/usr/ @@ -47,3 +41,10 @@ ENV RUST_CONFIGURE_ARGS \ --enable-cargo-openssl-static ENV SCRIPT python2.7 ../x.py dist --target $HOSTS --host $HOSTS + +# sccache +COPY sccache.sh /scripts/ +RUN sh /scripts/sccache.sh + +# init +ENTRYPOINT ["/usr/bin/dumb-init", "--"] diff --git a/src/ci/docker/dist-aarch64-linux/Dockerfile b/src/ci/docker/dist-aarch64-linux/Dockerfile index c8257c05acdd4..0134a5407932a 100644 --- a/src/ci/docker/dist-aarch64-linux/Dockerfile +++ b/src/ci/docker/dist-aarch64-linux/Dockerfile @@ -56,7 +56,7 @@ RUN mkdir /x-tools && chown rustbuild:rustbuild /x-tools USER rustbuild WORKDIR /tmp -COPY aarch64-linux-gnu.config build-toolchains.sh /tmp/ +COPY dist-aarch64-linux/aarch64-linux-gnu.config dist-aarch64-linux/build-toolchains.sh /tmp/ RUN ./build-toolchains.sh USER root diff --git a/src/ci/docker/dist-android/Dockerfile b/src/ci/docker/dist-android/Dockerfile index 711c0ee574700..13d76536113b2 100644 --- a/src/ci/docker/dist-android/Dockerfile +++ b/src/ci/docker/dist-android/Dockerfile @@ -2,33 +2,27 @@ FROM ubuntu:16.04 RUN apt-get update && \ apt-get install -y --no-install-recommends \ + ca-certificates \ + cmake \ + curl \ + file \ g++ \ + git \ + libssl-dev \ make \ - file \ - curl \ - ca-certificates \ + pkg-config \ python2.7 \ - git \ - cmake \ - unzip \ sudo \ - xz-utils \ - libssl-dev \ - pkg-config - -RUN curl -OL https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb && \ - dpkg -i dumb-init_*.deb && \ - rm dumb-init_*.deb - -RUN curl -o /usr/local/bin/sccache \ - https://s3.amazonaws.com/rust-lang-ci/rust-ci-mirror/2017-05-12-sccache-x86_64-unknown-linux-musl && \ - chmod +x /usr/local/bin/sccache + unzip \ + xz-utils -ENTRYPOINT ["/usr/bin/dumb-init", "--"] +# dumb-init +COPY dumb-init.sh /scripts/ +RUN sh /scripts/dumb-init.sh -# Install NDK -COPY install-ndk.sh /tmp -RUN . /tmp/install-ndk.sh && \ +# ndk +COPY android-ndk.sh /scripts/ +RUN . /scripts/android-ndk.sh && \ download_ndk android-ndk-r13b-linux-x86_64.zip && \ make_standalone_toolchain arm 9 && \ make_standalone_toolchain x86 9 && \ @@ -36,6 +30,7 @@ RUN . /tmp/install-ndk.sh && \ make_standalone_toolchain x86_64 21 && \ remove_ndk +# env ENV TARGETS=arm-linux-androideabi ENV TARGETS=$TARGETS,armv7-linux-androideabi ENV TARGETS=$TARGETS,i686-linux-android @@ -52,3 +47,10 @@ ENV RUST_CONFIGURE_ARGS \ --x86_64-linux-android-ndk=/android/ndk/x86_64-21 ENV SCRIPT python2.7 ../x.py dist --target $TARGETS + +# cache +COPY sccache.sh /scripts/ +RUN sh /scripts/sccache.sh + +# init +ENTRYPOINT ["/usr/bin/dumb-init", "--"] diff --git a/src/ci/docker/dist-android/install-ndk.sh b/src/ci/docker/dist-android/install-ndk.sh deleted file mode 100644 index 8081872119983..0000000000000 --- a/src/ci/docker/dist-android/install-ndk.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh -# Copyright 2016 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 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. - -set -ex - -URL=https://dl.google.com/android/repository - -download_ndk() { - mkdir -p /android/ndk - cd /android/ndk - curl -O $URL/$1 - unzip -q $1 - rm $1 - mv android-ndk-* ndk -} - -make_standalone_toolchain() { - # See https://developer.android.com/ndk/guides/standalone_toolchain.html - python2.7 /android/ndk/ndk/build/tools/make_standalone_toolchain.py \ - --install-dir /android/ndk/$1-$2 \ - --arch $1 \ - --api $2 -} - -remove_ndk() { - rm -rf /android/ndk/ndk -} diff --git a/src/ci/docker/dist-arm-linux/Dockerfile b/src/ci/docker/dist-arm-linux/Dockerfile index af2b58f7d6b7f..862818a7c9182 100644 --- a/src/ci/docker/dist-arm-linux/Dockerfile +++ b/src/ci/docker/dist-arm-linux/Dockerfile @@ -56,7 +56,7 @@ RUN mkdir /x-tools && chown rustbuild:rustbuild /x-tools USER rustbuild WORKDIR /tmp -COPY arm-linux-gnueabi.config build-toolchains.sh /tmp/ +COPY dist-arm-linux/arm-linux-gnueabi.config dist-arm-linux/build-toolchains.sh /tmp/ RUN ./build-toolchains.sh USER root diff --git a/src/ci/docker/dist-armhf-linux/Dockerfile b/src/ci/docker/dist-armhf-linux/Dockerfile index 076bc50946cac..7f1f91f844c77 100644 --- a/src/ci/docker/dist-armhf-linux/Dockerfile +++ b/src/ci/docker/dist-armhf-linux/Dockerfile @@ -56,7 +56,7 @@ RUN mkdir /x-tools && chown rustbuild:rustbuild /x-tools USER rustbuild WORKDIR /tmp -COPY arm-linux-gnueabihf.config build-toolchains.sh /tmp/ +COPY dist-armhf-linux/arm-linux-gnueabihf.config dist-armhf-linux/build-toolchains.sh /tmp/ RUN ./build-toolchains.sh USER root diff --git a/src/ci/docker/dist-armv7-linux/Dockerfile b/src/ci/docker/dist-armv7-linux/Dockerfile index 9367a5a6270cf..030fd24ebcdd0 100644 --- a/src/ci/docker/dist-armv7-linux/Dockerfile +++ b/src/ci/docker/dist-armv7-linux/Dockerfile @@ -56,7 +56,7 @@ RUN mkdir /x-tools && chown rustbuild:rustbuild /x-tools USER rustbuild WORKDIR /tmp -COPY build-toolchains.sh armv7-linux-gnueabihf.config /tmp/ +COPY dist-armv7-linux/build-toolchains.sh dist-armv7-linux/armv7-linux-gnueabihf.config /tmp/ RUN ./build-toolchains.sh USER root diff --git a/src/ci/docker/dist-fuchsia/Dockerfile b/src/ci/docker/dist-fuchsia/Dockerfile index 8699e0d87d7fa..d1d9767d35e63 100644 --- a/src/ci/docker/dist-fuchsia/Dockerfile +++ b/src/ci/docker/dist-fuchsia/Dockerfile @@ -21,7 +21,7 @@ RUN curl -L https://cmake.org/files/v3.8/cmake-3.8.0-rc1-Linux-x86_64.tar.gz | \ tar xzf - -C /usr/local --strip-components=1 WORKDIR /tmp -COPY shared.sh build-toolchain.sh compiler-rt-dso-handle.patch /tmp/ +COPY dist-fuchsia/shared.sh dist-fuchsia/build-toolchain.sh dist-fuchsia/compiler-rt-dso-handle.patch /tmp/ RUN /tmp/build-toolchain.sh RUN curl -OL https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb && \ diff --git a/src/ci/docker/dist-i586-gnu-i686-musl/Dockerfile b/src/ci/docker/dist-i586-gnu-i686-musl/Dockerfile index 3e823339eaaf9..805d238de1f9b 100644 --- a/src/ci/docker/dist-i586-gnu-i686-musl/Dockerfile +++ b/src/ci/docker/dist-i586-gnu-i686-musl/Dockerfile @@ -17,7 +17,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ pkg-config WORKDIR /build/ -COPY musl-libunwind-patch.patch build-musl.sh /build/ +COPY dist-i586-gnu-i686-musl/musl-libunwind-patch.patch dist-i586-gnu-i686-musl/build-musl.sh /build/ RUN sh /build/build-musl.sh && rm -rf /build RUN curl -OL https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb && \ diff --git a/src/ci/docker/dist-i686-freebsd/Dockerfile b/src/ci/docker/dist-i686-freebsd/Dockerfile index a1f36257f960a..9c4d43bfa92bc 100644 --- a/src/ci/docker/dist-i686-freebsd/Dockerfile +++ b/src/ci/docker/dist-i686-freebsd/Dockerfile @@ -16,7 +16,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libssl-dev \ pkg-config -COPY build-toolchain.sh /tmp/ +COPY dist-i686-freebsd/build-toolchain.sh /tmp/ RUN /tmp/build-toolchain.sh i686 RUN curl -OL https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb && \ diff --git a/src/ci/docker/dist-i686-linux/Dockerfile b/src/ci/docker/dist-i686-linux/Dockerfile index 8335147de60a0..a3c08e93ed158 100644 --- a/src/ci/docker/dist-i686-linux/Dockerfile +++ b/src/ci/docker/dist-i686-linux/Dockerfile @@ -29,13 +29,13 @@ ENV PATH=/rustroot/bin:$PATH ENV LD_LIBRARY_PATH=/rustroot/lib64:/rustroot/lib ENV PKG_CONFIG_PATH=/rustroot/lib/pkgconfig WORKDIR /tmp -COPY shared.sh build-binutils.sh /tmp/ +COPY dist-i686-linux/shared.sh dist-i686-linux/build-binutils.sh /tmp/ # We need a build of openssl which supports SNI to download artifacts from # static.rust-lang.org. This'll be used to link into libcurl below (and used # later as well), so build a copy of OpenSSL with dynamic libraries into our # generic root. -COPY build-openssl.sh /tmp/ +COPY dist-i686-linux/build-openssl.sh /tmp/ RUN ./build-openssl.sh # The `curl` binary on CentOS doesn't support SNI which is needed for fetching @@ -44,7 +44,7 @@ RUN ./build-openssl.sh # # Note that we also disable a bunch of optional features of curl that we don't # really need. -COPY build-curl.sh /tmp/ +COPY dist-i686-linux/build-curl.sh /tmp/ RUN ./build-curl.sh # binutils < 2.22 has a bug where the 32-bit executables it generates @@ -54,26 +54,26 @@ RUN ./build-curl.sh RUN ./build-binutils.sh # Need a newer version of gcc than centos has to compile LLVM nowadays -COPY build-gcc.sh /tmp/ +COPY dist-i686-linux/build-gcc.sh /tmp/ RUN ./build-gcc.sh # CentOS 5.5 has Python 2.4 by default, but LLVM needs 2.7+ -COPY build-python.sh /tmp/ +COPY dist-i686-linux/build-python.sh /tmp/ RUN ./build-python.sh # Apparently CentOS 5.5 desn't have `git` in yum, but we're gonna need it for # cloning, so download and build it here. -COPY build-git.sh /tmp/ +COPY dist-i686-linux/build-git.sh /tmp/ RUN ./build-git.sh # libssh2 (a dependency of Cargo) requires cmake 2.8.11 or higher but CentOS # only has 2.6.4, so build our own -COPY build-cmake.sh /tmp/ +COPY dist-i686-linux/build-cmake.sh /tmp/ RUN ./build-cmake.sh # for sanitizers, we need kernel headers files newer than the ones CentOS ships # with so we install newer ones here -COPY build-headers.sh /tmp/ +COPY dist-i686-linux/build-headers.sh /tmp/ RUN ./build-headers.sh RUN curl -Lo /rustroot/dumb-init \ diff --git a/src/ci/docker/dist-powerpc64-linux/Dockerfile b/src/ci/docker/dist-powerpc64-linux/Dockerfile index 58b09fd0fa731..bd38ee0c11158 100644 --- a/src/ci/docker/dist-powerpc64-linux/Dockerfile +++ b/src/ci/docker/dist-powerpc64-linux/Dockerfile @@ -56,8 +56,8 @@ RUN mkdir /x-tools && chown rustbuild:rustbuild /x-tools USER rustbuild WORKDIR /tmp -COPY patches/ /tmp/patches/ -COPY shared.sh powerpc64-linux-gnu.config build-powerpc64-toolchain.sh /tmp/ +COPY dist-powerpc64-linux/patches/ /tmp/patches/ +COPY dist-powerpc64-linux/shared.sh dist-powerpc64-linux/powerpc64-linux-gnu.config dist-powerpc64-linux/build-powerpc64-toolchain.sh /tmp/ RUN ./build-powerpc64-toolchain.sh USER root diff --git a/src/ci/docker/dist-powerpc64le-linux/Dockerfile b/src/ci/docker/dist-powerpc64le-linux/Dockerfile index 08f1d1d7ed5f7..cbded156b4cbd 100644 --- a/src/ci/docker/dist-powerpc64le-linux/Dockerfile +++ b/src/ci/docker/dist-powerpc64le-linux/Dockerfile @@ -59,7 +59,7 @@ WORKDIR /tmp USER root RUN apt-get install -y --no-install-recommends rpm2cpio cpio -COPY shared.sh build-powerpc64le-toolchain.sh /tmp/ +COPY dist-powerpc64le-linux/shared.sh dist-powerpc64le-linux/build-powerpc64le-toolchain.sh /tmp/ RUN ./build-powerpc64le-toolchain.sh RUN curl -o /usr/local/bin/sccache \ diff --git a/src/ci/docker/dist-s390x-linux/Dockerfile b/src/ci/docker/dist-s390x-linux/Dockerfile index 5eb238fa887b6..5c00287107aa3 100644 --- a/src/ci/docker/dist-s390x-linux/Dockerfile +++ b/src/ci/docker/dist-s390x-linux/Dockerfile @@ -56,8 +56,8 @@ RUN mkdir /x-tools && chown rustbuild:rustbuild /x-tools USER rustbuild WORKDIR /tmp -COPY patches/ /tmp/patches/ -COPY s390x-linux-gnu.config build-s390x-toolchain.sh /tmp/ +COPY dist-s390x-linux/patches/ /tmp/patches/ +COPY dist-s390x-linux/s390x-linux-gnu.config dist-s390x-linux/build-s390x-toolchain.sh /tmp/ RUN ./build-s390x-toolchain.sh USER root diff --git a/src/ci/docker/dist-x86_64-freebsd/Dockerfile b/src/ci/docker/dist-x86_64-freebsd/Dockerfile index 0ac58468147d2..a6c4eee5e812c 100644 --- a/src/ci/docker/dist-x86_64-freebsd/Dockerfile +++ b/src/ci/docker/dist-x86_64-freebsd/Dockerfile @@ -16,7 +16,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libssl-dev \ pkg-config -COPY build-toolchain.sh /tmp/ +COPY dist-x86_64-freebsd/build-toolchain.sh /tmp/ RUN /tmp/build-toolchain.sh x86_64 RUN curl -OL https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb && \ diff --git a/src/ci/docker/dist-x86_64-linux/Dockerfile b/src/ci/docker/dist-x86_64-linux/Dockerfile index d688bb7f8a4c4..e2e42836dcdaf 100644 --- a/src/ci/docker/dist-x86_64-linux/Dockerfile +++ b/src/ci/docker/dist-x86_64-linux/Dockerfile @@ -29,13 +29,13 @@ ENV PATH=/rustroot/bin:$PATH ENV LD_LIBRARY_PATH=/rustroot/lib64:/rustroot/lib ENV PKG_CONFIG_PATH=/rustroot/lib/pkgconfig WORKDIR /tmp -COPY shared.sh build-binutils.sh /tmp/ +COPY dist-x86_64-linux/shared.sh dist-x86_64-linux/build-binutils.sh /tmp/ # We need a build of openssl which supports SNI to download artifacts from # static.rust-lang.org. This'll be used to link into libcurl below (and used # later as well), so build a copy of OpenSSL with dynamic libraries into our # generic root. -COPY build-openssl.sh /tmp/ +COPY dist-x86_64-linux/build-openssl.sh /tmp/ RUN ./build-openssl.sh # The `curl` binary on CentOS doesn't support SNI which is needed for fetching @@ -44,7 +44,7 @@ RUN ./build-openssl.sh # # Note that we also disable a bunch of optional features of curl that we don't # really need. -COPY build-curl.sh /tmp/ +COPY dist-x86_64-linux/build-curl.sh /tmp/ RUN ./build-curl.sh # binutils < 2.22 has a bug where the 32-bit executables it generates @@ -54,26 +54,26 @@ RUN ./build-curl.sh RUN ./build-binutils.sh # Need a newer version of gcc than centos has to compile LLVM nowadays -COPY build-gcc.sh /tmp/ +COPY dist-x86_64-linux/build-gcc.sh /tmp/ RUN ./build-gcc.sh # CentOS 5.5 has Python 2.4 by default, but LLVM needs 2.7+ -COPY build-python.sh /tmp/ +COPY dist-x86_64-linux/build-python.sh /tmp/ RUN ./build-python.sh # Apparently CentOS 5.5 desn't have `git` in yum, but we're gonna need it for # cloning, so download and build it here. -COPY build-git.sh /tmp/ +COPY dist-x86_64-linux/build-git.sh /tmp/ RUN ./build-git.sh # libssh2 (a dependency of Cargo) requires cmake 2.8.11 or higher but CentOS # only has 2.6.4, so build our own -COPY build-cmake.sh /tmp/ +COPY dist-x86_64-linux/build-cmake.sh /tmp/ RUN ./build-cmake.sh # for sanitizers, we need kernel headers files newer than the ones CentOS ships # with so we install newer ones here -COPY build-headers.sh /tmp/ +COPY dist-x86_64-linux/build-headers.sh /tmp/ RUN ./build-headers.sh RUN curl -Lo /rustroot/dumb-init \ diff --git a/src/ci/docker/dist-x86_64-musl/Dockerfile b/src/ci/docker/dist-x86_64-musl/Dockerfile index 87550641bc6d5..2eea5ab146972 100644 --- a/src/ci/docker/dist-x86_64-musl/Dockerfile +++ b/src/ci/docker/dist-x86_64-musl/Dockerfile @@ -17,7 +17,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ pkg-config WORKDIR /build/ -COPY build-musl.sh /build/ +COPY dist-x86_64-musl/build-musl.sh /build/ RUN sh /build/build-musl.sh && rm -rf /build RUN curl -OL https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb && \ diff --git a/src/ci/docker/dist-x86_64-netbsd/Dockerfile b/src/ci/docker/dist-x86_64-netbsd/Dockerfile index b6d9c221c1ce8..f76e6271f4c8c 100644 --- a/src/ci/docker/dist-x86_64-netbsd/Dockerfile +++ b/src/ci/docker/dist-x86_64-netbsd/Dockerfile @@ -56,7 +56,7 @@ RUN mkdir /x-tools && chown rustbuild:rustbuild /x-tools USER rustbuild WORKDIR /tmp -COPY build-netbsd-toolchain.sh /tmp/ +COPY dist-x86_64-netbsd/build-netbsd-toolchain.sh /tmp/ RUN ./build-netbsd-toolchain.sh USER root diff --git a/src/ci/docker/dumb-init.sh b/src/ci/docker/dumb-init.sh new file mode 100644 index 0000000000000..839c390799278 --- /dev/null +++ b/src/ci/docker/dumb-init.sh @@ -0,0 +1,15 @@ +# Copyright 2017 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 or the MIT license +# , at your +# option. This file may not be copied, modified, or distributed +# except according to those terms. + +set -ex + +curl -OL https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb +dpkg -i dumb-init_*.deb +rm dumb-init_*.deb diff --git a/src/ci/docker/emscripten/Dockerfile b/src/ci/docker/emscripten/Dockerfile index 09657d2f89211..0f0e5b69c32cf 100644 --- a/src/ci/docker/emscripten/Dockerfile +++ b/src/ci/docker/emscripten/Dockerfile @@ -24,7 +24,7 @@ RUN curl -OL https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-ini ENTRYPOINT ["/usr/bin/dumb-init", "--"] WORKDIR /tmp -COPY build-emscripten.sh /tmp/ +COPY emscripten/build-emscripten.sh /tmp/ RUN ./build-emscripten.sh ENV PATH=$PATH:/tmp/emsdk_portable ENV PATH=$PATH:/tmp/emsdk_portable/clang/tag-e1.37.10/build_tag-e1.37.10_32/bin diff --git a/src/ci/docker/run.sh b/src/ci/docker/run.sh index 6abbf0530afa6..bb9a860574dd2 100755 --- a/src/ci/docker/run.sh +++ b/src/ci/docker/run.sh @@ -26,7 +26,8 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then build \ --rm \ -t rust-ci \ - "$docker_dir/$image" + -f "$docker_dir/$image/Dockerfile" \ + "$docker_dir" elif [ -f "$docker_dir/disabled/$image/Dockerfile" ]; then if [ -n "$TRAVIS_OS_NAME" ]; then echo Cannot run disabled images on travis! diff --git a/src/ci/docker/sccache.sh b/src/ci/docker/sccache.sh new file mode 100644 index 0000000000000..7a2befaf6715f --- /dev/null +++ b/src/ci/docker/sccache.sh @@ -0,0 +1,16 @@ +# Copyright 2017 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 or the MIT license +# , at your +# option. This file may not be copied, modified, or distributed +# except according to those terms. + +set -ex + +curl -o /usr/local/bin/sccache \ + https://s3.amazonaws.com/rust-lang-ci/rust-ci-mirror/2017-05-12-sccache-x86_64-unknown-linux-musl + +chmod +x /usr/local/bin/sccache From b9552963d1269ac6008dceda3c2cca65a2d746dc Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Wed, 17 May 2017 23:36:24 +0200 Subject: [PATCH 11/28] misc doc improvements for std::env --- src/libstd/env.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/libstd/env.rs b/src/libstd/env.rs index 64eb52e28bc42..96c10c5d10d1a 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -43,16 +43,19 @@ use sys::os as os_imp; /// use std::env; /// /// // We assume that we are in a valid directory. -/// let p = env::current_dir().unwrap(); -/// println!("The current directory is {}", p.display()); +/// let path = env::current_dir().unwrap(); +/// println!("The current directory is {}", path.display()); /// ``` #[stable(feature = "env", since = "1.0.0")] pub fn current_dir() -> io::Result { os_imp::getcwd() } -/// Changes the current working directory to the specified path, returning -/// whether the change was completed successfully or not. +/// Changes the current working directory to the specified path. +/// +/// Returns an [`Err`] if the operation fails. +/// +/// [`Err`]: ../../std/result/enum.Result.html#method.err /// /// # Examples /// @@ -65,8 +68,8 @@ pub fn current_dir() -> io::Result { /// println!("Successfully changed working directory to {}!", root.display()); /// ``` #[stable(feature = "env", since = "1.0.0")] -pub fn set_current_dir>(p: P) -> io::Result<()> { - os_imp::chdir(p.as_ref()) +pub fn set_current_dir>(path: P) -> io::Result<()> { + os_imp::chdir(path.as_ref()) } /// An iterator over a snapshot of the environment variables of this process. @@ -175,10 +178,10 @@ impl fmt::Debug for VarsOs { /// /// The returned result is [`Ok(s)`] if the environment variable is present and is /// valid unicode. If the environment variable is not present, or it is not -/// valid unicode, then [`Err`] will be returned. +/// valid unicode, then [`VarError`] will be returned. /// /// [`Ok(s)`]: ../result/enum.Result.html#variant.Ok -/// [`Err`]: ../result/enum.Result.html#variant.Err +/// [`VarError`]: enum.VarError.html /// /// # Examples /// @@ -199,7 +202,7 @@ pub fn var>(key: K) -> Result { fn _var(key: &OsStr) -> Result { match var_os(key) { Some(s) => s.into_string().map_err(VarError::NotUnicode), - None => Err(VarError::NotPresent) + None => Err(VarError::NotPresent), } } From f4e33a011ecbd4744c0a2c594ad69fd1a52bd9c5 Mon Sep 17 00:00:00 2001 From: Denis Andrejew Date: Thu, 18 May 2017 08:45:18 +0200 Subject: [PATCH 12/28] fix typo in libstd/sync/mpsc/mod.rs docs --- src/libstd/sync/mpsc/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 2cb649ce67b9c..284a5fbd9d506 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -1067,7 +1067,7 @@ impl Receiver { Receiver { inner: UnsafeCell::new(inner) } } - /// Attempts to return a pending value on this receiver without blocking + /// Attempts to return a pending value on this receiver without blocking. /// /// This method will never block the caller in order to wait for data to /// become available. Instead, this will always return immediately with a From 1eb6639508ce6874e4d5dbdb02dbb6111565d902 Mon Sep 17 00:00:00 2001 From: pravic Date: Thu, 18 May 2017 10:35:18 +0300 Subject: [PATCH 13/28] Make documentation works again by removing two unnecessary ES6 pieces. --- src/librustdoc/html/static/main.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index c115a6ccba609..f09ce1cc64849 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -215,14 +215,14 @@ } else if (ev.target.tagName === 'SPAN' && hasClass(ev.target.parentNode, 'line-numbers')) { var prev_id = 0; - function set_fragment(name) { + var set_fragment = function (name) { if (browserSupportsHistoryApi()) { history.replaceState(null, null, '#' + name); window.hashchange(); } else { location.replace('#' + name); } - } + }; var cur_id = parseInt(ev.target.id, 10); @@ -685,7 +685,7 @@ } function escape(content) { - let h1 = document.createElement('h1'); + var h1 = document.createElement('h1'); h1.textContent = content; return h1.innerHTML; } From 474cc91440ecb89a4d7ea81b1786fddbf2b70641 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Wed, 17 May 2017 16:41:07 +0200 Subject: [PATCH 14/28] Use in-memory representation for Fingerprint that is more amenable to hashing. --- src/librustc/ich/fingerprint.rs | 72 ++++++++++++--------------------- 1 file changed, 26 insertions(+), 46 deletions(-) diff --git a/src/librustc/ich/fingerprint.rs b/src/librustc/ich/fingerprint.rs index ccdbab88b8b9c..a947f6aeff709 100644 --- a/src/librustc/ich/fingerprint.rs +++ b/src/librustc/ich/fingerprint.rs @@ -10,95 +10,75 @@ use rustc_serialize::{Encodable, Decodable, Encoder, Decoder}; use rustc_data_structures::stable_hasher; -use rustc_data_structures::ToHex; - -const FINGERPRINT_LENGTH: usize = 16; +use std::mem; +use std::slice; #[derive(Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Clone, Copy)] -pub struct Fingerprint(pub [u8; FINGERPRINT_LENGTH]); +pub struct Fingerprint(u64, u64); impl Fingerprint { #[inline] pub fn zero() -> Fingerprint { - Fingerprint([0; FINGERPRINT_LENGTH]) + Fingerprint(0, 0) } + #[inline] pub fn from_smaller_hash(hash: u64) -> Fingerprint { - let mut result = Fingerprint::zero(); - result.0[0] = (hash >> 0) as u8; - result.0[1] = (hash >> 8) as u8; - result.0[2] = (hash >> 16) as u8; - result.0[3] = (hash >> 24) as u8; - result.0[4] = (hash >> 32) as u8; - result.0[5] = (hash >> 40) as u8; - result.0[6] = (hash >> 48) as u8; - result.0[7] = (hash >> 56) as u8; - result + Fingerprint(hash, hash) } + #[inline] pub fn to_smaller_hash(&self) -> u64 { - ((self.0[0] as u64) << 0) | - ((self.0[1] as u64) << 8) | - ((self.0[2] as u64) << 16) | - ((self.0[3] as u64) << 24) | - ((self.0[4] as u64) << 32) | - ((self.0[5] as u64) << 40) | - ((self.0[6] as u64) << 48) | - ((self.0[7] as u64) << 56) + self.0 } pub fn to_hex(&self) -> String { - self.0.to_hex() + format!("{:x}{:x}", self.0, self.1) } } impl Encodable for Fingerprint { #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { - for &byte in &self.0 { - s.emit_u8(byte)?; - } - Ok(()) + s.emit_u64(self.0.to_le())?; + s.emit_u64(self.1.to_le()) } } impl Decodable for Fingerprint { #[inline] fn decode(d: &mut D) -> Result { - let mut result = Fingerprint([0u8; FINGERPRINT_LENGTH]); - for byte in &mut result.0 { - *byte = d.read_u8()?; - } - Ok(result) + let _0 = u64::from_le(d.read_u64()?); + let _1 = u64::from_le(d.read_u64()?); + Ok(Fingerprint(_0, _1)) } } impl ::std::fmt::Display for Fingerprint { fn fmt(&self, formatter: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { - for i in 0 .. self.0.len() { - if i > 0 { - write!(formatter, "::")?; - } - - write!(formatter, "{}", self.0[i])?; - } - Ok(()) + write!(formatter, "{:x}-{:x}", self.0, self.1) } } - impl stable_hasher::StableHasherResult for Fingerprint { fn finish(mut hasher: stable_hasher::StableHasher) -> Self { - let mut fingerprint = Fingerprint::zero(); - fingerprint.0.copy_from_slice(hasher.finalize()); - fingerprint + let hash_bytes: &[u8] = hasher.finalize(); + + assert!(hash_bytes.len() >= mem::size_of::() * 2); + let hash_bytes: &[u64] = unsafe { + slice::from_raw_parts(hash_bytes.as_ptr() as *const u64, 2) + }; + + // The bytes returned bytes the Blake2B hasher are always little-endian. + Fingerprint(u64::from_le(hash_bytes[0]), u64::from_le(hash_bytes[1])) } } impl stable_hasher::HashStable for Fingerprint { + #[inline] fn hash_stable(&self, _: &mut CTX, hasher: &mut stable_hasher::StableHasher) { - ::std::hash::Hash::hash(&self.0, hasher); + ::std::hash::Hash::hash(self, hasher); } } From 4549423f28dc05ae47447a1111326b1b7055c1a9 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Thu, 18 May 2017 10:54:20 +0200 Subject: [PATCH 15/28] Use 128 instead of 64 bits for DefPath hashes --- src/librustc/hir/map/definitions.rs | 17 +++++++++-------- src/librustc/ich/hcx.rs | 2 +- src/librustc/middle/cstore.rs | 4 ++-- src/librustc/ty/mod.rs | 4 ++-- src/librustc/ty/sty.rs | 5 +++-- src/librustc/ty/trait_def.rs | 5 +++-- src/librustc_incremental/calculate_svh/mod.rs | 2 +- src/librustc_metadata/cstore_impl.rs | 3 ++- src/librustc_metadata/decoder.rs | 3 ++- 9 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs index 6118df2ddfc89..9537b40b28a0b 100644 --- a/src/librustc/hir/map/definitions.rs +++ b/src/librustc/hir/map/definitions.rs @@ -16,6 +16,7 @@ use hir; use hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE, DefIndexAddressSpace}; +use ich::Fingerprint; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::indexed_vec::IndexVec; use rustc_data_structures::stable_hasher::StableHasher; @@ -34,7 +35,7 @@ use util::nodemap::NodeMap; pub struct DefPathTable { index_to_key: [Vec; 2], key_to_index: FxHashMap, - def_path_hashes: [Vec; 2], + def_path_hashes: [Vec; 2], } // Unfortunately we have to provide a manual impl of Clone because of the @@ -55,7 +56,7 @@ impl DefPathTable { fn allocate(&mut self, key: DefKey, - def_path_hash: u64, + def_path_hash: Fingerprint, address_space: DefIndexAddressSpace) -> DefIndex { let index = { @@ -79,7 +80,7 @@ impl DefPathTable { } #[inline(always)] - pub fn def_path_hash(&self, index: DefIndex) -> u64 { + pub fn def_path_hash(&self, index: DefIndex) -> Fingerprint { self.def_path_hashes[index.address_space().index()] [index.as_array_index()] } @@ -146,8 +147,8 @@ impl Decodable for DefPathTable { let index_to_key_lo: Vec = Decodable::decode(d)?; let index_to_key_hi: Vec = Decodable::decode(d)?; - let def_path_hashes_lo: Vec = Decodable::decode(d)?; - let def_path_hashes_hi: Vec = Decodable::decode(d)?; + let def_path_hashes_lo: Vec = Decodable::decode(d)?; + let def_path_hashes_hi: Vec = Decodable::decode(d)?; let index_to_key = [index_to_key_lo, index_to_key_hi]; let def_path_hashes = [def_path_hashes_lo, def_path_hashes_hi]; @@ -210,7 +211,7 @@ pub struct DefKey { } impl DefKey { - fn compute_stable_hash(&self, parent_hash: u64) -> u64 { + fn compute_stable_hash(&self, parent_hash: Fingerprint) -> Fingerprint { let mut hasher = StableHasher::new(); // We hash a 0u8 here to disambiguate between regular DefPath hashes, @@ -221,7 +222,7 @@ impl DefKey { hasher.finish() } - fn root_parent_stable_hash(crate_name: &str, crate_disambiguator: &str) -> u64 { + fn root_parent_stable_hash(crate_name: &str, crate_disambiguator: &str) -> Fingerprint { let mut hasher = StableHasher::new(); // Disambiguate this from a regular DefPath hash, // see compute_stable_hash() above. @@ -396,7 +397,7 @@ impl Definitions { } #[inline(always)] - pub fn def_path_hash(&self, index: DefIndex) -> u64 { + pub fn def_path_hash(&self, index: DefIndex) -> Fingerprint { self.table.def_path_hash(index) } diff --git a/src/librustc/ich/hcx.rs b/src/librustc/ich/hcx.rs index 786d1c5035d96..f25ec8ecd4d71 100644 --- a/src/librustc/ich/hcx.rs +++ b/src/librustc/ich/hcx.rs @@ -110,7 +110,7 @@ impl<'a, 'tcx: 'a> StableHashingContext<'a, 'tcx> { } #[inline] - pub fn def_path_hash(&mut self, def_id: DefId) -> u64 { + pub fn def_path_hash(&mut self, def_id: DefId) -> ich::Fingerprint { self.tcx.def_path_hash(def_id) } diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index a68aca4600054..8ad1db7859566 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -282,7 +282,7 @@ pub trait CrateStore { -> Option; fn def_key(&self, def: DefId) -> DefKey; fn def_path(&self, def: DefId) -> hir_map::DefPath; - fn def_path_hash(&self, def: DefId) -> u64; + fn def_path_hash(&self, def: DefId) -> ich::Fingerprint; fn struct_field_names(&self, def: DefId) -> Vec; fn item_children(&self, did: DefId) -> Vec; fn load_macro(&self, did: DefId, sess: &Session) -> LoadedMacro; @@ -414,7 +414,7 @@ impl CrateStore for DummyCrateStore { fn def_path(&self, def: DefId) -> hir_map::DefPath { bug!("relative_def_path") } - fn def_path_hash(&self, def: DefId) -> u64 { + fn def_path_hash(&self, def: DefId) -> ich::Fingerprint { bug!("wa") } fn struct_field_names(&self, def: DefId) -> Vec { bug!("struct_field_names") } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index a86d7351ef472..359722ce96ec9 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -19,7 +19,7 @@ use dep_graph::DepNode; use hir::{map as hir_map, FreevarMap, TraitMap}; use hir::def::{Def, CtorKind, ExportMap}; use hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE}; -use ich::StableHashingContext; +use ich::{self, StableHashingContext}; use middle::const_val::ConstVal; use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem}; use middle::privacy::AccessLevels; @@ -2248,7 +2248,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } #[inline] - pub fn def_path_hash(self, def_id: DefId) -> u64 { + pub fn def_path_hash(self, def_id: DefId) -> ich::Fingerprint { if def_id.is_local() { self.hir.definitions().def_path_hash(def_id.index) } else { diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index cfbf1244db3ad..348d164af4190 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -29,6 +29,7 @@ use util::nodemap::FxHashMap; use serialize; use hir; +use ich; use self::InferTy::*; use self::TypeVariants::*; @@ -849,7 +850,7 @@ impl<'a, 'tcx, 'gcx> ExistentialProjection<'tcx> { self.item_name // safe to skip the binder to access a name } - pub fn sort_key(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> (u64, InternedString) { + pub fn sort_key(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> (ich::Fingerprint, InternedString) { // We want something here that is stable across crate boundaries. // The DefId isn't but the `deterministic_hash` of the corresponding // DefPath is. @@ -884,7 +885,7 @@ impl<'a, 'tcx, 'gcx> PolyExistentialProjection<'tcx> { self.skip_binder().item_name() } - pub fn sort_key(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> (u64, InternedString) { + pub fn sort_key(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> (ich::Fingerprint, InternedString) { self.skip_binder().sort_key(tcx) } diff --git a/src/librustc/ty/trait_def.rs b/src/librustc/ty/trait_def.rs index 865297c7ecbfd..86774136bd6cb 100644 --- a/src/librustc/ty/trait_def.rs +++ b/src/librustc/ty/trait_def.rs @@ -9,6 +9,7 @@ // except according to those terms. use hir::def_id::DefId; +use ich::Fingerprint; use traits::specialization_graph; use ty::fast_reject; use ty::fold::TypeFoldable; @@ -32,7 +33,7 @@ pub struct TraitDef { /// The ICH of this trait's DefPath, cached here so it doesn't have to be /// recomputed all the time. - pub def_path_hash: u64, + pub def_path_hash: Fingerprint, } // We don't store the list of impls in a flat list because each cached list of @@ -94,7 +95,7 @@ impl<'a, 'gcx, 'tcx> TraitDef { unsafety: hir::Unsafety, paren_sugar: bool, has_default_impl: bool, - def_path_hash: u64) + def_path_hash: Fingerprint) -> TraitDef { TraitDef { def_id, diff --git a/src/librustc_incremental/calculate_svh/mod.rs b/src/librustc_incremental/calculate_svh/mod.rs index 8cdabc1d894e2..c9ed9ad3c7d2d 100644 --- a/src/librustc_incremental/calculate_svh/mod.rs +++ b/src/librustc_incremental/calculate_svh/mod.rs @@ -224,7 +224,7 @@ impl<'a, 'tcx: 'a> ComputeItemHashesVisitor<'a, 'tcx> { { let tcx = self.hcx.tcx(); - let mut impls: Vec<(u64, Fingerprint)> = krate + let mut impls: Vec<(Fingerprint, Fingerprint)> = krate .trait_impls .iter() .map(|(&trait_id, impls)| { diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index 4b7083590d24a..7478f902e061a 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -17,6 +17,7 @@ use rustc::middle::cstore::{CrateStore, CrateSource, LibSource, DepKind, ExternCrate, NativeLibrary, MetadataLoader, LinkMeta, LinkagePreference, LoadedMacro, EncodedMetadata}; use rustc::hir::def; +use rustc::ich; use rustc::middle::lang_items; use rustc::session::Session; use rustc::ty::{self, TyCtxt}; @@ -337,7 +338,7 @@ impl CrateStore for cstore::CStore { self.get_crate_data(def.krate).def_path(def.index) } - fn def_path_hash(&self, def: DefId) -> u64 { + fn def_path_hash(&self, def: DefId) -> ich::Fingerprint { self.get_crate_data(def.krate).def_path_hash(def.index) } diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 754f27810c453..d8826d87d4d0f 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -16,6 +16,7 @@ use schema::*; use rustc::dep_graph::{DepGraph, DepNode, GlobalMetaDataKind}; use rustc::hir::map::{DefKey, DefPath, DefPathData}; use rustc::hir; +use rustc::ich; use rustc::middle::cstore::LinkagePreference; use rustc::hir::def::{self, Def, CtorKind}; @@ -1106,7 +1107,7 @@ impl<'a, 'tcx> CrateMetadata { } #[inline] - pub fn def_path_hash(&self, index: DefIndex) -> u64 { + pub fn def_path_hash(&self, index: DefIndex) -> ich::Fingerprint { self.def_path_table.def_path_hash(index) } From b2fc7b1cbeae1e6cb1a5b4797d221733592ae6a4 Mon Sep 17 00:00:00 2001 From: Michael Kohl Date: Thu, 11 May 2017 22:49:16 +0700 Subject: [PATCH 16/28] Add documentation for `ExitStatus` As requested in #29370. --- src/libstd/process.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 3896fc20a2dde..d0e7defbbbb9a 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -754,6 +754,13 @@ impl fmt::Debug for Stdio { } /// Describes the result of a process after it has terminated. +/// +/// This `struct` is used to represent the exit status of a child process. +/// Child processes are created via the [`Command`] struct and their exit +/// status is exposed through the [`status`] method. +/// +/// [`Command`]: struct.Command.html +/// [`status`]: struct.Command.html#method.status #[derive(PartialEq, Eq, Clone, Copy, Debug)] #[stable(feature = "process", since = "1.0.0")] pub struct ExitStatus(imp::ExitStatus); @@ -788,6 +795,22 @@ impl ExitStatus { /// On Unix, this will return `None` if the process was terminated /// by a signal; `std::os::unix` provides an extension trait for /// extracting the signal and other details from the `ExitStatus`. + /// + /// # Examples + /// + /// ```no_run + /// use std::process::Command; + /// + /// let status = Command::new("mkdir") + /// .arg("projects") + /// .status() + /// .expect("failed to execute mkdir"); + /// + /// match status.code() { + /// Some(code) => println!("Exited with status code: {}", code), + /// None => println!("Process terminated by signal") + /// } + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn code(&self) -> Option { self.0.code() From d15c950ac6604662b2e74420c73639f23396a93b Mon Sep 17 00:00:00 2001 From: Marco A L Barbosa Date: Thu, 18 May 2017 08:33:10 -0300 Subject: [PATCH 17/28] ci: move shared scripts to src/ci/docker/scripts/ --- src/ci/docker/arm-android/Dockerfile | 10 +++++----- src/ci/docker/disabled/dist-aarch64-android/Dockerfile | 6 +++--- src/ci/docker/disabled/dist-armv7-android/Dockerfile | 6 +++--- src/ci/docker/disabled/dist-i686-android/Dockerfile | 6 +++--- src/ci/docker/disabled/dist-x86_64-android/Dockerfile | 6 +++--- src/ci/docker/dist-android/Dockerfile | 6 +++--- src/ci/docker/{ => scripts}/android-ndk.sh | 0 src/ci/docker/{ => scripts}/android-sdk.sh | 0 src/ci/docker/{ => scripts}/android-start-emulator.sh | 0 src/ci/docker/{ => scripts}/dumb-init.sh | 0 src/ci/docker/{ => scripts}/sccache.sh | 0 11 files changed, 20 insertions(+), 20 deletions(-) rename src/ci/docker/{ => scripts}/android-ndk.sh (100%) rename src/ci/docker/{ => scripts}/android-sdk.sh (100%) rename src/ci/docker/{ => scripts}/android-start-emulator.sh (100%) rename src/ci/docker/{ => scripts}/dumb-init.sh (100%) rename src/ci/docker/{ => scripts}/sccache.sh (100%) diff --git a/src/ci/docker/arm-android/Dockerfile b/src/ci/docker/arm-android/Dockerfile index 6fd3ed7c6a9e9..2a928c5ec7e89 100644 --- a/src/ci/docker/arm-android/Dockerfile +++ b/src/ci/docker/arm-android/Dockerfile @@ -17,11 +17,11 @@ RUN apt-get update && \ xz-utils # dumb-init -COPY dumb-init.sh /scripts/ +COPY scripts/dumb-init.sh /scripts/ RUN sh /scripts/dumb-init.sh # ndk -COPY android-ndk.sh /scripts/ +COPY scripts/android-ndk.sh /scripts/ RUN . /scripts/android-ndk.sh && \ download_and_make_toolchain android-ndk-r13b-linux-x86_64.zip arm 9 @@ -35,7 +35,7 @@ RUN dpkg --add-architecture i386 && \ openjdk-9-jre-headless \ tzdata -COPY android-sdk.sh /scripts/ +COPY scripts/android-sdk.sh /scripts/ RUN . /scripts/android-sdk.sh && \ download_and_create_avd tools_r25.2.5-linux.zip armeabi-v7a 18 @@ -52,9 +52,9 @@ ENV RUST_CONFIGURE_ARGS \ ENV SCRIPT python2.7 ../x.py test --target $TARGETS # sccache -COPY sccache.sh /scripts/ +COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh # init -COPY android-start-emulator.sh /scripts/ +COPY scripts/android-start-emulator.sh /scripts/ ENTRYPOINT ["/usr/bin/dumb-init", "--", "/scripts/android-start-emulator.sh"] diff --git a/src/ci/docker/disabled/dist-aarch64-android/Dockerfile b/src/ci/docker/disabled/dist-aarch64-android/Dockerfile index 5a966518759e4..918d2911ae28f 100644 --- a/src/ci/docker/disabled/dist-aarch64-android/Dockerfile +++ b/src/ci/docker/disabled/dist-aarch64-android/Dockerfile @@ -17,11 +17,11 @@ RUN apt-get update && \ xz-utils # dumb-init -COPY dumb-init.sh /scripts/ +COPY scripts/dumb-init.sh /scripts/ RUN sh /scripts/dumb-init.sh # ndk -COPY android-ndk.sh /scripts/ +COPY scripts/android-ndk.sh /scripts/ RUN . /scripts/android-ndk.sh && \ download_and_make_toolchain android-ndk-r13b-linux-x86_64.zip arm64 21 @@ -43,7 +43,7 @@ ENV RUST_CONFIGURE_ARGS \ ENV SCRIPT python2.7 ../x.py dist --target $HOSTS --host $HOSTS # sccache -COPY sccache.sh /scripts/ +COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh # init diff --git a/src/ci/docker/disabled/dist-armv7-android/Dockerfile b/src/ci/docker/disabled/dist-armv7-android/Dockerfile index f92a28a794612..aed82e6c13872 100644 --- a/src/ci/docker/disabled/dist-armv7-android/Dockerfile +++ b/src/ci/docker/disabled/dist-armv7-android/Dockerfile @@ -17,11 +17,11 @@ RUN apt-get update && \ xz-utils # dumb-init -COPY dumb-init.sh /scripts/ +COPY scripts/dumb-init.sh /scripts/ RUN sh /scripts/dumb-init.sh # ndk -COPY android-ndk.sh /scripts/ +COPY scripts/android-ndk.sh /scripts/ RUN . /scripts/android-ndk.sh && \ download_ndk android-ndk-r13b-linux-x86_64.zip && \ make_standalone_toolchain arm 9 && \ @@ -61,7 +61,7 @@ ENV SCRIPT \ python2.7 ../x.py dist --host $HOSTS --target $HOSTS) # sccache -COPY sccache.sh /scripts/ +COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh # init diff --git a/src/ci/docker/disabled/dist-i686-android/Dockerfile b/src/ci/docker/disabled/dist-i686-android/Dockerfile index c475c19ebde76..f012e869e7885 100644 --- a/src/ci/docker/disabled/dist-i686-android/Dockerfile +++ b/src/ci/docker/disabled/dist-i686-android/Dockerfile @@ -17,11 +17,11 @@ RUN apt-get update && \ xz-utils # dumb-init -COPY dumb-init.sh /scripts/ +COPY scripts/dumb-init.sh /scripts/ RUN sh /scripts/dumb-init.sh # ndk -COPY android-ndk.sh /scripts/ +COPY scripts/android-ndk.sh /scripts/ RUN . /scripts/android-ndk.sh && \ download_ndk android-ndk-r13b-linux-x86_64.zip && \ make_standalone_toolchain x86 9 && \ @@ -61,7 +61,7 @@ ENV SCRIPT \ python2.7 ../x.py dist --host $HOSTS --target $HOSTS) # sccache -COPY sccache.sh /scripts/ +COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh # init diff --git a/src/ci/docker/disabled/dist-x86_64-android/Dockerfile b/src/ci/docker/disabled/dist-x86_64-android/Dockerfile index 4f4f5fae18d18..0c586452840f9 100644 --- a/src/ci/docker/disabled/dist-x86_64-android/Dockerfile +++ b/src/ci/docker/disabled/dist-x86_64-android/Dockerfile @@ -17,11 +17,11 @@ RUN apt-get update && \ xz-utils # dumb-init -COPY dumb-init.sh /scripts/ +COPY scripts/dumb-init.sh /scripts/ RUN sh /scripts/dumb-init.sh # ndk -COPY android-ndk.sh /scripts/ +COPY scripts/android-ndk.sh /scripts/ RUN . /scripts/android-ndk.sh && \ download_and_make_toolchain android-ndk-r13b-linux-x86_64.zip x86_64 21 @@ -43,7 +43,7 @@ ENV RUST_CONFIGURE_ARGS \ ENV SCRIPT python2.7 ../x.py dist --target $HOSTS --host $HOSTS # sccache -COPY sccache.sh /scripts/ +COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh # init diff --git a/src/ci/docker/dist-android/Dockerfile b/src/ci/docker/dist-android/Dockerfile index 13d76536113b2..31389dd148a8a 100644 --- a/src/ci/docker/dist-android/Dockerfile +++ b/src/ci/docker/dist-android/Dockerfile @@ -17,11 +17,11 @@ RUN apt-get update && \ xz-utils # dumb-init -COPY dumb-init.sh /scripts/ +COPY scripts/dumb-init.sh /scripts/ RUN sh /scripts/dumb-init.sh # ndk -COPY android-ndk.sh /scripts/ +COPY scripts/android-ndk.sh /scripts/ RUN . /scripts/android-ndk.sh && \ download_ndk android-ndk-r13b-linux-x86_64.zip && \ make_standalone_toolchain arm 9 && \ @@ -49,7 +49,7 @@ ENV RUST_CONFIGURE_ARGS \ ENV SCRIPT python2.7 ../x.py dist --target $TARGETS # cache -COPY sccache.sh /scripts/ +COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh # init diff --git a/src/ci/docker/android-ndk.sh b/src/ci/docker/scripts/android-ndk.sh similarity index 100% rename from src/ci/docker/android-ndk.sh rename to src/ci/docker/scripts/android-ndk.sh diff --git a/src/ci/docker/android-sdk.sh b/src/ci/docker/scripts/android-sdk.sh similarity index 100% rename from src/ci/docker/android-sdk.sh rename to src/ci/docker/scripts/android-sdk.sh diff --git a/src/ci/docker/android-start-emulator.sh b/src/ci/docker/scripts/android-start-emulator.sh similarity index 100% rename from src/ci/docker/android-start-emulator.sh rename to src/ci/docker/scripts/android-start-emulator.sh diff --git a/src/ci/docker/dumb-init.sh b/src/ci/docker/scripts/dumb-init.sh similarity index 100% rename from src/ci/docker/dumb-init.sh rename to src/ci/docker/scripts/dumb-init.sh diff --git a/src/ci/docker/sccache.sh b/src/ci/docker/scripts/sccache.sh similarity index 100% rename from src/ci/docker/sccache.sh rename to src/ci/docker/scripts/sccache.sh From 502eadbf8f68e647f43ca6af206977dd026184e4 Mon Sep 17 00:00:00 2001 From: Marco A L Barbosa Date: Thu, 18 May 2017 09:21:11 -0300 Subject: [PATCH 18/28] ci: add filesystem layout docs --- src/ci/docker/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ci/docker/README.md b/src/ci/docker/README.md index 6f3a7e091e1ed..627b5062df333 100644 --- a/src/ci/docker/README.md +++ b/src/ci/docker/README.md @@ -16,6 +16,12 @@ for example: Images will output artifacts in an `obj` dir at the root of a repository. +## Filesystem layout + +- Each directory, excluding `scripts` and `disabled`, corresponds to a docker image +- `scripts` contains files shared by docker images +- `disabled` contains images that are not build travis + ## Cross toolchains A number of these images take quite a long time to compile as they're building From ecfdc9ac1b5ad416661c46cea8075a8a85a09233 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Perennou Date: Wed, 17 May 2017 12:15:15 +0200 Subject: [PATCH 19/28] rustbuild: install rust-analysis and rust-src when extended build is enabled Signed-off-by: Marc-Antoine Perennou --- src/bootstrap/install.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/bootstrap/install.rs b/src/bootstrap/install.rs index 386b001971bad..5d5ee67c9569b 100644 --- a/src/bootstrap/install.rs +++ b/src/bootstrap/install.rs @@ -55,37 +55,47 @@ pub fn install(build: &Build, stage: u32, host: &str) { t!(fs::create_dir_all(&empty_dir)); if build.config.docs { install_sh(&build, "docs", "rust-docs", &build.rust_package_vers(), - stage, host, &prefix, &sysconfdir, &docdir, &bindir, &libdir, + stage, Some(host), &prefix, &sysconfdir, &docdir, &bindir, &libdir, &mandir, &empty_dir); } for target in build.config.target.iter() { install_sh(&build, "std", "rust-std", &build.rust_package_vers(), - stage, target, &prefix, &sysconfdir, &docdir, &bindir, &libdir, + stage, Some(target), &prefix, &sysconfdir, &docdir, &bindir, &libdir, &mandir, &empty_dir); } if build.config.extended { install_sh(&build, "cargo", "cargo", &build.cargo_package_vers(), - stage, host, &prefix, &sysconfdir, &docdir, &bindir, &libdir, + stage, Some(host), &prefix, &sysconfdir, &docdir, &bindir, &libdir, &mandir, &empty_dir); install_sh(&build, "rls", "rls", &build.rls_package_vers(), - stage, host, &prefix, &sysconfdir, &docdir, &bindir, &libdir, + stage, Some(host), &prefix, &sysconfdir, &docdir, &bindir, &libdir, + &mandir, &empty_dir); + install_sh(&build, "analysis", "rust-analysis", &build.rust_package_vers(), + stage, Some(host), &prefix, &sysconfdir, &docdir, &bindir, &libdir, + &mandir, &empty_dir); + install_sh(&build, "src", "rust-src", &build.rust_package_vers(), + stage, None, &prefix, &sysconfdir, &docdir, &bindir, &libdir, &mandir, &empty_dir); } install_sh(&build, "rustc", "rustc", &build.rust_package_vers(), - stage, host, &prefix, &sysconfdir, &docdir, &bindir, &libdir, + stage, Some(host), &prefix, &sysconfdir, &docdir, &bindir, &libdir, &mandir, &empty_dir); t!(fs::remove_dir_all(&empty_dir)); } -fn install_sh(build: &Build, package: &str, name: &str, version: &str, stage: u32, host: &str, +fn install_sh(build: &Build, package: &str, name: &str, version: &str, stage: u32, host: Option<&str>, prefix: &Path, sysconfdir: &Path, docdir: &Path, bindir: &Path, libdir: &Path, mandir: &Path, empty_dir: &Path) { - println!("Install {} stage{} ({})", package, stage, host); - let package_name = format!("{}-{}-{}", name, version, host); + println!("Install {} stage{} ({:?})", package, stage, host); + let package_name = if let Some(host) = host { + format!("{}-{}-{}", name, version, host) + } else { + format!("{}-{}", name, version) + }; let mut cmd = Command::new("sh"); cmd.current_dir(empty_dir) From 801e2b7bdf5a5bda966c9e5c81977da3bed1e6d0 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Perennou Date: Thu, 18 May 2017 10:56:25 +0200 Subject: [PATCH 20/28] rustbuild: refactor install Introduce a new Installer object that hold a reference to all the configured paths for installation Signed-off-by: Marc-Antoine Perennou --- src/bootstrap/install.rs | 177 +++++++++++++++++++++------------------ src/bootstrap/step.rs | 2 +- 2 files changed, 98 insertions(+), 81 deletions(-) diff --git a/src/bootstrap/install.rs b/src/bootstrap/install.rs index 5d5ee67c9569b..dce0b1670e181 100644 --- a/src/bootstrap/install.rs +++ b/src/bootstrap/install.rs @@ -21,93 +21,110 @@ use std::process::Command; use Build; use dist::{sanitize_sh, tmpdir}; -/// Installs everything. -pub fn install(build: &Build, stage: u32, host: &str) { - let prefix_default = PathBuf::from("/usr/local"); - let sysconfdir_default = PathBuf::from("/etc"); - let docdir_default = PathBuf::from("share/doc/rust"); - let bindir_default = PathBuf::from("bin"); - let libdir_default = PathBuf::from("lib"); - let mandir_default = PathBuf::from("share/man"); - let prefix = build.config.prefix.as_ref().unwrap_or(&prefix_default); - let sysconfdir = build.config.sysconfdir.as_ref().unwrap_or(&sysconfdir_default); - let docdir = build.config.docdir.as_ref().unwrap_or(&docdir_default); - let bindir = build.config.bindir.as_ref().unwrap_or(&bindir_default); - let libdir = build.config.libdir.as_ref().unwrap_or(&libdir_default); - let mandir = build.config.mandir.as_ref().unwrap_or(&mandir_default); - - let sysconfdir = prefix.join(sysconfdir); - let docdir = prefix.join(docdir); - let bindir = prefix.join(bindir); - let libdir = prefix.join(libdir); - let mandir = prefix.join(mandir); - - let destdir = env::var_os("DESTDIR").map(PathBuf::from); - - let prefix = add_destdir(&prefix, &destdir); - let sysconfdir = add_destdir(&sysconfdir, &destdir); - let docdir = add_destdir(&docdir, &destdir); - let bindir = add_destdir(&bindir, &destdir); - let libdir = add_destdir(&libdir, &destdir); - let mandir = add_destdir(&mandir, &destdir); - - let empty_dir = build.out.join("tmp/empty_dir"); - t!(fs::create_dir_all(&empty_dir)); - if build.config.docs { - install_sh(&build, "docs", "rust-docs", &build.rust_package_vers(), - stage, Some(host), &prefix, &sysconfdir, &docdir, &bindir, &libdir, - &mandir, &empty_dir); - } +pub struct Installer<'a> { + build: &'a Build, + prefix: PathBuf, + sysconfdir: PathBuf, + docdir: PathBuf, + bindir: PathBuf, + libdir: PathBuf, + mandir: PathBuf, +} - for target in build.config.target.iter() { - install_sh(&build, "std", "rust-std", &build.rust_package_vers(), - stage, Some(target), &prefix, &sysconfdir, &docdir, &bindir, &libdir, - &mandir, &empty_dir); - } +impl<'a> Installer<'a> { + pub fn new(build: &'a Build) -> Installer<'a> { + let prefix_default = PathBuf::from("/usr/local"); + let sysconfdir_default = PathBuf::from("/etc"); + let docdir_default = PathBuf::from("share/doc/rust"); + let bindir_default = PathBuf::from("bin"); + let libdir_default = PathBuf::from("lib"); + let mandir_default = PathBuf::from("share/man"); + let prefix = build.config.prefix.as_ref().unwrap_or(&prefix_default); + let sysconfdir = build.config.sysconfdir.as_ref().unwrap_or(&sysconfdir_default); + let docdir = build.config.docdir.as_ref().unwrap_or(&docdir_default); + let bindir = build.config.bindir.as_ref().unwrap_or(&bindir_default); + let libdir = build.config.libdir.as_ref().unwrap_or(&libdir_default); + let mandir = build.config.mandir.as_ref().unwrap_or(&mandir_default); + + let sysconfdir = prefix.join(sysconfdir); + let docdir = prefix.join(docdir); + let bindir = prefix.join(bindir); + let libdir = prefix.join(libdir); + let mandir = prefix.join(mandir); + + let destdir = env::var_os("DESTDIR").map(PathBuf::from); - if build.config.extended { - install_sh(&build, "cargo", "cargo", &build.cargo_package_vers(), - stage, Some(host), &prefix, &sysconfdir, &docdir, &bindir, &libdir, - &mandir, &empty_dir); - install_sh(&build, "rls", "rls", &build.rls_package_vers(), - stage, Some(host), &prefix, &sysconfdir, &docdir, &bindir, &libdir, - &mandir, &empty_dir); - install_sh(&build, "analysis", "rust-analysis", &build.rust_package_vers(), - stage, Some(host), &prefix, &sysconfdir, &docdir, &bindir, &libdir, - &mandir, &empty_dir); - install_sh(&build, "src", "rust-src", &build.rust_package_vers(), - stage, None, &prefix, &sysconfdir, &docdir, &bindir, &libdir, - &mandir, &empty_dir); + let prefix = add_destdir(&prefix, &destdir); + let sysconfdir = add_destdir(&sysconfdir, &destdir); + let docdir = add_destdir(&docdir, &destdir); + let bindir = add_destdir(&bindir, &destdir); + let libdir = add_destdir(&libdir, &destdir); + let mandir = add_destdir(&mandir, &destdir); + + Installer { + build, + prefix, + sysconfdir, + docdir, + bindir, + libdir, + mandir, + } } - install_sh(&build, "rustc", "rustc", &build.rust_package_vers(), - stage, Some(host), &prefix, &sysconfdir, &docdir, &bindir, &libdir, - &mandir, &empty_dir); + /// Installs everything. + pub fn install(&self, stage: u32, host: &str) { + let empty_dir = self.build.out.join("tmp/empty_dir"); + t!(fs::create_dir_all(&empty_dir)); - t!(fs::remove_dir_all(&empty_dir)); -} + if self.build.config.docs { + self.install_sh("docs", "rust-docs", &self.build.rust_package_vers(), + stage, Some(host), &empty_dir); + } -fn install_sh(build: &Build, package: &str, name: &str, version: &str, stage: u32, host: Option<&str>, - prefix: &Path, sysconfdir: &Path, docdir: &Path, bindir: &Path, libdir: &Path, - mandir: &Path, empty_dir: &Path) { - println!("Install {} stage{} ({:?})", package, stage, host); - let package_name = if let Some(host) = host { - format!("{}-{}-{}", name, version, host) - } else { - format!("{}-{}", name, version) - }; + for target in self.build.config.target.iter() { + self.install_sh("std", "rust-std", &self.build.rust_package_vers(), + stage, Some(target), &empty_dir); + } + + if self.build.config.extended { + self.install_sh("cargo", "cargo", &self.build.cargo_package_vers(), + stage, Some(host), &empty_dir); + self.install_sh("rls", "rls", &self.build.rls_package_vers(), + stage, Some(host), &empty_dir); + self.install_sh("analysis", "rust-analysis", &self.build.rust_package_vers(), + stage, Some(host), &empty_dir); + self.install_sh("src", "rust-src", &self.build.rust_package_vers(), + stage, None, &empty_dir); + } + + self.install_sh("rustc", "rustc", &self.build.rust_package_vers(), + stage, Some(host), &empty_dir); - let mut cmd = Command::new("sh"); - cmd.current_dir(empty_dir) - .arg(sanitize_sh(&tmpdir(build).join(&package_name).join("install.sh"))) - .arg(format!("--prefix={}", sanitize_sh(prefix))) - .arg(format!("--sysconfdir={}", sanitize_sh(sysconfdir))) - .arg(format!("--docdir={}", sanitize_sh(docdir))) - .arg(format!("--bindir={}", sanitize_sh(bindir))) - .arg(format!("--libdir={}", sanitize_sh(libdir))) - .arg(format!("--mandir={}", sanitize_sh(mandir))) - .arg("--disable-ldconfig"); - build.run(&mut cmd); + t!(fs::remove_dir_all(&empty_dir)); + } + + fn install_sh(&self, package: &str, name: &str, version: &str, + stage: u32, host: Option<&str>, empty_dir: &Path) { + println!("Install {} stage{} ({:?})", package, stage, host); + let package_name = if let Some(host) = host { + format!("{}-{}-{}", name, version, host) + } else { + format!("{}-{}", name, version) + }; + + let mut cmd = Command::new("sh"); + cmd.current_dir(empty_dir) + .arg(sanitize_sh(&tmpdir(self.build).join(&package_name).join("install.sh"))) + .arg(format!("--prefix={}", sanitize_sh(&self.prefix))) + .arg(format!("--sysconfdir={}", sanitize_sh(&self.sysconfdir))) + .arg(format!("--docdir={}", sanitize_sh(&self.docdir))) + .arg(format!("--bindir={}", sanitize_sh(&self.bindir))) + .arg(format!("--libdir={}", sanitize_sh(&self.libdir))) + .arg(format!("--mandir={}", sanitize_sh(&self.mandir))) + .arg("--disable-ldconfig"); + self.build.run(&mut cmd); + } } fn add_destdir(path: &Path, destdir: &Option) -> PathBuf { diff --git a/src/bootstrap/step.rs b/src/bootstrap/step.rs index 92666e8e63907..57915446e1d1a 100644 --- a/src/bootstrap/step.rs +++ b/src/bootstrap/step.rs @@ -761,7 +761,7 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules { .run(move |s| dist::rls(build, s.stage, s.target)); rules.dist("install", "path/to/nowhere") .dep(|s| s.name("default:dist")) - .run(move |s| install::install(build, s.stage, s.target)); + .run(move |s| install::Installer::new(build).install(s.stage, s.target)); rules.dist("dist-cargo", "cargo") .host(true) .only_host_build(true) From c5163aadc5e599d45e9022a3d8df4815b6066bdc Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Thu, 18 May 2017 21:22:15 +0300 Subject: [PATCH 21/28] Fix x.py --- src/bootstrap/bootstrap.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index e15304a7e6e67..bfba1a0dede24 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -398,13 +398,14 @@ def run(self, args, env=None, cwd=None): sys.exit(ret) def output(self, args, env=None, cwd=None): + default_encoding = sys.getdefaultencoding() proc = subprocess.Popen(args, stdout=subprocess.PIPE, env=env, cwd=cwd) (out, err) = proc.communicate() ret = proc.wait() if ret != 0: print(out) sys.exit(ret) - return out + return out.decode(default_encoding) def build_triple(self): default_encoding = sys.getdefaultencoding() @@ -570,10 +571,10 @@ def update_submodules(self): for submod in submodules: path, status = submod - if path.endswith(b"llvm") and \ + if path.endswith('llvm') and \ (self.get_toml('llvm-config') or self.get_mk('CFG_LLVM_ROOT')): continue - if path.endswith(b"jemalloc") and \ + if path.endswith('jemalloc') and \ (self.get_toml('jemalloc') or self.get_mk('CFG_JEMALLOC_ROOT')): continue submod_path = os.path.join(self.rust_root, path) From 9b184c0c17701d70f30f1f3c89b2c6c55c68b169 Mon Sep 17 00:00:00 2001 From: Marco A L Barbosa Date: Thu, 18 May 2017 17:11:46 -0300 Subject: [PATCH 22/28] ci: fix dist-powerpc-linux image --- src/ci/docker/dist-powerpc-linux/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ci/docker/dist-powerpc-linux/Dockerfile b/src/ci/docker/dist-powerpc-linux/Dockerfile index bff6504749e1a..0074665f34f7e 100644 --- a/src/ci/docker/dist-powerpc-linux/Dockerfile +++ b/src/ci/docker/dist-powerpc-linux/Dockerfile @@ -56,8 +56,8 @@ RUN mkdir /x-tools && chown rustbuild:rustbuild /x-tools USER rustbuild WORKDIR /tmp -COPY patches/ /tmp/patches/ -COPY powerpc-linux-gnu.config build-powerpc-toolchain.sh /tmp/ +COPY dist-powerpc-linux/patches/ /tmp/patches/ +COPY dist-powerpc-linux/powerpc-linux-gnu.config dist-powerpc-linux/build-powerpc-toolchain.sh /tmp/ RUN ./build-powerpc-toolchain.sh USER root From e86588e2286ac2c0fb4763bf2d8c3046d0abcc22 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 18 May 2017 16:11:22 -0700 Subject: [PATCH 23/28] Give a nicer error for non-Unicode arguments to rustc and rustdoc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, any non-Unicode argument would panic rustc: ``` $ rustc $'foo\x80bar' error: internal compiler error: unexpected panic note: the compiler unexpectedly panicked. this is a bug. note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: "foo�bar"', /checkout/src/libcore/result.rs:859 note: Run with `RUST_BACKTRACE=1` for a backtrace. ``` Now it gives a clean error: ``` $ rustc $'foo\x80bar' error: Argument 1 is not valid Unicode: "foo�bar" ``` Maybe fixes #15890, although we still can't *compile* arbitrary file names. --- src/librustc_driver/lib.rs | 11 ++++++++++- src/librustdoc/lib.rs | 11 +++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 34f636d0b9a12..18a57f78a5037 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -1148,9 +1148,18 @@ pub fn diagnostics_registry() -> errors::registry::Registry { Registry::new(&all_errors) } +fn get_args() -> Vec { + env::args_os().enumerate() + .map(|(i, arg)| arg.into_string().unwrap_or_else(|arg| { + early_error(ErrorOutputType::default(), + &format!("Argument {} is not valid Unicode: {:?}", i, arg)) + })) + .collect() +} + pub fn main() { env_logger::init().unwrap(); - let result = run(|| run_compiler(&env::args().collect::>(), + let result = run(|| run_compiler(&get_args(), &mut RustcDefaultCalls, None, None)); diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index bbaa7bc2fb65e..f682f6aa763c5 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -107,12 +107,19 @@ pub fn main() { const STACK_SIZE: usize = 32_000_000; // 32MB env_logger::init().unwrap(); let res = std::thread::Builder::new().stack_size(STACK_SIZE).spawn(move || { - let s = env::args().collect::>(); - main_args(&s) + get_args().map(|args| main_args(&args)).unwrap_or(1) }).unwrap().join().unwrap_or(101); process::exit(res as i32); } +fn get_args() -> Option> { + env::args_os().enumerate() + .map(|(i, arg)| arg.into_string().map_err(|arg| { + print_error(format!("Argument {} is not valid Unicode: {:?}", i, arg)); + }).ok()) + .collect() +} + fn stable(g: getopts::OptGroup) -> RustcOptGroup { RustcOptGroup::stable(g) } fn unstable(g: getopts::OptGroup) -> RustcOptGroup { RustcOptGroup::unstable(g) } From e48086c04fb8092253ab638c6b0aa82b09edc8d0 Mon Sep 17 00:00:00 2001 From: Oliver Middleton Date: Fri, 19 May 2017 02:59:04 +0100 Subject: [PATCH 24/28] rustdoc: Fix implementors list javascript * Use a different loop variable, `i` was already taken. This caused missing items in the implementors list. * Use `.getAttribute('href')` rather than `.href` to get the relative URL which is what it needs to actually fix the links. --- src/librustdoc/html/static/main.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index c115a6ccba609..e85f70ffedcc8 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1083,10 +1083,10 @@ code.innerHTML = structs[j]; var x = code.getElementsByTagName('a'); - for (var i = 0; i < x.length; i++) { - var href = x[i].href; + for (var k = 0; k < x.length; k++) { + var href = x[k].getAttribute('href'); if (href && href.indexOf('http') !== 0) { - x[i].href = rootPath + href; + x[k].setAttribute('href', rootPath + href); } } var li = document.createElement('li'); From 4cd838b274db73be8c974e5335b28f1b6f6b75a0 Mon Sep 17 00:00:00 2001 From: David LeGare Date: Thu, 18 May 2017 21:10:15 -0500 Subject: [PATCH 25/28] Normalize docs in windows::ffi and windows::fs - Remove `()` parens when referencing functions in docs. - Change some examples to be no_run instead of ignore. - Normalize style in examples for `OpenOptionsExt`. - Fix typo in windows mod docs. --- src/libstd/sys/windows/ext/ffi.rs | 10 +-- src/libstd/sys/windows/ext/fs.rs | 109 ++++++++++++++++-------------- src/libstd/sys/windows/ext/mod.rs | 2 +- 3 files changed, 64 insertions(+), 57 deletions(-) diff --git a/src/libstd/sys/windows/ext/ffi.rs b/src/libstd/sys/windows/ext/ffi.rs index cb13595fcd6d8..3f6c2827a3f93 100644 --- a/src/libstd/sys/windows/ext/ffi.rs +++ b/src/libstd/sys/windows/ext/ffi.rs @@ -26,7 +26,7 @@ pub trait OsStringExt { /// Creates an `OsString` from a potentially ill-formed UTF-16 slice of /// 16-bit code units. /// - /// This is lossless: calling [`encode_wide()`] on the resulting string + /// This is lossless: calling [`encode_wide`] on the resulting string /// will always return the original code units. /// /// # Examples @@ -41,7 +41,7 @@ pub trait OsStringExt { /// let string = OsString::from_wide(&source[..]); /// ``` /// - /// [`encode_wide()`]: ./trait.OsStrExt.html#tymethod.encode_wide + /// [`encode_wide`]: ./trait.OsStrExt.html#tymethod.encode_wide #[stable(feature = "rust1", since = "1.0.0")] fn from_wide(wide: &[u16]) -> Self; } @@ -59,8 +59,8 @@ pub trait OsStrExt { /// Re-encodes an `OsStr` as a wide character sequence, i.e. potentially /// ill-formed UTF-16. /// - /// This is lossless: calling [`OsString::from_wide()`] and then - /// `encode_wide()` on the result will yield the original code units. + /// This is lossless: calling [`OsString::from_wide`] and then + /// `encode_wide` on the result will yield the original code units. /// Note that the encoding does not add a final null terminator. /// /// # Examples @@ -78,7 +78,7 @@ pub trait OsStrExt { /// assert_eq!(&source[..], &result[..]); /// ``` /// - /// [`OsString::from_wide()`]: ./trait.OsStringExt.html#tymethod.from_wide + /// [`OsString::from_wide`]: ./trait.OsStringExt.html#tymethod.from_wide #[stable(feature = "rust1", since = "1.0.0")] fn encode_wide(&self) -> EncodeWide; } diff --git a/src/libstd/sys/windows/ext/fs.rs b/src/libstd/sys/windows/ext/fs.rs index 8b227573f9827..34f3a0196cedf 100644 --- a/src/libstd/sys/windows/ext/fs.rs +++ b/src/libstd/sys/windows/ext/fs.rs @@ -40,7 +40,7 @@ pub trait FileExt { /// /// # Examples /// - /// ``` + /// ```no_run /// use std::io; /// use std::fs::File; /// use std::os::windows::prelude::*; @@ -75,7 +75,7 @@ pub trait FileExt { /// /// # Examples /// - /// ``` + /// ```no_run /// use std::fs::File; /// use std::os::windows::prelude::*; /// @@ -120,10 +120,10 @@ pub trait OpenOptionsExt { /// /// ```no_run /// use std::fs::OpenOptions; - /// use std::os::windows::fs::OpenOptionsExt; + /// use std::os::windows::prelude::*; /// /// // Open without read and write permission, for example if you only need - /// // to call `stat()` on the file + /// // to call `stat` on the file /// let file = OpenOptions::new().access_mode(0).open("foo.txt"); /// ``` /// @@ -145,13 +145,14 @@ pub trait OpenOptionsExt { /// /// ```no_run /// use std::fs::OpenOptions; - /// use std::os::windows::fs::OpenOptionsExt; + /// use std::os::windows::prelude::*; /// /// // Do not allow others to read or modify this file while we have it open /// // for writing. - /// let file = OpenOptions::new().write(true) - /// .share_mode(0) - /// .open("foo.txt"); + /// let file = OpenOptions::new() + /// .write(true) + /// .share_mode(0) + /// .open("foo.txt"); /// ``` /// /// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx @@ -170,13 +171,15 @@ pub trait OpenOptionsExt { /// /// ```ignore /// extern crate winapi; + /// /// use std::fs::OpenOptions; - /// use std::os::windows::fs::OpenOptionsExt; + /// use std::os::windows::prelude::*; /// - /// let mut options = OpenOptions::new(); - /// options.create(true).write(true); - /// options.custom_flags(winapi::FILE_FLAG_DELETE_ON_CLOSE); - /// let file = options.open("foo.txt"); + /// let file = OpenOptions::new() + /// .create(true) + /// .write(true) + /// .custom_flags(winapi::FILE_FLAG_DELETE_ON_CLOSE) + /// .open("foo.txt"); /// ``` /// /// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx @@ -203,12 +206,15 @@ pub trait OpenOptionsExt { /// /// ```ignore /// extern crate winapi; + /// /// use std::fs::OpenOptions; - /// use std::os::windows::fs::OpenOptionsExt; + /// use std::os::windows::prelude::*; /// - /// let file = OpenOptions::new().write(true).create(true) - /// .attributes(winapi::FILE_ATTRIBUTE_HIDDEN) - /// .open("foo.txt"); + /// let file = OpenOptions::new() + /// .write(true) + /// .create(true) + /// .attributes(winapi::FILE_ATTRIBUTE_HIDDEN) + /// .open("foo.txt"); /// ``` /// /// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx @@ -226,17 +232,18 @@ pub trait OpenOptionsExt { /// /// # Examples /// - /// ```ignore + /// ```no_run /// use std::fs::OpenOptions; - /// use std::os::windows::fs::OpenOptionsExt; + /// use std::os::windows::prelude::*; /// - /// let options = OpenOptions::new(); - /// options.write(true).create(true); + /// let file = OpenOptions::new() + /// .write(true) + /// .create(true) /// - /// // Sets the flag value to `SecurityIdentification`. - /// options.security_qos_flags(1); + /// // Sets the flag value to `SecurityIdentification`. + /// options.security_qos_flags(1) /// - /// let file = options.open("foo.txt"); + /// .open("foo.txt"); /// ``` /// /// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx @@ -289,15 +296,15 @@ pub trait MetadataExt { /// /// # Examples /// - /// ```ignore + /// ```no_run /// use std::io; - /// use std::io::prelude::*; - /// use std::fs::File; + /// use std::fs; /// use std::os::windows::prelude::*; /// /// # fn foo() -> io::Result<()> { - /// let mut file = File::open("foo.txt")?; - /// let attributes = file.file_attributes(); + /// let metadata = fs::metadata("foo.txt")?; + /// let attributes = metadata.file_attributes(); + /// # Ok(()) /// # } /// ``` /// @@ -319,15 +326,15 @@ pub trait MetadataExt { /// /// # Examples /// - /// ```ignore + /// ```no_run /// use std::io; - /// use std::io::prelude::*; - /// use std::fs::File; + /// use std::fs; /// use std::os::windows::prelude::*; /// /// # fn foo() -> io::Result<()> { - /// let mut file = File::open("foo.txt")?; - /// let creation_time = file.creation_time(); + /// let metadata = fs::metadata("foo.txt")?; + /// let creation_time = metadata.creation_time(); + /// # Ok(()) /// # } /// ``` /// @@ -354,15 +361,15 @@ pub trait MetadataExt { /// /// # Examples /// - /// ```ignore + /// ```no_run /// use std::io; - /// use std::io::prelude::*; - /// use std::fs::File; + /// use std::fs; /// use std::os::windows::prelude::*; /// /// # fn foo() -> io::Result<()> { - /// let mut file = File::open("foo.txt")?; - /// let last_access_time = file.last_access_time(); + /// let metadata = fs::metadata("foo.txt")?; + /// let last_access_time = metadata.last_access_time(); + /// # Ok(()) /// # } /// ``` /// @@ -387,15 +394,15 @@ pub trait MetadataExt { /// /// # Examples /// - /// ```ignore + /// ```no_run /// use std::io; - /// use std::io::prelude::*; - /// use std::fs::File; + /// use std::fs; /// use std::os::windows::prelude::*; /// /// # fn foo() -> io::Result<()> { - /// let mut file = File::open("foo.txt")?; - /// let last_write_time = file.last_write_time(); + /// let metadata = fs::metadata("foo.txt")?; + /// let last_write_time = metadata.last_write_time(); + /// # Ok(()) /// # } /// ``` /// @@ -410,15 +417,15 @@ pub trait MetadataExt { /// /// # Examples /// - /// ```ignore + /// ```no_run /// use std::io; - /// use std::io::prelude::*; - /// use std::fs::File; + /// use std::fs; /// use std::os::windows::prelude::*; /// /// # fn foo() -> io::Result<()> { - /// let mut file = File::open("foo.txt")?; - /// let file_size = file.file_size(); + /// let metadata = fs::metadata("foo.txt")?; + /// let file_size = metadata.file_size(); + /// # Ok(()) /// # } /// ``` #[stable(feature = "metadata_ext", since = "1.1.0")] @@ -441,7 +448,7 @@ impl MetadataExt for Metadata { /// /// # Examples /// -/// ```ignore +/// ```no_run /// use std::os::windows::fs; /// /// # fn foo() -> std::io::Result<()> { @@ -462,7 +469,7 @@ pub fn symlink_file, Q: AsRef>(src: P, dst: Q) /// /// # Examples /// -/// ```ignore +/// ```no_run /// use std::os::windows::fs; /// /// # fn foo() -> std::io::Result<()> { diff --git a/src/libstd/sys/windows/ext/mod.rs b/src/libstd/sys/windows/ext/mod.rs index e07acad5e46c4..11b1337a8aec0 100644 --- a/src/libstd/sys/windows/ext/mod.rs +++ b/src/libstd/sys/windows/ext/mod.rs @@ -13,7 +13,7 @@ //! Provides access to platform-level information for Windows, and exposes //! Windows-specific idioms that would otherwise be inappropriate as part //! the core `std` library. These extensions allow developers to use -//! `std` types and idioms with Windows in a way that the noraml +//! `std` types and idioms with Windows in a way that the normal //! platform-agnostic idioms would not normally support. #![stable(feature = "rust1", since = "1.0.0")] From 41debc365e398b95742d9e6910705495e93c0ec6 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Mon, 15 May 2017 12:17:17 +0300 Subject: [PATCH 26/28] Try to optimise char patterns --- src/libcollections/benches/str.rs | 23 +++++++++++++++++------ src/libcollections/str.rs | 14 ++++++++++++++ src/libcore/str/pattern.rs | 28 +++++++++++++++++++++++++++- 3 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/libcollections/benches/str.rs b/src/libcollections/benches/str.rs index 7f727078101c4..fc4063fae9277 100644 --- a/src/libcollections/benches/str.rs +++ b/src/libcollections/benches/str.rs @@ -195,30 +195,34 @@ fn bench_contains_equal(b: &mut Bencher) { }) } + macro_rules! make_test_inner { - ($s:ident, $code:expr, $name:ident, $str:expr) => { + ($s:ident, $code:expr, $name:ident, $str:expr, $iters:expr) => { #[bench] fn $name(bencher: &mut Bencher) { let mut $s = $str; black_box(&mut $s); - bencher.iter(|| $code); + bencher.iter(|| for _ in 0..$iters { black_box($code); }); } } } macro_rules! make_test { ($name:ident, $s:ident, $code:expr) => { + make_test!($name, $s, $code, 1); + }; + ($name:ident, $s:ident, $code:expr, $iters:expr) => { mod $name { use test::Bencher; use test::black_box; // Short strings: 65 bytes each make_test_inner!($s, $code, short_ascii, - "Mary had a little lamb, Little lamb Mary had a littl lamb, lamb!"); + "Mary had a little lamb, Little lamb Mary had a littl lamb, lamb!", $iters); make_test_inner!($s, $code, short_mixed, - "ศไทย中华Việt Nam; Mary had a little lamb, Little lam!"); + "ศไทย中华Việt Nam; Mary had a little lamb, Little lam!", $iters); make_test_inner!($s, $code, short_pile_of_poo, - "💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩!"); + "💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩!", $iters); make_test_inner!($s, $code, long_lorem_ipsum,"\ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse quis lorem sit amet dolor \ ultricies condimentum. Praesent iaculis purus elit, ac malesuada quam malesuada in. Duis sed orci \ @@ -253,7 +257,7 @@ Nam lectus enim, dapibus non nisi tempor, consectetur convallis massa. Maecenas feugiat. Etiam quis mauris vel risus luctus mattis a a nunc. Nullam orci quam, imperdiet id \ vehicula in, porttitor ut nibh. Duis sagittis adipiscing nisl vitae congue. Donec mollis risus eu \ leo suscipit, varius porttitor nulla porta. Pellentesque ut sem nec nisi euismod vehicula. Nulla \ -malesuada sollicitudin quam eu fermentum!"); +malesuada sollicitudin quam eu fermentum!", $iters); } } } @@ -288,6 +292,13 @@ make_test!(find_zzz_char, s, s.find('\u{1F4A4}')); make_test!(rfind_zzz_char, s, s.rfind('\u{1F4A4}')); make_test!(find_zzz_str, s, s.find("\u{1F4A4}")); +make_test!(starts_with_ascii_char, s, s.starts_with('/'), 1024); +make_test!(ends_with_ascii_char, s, s.ends_with('/'), 1024); +make_test!(starts_with_unichar, s, s.starts_with('\u{1F4A4}'), 1024); +make_test!(ends_with_unichar, s, s.ends_with('\u{1F4A4}'), 1024); +make_test!(starts_with_str, s, s.starts_with("💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩"), 1024); +make_test!(ends_with_str, s, s.ends_with("💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩"), 1024); + make_test!(split_space_char, s, s.split(' ').count()); make_test!(split_terminator_space_char, s, s.split_terminator(' ').count()); diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 5f4578bbeb368..7e67befb700db 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -813,6 +813,7 @@ impl str { /// assert!(!bananas.contains("apples")); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[inline] pub fn contains<'a, P: Pattern<'a>>(&'a self, pat: P) -> bool { core_str::StrExt::contains(self, pat) } @@ -900,6 +901,7 @@ impl str { /// assert_eq!(s.find(x), None); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[inline] pub fn find<'a, P: Pattern<'a>>(&'a self, pat: P) -> Option { core_str::StrExt::find(self, pat) } @@ -944,6 +946,7 @@ impl str { /// assert_eq!(s.rfind(x), None); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[inline] pub fn rfind<'a, P: Pattern<'a>>(&'a self, pat: P) -> Option where P::Searcher: ReverseSearcher<'a> { @@ -1057,6 +1060,7 @@ impl str { /// /// [`split_whitespace`]: #method.split_whitespace #[stable(feature = "rust1", since = "1.0.0")] + #[inline] pub fn split<'a, P: Pattern<'a>>(&'a self, pat: P) -> Split<'a, P> { core_str::StrExt::split(self, pat) } @@ -1106,6 +1110,7 @@ impl str { /// assert_eq!(v, ["ghi", "def", "abc"]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[inline] pub fn rsplit<'a, P: Pattern<'a>>(&'a self, pat: P) -> RSplit<'a, P> where P::Searcher: ReverseSearcher<'a> { @@ -1152,6 +1157,7 @@ impl str { /// assert_eq!(v, ["A", "", "B", ""]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[inline] pub fn split_terminator<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitTerminator<'a, P> { core_str::StrExt::split_terminator(self, pat) } @@ -1195,6 +1201,7 @@ impl str { /// assert_eq!(v, ["", "B", "", "A"]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[inline] pub fn rsplit_terminator<'a, P: Pattern<'a>>(&'a self, pat: P) -> RSplitTerminator<'a, P> where P::Searcher: ReverseSearcher<'a> { @@ -1247,6 +1254,7 @@ impl str { /// assert_eq!(v, ["abc", "defXghi"]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[inline] pub fn splitn<'a, P: Pattern<'a>>(&'a self, n: usize, pat: P) -> SplitN<'a, P> { core_str::StrExt::splitn(self, n, pat) } @@ -1294,6 +1302,7 @@ impl str { /// assert_eq!(v, ["ghi", "abc1def"]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[inline] pub fn rsplitn<'a, P: Pattern<'a>>(&'a self, n: usize, pat: P) -> RSplitN<'a, P> where P::Searcher: ReverseSearcher<'a> { @@ -1334,6 +1343,7 @@ impl str { /// assert_eq!(v, ["1", "2", "3"]); /// ``` #[stable(feature = "str_matches", since = "1.2.0")] + #[inline] pub fn matches<'a, P: Pattern<'a>>(&'a self, pat: P) -> Matches<'a, P> { core_str::StrExt::matches(self, pat) } @@ -1370,6 +1380,7 @@ impl str { /// assert_eq!(v, ["3", "2", "1"]); /// ``` #[stable(feature = "str_matches", since = "1.2.0")] + #[inline] pub fn rmatches<'a, P: Pattern<'a>>(&'a self, pat: P) -> RMatches<'a, P> where P::Searcher: ReverseSearcher<'a> { @@ -1415,6 +1426,7 @@ impl str { /// assert_eq!(v, [(0, "aba")]); // only the first `aba` /// ``` #[stable(feature = "str_match_indices", since = "1.5.0")] + #[inline] pub fn match_indices<'a, P: Pattern<'a>>(&'a self, pat: P) -> MatchIndices<'a, P> { core_str::StrExt::match_indices(self, pat) } @@ -1457,6 +1469,7 @@ impl str { /// assert_eq!(v, [(2, "aba")]); // only the last `aba` /// ``` #[stable(feature = "str_match_indices", since = "1.5.0")] + #[inline] pub fn rmatch_indices<'a, P: Pattern<'a>>(&'a self, pat: P) -> RMatchIndices<'a, P> where P::Searcher: ReverseSearcher<'a> { @@ -1737,6 +1750,7 @@ impl str { /// assert_eq!(s, s.replace("cookie monster", "little lamb")); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[inline] pub fn replace<'a, P: Pattern<'a>>(&'a self, from: P, to: &str) -> String { let mut result = String::new(); let mut last_end = 0; diff --git a/src/libcore/str/pattern.rs b/src/libcore/str/pattern.rs index 8493afe98bc57..4918e37eb35f0 100644 --- a/src/libcore/str/pattern.rs +++ b/src/libcore/str/pattern.rs @@ -429,7 +429,33 @@ impl<'a> DoubleEndedSearcher<'a> for CharSearcher<'a> {} /// Searches for chars that are equal to a given char impl<'a> Pattern<'a> for char { - pattern_methods!(CharSearcher<'a>, CharEqPattern, CharSearcher); + type Searcher = CharSearcher<'a>; + + #[inline] + fn into_searcher(self, haystack: &'a str) -> Self::Searcher { + CharSearcher(CharEqPattern(self).into_searcher(haystack)) + } + + #[inline] + fn is_contained_in(self, haystack: &'a str) -> bool { + if (self as u32) < 128 { + haystack.as_bytes().contains(&(self as u8)) + } else { + let mut buffer = [0u8; 4]; + self.encode_utf8(&mut buffer).is_contained_in(haystack) + } + } + + #[inline] + fn is_prefix_of(self, haystack: &'a str) -> bool { + CharEqPattern(self).is_prefix_of(haystack) + } + + #[inline] + fn is_suffix_of(self, haystack: &'a str) -> bool where Self::Searcher: ReverseSearcher<'a> + { + CharEqPattern(self).is_suffix_of(haystack) + } } ///////////////////////////////////////////////////////////////////////////// From b5acbd3f0360b221e9885be4c99957272b0ede82 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Fri, 19 May 2017 10:55:25 +0200 Subject: [PATCH 27/28] debuginfo: Generate unique DW_AT_names for compilation units to work around OSX linker bug. --- src/librustc_trans/context.rs | 5 +- src/librustc_trans/debuginfo/metadata.rs | 29 +++++----- src/test/debuginfo/multi-cgu.rs | 67 ++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 14 deletions(-) create mode 100644 src/test/debuginfo/multi-cgu.rs diff --git a/src/librustc_trans/context.rs b/src/librustc_trans/context.rs index 90cda2f5cad3d..c2f2c63790a4c 100644 --- a/src/librustc_trans/context.rs +++ b/src/librustc_trans/context.rs @@ -375,7 +375,10 @@ impl<'a, 'tcx> LocalCrateContext<'a, 'tcx> { let dbg_cx = if shared.tcx.sess.opts.debuginfo != NoDebugInfo { let dctx = debuginfo::CrateDebugContext::new(llmod); - debuginfo::metadata::compile_unit_metadata(shared, &dctx, shared.tcx.sess); + debuginfo::metadata::compile_unit_metadata(shared, + codegen_unit.name(), + &dctx, + shared.tcx.sess); Some(dctx) } else { None diff --git a/src/librustc_trans/debuginfo/metadata.rs b/src/librustc_trans/debuginfo/metadata.rs index 188f8ee336637..7d8b8161abe02 100644 --- a/src/librustc_trans/debuginfo/metadata.rs +++ b/src/librustc_trans/debuginfo/metadata.rs @@ -762,23 +762,30 @@ fn pointer_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, } pub fn compile_unit_metadata(scc: &SharedCrateContext, + codegen_unit_name: &str, debug_context: &CrateDebugContext, sess: &Session) -> DIDescriptor { - let compile_unit_name = match sess.local_crate_source_file { - None => fallback_path(scc), - Some(ref path) => { - CString::new(&path[..]).unwrap() - } + let mut name_in_debuginfo = match sess.local_crate_source_file { + Some(ref path) => path.clone(), + None => scc.tcx().crate_name(LOCAL_CRATE).to_string(), }; - debug!("compile_unit_metadata: {:?}", compile_unit_name); + // The OSX linker has an idiosyncrasy where it will ignore some debuginfo + // if multiple object files with the same DW_AT_name are linked together. + // As a workaround we generate unique names for each object file. Those do + // not correspond to an actual source file but that should be harmless. + if scc.sess().target.target.options.is_like_osx { + name_in_debuginfo.push_str("@"); + name_in_debuginfo.push_str(codegen_unit_name); + } + + debug!("compile_unit_metadata: {:?}", name_in_debuginfo); // FIXME(#41252) Remove "clang LLVM" if we can get GDB and LLVM to play nice. let producer = format!("clang LLVM (rustc version {})", (option_env!("CFG_VERSION")).expect("CFG_VERSION")); - let compile_unit_name = compile_unit_name.as_ptr(); - + let name_in_debuginfo = CString::new(name_in_debuginfo).unwrap(); let work_dir = CString::new(&sess.working_dir.0[..]).unwrap(); let producer = CString::new(producer).unwrap(); let flags = "\0"; @@ -786,7 +793,7 @@ pub fn compile_unit_metadata(scc: &SharedCrateContext, unsafe { let file_metadata = llvm::LLVMRustDIBuilderCreateFile( - debug_context.builder, compile_unit_name, work_dir.as_ptr()); + debug_context.builder, name_in_debuginfo.as_ptr(), work_dir.as_ptr()); return llvm::LLVMRustDIBuilderCreateCompileUnit( debug_context.builder, @@ -798,10 +805,6 @@ pub fn compile_unit_metadata(scc: &SharedCrateContext, 0, split_name.as_ptr() as *const _) }; - - fn fallback_path(scc: &SharedCrateContext) -> CString { - CString::new(scc.tcx().crate_name(LOCAL_CRATE).to_string()).unwrap() - } } struct MetadataCreationResult { diff --git a/src/test/debuginfo/multi-cgu.rs b/src/test/debuginfo/multi-cgu.rs new file mode 100644 index 0000000000000..f4f9f92396f2c --- /dev/null +++ b/src/test/debuginfo/multi-cgu.rs @@ -0,0 +1,67 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + + +// This test case makes sure that we get proper break points for binaries +// compiled with multiple codegen units. (see #39160) + + +// min-lldb-version: 310 + +// compile-flags:-g -Ccodegen-units=2 + +// === GDB TESTS =============================================================== + +// gdb-command:run + +// gdb-command:print xxx +// gdb-check:$1 = 12345 +// gdb-command:continue + +// gdb-command:print yyy +// gdb-check:$2 = 67890 +// gdb-command:continue + + +// === LLDB TESTS ============================================================== + +// lldb-command:run + +// lldb-command:print xxx +// lldb-check:[...]$0 = 12345 +// lldb-command:continue + +// lldb-command:print yyy +// lldb-check:[...]$1 = 67890 +// lldb-command:continue + + +#![feature(omit_gdb_pretty_printer_section)] +#![omit_gdb_pretty_printer_section] + +mod a { + pub fn foo(xxx: u32) { + super::_zzz(); // #break + } +} + +mod b { + pub fn bar(yyy: u64) { + super::_zzz(); // #break + } +} + +fn main() { + a::foo(12345); + b::bar(67890); +} + +#[inline(never)] +fn _zzz() {} From a89292514b6d4c4e9be7d6d527ad72e08e27173c Mon Sep 17 00:00:00 2001 From: David LeGare Date: Fri, 19 May 2017 07:29:52 -0500 Subject: [PATCH 28/28] Fix doc test failure for OpenOptionsExt --- src/libstd/sys/windows/ext/fs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/sys/windows/ext/fs.rs b/src/libstd/sys/windows/ext/fs.rs index 34f3a0196cedf..2d00cb38ec4fc 100644 --- a/src/libstd/sys/windows/ext/fs.rs +++ b/src/libstd/sys/windows/ext/fs.rs @@ -241,7 +241,7 @@ pub trait OpenOptionsExt { /// .create(true) /// /// // Sets the flag value to `SecurityIdentification`. - /// options.security_qos_flags(1) + /// .security_qos_flags(1) /// /// .open("foo.txt"); /// ```