Skip to content
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

V Version Manager #21797

Open
2 tasks
enghitalo opened this issue Jul 3, 2024 · 2 comments
Open
2 tasks

V Version Manager #21797

enghitalo opened this issue Jul 3, 2024 · 2 comments
Labels
Feature Request This issue is made to request a feature.

Comments

@enghitalo
Copy link
Contributor

enghitalo commented Jul 3, 2024

Describe the feature

Something like sdkman or nvm to avoid compatibility problems with packages and in production softwares.
maybe:
v.mod

Module {
	name: 'v2048',
	description: 'A simple 2048 game written in V.',
	version: '0.0.2',
	license: 'MIT'
	repo_url: 'https://github.com/spytheman/v2048',
	dependencies: [],
+	v_version: '>= 0.4.6 && <= weekly.2024.23'
or
+	v_version: 'latest'
}

.vvmrc

0.4.6

or

latest

Use Case

Build to production

Proposed Solution

When running v <project> or v run <project> it must the get the version in .vvmrc (if it exists), and then run the project with that version of V.
If the version is not found in .vvmrc then it should use the latest version of V installed on the system or the in use version of V.
If the version in .vvmrc is not installed on the system, it should install that version and then run the project with that version of V,
Maybe installing it at /usr/lib/v/<version>/bin/v and/or /usr/local/bin/v<version>.

Other Information

It is need verify if will need have some change how vlib/v/util/version/version.v, cmd/tools/vup.v and @VCURRENTHASH works.

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

Version used

V 0.4.6 209063f

Environment details (OS name and version, etc.)

all

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@enghitalo enghitalo added the Feature Request This issue is made to request a feature. label Jul 3, 2024
@enghitalo
Copy link
Contributor Author

Something like

#!/bin/bash

# Function to print an error message and exit
function error_exit {
    echo "$1" 1>&2
    exit 1
}

# Function to get the latest installed version of V
function get_latest_installed_version {
    local latest_version=$(ls /usr/lib/v | sort -V | tail -n 1)
    if [[ -z "$latest_version" ]]; then
        error_exit "No V versions found. Please install V."
    fi
    echo "$latest_version"
}

# Function to install the specified version of V
function install_v_version {
    local version=$1
    echo "Installing V version $version..."

    wget "https://github.com/vlang/v/releases/download/$version/v_linux.zip" -O /tmp/v-$version.zip
    mkdir -p "/usr/lib/v/$version/bin"
    unzip -jo /tmp/v-$version.zip v/v -d /usr/lib/v/$version/bin
    ln -sf "/usr/lib/v/$version/bin/v" "/usr/local/bin/v$version"
}

# Determine the project directory
PROJECT_DIR=$(pwd)
if [[ -z "$1" ]]; then
    error_exit "Please specify a project directory or file."
fi

# Check if the specified argument is a directory or file
if [[ -d "$1" ]]; then
    PROJECT_DIR="$1"
elif [[ -f "$1" ]]; then
    PROJECT_DIR=$(dirname "$1")
else
    error_exit "Invalid project directory or file specified."
fi

# Look for .vvmrc file
VVMRC_FILE="$PROJECT_DIR/.vvmrc"
if [[ -f "$VVMRC_FILE" ]]; then
    V_VERSION=$(cat "$VVMRC_FILE" | tr -d '[:space:]')
else
    V_VERSION=$(get_latest_installed_version)
fi

# Check if the specified version is installed
if [[ ! -x "/usr/lib/v/$V_VERSION/bin/v" ]]; then
    install_v_version "$V_VERSION"
fi

# Run the project with the specified version of V
/usr/lib/v/$V_VERSION/bin/v "$@"

@JalonSolov
Copy link
Contributor

I am still against adding things like this until 1.0 or after.

At present, people are still better off always using the latest version of V, even if there was a change that means they need to update their code - often those changes are necessary to avoid more serious issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request This issue is made to request a feature.
Projects
None yet
Development

No branches or pull requests

2 participants