Skip to content

#291: Save dependencies to clib manifest by default #299

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

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ install: $(BINS)
uninstall:
$(foreach c, $(BINS), $(RM) $(PREFIX)/bin/$(c);)

test:
test: $(BINS)
@./test.sh

# create a list of auto dependencies
Expand Down
28 changes: 18 additions & 10 deletions src/clib-install.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ struct options {
char *token;
int verbose;
int dev;
int save;
int savedev;
int nosave;
int force;
int global;
int skip_cache;
Expand Down Expand Up @@ -89,15 +89,20 @@ static void setopt_dev(command_t *self) {
}

static void setopt_save(command_t *self) {
opts.save = 1;
debug(&debugger, "set save flag");
logger_warn("deprecated", "--save option is deprecated "
"(dependencies are now saved by default)");
}

static void setopt_savedev(command_t *self) {
opts.savedev = 1;
debug(&debugger, "set savedev flag");
}

static void setopt_nosave(command_t *self) {
opts.nosave = 1;
debug(&debugger, "set nosave flag");
}

static void setopt_force(command_t *self) {
opts.force = 1;
debug(&debugger, "set force flag");
Expand Down Expand Up @@ -304,10 +309,9 @@ static int install_package(const char *slug) {
pkg->repo = strdup(slug);
}

if (opts.save)
save_dependency(pkg);
if (opts.savedev)
save_dev_dependency(pkg);
if (!opts.nosave) {
opts.savedev ? save_dev_dependency(pkg) : save_dependency(pkg);
}

cleanup:
clib_package_free(pkg);
Expand Down Expand Up @@ -371,10 +375,14 @@ int main(int argc, char *argv[]) {
command_option(&program, "-d", "--dev", "install development dependencies",
setopt_dev);
command_option(&program, "-S", "--save",
"save dependency in clib.json or package.json", setopt_save);
"[DEPRECATED] save dependency in clib.json or package.json",
setopt_save);
command_option(&program, "-D", "--save-dev",
"save development dependency in clib.json or package.json",
setopt_savedev);
command_option(&program, "-N", "--no-save",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not super sure about the shorthand flag. If commander supports passing NULL here, maybe we just allow the long option only?

Copy link
Member

Choose a reason for hiding this comment

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

I think -N is okay!

Copy link
Member

@diasbruno diasbruno Nov 3, 2023

Choose a reason for hiding this comment

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

I opened a PR long time ago on commander to omit the short version. clibs/commander#25
I'll see if it still valid...

Copy link
Contributor Author

@exbotanical exbotanical Nov 4, 2023

Choose a reason for hiding this comment

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

@jwerle Cool, sounds good.

What's the standard procedure for clib - I push a tag (for this I'd bump the minor version) and merge? Thanks for the reviews!

"don't save dependency in clib.json or package.json",
setopt_nosave);
command_option(&program, "-f", "--force",
"force the action of something, like overwriting a file",
setopt_force);
Expand Down Expand Up @@ -430,8 +438,8 @@ int main(int argc, char *argv[]) {
unsigned long int size = strlen(prefix) + 1;
opts.prefix = malloc(size);

memset((void *) opts.prefix, 0, size);
memcpy((void *) opts.prefix, prefix, size);
memset((void *)opts.prefix, 0, size);
memcpy((void *)opts.prefix, prefix, size);
}

clib_cache_init(CLIB_PACKAGE_CACHE_TIME);
Expand Down
2 changes: 1 addition & 1 deletion test/install-binary-dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

clib install -c stephenmathieson/[email protected] -P tmp > /dev/null || {
clib install -c -N stephenmathieson/[email protected] -P tmp > /dev/null || {
echo >&2 "Failed to install stephenmathieson/tabs-to-spaces"
exit 1
}
Expand Down
2 changes: 1 addition & 1 deletion test/install-brace-expansion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ throw() {
exit 1
}

clib install -c -o tmp stephenmathieson/trim.c stephenmathieson/case.c > /dev/null ||
clib install -c -N -o tmp stephenmathieson/trim.c stephenmathieson/case.c > /dev/null ||
throw "expecting successful exit code"

[ -d ./tmp/case ] && [ -f ./tmp/case/package.json ] ||
Expand Down
2 changes: 1 addition & 1 deletion test/install-multiple-clibs-libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ throw() {
exit 1
}

clib install -c -o tmp ms file hash > /dev/null ||
clib install -c -N -o tmp ms file hash > /dev/null ||
throw "expecting successful exit code"

[ -d ./tmp/ms ] && [ -f ./tmp/ms/package.json ] ||
Expand Down
2 changes: 1 addition & 1 deletion test/install-multiple-libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ throw() {
exit 1
}

clib install -c -o tmp \
clib install -c -N -o tmp \
stephenmathieson/case.c stephenmathieson/trim.c > /dev/null ||
throw "expecting successful exit code"

Expand Down
30 changes: 30 additions & 0 deletions test/install-no-save.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh
mkdir -p tmp/test-save
cp test/data/test-save-package.json tmp/test-save/package.json

cd tmp/test-save || exit
../../clib-install -c --no-save stephenmathieson/[email protected] >/dev/null
../../clib-install -c -N darthtrevino/[email protected] >/dev/null
../../clib-install -c --dev --no-save jwerle/[email protected] >/dev/null
../../clib-install -c -d --no-save clibs/[email protected] >/dev/null
cd - || exit

if grep --quiet "stephenmathieson/tabs-to-spaces" tmp/test-save/package.json; then
echo >&2 "Found stephenmathieson/tabs-to-spaces saved in package.json but --no-save was used"
exit 1
fi

if grep --quiet "darthtrevino/str-concat" tmp/test-save/package.json; then
echo >&2 "Found darthtrevino/strconcat saved in package.json but --no-save was used"
exit 1
fi

if grep --quiet "jwerle/fs.c" tmp/test-save/package.json; then
echo >&2 "Found jwerle/fs.c saved in package.json but --no-save was used"
exit 1
fi

if grep --quiet "clibs/parson" tmp/test-save/package.json; then
echo >&2 "Found clibs/parson saved in package.json but --no-save was used"
exit 1
fi
6 changes: 3 additions & 3 deletions test/install-save.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ mkdir -p tmp/test-save
cp test/data/test-save-package.json tmp/test-save/package.json

cd tmp/test-save || exit
../../clib-install -c --save stephenmathieson/[email protected] >/dev/null
../../clib-install -c -S darthtrevino/[email protected] >/dev/null
../../clib-install -c --save-dev jwerle/[email protected] >/dev/null
../../clib-install -c stephenmathieson/[email protected] >/dev/null
../../clib-install -c darthtrevino/[email protected] >/dev/null
../../clib-install -c --dev jwerle/[email protected] >/dev/null
../../clib-install -c -D clibs/[email protected] >/dev/null
cd - || exit

Expand Down
2 changes: 1 addition & 1 deletion test/uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

mkdir -p tmp/bin

clib install -c stephenmathieson/[email protected] -P tmp > /dev/null || {
clib install -c -N stephenmathieson/[email protected] -P tmp > /dev/null || {
echo >&2 "Failed to install stephenmathieson/tabs-to-spaces"
exit 1
}
Expand Down