Skip to content

Commit

Permalink
write no_proxy to env when install, but spare it when install(?);
Browse files Browse the repository at this point in the history
temporarily remove 'diskReq' display;
  • Loading branch information
J-ZhengLi committed Aug 28, 2024
1 parent a1e2a63 commit 1679703
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 23 deletions.
8 changes: 4 additions & 4 deletions installer/src/view/FolderView.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script setup lang="ts">
import { event } from '@tauri-apps/api';
import { onMounted, ref } from 'vue';
import { onMounted } from 'vue';
import { useCustomRouter } from '../router';
import { installConf, invokeCommand } from '../utils';
const { routerPush, routerBack } = useCustomRouter();
const diskRequire = ref(33);
// const diskRequire = ref(33);
function handleNextClick() {
routerPush('/components');
Expand Down Expand Up @@ -49,9 +49,9 @@ onMounted(() => {
<base-button ml="12px" @click="openFolder">选择文件夹</base-button>
</div>
</div>
<div mx="12px">
<!-- <div mx="12px">
<p>至少需要{{ diskRequire.toFixed(1) }}M的磁盘空间</p>
</div>
</div> -->
<div h="60px" flex="~ justify-end items-center">
<base-button mr="12px" @click="routerBack">上一步</base-button>
<base-button mr="12px" @click="handleNextClick">下一步</base-button>
Expand Down
7 changes: 5 additions & 2 deletions resources/toolset_manifest.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[proxy]
no-proxy = "localhost,127.0.0.1"

[rust]
version = "stable"
group = "Rust"
Expand Down Expand Up @@ -28,8 +31,8 @@ Misc = [ "flamegraph", "cargo-expand" ]
[tools.target.x86_64-pc-windows-msvc]
buildtools = { required = true, path = "packages/x86_64-pc-windows-msvc/BuildTools-With-SDK.zip", version = "1" }
cargo-llvm-cov = { optional = true, url = "https://github.com/taiki-e/cargo-llvm-cov/releases/download/v0.6.11/cargo-llvm-cov-x86_64-pc-windows-msvc.zip", version = "0.6.11" }
vscode = { path = "packages/x86_64-pc-windows-msvc/VSCode-win32-x64-1.91.1.zip", version = "1.91.1" }
vscode-rust-analyzer = { path = "packages/x86_64-pc-windows-msvc/rust-lang.rust-analyzer-0.4.2054@win32-x64.vsix", version = "0.4.2054" }
vscode = { path = "packages/x86_64-pc-windows-gnu/VSCode-win32-x64-1.91.1.zip", version = "1.91.1" }
vscode-rust-analyzer = { path = "packages/x86_64-pc-windows-gnu/rust-lang.rust-analyzer-0.4.2054@win32-x64.vsix", version = "0.4.2054" }
cargo-expand = { optional = true, ver = "1.0.88" }

[tools.target.x86_64-pc-windows-gnu]
Expand Down
42 changes: 30 additions & 12 deletions src/core/os/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,16 @@ pub(super) fn add_to_path(path: &Path) -> Result<()> {
for sh in shell::get_available_shells() {
for rc in sh.update_rcs() {
let rc_content = utils::read_to_string(&rc)?;
let new_content = config_section_with_updated_path(sh.as_ref(), path_str, &rc_content);
let Some(new_content) =
config_section_with_updated_path(sh.as_ref(), path_str, &rc_content)
else {
println!(
"warning: unable to add path '{}' to rc file '{}' as it might already exists.",
path.display(),
rc.display(),
);
continue;
};
utils::write_file(&rc, &new_content, false).with_context(|| {
format!(
"failed to append PATH variable to shell profile: '{}'",
Expand All @@ -168,22 +177,29 @@ pub(super) fn add_to_path(path: &Path) -> Result<()> {
Ok(())
}

/// Attempt to return a new config section with updated path string.
/// Return `None` if it doesn't need to be updated or it cannot be updated.
fn config_section_with_updated_path(
sh: &dyn shell::UnixShell,
path_str: &str,
old_content: &str,
) -> String {
) -> Option<String> {
if let Some(existing_configs) = get_sub_string_between(
old_content,
shell::RC_FILE_SECTION_START,
shell::RC_FILE_SECTION_END,
) {
// Find the line that is setting path variable
let maybe_setting_path = existing_configs.lines().find(|line| line.contains("PATH"));
// Safe to unwrap, the function could only return `None` when removing.
let new_content = sh
.command_to_update_path(maybe_setting_path, path_str, false)
.unwrap();

// Check if the path was already exported.
if let Some(path_export) = maybe_setting_path {
if path_export.contains(&path_str) {
return None;
}
}

let new_content = sh.command_to_update_path(maybe_setting_path, path_str, false)?;

let mut new_configs = existing_configs.clone();
if let Some(setting_path) = maybe_setting_path {
Expand All @@ -193,11 +209,11 @@ fn config_section_with_updated_path(
new_configs.push_str(&new_content);
}

old_content.replace(&existing_configs, &new_configs)
Some(old_content.replace(&existing_configs, &new_configs))
} else {
// No previous configuration (this might never happed tho)
let path_configs = sh.command_to_update_path(None, path_str, false).unwrap();
sh.script_content(&path_configs)
let path_configs = sh.command_to_update_path(None, path_str, false)?;
Some(sh.script_content(&path_configs))
}
}

Expand Down Expand Up @@ -679,7 +695,8 @@ export PATH=/some/user/defined/bin:$PATH

let path_to_add = "/path/to/rust/bin";
let shell = shell::Bash;
let new_content = config_section_with_updated_path(&shell, path_to_add, existing_rc);
let new_content =
config_section_with_updated_path(&shell, path_to_add, existing_rc).unwrap();

assert_eq!(
new_content,
Expand Down Expand Up @@ -716,9 +733,10 @@ export PATH=/some/user/defined/bin:$PATH
let path_to_add = "/path/to/python/bin";
let another_path_to_add = "/path/to/ruby/bin";
let shell = shell::Bash;
let new_content = config_section_with_updated_path(&shell, path_to_add, existing_rc);
let new_content =
config_section_with_updated_path(&shell, another_path_to_add, &new_content);
config_section_with_updated_path(&shell, path_to_add, existing_rc).unwrap();
let new_content =
config_section_with_updated_path(&shell, another_path_to_add, &new_content).unwrap();

assert_eq!(
new_content,
Expand Down
22 changes: 17 additions & 5 deletions src/core/os/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ pub(crate) mod rustup {
if env.get_raw_value(key).is_err() {
return Ok(());
}
// Delete for current process
env::remove_var(key);
// Delete for user environment
env.delete_value(key)?;
} else {
// Set for current process
Expand All @@ -221,7 +224,7 @@ pub(crate) mod rustup {
bytes: to_winreg_bytes(val),
vtype: RegType::REG_EXPAND_SZ,
};
// Set for persist user environment
// Set for user environment
env.set_raw_value(key, &reg_value)?;
}

Expand All @@ -244,12 +247,24 @@ pub(crate) mod rustup {
}
}

/// Attempt to find the position of given path in the `PATH` environment variable.
fn find_path_in_env(paths: &[u16], path_bytes: &[u16]) -> Option<usize> {
paths
.windows(path_bytes.len())
.position(|path| path == path_bytes)
}

pub(crate) fn add_to_path(path: &Path) -> Result<()> {
let Some(old_path) = get_windows_path_var()? else {
return Ok(());
};
let path_bytes = path.as_os_str().encode_wide().collect::<Vec<_>>();

if find_path_in_env(&old_path, &path_bytes).is_some() {
// The path is already added, return without doing anything.
return Ok(());
};

let mut new_path = path_bytes;
new_path.push(b';' as u16);
new_path.extend_from_slice(&old_path);
Expand All @@ -268,10 +283,7 @@ pub(crate) mod rustup {
};
let path_bytes = path.as_os_str().encode_wide().collect::<Vec<_>>();

let Some(idx) = old_path
.windows(path_bytes.len())
.position(|path| path == path_bytes)
else {
let Some(idx) = find_path_in_env(&old_path, &path_bytes) else {
// The path is not added, return without doing anything.
return Ok(());
};
Expand Down

0 comments on commit 1679703

Please sign in to comment.