Skip to content

Commit c12ef25

Browse files
committed
update: Fix clib-update with the new way of fetching packages, fix a bug with downloading packages from gitlab, move common definitinos to clib-settings
1 parent 8adc255 commit c12ef25

13 files changed

+178
-187
lines changed

src/clib-build.c

+1-8
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,14 @@
4040
#include <path-join/path-join.h>
4141
#include <str-flatten/str-flatten.h>
4242
#include <trim/trim.h>
43-
43+
#include "clib-settings.h"
4444
#include "version.h"
4545

46-
#define CLIB_PACKAGE_CACHE_TIME 30 * 24 * 60 * 60
4746
#define PROGRAM_NAME "clib-build"
4847

4948
#define SX(s) #s
5049
#define S(s) SX(s)
5150

52-
#ifdef HAVE_PTHREADS
53-
#define MAX_THREADS 4
54-
#endif
55-
5651
#ifndef DEFAULT_MAKE_CLEAN_TARGET
5752
#define DEFAULT_MAKE_CLEAN_TARGET "clean"
5853
#endif
@@ -83,8 +78,6 @@ struct options {
8378
#endif
8479
};
8580

86-
const char *manifest_names[] = {"clib.json", "package.json", 0};
87-
8881
clib_package_opts_t build_package_opts = {0};
8982
clib_package_t *root_package = 0;
9083

src/clib-configure.c

+1-8
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,14 @@
4040
#include <path-join/path-join.h>
4141
#include <str-flatten/str-flatten.h>
4242
#include <trim/trim.h>
43-
43+
#include "clib-settings.h"
4444
#include "version.h"
4545

46-
#define CLIB_PACKAGE_CACHE_TIME 30 * 24 * 60 * 60
4746
#define PROGRAM_NAME "clib-configure"
4847

4948
#define SX(s) #s
5049
#define S(s) SX(s)
5150

52-
#ifdef HAVE_PTHREADS
53-
#define MAX_THREADS 4
54-
#endif
55-
5651
#if defined(_WIN32) || defined(WIN32) || defined(__MINGW32__) || \
5752
defined(__MINGW64__) || defined(__CYGWIN__)
5853
#define setenv(k, v, _) _putenv_s(k, v)
@@ -74,8 +69,6 @@ struct options {
7469
#endif
7570
};
7671

77-
const char *manifest_names[] = {"clib.json", "package.json", 0};
78-
7972
clib_package_opts_t configure_package_opts = {0};
8073
clib_package_t *root_package = 0;
8174

src/clib-install.c

+1-8
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,11 @@
2323
#include <stdlib.h>
2424
#include <string.h>
2525
#include "clib-package-installer.h"
26-
27-
#define CLIB_PACKAGE_CACHE_TIME 30 * 24 * 60 * 60
26+
#include "clib-settings.h"
2827

2928
#define SX(s) #s
3029
#define S(s) SX(s)
3130

32-
#ifdef HAVE_PTHREADS
33-
#define MAX_THREADS 12
34-
#endif
35-
3631
#if defined(_WIN32) || defined(WIN32) || defined(__MINGW32__) || \
3732
defined(__MINGW64__) || defined(__CYGWIN__)
3833
#define setenv(k, v, _) _putenv_s(k, v)
@@ -61,8 +56,6 @@ struct options {
6156

6257
static struct options opts = {0};
6358

64-
static const char *manifest_names[] = {"clib.json", "package.json", NULL};
65-
6659
static clib_package_t *root_package = NULL;
6760
static clib_secrets_t secrets = NULL;
6861
static registries_t registries = NULL;

src/clib-search.c

+116-116
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
#include <string.h>
2828
#include <time.h>
2929
#include <url/url.h>
30+
#include "clib-settings.h"
3031

3132
#define CLIB_SEARCH_CACHE_TIME 1 * 24 * 60 * 60
3233

33-
#if defined(_WIN32) || defined(WIN32) || defined(__MINGW32__) || \
34-
defined(__MINGW64__) || defined(__CYGWIN__)
34+
#if defined(_WIN32) || defined(WIN32) || defined(__MINGW32__) || defined(__MINGW64__) || defined(__CYGWIN__)
3535
#define setenv(k, v, _) _putenv_s(k, v)
3636
#define realpath(a, b) _fullpath(a, b, strlen(a))
3737
#endif
@@ -48,50 +48,50 @@ static void setopt_nocache(command_t *self) { opt_cache = 0; }
4848

4949
static void setopt_json(command_t *self) { opt_json = 1; }
5050

51-
#define COMPARE(v) \
52-
{ \
53-
if (NULL == v) { \
54-
rc = 0; \
55-
goto cleanup; \
56-
} \
57-
case_lower(v); \
58-
for (int i = 0; i < count; i++) { \
59-
if (strstr(v, args[i])) { \
60-
rc = 1; \
61-
break; \
62-
} \
63-
} \
51+
#define COMPARE(v) \
52+
{ \
53+
if (NULL == v) { \
54+
rc = 0; \
55+
goto cleanup; \
56+
} \
57+
case_lower(v); \
58+
for (int i = 0; i < count; i++) { \
59+
if (strstr(v, args[i])) { \
60+
rc = 1; \
61+
break; \
62+
} \
63+
} \
6464
}
6565

6666
static int matches(int count, char *args[], registry_package_ptr_t pkg) {
67-
// Display all packages if there's no query
68-
if (0 == count)
69-
return 1;
70-
71-
char *description = NULL;
72-
char *name = NULL;
73-
char *repo = NULL;
74-
char *href = NULL;
75-
int rc = 0;
76-
77-
name = clib_package_parse_name(registry_package_get_id(pkg));
78-
COMPARE(name);
79-
80-
description = strdup(registry_package_get_description(pkg));
81-
COMPARE(description);
82-
83-
repo = strdup(registry_package_get_id(pkg));
84-
COMPARE(repo);
85-
86-
href = strdup(registry_package_get_href(pkg));
87-
COMPARE(href);
88-
89-
cleanup:
90-
free(description);
91-
free(name);
92-
free(repo);
93-
free(href);
94-
return rc;
67+
// Display all packages if there's no query
68+
if (0 == count)
69+
return 1;
70+
71+
char *description = NULL;
72+
char *name = NULL;
73+
char *repo = NULL;
74+
char *href = NULL;
75+
int rc = 0;
76+
77+
name = clib_package_parse_name(registry_package_get_id(pkg));
78+
COMPARE(name);
79+
80+
description = strdup(registry_package_get_description(pkg));
81+
COMPARE(description);
82+
83+
repo = strdup(registry_package_get_id(pkg));
84+
COMPARE(repo);
85+
86+
href = strdup(registry_package_get_href(pkg));
87+
COMPARE(href);
88+
89+
cleanup:
90+
free(description);
91+
free(name);
92+
free(repo);
93+
free(href);
94+
return rc;
9595
}
9696

9797
/*
@@ -125,67 +125,67 @@ static char *wiki_html_cache() {
125125
static void display_package(const registry_package_ptr_t pkg,
126126
cc_color_t fg_color_highlight,
127127
cc_color_t fg_color_text) {
128-
cc_fprintf(fg_color_highlight, stdout, " %s\n", registry_package_get_id(pkg));
129-
printf(" url: ");
130-
cc_fprintf(fg_color_text, stdout, "%s\n", registry_package_get_href(pkg));
131-
printf(" desc: ");
132-
cc_fprintf(fg_color_text, stdout, "%s\n", registry_package_get_description(pkg));
133-
printf("\n");
128+
cc_fprintf(fg_color_highlight, stdout, " %s\n", registry_package_get_id(pkg));
129+
printf(" url: ");
130+
cc_fprintf(fg_color_text, stdout, "%s\n", registry_package_get_href(pkg));
131+
printf(" desc: ");
132+
cc_fprintf(fg_color_text, stdout, "%s\n", registry_package_get_description(pkg));
133+
printf("\n");
134134
}
135135

136136
static void add_package_to_json(const registry_package_ptr_t pkg,
137137
JSON_Array *json_list) {
138-
JSON_Value *json_pkg_root = json_value_init_object();
139-
JSON_Object *json_pkg = json_value_get_object(json_pkg_root);
138+
JSON_Value *json_pkg_root = json_value_init_object();
139+
JSON_Object *json_pkg = json_value_get_object(json_pkg_root);
140140

141-
json_object_set_string(json_pkg, "repo", registry_package_get_id(pkg));
142-
json_object_set_string(json_pkg, "href", registry_package_get_href(pkg));
143-
json_object_set_string(json_pkg, "description", registry_package_get_description(pkg));
144-
json_object_set_string(json_pkg, "category", registry_package_get_category(pkg));
141+
json_object_set_string(json_pkg, "repo", registry_package_get_id(pkg));
142+
json_object_set_string(json_pkg, "href", registry_package_get_href(pkg));
143+
json_object_set_string(json_pkg, "description", registry_package_get_description(pkg));
144+
json_object_set_string(json_pkg, "category", registry_package_get_category(pkg));
145145

146-
json_array_append_value(json_list, json_pkg_root);
146+
json_array_append_value(json_list, json_pkg_root);
147147
}
148148

149149
int main(int argc, char *argv[]) {
150-
opt_color = 1;
151-
opt_cache = 1;
150+
opt_color = 1;
151+
opt_cache = 1;
152152

153-
debug_init(&debugger, "clib-search");
153+
debug_init(&debugger, "clib-search");
154154

155-
clib_cache_init(CLIB_SEARCH_CACHE_TIME);
155+
clib_cache_init(CLIB_SEARCH_CACHE_TIME);
156156

157-
command_t program;
158-
command_init(&program, "clib-search", CLIB_VERSION);
159-
program.usage = "[options] [query ...]";
157+
command_t program;
158+
command_init(&program, "clib-search", CLIB_VERSION);
159+
program.usage = "[options] [query ...]";
160160

161-
command_option(&program, "-n", "--no-color", "don't colorize output",
162-
setopt_nocolor);
161+
command_option(&program, "-n", "--no-color", "don't colorize output",
162+
setopt_nocolor);
163163

164-
command_option(&program, "-c", "--skip-cache", "skip the search cache",
165-
setopt_nocache);
164+
command_option(&program, "-c", "--skip-cache", "skip the search cache",
165+
setopt_nocache);
166166

167-
command_option(&program, "-j", "--json", "generate a serialized JSON output",
168-
setopt_json);
167+
command_option(&program, "-j", "--json", "generate a serialized JSON output",
168+
setopt_json);
169169

170-
command_parse(&program, argc, argv);
170+
command_parse(&program, argc, argv);
171171

172-
for (int i = 0; i < program.argc; i++)
173-
case_lower(program.argv[i]);
172+
for (int i = 0; i < program.argc; i++)
173+
case_lower(program.argv[i]);
174174

175-
// set color theme
176-
cc_color_t fg_color_highlight = opt_color ? CC_FG_DARK_CYAN : CC_FG_NONE;
177-
cc_color_t fg_color_text = opt_color ? CC_FG_DARK_GRAY : CC_FG_NONE;
175+
// set color theme
176+
cc_color_t fg_color_highlight = opt_color ? CC_FG_DARK_CYAN : CC_FG_NONE;
177+
cc_color_t fg_color_text = opt_color ? CC_FG_DARK_GRAY : CC_FG_NONE;
178178

179-
// We search the local manifest for extra registries.
180-
// It is important to give the extra registries preference over the default registry.
181-
clib_secrets_t secrets = clib_secrets_load_from_file("clib_secrets.json");
179+
// We search the local manifest for extra registries.
180+
// It is important to give the extra registries preference over the default registry.
181+
clib_secrets_t secrets = clib_secrets_load_from_file("clib_secrets.json");
182182

183-
clib_package_t *package = clib_package_load_local_manifest(0);
184-
registries_t registries = registry_manager_init_registries(package->registries, secrets);
185-
registry_manager_fetch_registries(registries);
183+
clib_package_t *package = clib_package_load_local_manifest(0);
184+
registries_t registries = registry_manager_init_registries(package->registries, secrets);
185+
registry_manager_fetch_registries(registries);
186186

187-
// TODO, implement caching for the new registries.
188-
/*
187+
// TODO, implement caching for the new registries.
188+
/*
189189
char *html = wiki_html_cache();
190190
if (NULL == html) {
191191
command_free(&program);
@@ -197,45 +197,45 @@ int main(int argc, char *argv[]) {
197197
debug(&debugger, "found %zu packages", pkgs->len);
198198
*/
199199

200-
registry_iterator_t it = registry_iterator_new(registries);
201-
registry_ptr_t registry = NULL;
202-
while ((registry = registry_iterator_next(it))) {
203-
printf("SEARCH: packages from %s\n", registry_get_url(registry));
204-
registry_package_ptr_t pkg;
205-
registry_package_iterator_t it = registry_package_iterator_new(registry);
200+
registry_iterator_t it = registry_iterator_new(registries);
201+
registry_ptr_t registry = NULL;
202+
while ((registry = registry_iterator_next(it))) {
203+
printf("SEARCH: packages from %s\n", registry_get_url(registry));
204+
registry_package_ptr_t pkg;
205+
registry_package_iterator_t it = registry_package_iterator_new(registry);
206206

207-
JSON_Array *json_list = NULL;
208-
JSON_Value *json_list_root = NULL;
207+
JSON_Array *json_list = NULL;
208+
JSON_Value *json_list_root = NULL;
209209

210-
if (opt_json) {
211-
json_list_root = json_value_init_array();
212-
json_list = json_value_get_array(json_list_root);
213-
}
210+
if (opt_json) {
211+
json_list_root = json_value_init_array();
212+
json_list = json_value_get_array(json_list_root);
213+
}
214214

215-
printf("\n");
216-
217-
while ((pkg = registry_package_iterator_next(it))) {
218-
if (matches(program.argc, program.argv, pkg)) {
219-
if (opt_json) {
220-
add_package_to_json(pkg, json_list);
221-
} else {
222-
display_package(pkg, fg_color_highlight, fg_color_text);
223-
}
224-
} else {
225-
debug(&debugger, "skipped package %s", registry_package_get_id(pkg));
226-
}
227-
}
215+
printf("\n");
228216

217+
while ((pkg = registry_package_iterator_next(it))) {
218+
if (matches(program.argc, program.argv, pkg)) {
229219
if (opt_json) {
230-
char *serialized = json_serialize_to_string_pretty(json_list_root);
231-
puts(serialized);
232-
233-
json_free_serialized_string(serialized);
234-
json_value_free(json_list_root);
220+
add_package_to_json(pkg, json_list);
221+
} else {
222+
display_package(pkg, fg_color_highlight, fg_color_text);
235223
}
224+
} else {
225+
debug(&debugger, "skipped package %s", registry_package_get_id(pkg));
226+
}
227+
}
236228

237-
registry_package_iterator_destroy(it);
229+
if (opt_json) {
230+
char *serialized = json_serialize_to_string_pretty(json_list_root);
231+
puts(serialized);
232+
233+
json_free_serialized_string(serialized);
234+
json_value_free(json_list_root);
238235
}
239-
command_free(&program);
240-
return 0;
236+
237+
registry_package_iterator_destroy(it);
238+
}
239+
command_free(&program);
240+
return 0;
241241
}

src/clib-settings.h

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef CLIB_SRC_CLIB_SETTINGS_H
2+
#define CLIB_SRC_CLIB_SETTINGS_H
3+
4+
// Shared settings
5+
#define CLIB_PACKAGE_CACHE_TIME 30 * 24 * 60 * 60
6+
7+
#ifdef HAVE_PTHREADS
8+
#define MAX_THREADS 12
9+
#endif
10+
11+
const char *manifest_names[] = {"clib.json", "package.json", 0};
12+
13+
#endif//CLIB_SRC_CLIB_SETTINGS_H

0 commit comments

Comments
 (0)