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

feat: add ability to store different versions of plugin #58

Merged
merged 4 commits into from
Feb 5, 2025

Conversation

dodokek
Copy link
Contributor

@dodokek dodokek commented Feb 4, 2025

Additionally fix .so file naming libtest-plugin.so -> libtest_plugin.so

Closes #51, #34

@dodokek dodokek force-pushed the more_versions branch 3 times, most recently from aab5e0b to 566f605 Compare February 4, 2025 14:21
@lowitea
Copy link
Collaborator

lowitea commented Feb 4, 2025

Я ещё не успел добавить соглашение про наименования коммитов, но давай, пожалуйста, соблюдать этот https://www.conventionalcommits.org/en/v1.0.0/

@@ -88,6 +88,9 @@ enum Plugin {
},
/// Alias for cargo build command
Build {
#[arg(long, value_name = "TARGET_DIR", default_value = "target")]
target_dir: PathBuf,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Надо добавить в редми

@@ -109,5 +137,7 @@ pub fn main(_params: &Params) {
}
}

// When plugin version is changed you MUST run cargo update before further use
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да вот нет, раз ты добавил тут перебилд при изменении Cargo.toml то не надо, тут стоит написать как раз что ты добавил это чтобы не делать cargo update

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хмм, я подумал сначала что мы не хотим злить людей, которые за выполнение пайплайна с cargo update, тогда поменяю да

Comment on lines 18 to 26
// Not proud with this code
Path::new(&env::var("OUT_DIR").unwrap())
.parent()
.unwrap()
.parent()
.unwrap()
.parent()
.unwrap()
.to_path_buf()
Copy link
Collaborator

@lowitea lowitea Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Должно примерно так сработать

Suggested change
// Not proud with this code
Path::new(&env::var("OUT_DIR").unwrap())
.parent()
.unwrap()
.parent()
.unwrap()
.parent()
.unwrap()
.to_path_buf()
Path::new(&env::var("OUT_DIR").unwrap())
.iter()
.nth_back(3)
.unwrap()
.into()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почитал доку Path, есть схема работы с этой штукой

Path::new(&env::var("OUT_DIR").unwrap())
        .ancestors()
        .take(4)
        .collect()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Огонь, а я этот метод не заметил

Path::new(&manifest_dir_string)
.join("target")
.join(build_type)
// Get output path from env variable to get path up until debug/ or release/ folder
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это надо переместить в докстринг функции

let pkg_version = env::var("CARGO_PKG_VERSION").unwrap();
let pkg_name = env::var("CARGO_PKG_NAME").unwrap();
let plugin_path = out_dir.join(&pkg_name).join(&pkg_version);
let lib_name = format!("lib{}.{}", pkg_name.replace('-', "_"), LIB_EXT);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
let lib_name = format!("lib{}.{}", pkg_name.replace('-', "_"), LIB_EXT);
let lib_name = format!("lib{}.{LIB_EXT}", pkg_name.replace('-', "_"));


for plugin_artefact in fs::read_dir(&plugin_version_path).unwrap() {
let entry = plugin_artefact.unwrap();
if entry.file_type().unwrap().is_symlink() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Предлагаю уменьшить вложенность и сделать "если не симлинт, тогда continue"

Comment on lines 55 to 63
if fs::exists(plugin_version_path.join(&lib_name)).unwrap() {
fs::remove_file(plugin_version_path.join(&lib_name)).unwrap();
}
fs::copy(out_dir.join(&lib_name), plugin_version_path.join(&lib_name)).unwrap();

// Copy manifest file
if fs::exists(plugin_version_path.join("manifest.yaml")).unwrap() {
fs::remove_file(plugin_version_path.join("manifest.yaml")).unwrap();
}
Copy link
Collaborator

@lowitea lowitea Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У тебя тут довольно странный код получается, логика странная, ты ищешь первую симлинку и если находишь, то начинаешь удалять остальные симлинки в папке. Надо просто проверить что найденная симлинка, это симлинка на бинарь, и тогда её удалить и заменить на файл. А на манифест вообще симлинки не надо делать, ты в билдскрипте его сам генеришь, надо просто всегда вместо симлинка копировать манифест в папку с версией

Comment on lines 71 to 73
if fs::exists(plugin_version_path.join("migrations")).unwrap() {
fs::remove_file(plugin_version_path.join("migrations")).unwrap();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

На миграции тоже симлинки не нужены, проще сразу их положить файлами в папку с версией

@@ -1,5 +1,6 @@
use anyhow::{bail, Context, Result};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не забудь поправить сообщение коммита

Cargo.toml Outdated
@@ -36,6 +36,7 @@ nix = "0.29.0"
colored = "3"
rand = "0.9"
derive_builder = "0.20"
toml_edit = "0.22.23"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это видимо должно быть в dev-dependencies

@dodokek dodokek force-pushed the more_versions branch 3 times, most recently from 5ae6404 to 6270e99 Compare February 5, 2025 11:03
Comment on lines 54 to 58
// Need to remove symlink before copying in order to properly replace symlink with file
if fs::exists(plugin_version_path.join(&lib_name)).unwrap() {
fs::remove_file(plugin_version_path.join(&lib_name)).unwrap();
}
fs::copy(out_dir.join(&lib_name), plugin_version_path.join(&lib_name)).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: можно было бы plugin_version_path.join(&lib_name) в переменную вынести

Comment on lines 54 to 58
// Need to remove symlink before copying in order to properly replace symlink with file
if fs::exists(plugin_version_path.join(&lib_name)).unwrap() {
fs::remove_file(plugin_version_path.join(&lib_name)).unwrap();
}
fs::copy(out_dir.join(&lib_name), plugin_version_path.join(&lib_name)).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit2: И кажется можно без if просто сразу попробовать удалить и забить на ошибку

tests/run.rs Outdated
}

let mut plugin_creation_proc =
run_pike(vec!["plugin", "new", "test_plugin"], TESTS_DIR).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давай сделаем тире в имени проекта и дополнительно проверим что ссылка ссылается на валидное имя. Раз чинили тут это

@dodokek dodokek force-pushed the more_versions branch 3 times, most recently from 5fa5b41 to 55fd54a Compare February 5, 2025 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants