You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2006/11/02 17:36:09 UTC
svn commit: r470412 - in
/lucene/lucy/trunk/charmonizer/src/Charmonizer/Core: Compiler.charm
Compiler.harm
Author: marvin
Date: Thu Nov 2 08:36:08 2006
New Revision: 470412
URL: http://svn.apache.org/viewvc?view=rev&rev=470412
Log:
Add the add_inc_dir() method to Compiler which adds an include dir for the
compiler to search. Start off by adding the current directory (which was the
hard-coded prior behavior).
Modified:
lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.charm
lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.harm
Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.charm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.charm?view=diff&rev=470412&r1=470411&r2=470412
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.charm (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.charm Thu Nov 2 08:36:08 2006
@@ -21,6 +21,9 @@
const char *code, size_t code_len);
static void
+add_inc_dir(Compiler *self, const char *dir);
+
+static void
test_compile(Compiler *self);
chaz_Compiler*
@@ -42,13 +45,19 @@
self->buf_len = 0;
self->compile_exe = compile_exe;
self->compile_obj = compile_obj;
+ self->add_inc_dir = add_inc_dir;
self->destroy = destroy;
+ self->inc_dirs = (char**)calloc(sizeof(char*), 1);
/* set compiler-specific vars */
self->include_flag = strdup(compiler_spec->include_flag);
self->object_flag = strdup(compiler_spec->object_flag);
self->exe_flag = strdup(compiler_spec->exe_flag);
+ /* add the current directory as an include dir */
+ self->add_inc_dir(self, ".");
+
+ /* if we can't compile anything, game over */
test_compile(self);
return self;
@@ -57,6 +66,13 @@
static void
destroy(Compiler *self)
{
+ char **inc_dirs;
+
+ for (inc_dirs = self->inc_dirs; *inc_dirs != NULL; inc_dirs++) {
+ free(*inc_dirs);
+ }
+ free(self->inc_dirs);
+
free(self->buf);
free(self->cc_command);
free(self->cc_flags);
@@ -73,6 +89,7 @@
chaz_bool_t successful;
OperSys *os = self->os;
char *exe_full_filepath = NULL;
+ char **inc_dirs;
/* tack the exe_ext onto the path */
join_strings(&exe_full_filepath, 0, exe_path, os->exe_ext, NULL);
@@ -80,22 +97,26 @@
/* write the source file */
write_file(source_path, code, code_len);
- /* compile the source */
+ /* prepare the compiler command */
if (verbosity < 2 && chaz_ModHand_charm_run_available) {
- join_strings(&(self->buf), self->buf_len,
+ self->buf_len = join_strings(&(self->buf), self->buf_len,
os->local_command_start, "_charm_run ", self->cc_command, " ",
- source_path, " ", self->exe_flag, exe_full_filepath, " ",
- self->include_flag, ". ", self->cc_flags, NULL);
+ source_path, " ", self->exe_flag, exe_full_filepath, " ", NULL);
}
else {
- join_strings(&(self->buf), self->buf_len,
+ self->buf_len = join_strings(&(self->buf), self->buf_len,
self->cc_command, " ", source_path, " ", self->exe_flag,
- exe_full_filepath, " ", self->include_flag, ". ", self->cc_flags,
- NULL);
+ exe_full_filepath, " ", NULL);
}
- system(self->buf);
+ for (inc_dirs = self->inc_dirs; *inc_dirs != NULL; inc_dirs++) {
+ self->buf_len = append_strings(&(self->buf), self->buf_len,
+ self->include_flag, *inc_dirs, " ", NULL);
+ }
+ self->buf_len = append_strings(&(self->buf), self->buf_len,
+ self->cc_flags, " ", NULL);
- /* see if compilation was successful */
+ /* execute the compiler command and detect success/failure */
+ system(self->buf);
successful = can_open_file(exe_full_filepath);
free(exe_full_filepath);
@@ -155,6 +176,22 @@
if (!success)
die("Failed to compile a small test file");
+}
+
+static void
+add_inc_dir(Compiler *self, const char *dir)
+{
+ size_t num_dirs = 2; /* includes the passed-in dir */
+ char **dirs = self->inc_dirs;
+
+ while (*dirs++ != NULL) {
+ num_dirs++;
+ }
+
+ self->inc_dirs == realloc(self->inc_dirs, num_dirs + 1);
+ self->inc_dirs[num_dirs] = NULL;
+ self->inc_dirs[num_dirs - 1] = strdup(dir);
+
}
/**
Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.harm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.harm?view=diff&rev=470412&r1=470411&r2=470412
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.harm (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.harm Thu Nov 2 08:36:08 2006
@@ -26,6 +26,12 @@
const char *obj_path, const char *code,
size_t code_len);
+/* Add an include directory which will be used for all future compilation
+ * attempts.
+ */
+typedef void
+(*chaz_CC_add_inc_dir_t)(chaz_Compiler *self, const char *dir);
+
/* Destructor.
*/
typedef void
@@ -38,10 +44,12 @@
char *include_flag;
char *object_flag;
char *exe_flag;
+ char **inc_dirs;
char *buf;
size_t buf_len;
chaz_CC_compile_exe_t compile_exe;
chaz_CC_compile_obj_t compile_obj;
+ chaz_CC_add_inc_dir_t add_inc_dir;
chaz_CC_destroy_t destroy;
};
@@ -55,6 +63,7 @@
# define Compiler chaz_Compiler
# define CC_compile_exe_t chaz_CC_compile_exe_t
# define CC_compile_obj_t chaz_CC_compile_obj_t
+# define CC_add_inc_dir_t chaz_CC_add_inc_dir_t
# define CC_destroy_t chaz_CC_destroy_t
# define CC_new chaz_CC_new
#endif