Skip to content

Commit 7341d68

Browse files
committed
Produce source package in rust-installer format in addition to vanilla tarball
Copy source files from rust code Add missing wildcard Remove unused function Remove use of tar --transform
1 parent f55ac69 commit 7341d68

File tree

7 files changed

+230
-10
lines changed

7 files changed

+230
-10
lines changed

mk/dist.mk

+24-9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ PKG_NAME := $(CFG_PACKAGE_NAME)
2424
STD_PKG_NAME := rust-std-$(CFG_PACKAGE_VERS)
2525
DOC_PKG_NAME := rust-docs-$(CFG_PACKAGE_VERS)
2626
MINGW_PKG_NAME := rust-mingw-$(CFG_PACKAGE_VERS)
27+
SRC_PKG_NAME := rust-src-$(CFG_PACKAGE_VERS)
2728

2829
# License suitable for displaying in a popup
2930
LICENSE.txt: $(S)COPYRIGHT $(S)LICENSE-APACHE $(S)LICENSE-MIT
@@ -71,10 +72,10 @@ PKG_FILES := \
7172

7273
UNROOTED_PKG_FILES := $(patsubst $(S)%,./%,$(PKG_FILES))
7374

74-
$(PKG_TAR): $(PKG_FILES)
75-
@$(call E, making dist dir)
76-
$(Q)rm -Rf tmp/dist/$(PKG_NAME)
77-
$(Q)mkdir -p tmp/dist/$(PKG_NAME)
75+
tmp/dist/$$(SRC_PKG_NAME)-image: $(PKG_FILES)
76+
@$(call E, making src image)
77+
$(Q)rm -Rf tmp/dist/$(SRC_PKG_NAME)-image
78+
$(Q)mkdir -p tmp/dist/$(SRC_PKG_NAME)-image/lib/rustlib/src/rust
7879
$(Q)tar \
7980
-C $(S) \
8081
-f - \
@@ -87,10 +88,11 @@ $(PKG_TAR): $(PKG_FILES)
8788
--exclude=*/llvm/test/*/*/*.ll \
8889
--exclude=*/llvm/test/*/*/*.td \
8990
--exclude=*/llvm/test/*/*/*.s \
90-
-c $(UNROOTED_PKG_FILES) | tar -x -f - -C tmp/dist/$(PKG_NAME)
91+
-c $(UNROOTED_PKG_FILES) | tar -x -f - -C tmp/dist/$(SRC_PKG_NAME)-image/lib/rustlib/src/rust
92+
93+
$(PKG_TAR): tmp/dist/$$(SRC_PKG_NAME)-image
9194
@$(call E, making $@)
92-
$(Q)tar -czf $(PKG_TAR) -C tmp/dist $(PKG_NAME)
93-
$(Q)rm -Rf tmp/dist/$(PKG_NAME)
95+
$(Q)tar -czf $(PKG_TAR) -C tmp/dist/$(SRC_PKG_NAME)-image/lib/rustlib/src rust --transform 's,^rust,$(PKG_NAME),S'
9496

9597
dist-tar-src: $(PKG_TAR)
9698

@@ -259,6 +261,19 @@ endef
259261
$(foreach host,$(CFG_HOST),\
260262
$(eval $(call DEF_INSTALLER,$(host))))
261263

264+
dist/$(SRC_PKG_NAME).tar.gz: tmp/dist/$(SRC_PKG_NAME)-image
265+
@$(call E, build: $@)
266+
$(Q)$(S)src/rust-installer/gen-installer.sh \
267+
--product-name=Rust \
268+
--rel-manifest-dir=rustlib \
269+
--success-message=Awesome-Source. \
270+
--image-dir=tmp/dist/$(SRC_PKG_NAME)-image \
271+
--work-dir=tmp/dist \
272+
--output-dir=dist \
273+
--package-name=$(SRC_PKG_NAME) \
274+
--component-name=rust-src \
275+
--legacy-manifest-dirs=rustlib,cargo
276+
262277
# When generating packages for the standard library, we've actually got a lot of
263278
# artifacts to choose from. Each of the CFG_HOST compilers will have a copy of
264279
# the standard library for each CFG_TARGET, but we only want to generate one
@@ -329,8 +344,8 @@ distcheck-docs: dist-docs
329344
# Primary targets (dist, distcheck)
330345
######################################################################
331346

332-
MAYBE_DIST_TAR_SRC=dist-tar-src
333-
MAYBE_DISTCHECK_TAR_SRC=distcheck-tar-src
347+
MAYBE_DIST_TAR_SRC=dist-tar-src dist/$(SRC_PKG_NAME).tar.gz
348+
MAYBE_DISTCHECK_TAR_SRC=distcheck-tar-src dist/$(SRC_PKG_NAME).tar.gz
334349

335350
# FIXME #13224: On OS X don't produce tarballs simply because --exclude-vcs don't work.
336351
# This is a huge hack because I just don't have time to figure out another solution.

src/bootstrap/Cargo.lock

+56
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bootstrap/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ kernel32-sys = "0.2"
3232
gcc = { git = "https://github.com/alexcrichton/gcc-rs" }
3333
libc = "0.2"
3434
md5 = "0.1"
35+
regex = "0.1.73"

src/bootstrap/dist.rs

+115-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ use std::path::{PathBuf, Path};
2424
use std::process::Command;
2525

2626
use {Build, Compiler};
27-
use util::{cp_r, libdir, is_dylib};
27+
use util::{cp_r, libdir, is_dylib, cp_filtered, copy};
28+
use regex::{RegexSet, quote};
2829

2930
fn package_vers(build: &Build) -> &str {
3031
match &build.config.channel[..] {
@@ -284,6 +285,119 @@ pub fn std(build: &Build, compiler: &Compiler, target: &str) {
284285
t!(fs::remove_dir_all(&image));
285286
}
286287

288+
/// Creates the `rust-src` installer component and the plain source tarball
289+
pub fn rust_src(build: &Build) {
290+
println!("Dist src");
291+
let plain_name = format!("rustc-{}-src", package_vers(build));
292+
let name = format!("rust-src-{}", package_vers(build));
293+
let image = tmpdir(build).join(format!("{}-image", name));
294+
let _ = fs::remove_dir_all(&image);
295+
296+
let dst = image.join("lib/rustlib/src");
297+
let dst_src = dst.join("rust");
298+
let plain_dst_src = dst.join(&plain_name);
299+
t!(fs::create_dir_all(&dst_src));
300+
301+
// This is the set of root paths which will become part of the source package
302+
let src_files = [
303+
"COPYRIGHT",
304+
"LICENSE-APACHE",
305+
"LICENSE-MIT",
306+
"CONTRIBUTING.md",
307+
"README.md",
308+
"RELEASES.md",
309+
"configure",
310+
"Makefile.in"
311+
];
312+
let src_dirs = [
313+
"man",
314+
"src",
315+
"mk"
316+
];
317+
318+
// Exclude paths matching these wildcard expressions
319+
let excludes = [
320+
// exclude-vcs
321+
"CVS", "RCS", "SCCS", ".git", ".gitignore", ".gitmodules", ".gitattributes", ".cvsignore",
322+
".svn", ".arch-ids", "{arch}", "=RELEASE-ID", "=meta-update", "=update", ".bzr",
323+
".bzrignore", ".bzrtags", ".hg", ".hgignore", ".hgrags", "_darcs",
324+
// extensions
325+
"*~", "*.pyc",
326+
// misc
327+
"llvm/test/*/*.ll",
328+
"llvm/test/*/*.td",
329+
"llvm/test/*/*.s",
330+
"llvm/test/*/*/*.ll",
331+
"llvm/test/*/*/*.td",
332+
"llvm/test/*/*/*.s"
333+
];
334+
335+
// Construct a set of regexes for efficiently testing whether paths match one of the above
336+
// expressions.
337+
let regex_set = t!(RegexSet::new(
338+
// This converts a wildcard expression to a regex
339+
excludes.iter().map(|&s| {
340+
// Prefix ensures that matching starts on a path separator boundary
341+
r"^(.*[\\/])?".to_owned() + (
342+
// Escape the expression to produce a regex matching exactly that string
343+
&quote(s)
344+
// Replace slashes with a pattern matching either forward or backslash
345+
.replace(r"/", r"[\\/]")
346+
// Replace wildcards with a pattern matching a single path segment, ie. containing
347+
// no slashes.
348+
.replace(r"\*", r"[^\\/]*")
349+
// Suffix anchors to the end of the path
350+
) + "$"
351+
})
352+
));
353+
354+
// Create a filter which skips files which match the regex set or contain invalid unicode
355+
let filter_fn = move |path: &Path| {
356+
if let Some(path) = path.to_str() {
357+
!regex_set.is_match(path)
358+
} else {
359+
false
360+
}
361+
};
362+
363+
// Copy the directories using our filter
364+
for item in &src_dirs {
365+
let dst = &dst_src.join(item);
366+
t!(fs::create_dir(dst));
367+
cp_filtered(&build.src.join(item), dst, &filter_fn);
368+
}
369+
// Copy the files normally
370+
for item in &src_files {
371+
copy(&build.src.join(item), &dst_src.join(item));
372+
}
373+
374+
// Create source tarball in rust-installer format
375+
let mut cmd = Command::new("sh");
376+
cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh")))
377+
.arg("--product-name=Rust")
378+
.arg("--rel-manifest-dir=rustlib")
379+
.arg("--success-message=Awesome-Source.")
380+
.arg(format!("--image-dir={}", sanitize_sh(&image)))
381+
.arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build))))
382+
.arg(format!("--output-dir={}", sanitize_sh(&distdir(build))))
383+
.arg(format!("--package-name={}", name))
384+
.arg("--component-name=rust-src")
385+
.arg("--legacy-manifest-dirs=rustlib,cargo");
386+
build.run(&mut cmd);
387+
388+
// Rename directory, so that root folder of tarball has the correct name
389+
t!(fs::rename(&dst_src, &plain_dst_src));
390+
391+
// Create plain source tarball
392+
let mut cmd = Command::new("tar");
393+
cmd.arg("-czf").arg(sanitize_sh(&distdir(build).join(&format!("{}.tar.gz", plain_name))))
394+
.arg(&plain_name)
395+
.current_dir(&dst);
396+
build.run(&mut cmd);
397+
398+
t!(fs::remove_dir_all(&image));
399+
}
400+
287401
fn install(src: &Path, dstdir: &Path, perms: u32) {
288402
let dst = dstdir.join(src.file_name().unwrap());
289403
t!(fs::create_dir_all(dstdir));

src/bootstrap/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extern crate md5;
2626
extern crate num_cpus;
2727
extern crate rustc_serialize;
2828
extern crate toml;
29+
extern crate regex;
2930

3031
use std::cell::RefCell;
3132
use std::collections::HashMap;
@@ -451,6 +452,7 @@ impl Build {
451452
DistMingw { _dummy } => dist::mingw(self, target.target),
452453
DistRustc { stage } => dist::rustc(self, stage, target.target),
453454
DistStd { compiler } => dist::std(self, &compiler, target.target),
455+
DistSrc { _dummy } => dist::rust_src(self),
454456

455457
DebuggerScripts { stage } => {
456458
let compiler = Compiler::new(stage, target.target);

src/bootstrap/step.rs

+3
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ macro_rules! targets {
140140
(dist_mingw, DistMingw { _dummy: () }),
141141
(dist_rustc, DistRustc { stage: u32 }),
142142
(dist_std, DistStd { compiler: Compiler<'a> }),
143+
(dist_src, DistSrc { _dummy: () }),
143144

144145
// Misc targets
145146
(android_copy_libs, AndroidCopyLibs { compiler: Compiler<'a> }),
@@ -568,12 +569,14 @@ impl<'a> Step<'a> {
568569
vec![self.libtest(compiler)]
569570
}
570571
}
572+
Source::DistSrc { _dummy: _ } => Vec::new(),
571573

572574
Source::Dist { stage } => {
573575
let mut base = Vec::new();
574576

575577
for host in build.config.host.iter() {
576578
let host = self.target(host);
579+
base.push(host.dist_src(()));
577580
base.push(host.dist_rustc(stage));
578581
if host.target.contains("windows-gnu") {
579582
base.push(host.dist_mingw(()));

src/bootstrap/util.rs

+29
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,35 @@ pub fn cp_r(src: &Path, dst: &Path) {
6767
}
6868
}
6969

70+
/// Copies the `src` directory recursively to `dst`. Both are assumed to exist
71+
/// when this function is called. Unwanted files or directories can be skipped
72+
/// by returning `false` from the filter function.
73+
pub fn cp_filtered<F: Fn(&Path) -> bool>(src: &Path, dst: &Path, filter: &F) {
74+
// Inner function does the actual work
75+
fn recurse<F: Fn(&Path) -> bool>(src: &Path, dst: &Path, relative: &Path, filter: &F) {
76+
for f in t!(fs::read_dir(src)) {
77+
let f = t!(f);
78+
let path = f.path();
79+
let name = path.file_name().unwrap();
80+
let dst = dst.join(name);
81+
let relative = relative.join(name);
82+
// Only copy file or directory if the filter function returns true
83+
if filter(&relative) {
84+
if t!(f.file_type()).is_dir() {
85+
let _ = fs::remove_dir_all(&dst);
86+
t!(fs::create_dir(&dst));
87+
recurse(&path, &dst, &relative, filter);
88+
} else {
89+
let _ = fs::remove_file(&dst);
90+
copy(&path, &dst);
91+
}
92+
}
93+
}
94+
}
95+
// Immediately recurse with an empty relative path
96+
recurse(src, dst, Path::new(""), filter)
97+
}
98+
7099
/// Given an executable called `name`, return the filename for the
71100
/// executable for a particular target.
72101
pub fn exe(name: &str, target: &str) -> String {

0 commit comments

Comments
 (0)