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 2009/03/12 05:16:12 UTC

svn commit: r752768 - in /lucene/lucy/trunk/charmonizer: ./ src/Charmonizer/Probe/ src/Charmonizer/Test/

Author: marvin
Date: Thu Mar 12 04:16:10 2009
New Revision: 752768

URL: http://svn.apache.org/viewvc?rev=752768&view=rev
Log:
Expand directory probing to include dirent.h, mkdir.  Add a header probe for
sys/mman.h.

Added:
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/DirManip.charm
      - copied, changed from r692704, lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/DirSep.charm
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/DirManip.harm
      - copied, changed from r692704, lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/DirSep.harm
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/DirManip.charm
Removed:
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/DirSep.charm
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/DirSep.harm
Modified:
    lucene/lucy/trunk/charmonizer/charmonize.c
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/AllTests.charm
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/AllTests.harm

Modified: lucene/lucy/trunk/charmonizer/charmonize.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/charmonize.c?rev=752768&r1=752767&r2=752768&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/charmonize.c (original)
+++ lucene/lucy/trunk/charmonizer/charmonize.c Thu Mar 12 04:16:10 2009
@@ -7,13 +7,15 @@
 #include <string.h>
 #include <stdarg.h>
 #include "Charmonizer/Probe.h"
-#include "Charmonizer/Probe/DirSep.h"
+#include "Charmonizer/Probe/DirManip.h"
 #include "Charmonizer/Probe/FuncMacro.h"
 #include "Charmonizer/Probe/Headers.h"
 #include "Charmonizer/Probe/Integers.h"
 #include "Charmonizer/Probe/LargeFiles.h"
 #include "Charmonizer/Probe/UnusedVars.h"
 #include "Charmonizer/Probe/VariadicMacros.h"
+#include "Charmonizer/Core/HeadCheck.h"
+#include "Charmonizer/Core/ModHandler.h"
 
 char *cc_command, *cc_flags, *os_name, *verbosity_str;
 
@@ -49,7 +51,7 @@
     init(argc, argv);
 
     /* modules section */
-    chaz_DirSep_run();
+    chaz_DirManip_run();
     chaz_Headers_run();
     chaz_FuncMacro_run();
     chaz_Integers_run();
@@ -151,7 +153,9 @@
 static void
 write_charmony_postamble(void)
 {
-    /* No postamble for now. */
+    if (chaz_HeadCheck_check_header("sys/mman.h")) {
+        chaz_ModHand_append_conf("#define CHY_HAS_SYS_MMAN_H\n\n");
+    }
 }
 
 void 

Copied: lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/DirManip.charm (from r692704, lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/DirSep.charm)
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/DirManip.charm?p2=lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/DirManip.charm&p1=lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/DirSep.charm&r1=692704&r2=752768&rev=752768&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/DirSep.charm (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/DirManip.charm Thu Mar 12 04:16:10 2009
@@ -1,126 +1,121 @@
 #define CHAZ_USE_SHORT_NAMES
 
 #include "Charmonizer/Core/ModHandler.h"
+#include "Charmonizer/Core/Dir.h"
 #include "Charmonizer/Core/Util.h"
 #include "Charmonizer/Core/HeadCheck.h"
-#include "Charmonizer/Probe/DirSep.h"
+#include "Charmonizer/Probe/DirManip.h"
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 
-/* TODO: move mkdir and rmdir to a Core module a la Stat. */
-static char mkdir_code[] = METAQUOTE
-    #include "_charm.h"
-    %s
-    #include <sys/stat.h>
-    int main () {
-        Charm_Setup;
-        if (mkdir("_charm_test_dir_orig", 0777) == 0) {
-            printf("1");
-        }
-        return 0;
+void
+chaz_DirManip_run(void) 
+{
+    FILE *f;
+    char dir_sep[3];
+    chaz_bool_t dir_sep_is_valid = false;
+    chaz_bool_t remove_zaps_dirs = false;
+    chaz_bool_t has_dirent_h = check_header("dirent.h");
+    chaz_bool_t has_direct_h = check_header("direct.h");
+    chaz_bool_t has_dirent_d_namlen = false;
+    chaz_bool_t has_dirent_d_type   = false;
+
+    START_RUN("DirManip");
+    Dir_init();
+
+    /* Header checks. */
+    if (has_dirent_h) {
+        append_conf("#define CHY_HAS_DIRENT_H\n");
     }
-METAQUOTE;
-
-static char *headers[] = {
-    "direct.h",
-    "unistd.h",
-    "sys/stat.h",
-    NULL,
-};
-
-static char rmdir_code[] = METAQUOTE
-    #include "_charm.h"
-    %s
-    int main () {
-        Charm_Setup;
-        printf("1");
-        rmdir("_charm_test_dir_orig");
-        rmdir("_charm_test_dir_mod");
-        return 0;
+    if (has_direct_h) {
+        append_conf("#define CHY_HAS_DIRECT_H\n");
     }
-METAQUOTE;
 
-void
-chaz_DirSep_run(void) 
-{
-    int          i;
-    char        *output;
-    size_t       output_len;
-    char         dir_sep[3];
-    chaz_bool_t  dir_sep_is_valid = false;
-    char        *includes_buf = strdup("");
-    size_t       inc_buf_len = 2;
-    size_t       needed;
-    char        *code_buf;
-
-    START_RUN("DirSep");
-
-    /* Include any possible relevant headers. */
-    for (i = 0; headers[i] != NULL; i++) {
-        if (!check_header(headers[i])) 
-            break;
-        inc_buf_len = append_strings(&includes_buf, inc_buf_len, "#include <",
-            headers[i], ">\n", NULL);
-    }
-    needed = strlen(mkdir_code) + inc_buf_len + 10;
-    code_buf = malloc(needed);
-    sprintf(code_buf, mkdir_code, includes_buf);
-
-    /* create a directory */
-    output = capture_output(code_buf, strlen(code_buf), &output_len);
-
-    if (output != NULL && (strcmp(output, "1") == 0)) {
-        FILE *f;
-
-        /* clean up */
-        free(output);
-
-        /* try to create files under the new directory */
-        if ( (f = fopen("_charm_test_dir_orig\\backslash", "w")) != NULL)
-            fclose(f);
-        if ( (f = fopen("_charm_test_dir_orig/slash", "w")) != NULL)
-            fclose(f);
-
-        /* rename the directory, and see which file we can get to */
-        rename("_charm_test_dir_orig", "_charm_test_dir_mod");
-        if ( (f = fopen("_charm_test_dir_mod\\backslash", "r")) != NULL) {
-            fclose(f);
-            strcpy(dir_sep, "\\\\");
-            dir_sep_is_valid = true;
+    /* Check for members in struct dirent. */
+    if (has_dirent_h) {
+        has_dirent_d_namlen = HeadCheck_contains_member("struct dirent", 
+            "d_namlen", "#include <sys/types.h>\n#include <dirent.h>");
+        if (has_dirent_d_namlen) {
+            append_conf("#define CHY_HAS_DIRENT_D_NAMLEN\n", dir_sep);
         }
-        else if ( (f = fopen("_charm_test_dir_mod/slash", "r")) != NULL) {
-            fclose(f);
-            strcpy(dir_sep, "/");
-            dir_sep_is_valid = true;
+        has_dirent_d_type = HeadCheck_contains_member("struct dirent", 
+            "d_type", "#include <sys/types.h>\n#include <dirent.h>");
+        if (has_dirent_d_type) {
+            append_conf("#define CHY_HAS_DIRENT_D_TYPE\n", dir_sep);
         }
     }
 
-    /* clean up - delete all possible files without verifying */
+    if (Dir_mkdir_num_args == 2) {
+        /* It's two args, but the command isn't "mkdir". */
+        append_conf("#define chy_makedir(_dir, _mode) %s(_dir, _mode)\n",
+            Dir_mkdir_command);
+        append_conf("#define CHY_MAKEDIR_MODE_IGNORED 0\n");
+    }
+    else if (Dir_mkdir_num_args == 1) {
+        /* It's one arg... mode arg will be ignored. */
+        append_conf("#define chy_makedir(_dir, _mode) %s(_dir)\n",
+            Dir_mkdir_command);
+        append_conf("#define CHY_MAKEDIR_MODE_IGNORED 1\n");
+    }
+
+    /* Create a directory. */
+    Dir_mkdir("_charm_test_dir_orig");
+
+    /* Try to create files under the new directory. */
+    if ( (f = fopen("_charm_test_dir_orig\\backslash", "w")) != NULL) {
+        fclose(f);
+    }
+    if ( (f = fopen("_charm_test_dir_orig/slash", "w")) != NULL) {
+        fclose(f);
+    }
+
+    /* Rename the directory, then see which file we can get to. */
+    rename("_charm_test_dir_orig", "_charm_test_dir_mod");
+    if ( (f = fopen("_charm_test_dir_mod\\backslash", "r")) != NULL) {
+        fclose(f);
+        strcpy(dir_sep, "\\\\");
+        dir_sep_is_valid = true;
+    }
+    else if ( (f = fopen("_charm_test_dir_mod/slash", "r")) != NULL) {
+        fclose(f);
+        strcpy(dir_sep, "/");
+        dir_sep_is_valid = true;
+    }
+    if (dir_sep_is_valid) {
+        append_conf("#define CHY_DIR_SEP \"%s\"\n", dir_sep);
+    }
+
+    /* Clean up - delete all possible files without verifying. */
     remove("_charm_test_dir_mod/slash");
     remove("_charm_test_dir_mod\\backslash");
     remove("_charm_test_dir_orig/slash");
     remove("_charm_test_dir_orig\\backslash");
-    remove("_charm_test_dir_orig");
-    remove("_charm_test_dir_mod");
+    Dir_rmdir("_charm_test_dir_orig");
+    Dir_rmdir("_charm_test_dir_mod");
 
-    /* Try rmdir. */
-    sprintf(code_buf, rmdir_code, includes_buf);
-    output = capture_output(code_buf, strlen(code_buf), &output_len);
+    /* See whether remove works on directories. */
+    Dir_mkdir("_charm_test_remove_me");
+    if (0 == remove("_charm_test_remove_me")) {
+        remove_zaps_dirs = true;
+        append_conf("#define CHY_REMOVE_ZAPS_DIRS\n");
+    }
+    Dir_rmdir("_charm_test_remove_me");
 
-    if (dir_sep_is_valid) {
-        append_conf("#define CHY_DIR_SEP \"%s\"\n", dir_sep);
+    /* Shorten. */
+    START_SHORT_NAMES;
+    if (dir_sep_is_valid) { shorten_macro("DIR_SEP"); }
+    if (has_dirent_h)     { shorten_macro("HAS_DIRENT_H"); }
+    if (has_direct_h)     { shorten_macro("HAS_DIRECT_H"); }
+    if (has_dirent_d_namlen) { shorten_macro("HAS_DIRENT_D_NAMLEN"); }
+    if (has_dirent_d_type)   { shorten_macro("HAS_DIRENT_D_TYPE"); }
+    shorten_function("makedir");
+    shorten_macro("MAKEDIR_MODE_IGNORED");
+    if (remove_zaps_dirs) { shorten_macro("REMOVE_ZAPS_DIRS"); }
 
-        /* shorten */
-        START_SHORT_NAMES;
-        shorten_macro("DIR_SEP");
-        END_SHORT_NAMES;
-    }
+    END_SHORT_NAMES;
 
     END_RUN;
-
-    free(code_buf);
-    free(includes_buf);
 }
 
 

Copied: lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/DirManip.harm (from r692704, lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/DirSep.harm)
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/DirManip.harm?p2=lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/DirManip.harm&p1=lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/DirSep.harm&r1=692704&r2=752768&rev=752768&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/DirSep.harm (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/DirManip.harm Thu Mar 12 04:16:10 2009
@@ -1,21 +1,45 @@
-/* Charmonizer/Probe/DirSep.h
+/* Charmonizer/Probe/DirManip.h
  */
 
-#ifndef H_CHAZ_DIR_SEP
-#define H_CHAZ_DIR_SEP 
+#ifndef H_CHAZ_DIRMANIP
+#define H_CHAZ_DIRMANIP 
 
-/* Run the DirSep module.
+/* The DirManip module exports or aliases symbols related to directory and file
+ * manipulation.
  *
- * Exports one symbol, which is a string representing the system's directory
- * separator.
+ * Defined if the header files dirent.h and direct.h are available, respectively:
+ *
+ * HAS_DIRENT_H
+ * HAS_DIRECT_H
+ *
+ * Defined if struct dirent has these members.
  * 
- * DIR_SEP
+ * HAS_DIRENT_D_NAMLEN
+ * HAS_DIRENT_D_TYPE
+ *
+ * The "makedir" macro will be aliased to the POSIX-specified two-argument
+ * "mkdir" interface:  
+ * 
+ * makedir 
+ *
+ * On some systems, the second argument to makedir will be ignored, in which
+ * case this symbol will be true; otherwise, it will be false: (TODO: This
+ * isn't verified and may sometimes be incorrect.)
  * 
+ * MAKEDIR_MODE_IGNORED
+ *
+ * String representing the system's directory separator:
+ * 
+ * DIR_SEP
+ *
+ * True if the remove() function removes directories, false otherwise:
+ *
+ * REMOVE_ZAPS_DIRS
  */
-void chaz_DirSep_run(void);
+void chaz_DirManip_run(void);
 
 #ifdef CHAZ_USE_SHORT_NAMES
-  #define DirSep_run    chaz_DirSep_run
+  #define DirManip_run    chaz_DirManip_run
 #endif
 
 #endif /* H_CHAZ_DIR_SEP */

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/AllTests.charm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/AllTests.charm?rev=752768&r1=752767&r2=752768&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/AllTests.charm (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/AllTests.charm Thu Mar 12 04:16:10 2009
@@ -12,14 +12,15 @@
     chaz_Test_init();
 
     /* create a null-terminated array of test batches to iterate over */
-    batches = malloc(7 * sizeof(TestBatch*));
-    batches[0] = chaz_TFuncMacro_prepare();
-    batches[1] = chaz_THeaders_prepare();
-    batches[2] = chaz_TIntegers_prepare();
-    batches[3] = chaz_TLargeFiles_prepare();
-    batches[4] = chaz_TUnusedVars_prepare();
-    batches[5] = chaz_TVariadicMacros_prepare();
-    batches[6] = NULL;
+    batches = malloc(8 * sizeof(TestBatch*));
+    batches[0] = chaz_TDirManip_prepare();
+    batches[1] = chaz_TFuncMacro_prepare();
+    batches[2] = chaz_THeaders_prepare();
+    batches[3] = chaz_TIntegers_prepare();
+    batches[4] = chaz_TLargeFiles_prepare();
+    batches[5] = chaz_TUnusedVars_prepare();
+    batches[6] = chaz_TVariadicMacros_prepare();
+    batches[7] = NULL;
 }
 
 void

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/AllTests.harm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/AllTests.harm?rev=752768&r1=752767&r2=752768&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/AllTests.harm (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/AllTests.harm Thu Mar 12 04:16:10 2009
@@ -28,6 +28,10 @@
  * problem of silent failure is less severe than it appears, affecting only
  * fallbacks.
  */
+
+chaz_TestBatch* 
+chaz_TDirManip_prepare();
+
 chaz_TestBatch* 
 chaz_TFuncMacro_prepare();
 
@@ -47,6 +51,9 @@
 chaz_TVariadicMacros_prepare();
 
 void
+chaz_TDirManip_run(chaz_TestBatch *batch);
+
+void
 chaz_TFuncMacro_run(chaz_TestBatch *batch);
 
 void
@@ -65,6 +72,7 @@
 chaz_TVariadicMacros_run(chaz_TestBatch *batch);
 
 #ifdef CHAZ_USE_SHORT_NAMES
+  #define TDirManip_prepare            chaz_TDirManip_prepare
   #define TFuncMacro_prepare           chaz_TFuncMacro_prepare
   #define THeaders_prepare             chaz_THeaders_prepare
   #define TIntegers_prepare            chaz_TIntegers_prepare

Added: lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/DirManip.charm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/DirManip.charm?rev=752768&view=auto
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/DirManip.charm (added)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/DirManip.charm Thu Mar 12 04:16:10 2009
@@ -0,0 +1,74 @@
+#define CHAZ_USE_SHORT_NAMES
+
+#include "Charmonizer/Test.h"
+#include "Charmonizer/Test/AllTests.h"
+#include <stdio.h>
+#include <string.h>
+#include "charmony.h"
+#ifdef HAS_DIRENT_H
+  #include <dirent.h>
+#endif
+#ifdef HAS_SYS_STAT_H
+  #include <sys/stat.h>
+#endif
+#ifdef HAS_SYS_TYPES_H
+  #include <sys/stat.h>
+#endif
+#ifdef HAS_UNISTD_H
+  #include <unistd.h>
+#endif
+#ifdef HAS_DIRECT_H
+  #include <direct.h>
+#endif
+
+TestBatch*
+chaz_TDirManip_prepare()
+{
+    return Test_new_batch("Integers", 6, chaz_TDirManip_run);
+}
+
+void
+chaz_TDirManip_run(TestBatch *batch)
+{
+    ASSERT_INT_EQ(batch, 0, makedir("_chaz_test_dir", 0777), "makedir");
+    ASSERT_INT_EQ(batch, 0, makedir("_chaz_test_dir" DIR_SEP "deep", 0777),
+        "makedir with DIR_SEP");
+    ASSERT_INT_EQ(batch, 0, rmdir("_chaz_test_dir" DIR_SEP "deep"),
+        "rmdir with DIR_SEP");
+    ASSERT_INT_EQ(batch, 0, rmdir("_chaz_test_dir"), "rmdir");
+#ifdef CHY_HAS_DIRENT_D_NAMLEN
+    {
+        struct dirent entry;
+        entry.d_namlen = 5;
+        ASSERT_INT_EQ(batch, 5, entry.d_namlen, "d_namlen");
+    }
+#else
+    SKIP(batch, "no d_namlen member on this platform");
+#endif
+#ifdef CHY_HAS_DIRENT_D_TYPE
+    {
+        struct dirent entry;
+        entry.d_type = 5;
+        ASSERT_INT_EQ(batch, 5, entry.d_type, "d_type");
+    }
+#else
+    SKIP(batch, "no d_type member on this platform");
+#endif
+}
+
+/**
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+