-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
aab5e0b
to
566f605
Compare
Я ещё не успел добавить соглашение про наименования коммитов, но давай, пожалуйста, соблюдать этот 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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Надо добавить в редми
src/helpers/build/mod.rs
Outdated
@@ -109,5 +137,7 @@ pub fn main(_params: &Params) { | |||
} | |||
} | |||
|
|||
// When plugin version is changed you MUST run cargo update before further use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Да вот нет, раз ты добавил тут перебилд при изменении Cargo.toml то не надо, тут стоит написать как раз что ты добавил это чтобы не делать cargo update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Хмм, я подумал сначала что мы не хотим злить людей, которые за выполнение пайплайна с cargo update
, тогда поменяю да
src/helpers/build/mod.rs
Outdated
// Not proud with this code | ||
Path::new(&env::var("OUT_DIR").unwrap()) | ||
.parent() | ||
.unwrap() | ||
.parent() | ||
.unwrap() | ||
.parent() | ||
.unwrap() | ||
.to_path_buf() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Должно примерно так сработать
// 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() |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Огонь, а я этот метод не заметил
src/helpers/build/mod.rs
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это надо переместить в докстринг функции
src/helpers/build/mod.rs
Outdated
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
let lib_name = format!("lib{}.{}", pkg_name.replace('-', "_"), LIB_EXT); | |
let lib_name = format!("lib{}.{LIB_EXT}", pkg_name.replace('-', "_")); |
src/helpers/build/mod.rs
Outdated
|
||
for plugin_artefact in fs::read_dir(&plugin_version_path).unwrap() { | ||
let entry = plugin_artefact.unwrap(); | ||
if entry.file_type().unwrap().is_symlink() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Предлагаю уменьшить вложенность и сделать "если не симлинт, тогда continue"
src/helpers/build/mod.rs
Outdated
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(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
У тебя тут довольно странный код получается, логика странная, ты ищешь первую симлинку и если находишь, то начинаешь удалять остальные симлинки в папке. Надо просто проверить что найденная симлинка, это симлинка на бинарь, и тогда её удалить и заменить на файл. А на манифест вообще симлинки не надо делать, ты в билдскрипте его сам генеришь, надо просто всегда вместо симлинка копировать манифест в папку с версией
src/helpers/build/mod.rs
Outdated
if fs::exists(plugin_version_path.join("migrations")).unwrap() { | ||
fs::remove_file(plugin_version_path.join("migrations")).unwrap(); | ||
} |
There was a problem hiding this comment.
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}; |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это видимо должно быть в dev-dependencies
5ae6404
to
6270e99
Compare
src/helpers/build/mod.rs
Outdated
// 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(); |
There was a problem hiding this comment.
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) в переменную вынести
src/helpers/build/mod.rs
Outdated
// 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(); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Давай сделаем тире в имени проекта и дополнительно проверим что ссылка ссылается на валидное имя. Раз чинили тут это
5fa5b41
to
55fd54a
Compare
55fd54a
to
97db00c
Compare
Additionally fix .so file naming
libtest-plugin.so
->libtest_plugin.so
Closes #51, #34