-
Notifications
You must be signed in to change notification settings - Fork 73
1719: Rust Integration #1913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
laert-ll
wants to merge
32
commits into
devonfw:main
Choose a base branch
from
laert-ll:feature/1719-rust-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
1719: Rust Integration #1913
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
f84c283
Add Rust URL updater using rustup script
tmukh a5b2607
Add Rust commandlet installer with Windows MSVC setup
tmukh 6b3dd08
#1719: Change Rust MSVC Name
tmukh a183880
Added Rust commandlet properties
tmukh 539c119
Apply suggestions from code review
hohwille 29eaf5e
fix installDependencies
hohwille fcbc211
do not mock commandlet
hohwille d76c043
#1719: Refactor LocalToolCommandlet and Rust.java
laert-ll 168699a
#1719: Add getDownloadedToolFile method
laert-ll 9a92b3d
#1719: More refactoring
laert-ll c6c07b4
#1719: Revert unnecessary docstring change
laert-ll f513119
#1719: Cleanup
laert-ll 2843a85
#1719: Cleanup
laert-ll 0aeaf68
#1719: Rename of RustGithubUrlTagUpdaterTest
laert-ll c1dd198
#1719: Revert rename of RustGithubUrlTagUpdaterTest
laert-ll 582b49b
#1719: Removed installDependencies method
laert-ll f4227f8
#1719: MSVC url updater and installation with dependencies.json
laert-ll 847a181
#1719: MSVC download link
laert-ll 06b410b
#1719: Fixing MSVC commandlet
laert-ll 1c6a285
#1719: Fix MSVC commandlet
laert-ll 7ccfb3b
#1719: Refactor MSVC commandlet
laert-ll 6eb3e02
#1719: Add MSVC help message
laert-ll c116ad1
#1719: Temporary tests fix
laert-ll 13ccd61
#1719: Extend RustTest.java
laert-ll 04d1de8
#1719: Remove unnecessary RustGithubUrlTagUpdaterTest.java
laert-ll 6032e89
#1719: Add License, tiny Msvc.java tweaks
laert-ll 684727e
#1719: Cleanup
laert-ll dc473a5
#1719: Fix
laert-ll 08ccac2
Fix CHANGELOG.adoc rebase conflict.
laert-ll 133b2a7
#1719: Revert temporary tests bug fix
laert-ll acefc08
#1719: Implement review suggestions for MSVC non-Windows installation
laert-ll 529b3ff
#1719: Implement review suggestion for unneccessary getDownloadedTool…
laert-ll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
cli/src/main/java/com/devonfw/tools/ide/tool/msvc/Msvc.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.devonfw.tools.ide.tool.msvc; | ||
|
|
||
| import java.nio.file.Path; | ||
| import java.util.Set; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import com.devonfw.tools.ide.common.Tag; | ||
| import com.devonfw.tools.ide.context.IdeContext; | ||
| import com.devonfw.tools.ide.process.ProcessErrorHandling; | ||
| import com.devonfw.tools.ide.tool.LocalToolCommandlet; | ||
| import com.devonfw.tools.ide.tool.ToolInstallRequest; | ||
| import com.devonfw.tools.ide.tool.ToolInstallation; | ||
|
|
||
| public class Msvc extends LocalToolCommandlet { | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(Msvc.class); | ||
|
|
||
| public Msvc(IdeContext context) { | ||
| super(context, "msvc", Set.of(Tag.BUILD, Tag.CPP)); | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean isExtract() { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public ToolInstallation installTool(ToolInstallRequest request) { | ||
|
|
||
| if (this.context.getSystemInfo().isWindows()) { | ||
| return super.installTool(request); | ||
| } | ||
| LOG.trace("Skipping msvc installation that is only available on Windows."); | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| protected void installDownloadedToolPayload(ToolInstallRequest request, Path installationPath, Path installer) { | ||
|
|
||
| this.context.getFileAccess().mkdirs(installationPath); | ||
|
|
||
| this.context.newProcess().errorHandling(ProcessErrorHandling.THROW_CLI) | ||
| .executable(installer) | ||
| .withExitCodeAcceptor(code -> (code == 0) || (code == 3010)) | ||
| .addArgs("--installPath", installationPath.toString(), | ||
| "--add", "Microsoft.VisualStudio.Workload.VCTools", | ||
| "--quiet", "--wait", "--norestart", "--nocache") | ||
| .run(); | ||
| } | ||
| } |
97 changes: 97 additions & 0 deletions
97
cli/src/main/java/com/devonfw/tools/ide/tool/rust/Rust.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| package com.devonfw.tools.ide.tool.rust; | ||
|
|
||
| import java.nio.file.Files; | ||
| import java.nio.file.LinkOption; | ||
| import java.nio.file.Path; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| import com.devonfw.tools.ide.common.Tag; | ||
| import com.devonfw.tools.ide.context.IdeContext; | ||
| import com.devonfw.tools.ide.io.FileAccess; | ||
| import com.devonfw.tools.ide.process.EnvironmentContext; | ||
| import com.devonfw.tools.ide.process.ProcessContext; | ||
| import com.devonfw.tools.ide.process.ProcessErrorHandling; | ||
| import com.devonfw.tools.ide.tool.LocalToolCommandlet; | ||
| import com.devonfw.tools.ide.tool.ToolInstallRequest; | ||
| import com.devonfw.tools.ide.tool.ToolInstallation; | ||
| import com.devonfw.tools.ide.version.VersionIdentifier; | ||
|
|
||
| /** | ||
| * {@link LocalToolCommandlet} for <a href="https://www.rust-lang.org/">Rust</a>. | ||
| */ | ||
| public class Rust extends LocalToolCommandlet { | ||
|
|
||
| /** | ||
| * The constructor. | ||
| * | ||
| * @param context the {@link IdeContext}. | ||
| */ | ||
| public Rust(IdeContext context) { | ||
|
|
||
| super(context, "rust", Set.of(Tag.RUST)); | ||
| } | ||
|
|
||
| @Override | ||
| public String getBinaryName() { | ||
|
|
||
| return "rustc"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getToolHelpArguments() { | ||
|
|
||
| return "--help"; | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean isExtract() { | ||
|
|
||
| // The rustup installer script is an executable script and must not be extracted. | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| protected void installDownloadedToolPayload(ToolInstallRequest request, Path installationPath, Path installerScript) { | ||
|
|
||
| VersionIdentifier resolvedVersion = request.getRequested().getResolvedVersion(); | ||
| FileAccess fileAccess = this.context.getFileAccess(); | ||
|
|
||
| Path cargoHome = installationPath.resolve(".cargo"); | ||
| Path rustupHome = installationPath.resolve(".rustup"); | ||
| fileAccess.mkdirs(cargoHome); | ||
| fileAccess.mkdirs(rustupHome); | ||
|
|
||
| if (Files.isDirectory(installerScript)) { | ||
| // ToolRepositoryMock may provide an unpacked folder instead of a single download file. | ||
| installerScript = installerScript.resolve("content.sh"); | ||
| } | ||
|
|
||
| ProcessContext process = request.getProcessContext().createChild().errorHandling(ProcessErrorHandling.THROW_CLI).directory(installationPath) | ||
| .withEnvVar("CARGO_HOME", cargoHome.toString()).withEnvVar("RUSTUP_HOME", rustupHome.toString()); | ||
|
|
||
| List<String> installerArgs = List.of("-y", "--no-modify-path", "--profile", "default", "--default-toolchain", resolvedVersion.toString()); | ||
|
|
||
| process.executable(this.context.findBashRequired()).addArgs(installerScript.toAbsolutePath().toString()).addArgs(installerArgs); | ||
| process.run(); | ||
|
|
||
| Path cargoBin = cargoHome.resolve("bin"); | ||
| Path toolBin = installationPath.resolve("bin"); | ||
| if (Files.exists(toolBin, LinkOption.NOFOLLOW_LINKS)) { | ||
| fileAccess.delete(toolBin); | ||
| } | ||
| if (Files.isDirectory(cargoBin)) { | ||
| fileAccess.symlink(cargoBin, toolBin); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void setEnvironment(EnvironmentContext environmentContext, ToolInstallation toolInstallation, boolean additionalInstallation) { | ||
|
|
||
| super.setEnvironment(environmentContext, toolInstallation, additionalInstallation); | ||
| Path rootDir = toolInstallation.rootDir(); | ||
| environmentContext.withEnvVar("CARGO_HOME", rootDir.resolve(".cargo").toString()); | ||
| environmentContext.withEnvVar("RUSTUP_HOME", rootDir.resolve(".rustup").toString()); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
cli/src/test/java/com/devonfw/tools/ide/tool/rust/RustTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.devonfw.tools.ide.tool.rust; | ||
|
|
||
| import java.nio.file.Path; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import com.devonfw.tools.ide.context.AbstractIdeContextTest; | ||
| import com.devonfw.tools.ide.context.IdeTestContext; | ||
|
|
||
| /** | ||
| * Test of {@link Rust}. | ||
| */ | ||
| class RustTest extends AbstractIdeContextTest { | ||
|
|
||
| private static final String PROJECT_RUST = "rust"; | ||
|
|
||
| private static final String RUST_VERSION = "1.80.1"; | ||
|
|
||
| @Test | ||
| void testRustInstallViaRustupScript() { | ||
|
|
||
| // arrange | ||
| IdeTestContext context = newContext(PROJECT_RUST); | ||
| Rust rust = new Rust(context); | ||
|
|
||
| // act | ||
| rust.install(); | ||
|
|
||
| // assert | ||
| assertThat(context.getSoftwarePath().resolve("rust/.ide.software.version")).exists().hasContent(RUST_VERSION); | ||
| assertThat(context).logAtSuccess().hasMessageContaining("Successfully installed rust in version " + RUST_VERSION); | ||
| } | ||
|
|
||
| @Test | ||
| void testRustInstallProducesCargoLayoutAndBinLink() { | ||
|
|
||
| // arrange | ||
| IdeTestContext context = newContext(PROJECT_RUST); | ||
| Rust rust = new Rust(context); | ||
| String rustcName = context.getSystemInfo().isWindows() ? "rustc.cmd" : "rustc"; | ||
|
|
||
| // act | ||
| rust.install(); | ||
|
|
||
| // assert | ||
| Path softwareRust = context.getSoftwarePath().resolve("rust"); | ||
| assertThat(softwareRust.resolve(".cargo")).exists(); | ||
| assertThat(softwareRust.resolve(".rustup")).exists(); | ||
| assertThat(softwareRust.resolve(".cargo/bin").resolve(rustcName)).exists(); | ||
| assertThat(softwareRust.resolve("bin").resolve(rustcName)).exists(); | ||
| } | ||
| } |
2 changes: 2 additions & 0 deletions
2
cli/src/test/resources/ide-projects/rust/_ide/urls/rust/rust/1.80.1/urls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| https://sh.rustup.rs | ||
|
|
Empty file.
Empty file.
17 changes: 17 additions & 0 deletions
17
cli/src/test/resources/ide-projects/rust/repository/rust/rust/default/content.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #!/usr/bin/env bash | ||
| set -eu | ||
|
|
||
| mkdir -p "${CARGO_HOME}/bin" | ||
| mkdir -p "${RUSTUP_HOME}" | ||
|
|
||
| cat > "${CARGO_HOME}/bin/rustc" <<'EOF' | ||
| #!/usr/bin/env bash | ||
| echo rustc "$@" | ||
| EOF | ||
| chmod +x "${CARGO_HOME}/bin/rustc" | ||
|
|
||
| cat > "${CARGO_HOME}/bin/rustc.cmd" <<'EOF' | ||
| @echo off | ||
| echo rustc %* | ||
| EOF | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.