Skip to content

Commit d84a22a

Browse files
committed
rustpkg: Register correct dependencies for built and installed files
as per #9112 Closes #9112
1 parent 4dacd73 commit d84a22a

File tree

6 files changed

+84
-8
lines changed

6 files changed

+84
-8
lines changed

src/librustpkg/api.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use target::*;
1616
use version::Version;
1717
use workcache_support::*;
1818

19+
use std::os;
1920
use extra::arc::{Arc,RWArc};
2021
use extra::workcache;
2122
use extra::workcache::{Database, Logger, FreshnessMap};
@@ -40,11 +41,13 @@ pub fn new_default_context(c: workcache::Context, p: Path) -> BuildContext {
4041
}
4142

4243
fn file_is_fresh(path: &str, in_hash: &str) -> bool {
43-
in_hash == digest_file_with_date(&Path(path))
44+
let path = Path(path);
45+
os::path_exists(&path) && in_hash == digest_file_with_date(&path)
4446
}
4547

4648
fn binary_is_fresh(path: &str, in_hash: &str) -> bool {
47-
in_hash == digest_only_date(&Path(path))
49+
let path = Path(path);
50+
os::path_exists(&path) && in_hash == digest_only_date(&path)
4851
}
4952

5053
pub fn new_workcache_context(p: &Path) -> workcache::Context {

src/librustpkg/exit_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
pub static copy_failed_code: int = 65;
11+
pub static COPY_FAILED_CODE: int = 65;

src/librustpkg/path_util.rs

-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ fn target_bin_dir(workspace: &Path) -> Path {
118118
/// directory is, and if the file exists, return it.
119119
pub fn built_executable_in_workspace(pkgid: &PkgId, workspace: &Path) -> Option<Path> {
120120
let mut result = target_build_dir(workspace);
121-
// should use a target-specific subdirectory
122121
result = mk_output_path(Main, Build, pkgid, result);
123122
debug!("built_executable_in_workspace: checking whether %s exists",
124123
result.to_str());

src/librustpkg/rustpkg.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use package_source::PkgSrc;
4747
use target::{WhatToBuild, Everything, is_lib, is_main, is_test, is_bench};
4848
// use workcache_support::{discover_outputs, digest_only_date};
4949
use workcache_support::digest_only_date;
50-
use exit_codes::copy_failed_code;
50+
use exit_codes::COPY_FAILED_CODE;
5151

5252
pub mod api;
5353
mod conditions;
@@ -789,10 +789,10 @@ pub fn main_args(args: &[~str]) {
789789
}.run(sub_cmd, rm_args.clone())
790790
};
791791
// FIXME #9262: This is using the same error code for all errors,
792-
// and at least one test case succeeds if rustpkg returns copy_failed_code,
792+
// and at least one test case succeeds if rustpkg returns COPY_FAILED_CODE,
793793
// when actually, it might set the exit code for that even if a different
794794
// unhandled condition got raised.
795-
if result.is_err() { os::set_exit_status(copy_failed_code); }
795+
if result.is_err() { os::set_exit_status(COPY_FAILED_CODE); }
796796

797797
}
798798

src/librustpkg/tests.rs

+53
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,13 @@ fn executable_exists(repo: &Path, short_name: &str) -> bool {
355355
os::path_exists(&exec) && is_rwx(&exec)
356356
}
357357

358+
fn remove_executable_file(p: &PkgId, workspace: &Path) {
359+
let exec = target_executable_in_workspace(&PkgId::new(p.short_name), workspace);
360+
if os::path_exists(&exec) {
361+
assert!(os::remove_file(&exec));
362+
}
363+
}
364+
358365
fn assert_built_executable_exists(repo: &Path, short_name: &str) {
359366
assert!(built_executable_exists(repo, short_name));
360367
}
@@ -368,6 +375,14 @@ fn built_executable_exists(repo: &Path, short_name: &str) -> bool {
368375
}
369376
}
370377

378+
fn remove_built_executable_file(p: &PkgId, workspace: &Path) {
379+
let exec = built_executable_in_workspace(&PkgId::new(p.short_name), workspace);
380+
match exec {
381+
Some(r) => assert!(os::remove_file(&r)),
382+
None => ()
383+
}
384+
}
385+
371386
fn object_file_exists(repo: &Path, short_name: &str) -> bool {
372387
file_exists(repo, short_name, "o")
373388
}
@@ -1705,6 +1720,44 @@ fn test_dependencies_terminate() {
17051720
command_line_test([~"install", ~"b"], &workspace);
17061721
}
17071722
1723+
#[test]
1724+
fn install_after_build() {
1725+
let b_id = PkgId::new("b");
1726+
let workspace = create_local_package(&b_id);
1727+
command_line_test([~"build", ~"b"], &workspace);
1728+
command_line_test([~"install", ~"b"], &workspace);
1729+
assert_executable_exists(&workspace, b_id.short_name);
1730+
assert_lib_exists(&workspace, &b_id.path, NoVersion);
1731+
}
1732+
1733+
#[test]
1734+
fn reinstall() {
1735+
let b = PkgId::new("b");
1736+
let workspace = create_local_package(&b);
1737+
// 1. Install, then remove executable file, then install again,
1738+
// and make sure executable was re-installed
1739+
command_line_test([~"install", ~"b"], &workspace);
1740+
assert_executable_exists(&workspace, b.short_name);
1741+
assert_lib_exists(&workspace, &b.path, NoVersion);
1742+
remove_executable_file(&b, &workspace);
1743+
command_line_test([~"install", ~"b"], &workspace);
1744+
assert_executable_exists(&workspace, b.short_name);
1745+
// 2. Build, then remove build executable file, then build again,
1746+
// and make sure executable was re-built.
1747+
command_line_test([~"build", ~"b"], &workspace);
1748+
remove_built_executable_file(&b, &workspace);
1749+
command_line_test([~"build", ~"b"], &workspace);
1750+
assert_built_executable_exists(&workspace, b.short_name);
1751+
// 3. Install, then remove both executable and built executable,
1752+
// then install again, make sure both were recreated
1753+
command_line_test([~"install", ~"b"], &workspace);
1754+
remove_executable_file(&b, &workspace);
1755+
remove_built_executable_file(&b, &workspace);
1756+
command_line_test([~"install", ~"b"], &workspace);
1757+
assert_executable_exists(&workspace, b.short_name);
1758+
assert_built_executable_exists(&workspace, b.short_name);
1759+
}
1760+
17081761
/// Returns true if p exists and is executable
17091762
fn is_executable(p: &Path) -> bool {
17101763
use std::libc::consts::os::posix88::{S_IXUSR};

src/librustpkg/util.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,28 @@ pub fn compile_input(context: &BuildContext,
283283

284284
debug!("calling compile_crate_from_input, workspace = %s,
285285
building_library = %?", out_dir.to_str(), sess.building_library);
286-
compile_crate_from_input(in_file, exec, context.compile_upto(), &out_dir, sess, crate)
286+
let result = compile_crate_from_input(in_file,
287+
exec,
288+
context.compile_upto(),
289+
&out_dir,
290+
sess,
291+
crate);
292+
// Discover the output
293+
let discovered_output = if what == Lib {
294+
installed_library_in_workspace(&pkg_id.path, workspace)
295+
}
296+
else {
297+
result
298+
};
299+
debug!("About to discover output %s", discovered_output.to_str());
300+
for p in discovered_output.iter() {
301+
if os::path_exists(p) {
302+
exec.discover_output("binary", p.to_str(), digest_only_date(p));
303+
}
304+
// Nothing to do if it doesn't exist -- that could happen if we had the
305+
// -S or -emit-llvm flags, etc.
306+
}
307+
discovered_output
287308
}
288309

289310
// Should use workcache to avoid recompiling when not necessary

0 commit comments

Comments
 (0)