Skip to content

Commit

Permalink
Create hardlinks in installer CA
Browse files Browse the repository at this point in the history
  • Loading branch information
Boddlnagg committed Aug 13, 2016
1 parent ae5d5ed commit c12368e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/rustup-win-installer/build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::env;

fn main() {
println!("cargo:rustc-link-lib=static=wcautil");
println!("cargo:rustc-link-lib=static=dutil");
println!("cargo:rustc-link-lib=dylib=msi");
println!("cargo:rustc-link-lib=dylib=wcautil");
println!("cargo:rustc-link-lib=dylib=dutil");
println!("cargo:rustc-link-lib=dylib=user32");
println!("cargo:rustc-link-lib=dylib=mincore");

Expand Down
3 changes: 2 additions & 1 deletion src/rustup-win-installer/msi/rustup.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
<Custom Action="AssignInstallLocation" After="RustupSetInstallLocation"/>
<Custom Action="SetInstallOptions" Before="InstallInitialize">NOT Installed</Custom>
<Custom Action="RustupInstall" After="InstallFiles">NOT Installed</Custom>
<Custom Action="RustupUninstall" Before="RemoveFiles">Installed</Custom>
<!-- Run RustupUninstall only on true uninstall, not on upgrade -->
<Custom Action="RustupUninstall" After="RemoveFiles">Installed AND (NOT UPGRADINGPRODUCTCODE)</Custom>
</InstallExecuteSequence>

<!-- Send a WM_SETTINGCHANGE message to tell processes like explorer to update their
Expand Down
23 changes: 18 additions & 5 deletions src/rustup-win-installer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ pub const LOGMSG_TRACEONLY: i32 = 0;
pub const LOGMSG_VERBOSE: i32 = 1;
pub const LOGMSG_STANDARD: i32 = 2;

// TODO: share this with self_update.rs
static TOOLS: &'static [&'static str]
= &["rustc", "rustdoc", "cargo", "rust-lldb", "rust-gdb"];

#[no_mangle]
/// This is run as an `immediate` action early in the install sequence
pub unsafe extern "system" fn RustupSetInstallLocation(hInstall: MSIHANDLE) -> UINT {
Expand All @@ -26,30 +30,39 @@ pub unsafe extern "system" fn RustupSetInstallLocation(hInstall: MSIHANDLE) -> U
}

#[no_mangle]
/// This is be run as a `deferred` action after `InstallFiles`
/// This is be run as a `deferred` action after `InstallFiles` on install and upgrade
pub unsafe extern "system" fn RustupInstall(hInstall: MSIHANDLE) -> UINT {
let name = CString::new("RustupInstall").unwrap();
let hr = WcaInitialize(hInstall, name.as_ptr());
// For deferred custom actions, all data must be passed through the `CustomActionData` property
let custom_action_data = get_property("CustomActionData");
// TODO: use rustup_utils::cargo_home() or pass through CustomActionData
let path = PathBuf::from(::std::env::var_os("USERPROFILE").unwrap()).join(".rustup-test");
let exe_installed = path.join("bin").join("rustup.exe").exists();
let bin_path = path.join("bin");
let rustup_path = bin_path.join("rustup.exe");
let exe_installed = rustup_path.exists();
log(&format!("Hello World from RustupInstall, confirming that rustup.exe has been installed: {}! CustomActionData: {}", exe_installed, custom_action_data));
for tool in TOOLS {
let ref tool_path = bin_path.join(&format!("{}.exe", tool));
::rustup::utils::hardlink_file(&rustup_path, tool_path);
}
// TODO: install default toolchain and report progress to UI
WcaFinalize(hr)
}

#[no_mangle]
/// This is be run as a `deferred` action before `RemoveFiles` on uninstall
/// This is be run as a `deferred` action after `RemoveFiles` on uninstall (not on upgrade!)
pub unsafe extern "system" fn RustupUninstall(hInstall: MSIHANDLE) -> UINT {
let name = CString::new("RustupUninstall").unwrap();
let hr = WcaInitialize(hInstall, name.as_ptr());
// For deferred custom actions, all data must be passed through the `CustomActionData` property
let custom_action_data = get_property("CustomActionData");
// TODO: use rustup_utils::cargo_home() or pass through CustomActionData
let path = PathBuf::from(::std::env::var_os("USERPROFILE").unwrap()).join(".rustup-test");
let exe_installed = path.join("bin").join("rustup.exe").exists();
log(&format!("Hello World from RustupUninstall, confirming that rustup.exe has not yet been removed: {}! CustomActionData: {}", exe_installed, custom_action_data));
let exe_deleted = !path.join("bin").join("rustup.exe").exists();
log(&format!("Hello World from RustupUninstall, confirming that rustup.exe has been deleted: {}! CustomActionData: {}", exe_deleted, custom_action_data));
// TODO: Remove .cargo and .multirust
::rustup::utils::remove_dir("rustup-test", &path, &|_| {});
WcaFinalize(hr)
}

Expand Down

0 comments on commit c12368e

Please sign in to comment.