Skip to Content.
Sympa Menu

cc-devel - Re: [cc-devel] [ cctools-Bugs-1827893 ] liblicense make check fail

cc-devel AT lists.ibiblio.org

Subject: Developer discussion for Creative Commons technology and tools

List archive

Chronological Thread  
  • From: Hubert Figuiere <hub AT figuiere.net>
  • To: creative commons developers <cc-devel AT lists.ibiblio.org>
  • Subject: Re: [cc-devel] [ cctools-Bugs-1827893 ] liblicense make check fail
  • Date: Thu, 08 Nov 2007 01:49:36 -0500


On Wed, 2007-11-07 at 23:11 -0500, Hubert Figuiere wrote:
> On Thu, 2007-11-08 at 13:23 +1100, Peter Miller wrote:
> > If that's too radical, some kind of LIBLICENSE_MODULE_PATH environment
> > variable is clearly necessary, so that the automated tests can set it
> > and be guaranteed to be testing the modules built in the local checkout,
> > and not the installed modules.
>
> Given the current hierarchy we'd have to have a hook to make check to do
>
> (cd $top_builddir/modules ; DESTDIR=$builddir/modules make install)
>
> prior to actually running the checks.

I actually have done it and it works.

See attached patch.
PLEASE DO NOT COMMIT IT. This patch contain other minor changes that are
already in the patch queue.

I'll clean it up and attach to the bug.

Hub
Index: tests/Makefile.am
===================================================================
--- tests/Makefile.am	(revision 7906)
+++ tests/Makefile.am	(working copy)
@@ -18,12 +18,23 @@
 # Copyright (C) 2007 Peter Miller
 
 AM_CFLAGS = -I$(top_builddir)/liblicense
+AM_LDFLAGS=-static
 
+THISDIR = $(shell pwd)
+
+DEBUG_LL_MODULES_PATH=$(THISDIR)/_prefix/$(prefix)
+
+TESTS_ENVIRONMENT = LL_IO_MODULE_DIR=$(DEBUG_LL_MODULES_PATH)/lib/liblicense/io/ \
+	 LL_CONFIG_MODULE_DIR=$(DEBUG_LL_MODULES_PATH)/lib/liblicense/config/
 TESTS = test test_list test_default test_mw test_read test_info test_write test_chooser
 
-check_PROGRAMS = $(TESTS)
-noinst_PROGRAMS = $(TESTS)
+modules:
+	mkdir -p _prefix
+	(cd $(top_builddir)/modules ; DESTDIR=$(THISDIR)/_prefix make install)
 
+
+check_PROGRAMS = modules $(TESTS)
+
 test_SOURCES = \
 	test.c
 
Index: liblicense/modules.h
===================================================================
--- liblicense/modules.h	(revision 0)
+++ liblicense/modules.h	(revision 0)
@@ -0,0 +1,28 @@
+/*
+ * Creative Commons has made the contents of this file
+ * available under a CC-GNU-LGPL license:
+ *
+ * http://creativecommons.org/licenses/LGPL/2.1/
+ *
+ * A copy of the full license can be found as part of this
+ * distribution in the file COPYING.
+ *
+ * You may use the liblicense software in accordance with the
+ * terms of that license. You agree that you are solely
+ * responsible for your use of the liblicense software and you
+ * represent and warrant to Creative Commons that your use
+ * of the liblicense software will comply with the CC-GNU-LGPL.
+ *
+ * Copyright 2007, Creative Commons, www.creativecommons.org.
+ * Copyright 2007, Hubert Figuiere
+ */
+
+
+#ifndef __MODULES_H__
+#define __MODULES_H__
+
+extern const char *liblicense_io_module_dir;
+extern const char *liblicense_config_module_dir;
+
+
+#endif
Index: liblicense/liblicense.h
===================================================================
--- liblicense/liblicense.h	(revision 7906)
+++ liblicense/liblicense.h	(working copy)
@@ -868,11 +868,11 @@
 
 struct _LLModuleDesc
 {
-  char *name;
-  char *description;
-  char *version;
+  const char *name;
+  const char *description;
+  const char *version;
   int features;
-  char *mime_types;
+  const char *mime_types;
   LLModuleInitFunc module_init;
   LLModuleReadFunc read;
   LLModuleWriteFunc write;
Index: liblicense/module_wrangler.c
===================================================================
--- liblicense/module_wrangler.c	(revision 7906)
+++ liblicense/module_wrangler.c	(working copy)
@@ -37,6 +37,11 @@
 #include "config.h"
 #endif
 
+#include "modules.h"
+
+const char *liblicense_io_module_dir;
+const char *liblicense_config_module_dir;
+
 LLModuleDesc **_ll_module_list = NULL;
 
 int _ll_so_filter(const struct dirent * d) {
@@ -49,11 +54,14 @@
 	LLModuleDesc **curr_module;
 	int i;
 
+	liblicense_io_module_dir = getenv("LL_IO_MODULE_DIR");
+	if (liblicense_io_module_dir == NULL)
+		liblicense_io_module_dir = LIBLICENSE_IO_MODULE_DIR;
 	if (_ll_module_list) return;
-	n = scandir(LIBLICENSE_IO_MODULE_DIR , &namelist, _ll_so_filter, alphasort);
+	n = scandir(liblicense_io_module_dir , &namelist, _ll_so_filter, alphasort);
 	if (n==-1) {
 		fprintf(stderr, "scandir(\"%s\"): %s\n",
-                        LIBLICENSE_IO_MODULE_DIR, strerror(errno));
+                        liblicense_io_module_dir, strerror(errno));
 		return;
 	}
 
@@ -61,11 +69,11 @@
 	curr_module = _ll_module_list;
 
 	for (i=0;i<n;++i) {
-		char reg_file[strlen(LIBLICENSE_IO_MODULE_DIR)+strlen(namelist[i]->d_name)+1];
+		char reg_file[strlen(liblicense_io_module_dir)+strlen(namelist[i]->d_name)+1];
 		void *handle;
 
 		reg_file[0]='\0';
-		strcat(reg_file,LIBLICENSE_IO_MODULE_DIR);
+		strcat(reg_file,liblicense_io_module_dir);
 		strcat(reg_file,namelist[i]->d_name);
 
 		handle = dlopen(reg_file,RTLD_LAZY);
@@ -91,12 +99,14 @@
 
 void ll_stop_modules() {
 	LLModuleDesc **curr_module = _ll_module_list;
-	while (*curr_module) {
-		dlclose((*curr_module)->handle);
-		++curr_module;
+	if( curr_module ) {
+		while (*curr_module) {
+			dlclose((*curr_module)->handle);
+			++curr_module;
+		}
+		free(_ll_module_list);
+		_ll_module_list = NULL;
 	}
-	free(_ll_module_list);
-	_ll_module_list = NULL;
 }
 
 ll_module_t* ll_get_config_modules() {
@@ -105,9 +115,13 @@
   ll_module_t* result;
   int i;
 
-  n = scandir(LIBLICENSE_CONFIG_MODULE_DIR , &namelist, _ll_so_filter, alphasort);
+  liblicense_config_module_dir = getenv("LL_CONFIG_MODULE_DIR");
+  if (liblicense_config_module_dir == NULL)
+	  liblicense_config_module_dir = LIBLICENSE_CONFIG_MODULE_DIR;
+
+  n = scandir(liblicense_config_module_dir, &namelist, _ll_so_filter, alphasort);
   if (n==-1) {
-  	fprintf(stderr, "scandir(\"%s\"): %s", LIBLICENSE_CONFIG_MODULE_DIR,
+	  fprintf(stderr, "scandir(\"%s\"): %s", liblicense_config_module_dir,
             strerror(errno));
   	return ll_new_list(0);
   }
Index: liblicense/Makefile.am
===================================================================
--- liblicense/Makefile.am	(revision 7906)
+++ liblicense/Makefile.am	(working copy)
@@ -50,4 +50,5 @@
 	write_license.c \
 	$(licenses)
 
+noinst_HEADERS = modules.h
 include_HEADERS = liblicense.h
Index: liblicense/system_default.c
===================================================================
--- liblicense/system_default.c	(revision 7906)
+++ liblicense/system_default.c	(working copy)
@@ -30,6 +30,8 @@
 #include "config.h"
 #endif
 
+#include "modules.h"
+
 int
 ll_set_default (const ll_uri_t u)
 {
@@ -47,12 +49,12 @@
     {
       int (*set_default) (ll_uri_t);
 
-      ll_module_init (LIBLICENSE_CONFIG_MODULE_DIR, modules[i]);
+      ll_module_init (liblicense_config_module_dir, modules[i]);
       set_default =
-        ll_get_module_symbol (LIBLICENSE_CONFIG_MODULE_DIR, modules[i],
+        ll_get_module_symbol (liblicense_config_module_dir, modules[i],
                               "set_default");
       result = (result && set_default (u));
-      ll_module_shutdown (LIBLICENSE_CONFIG_MODULE_DIR, modules[i]);
+      ll_module_shutdown (liblicense_config_module_dir, modules[i]);
       i++;
     }
   ll_free_list (modules);
@@ -81,12 +83,12 @@
     {
       ll_uri_t (*get_default) (void);
 
-      ll_module_init (LIBLICENSE_CONFIG_MODULE_DIR, modules[i]);
+      ll_module_init (liblicense_config_module_dir, modules[i]);
       get_default =
-        ll_get_module_symbol (LIBLICENSE_CONFIG_MODULE_DIR, modules[i],
+        ll_get_module_symbol (liblicense_config_module_dir, modules[i],
                               "get_default");
       responses[i] = get_default ();
-      ll_module_shutdown (LIBLICENSE_CONFIG_MODULE_DIR, modules[i]);
+      ll_module_shutdown (liblicense_config_module_dir, modules[i]);
       i++;
     }
   final_answer = ll_list_mode (responses, "");
Index: liblicense/licenses_cached.c
===================================================================
--- liblicense/licenses_cached.c	(revision 7906)
+++ liblicense/licenses_cached.c	(working copy)
@@ -67,13 +67,13 @@
 	return strstr(d->d_name,".rdf")!=NULL;
 }
 char* _ll_cache_time_filename() {
+    struct stat sb;
 	char* home = getenv("HOME");
     char* path = (char*) calloc((strlen(home)+strlen("/.license/last_cache.time")+1),sizeof(char));
     path[0] = '\0';
     strcat(path,home);
     strcat(path,"/.license/");
     /* make directory as needed*/
-    struct stat sb;
     if (stat(path, &sb) == -1) {
         if (mkdir(path,(S_IRWXU | S_IRGRP | S_IROTH))==-1) {
             fprintf(stderr,"Failed to make directory.\n");
@@ -87,29 +87,32 @@
     return path;
 }
 int _ll_last_cache_time() {
+	FILE* file;
+    char tmp[15] = "";
+	time_t t;
 	char* path = _ll_cache_time_filename();
 	if (path == NULL) {
         free(path);
         return 0;
     }
-    FILE* file = fopen(path,"r");
+    file = fopen(path,"r");
     free(path);
     if (file==NULL)
         return 0;
-    char tmp[15] = "";
     fgets(tmp,15,file);
     fclose(file);
-    time_t t = (time_t) atoi(tmp);
+    t = (time_t) atoi(tmp);
     return t;
 }
 
 int _ll_update_cache_time() {
+	FILE* file;
 	char* path = _ll_cache_time_filename();
 	if (path == NULL) {
         free(path);
         return false;
     }
-    FILE* file = fopen(path,"w");
+    file = fopen(path,"w");
     free(path);
     fprintf(file,"%d",(int) time(NULL));
     fclose(file);
@@ -117,6 +120,10 @@
 }
 
 int ll_update_cache() {
+	int i;
+	int n;
+	time_t last_cache;
+	struct dirent **namelist;
 	/* check last update time versus license file update */
 
 	/* create table if it doesn't exist. */
@@ -127,10 +134,8 @@
 		return false;
 	}
 	/* insert newly modified files */
-	struct dirent **namelist;
-	int n = scandir(LICENSE_DIR, &namelist, _ll_rdf_filter, alphasort);
-	int i;
-	time_t last_cache = _ll_last_cache_time();
+	n = scandir(LICENSE_DIR, &namelist, _ll_rdf_filter, alphasort);
+	last_cache = _ll_last_cache_time();
 	for (i=0;i<n;++i) {
 		ll_uri_t u = ll_filename_to_uri(namelist[i]->d_name);
 		ll_filename_t fn = ll_uri_to_filename(u);
@@ -143,12 +148,12 @@
 			continue;
 		}
 		if (fileinfo.st_mtime>last_cache) {
+			char* query;
 			/* Get data */
 			ll_juris_t j = ll_get_jurisdiction(u);
 			ll_uri_t *successor = ll_get_attribute(u, LL_ATTRIBUTE_URI_REPLACED_BY,0);
 			int obsolete = ll_list_length(successor);
 			ll_free_list(successor);
-			char* query;
 			/* build insert query */
 			if (j!=NULL){
 				size_t buf_size = sizeof(char)*(strlen("INSERT INTO licenses VALUES ('','',)")+strlen(u)+strlen(j)+2);
@@ -172,17 +177,20 @@
 }
 // initializes the library and its dependencies.
 int ll_init() {
+	char* home;
+	char* path;
+    struct stat sb;
+
 	raptor_init();
 	setlocale(LC_ALL,"");
 
 	/* get the filename for the cache */
-	char* home = getenv("HOME");
-    char* path = (char*) calloc((strlen(home)+strlen("/.license/license_cache.db")+1),sizeof(char));
+	home = getenv("HOME");
+    path = (char*) calloc((strlen(home)+strlen("/.license/license_cache.db")+1),sizeof(char));
     path[0] = '\0';
     strcat(path,home);
     strcat(path,"/.license/");
     /* make directory as needed*/
-    struct stat sb;
     if (stat(path, &sb) == -1) {
         if (mkdir(path,(S_IRWXU | S_IRGRP | S_IROTH))==-1) {
             fprintf(stderr,"Failed to make directory.\n");
@@ -218,9 +226,11 @@
 // returns a null-terminated list of all general licenses in a family.
 ll_uri_t* ll_get_licenses(const ll_juris_t _j) {
 	ll_juris_t j = _j;
-	if (j && strcmp(j,"unported") == 0) j = NULL;
+	ll_uri_t* result;
+	char* query;
+	if (j && strcmp(j,"unported") == 0) 
+		j = NULL;
 
-	char* query;
 	if (j!=NULL){
 		size_t buf_size = sizeof(char)*(strlen("SELECT uri FROM licenses WHERE jurisdiction='' AND obsolete=0 LIMIT 15")+strlen(j)+1);
 		query = (char*) malloc(buf_size);
@@ -228,7 +238,7 @@
 	} else {
 		query = strdup("SELECT uri FROM licenses WHERE jurisdiction ISNULL AND obsolete=0 LIMIT 15");
 	}
-	ll_uri_t* result = _ll_query(query,15);
+	result = _ll_query(query,15);
 	free(query);
   	return result;
 }



Archive powered by MHonArc 2.6.24.

Top of Page