RNA
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 8 Jan 2009 13:57:29 +0000 (13:57 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 8 Jan 2009 13:57:29 +0000 (13:57 +0000)
* The generated code is now split into multiple files instead
  of a single big one. Scons, make and cmake are updated to
  deal with this.

14 files changed:
source/blender/makesrna/RNA_types.h
source/blender/makesrna/intern/CMakeLists.txt
source/blender/makesrna/intern/Makefile
source/blender/makesrna/intern/SConscript
source/blender/makesrna/intern/makesrna.c
source/blender/makesrna/intern/rna_ID.c
source/blender/makesrna/intern/rna_internal.h
source/blender/makesrna/intern/rna_lattice.c
source/blender/makesrna/intern/rna_meta.c
source/blender/makesrna/intern/rna_modifier.c
source/blender/makesrna/intern/rna_object.c
source/blender/makesrna/intern/rna_rna.c
source/blender/makesrna/intern/rna_scene.c
source/blender/makesrna/intern/rna_text.c

index e4aceb0a81ba9a6655d8f5c1d4ae3a8d36017159..fc98a0ad594c1bfea4f436273c611a4914442570 100644 (file)
@@ -132,7 +132,8 @@ typedef enum StructFlag {
        STRUCT_ID = 1,
 
        /* internal flags */
-       STRUCT_RUNTIME = 2
+       STRUCT_RUNTIME = 2,
+       STRUCT_GENERATED = 4
 } StructFlag;
 
 typedef struct StructRNA StructRNA;
index 4a537d031a0bdbfcc9095c35d99a1a08361700e0..5eaef1ab246c30eedaf565d10b10f6ba9c9aac62 100644 (file)
@@ -24,8 +24,7 @@
 #
 # ***** END GPL LICENSE BLOCK *****
 
-SET(SRC
-     makesrna.c
+SET(DEFSRC
      rna_action.c
      rna_actuator.c
      rna_armature.c
@@ -36,7 +35,6 @@ SET(SRC
      rna_constraint.c
      rna_controller.c
      rna_curve.c
-     rna_define.c
      rna_fluidsim.c
      rna_group.c
      rna_ID.c
@@ -70,7 +68,58 @@ SET(SRC
      rna_userdef.c
      rna_vfont.c
      rna_wm.c
-     rna_world.c
+     rna_world.c)
+
+SET(GENSRC
+     rna_action_gen.c
+     rna_actuator_gen.c
+     rna_armature_gen.c
+     rna_brush_gen.c
+     rna_camera_gen.c
+     rna_cloth_gen.c
+     rna_color_gen.c
+     rna_constraint_gen.c
+     rna_controller_gen.c
+     rna_curve_gen.c
+     rna_fluidsim_gen.c
+     rna_group_gen.c
+     rna_ID_gen.c
+     rna_image_gen.c
+     rna_ipo_gen.c
+     rna_key_gen.c
+     rna_lamp_gen.c
+     rna_lattice_gen.c
+     rna_main_gen.c
+     rna_material_gen.c
+     rna_mesh_gen.c
+     rna_meta_gen.c
+     rna_modifier_gen.c
+     rna_nodetree_gen.c
+     rna_object_gen.c
+     rna_object_force_gen.c
+     rna_packedfile_gen.c
+     rna_particle_gen.c
+     rna_pose_gen.c
+     rna_property_gen.c
+     rna_radio_gen.c
+     rna_rna_gen.c
+     rna_scene_gen.c
+     rna_screen_gen.c
+     rna_scriptlink_gen.c
+     rna_sensor_gen.c
+     rna_sequence_gen.c
+     rna_sound_gen.c
+     rna_text_gen.c
+     rna_texture_gen.c
+     rna_userdef_gen.c
+     rna_vfont_gen.c
+     rna_wm_gen.c
+     rna_world_gen.c)
+
+SET(SRC
+     makesrna.c
+     rna_define.c
+     ${DEFSRC}
      ../../../../intern/guardedalloc/intern/mallocn.c
      ../../../../intern/guardedalloc/intern/mmap_win.c)
 
@@ -81,15 +130,16 @@ FILE(GLOB INC_FILES ../*.h ../../makesdna/*.h)
 ADD_EXECUTABLE(makesrna ${SRC} ${INC_FILES})
 TARGET_LINK_LIBRARIES(makesrna bf_dna)
 
-# Output rna.c
+# Output rna_*_gen.c
 ADD_CUSTOM_COMMAND(
-  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rna.c
-  COMMAND ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/makesrna ${CMAKE_CURRENT_BINARY_DIR}/rna.c ${CMAKE_SOURCE_DIR}/source/blender/makesrna/
+  OUTPUT ${GENSRC}
+  COMMAND ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/makesrna ${CMAKE_CURRENT_BINARY_DIR}/ ${CMAKE_SOURCE_DIR}/source/blender/makesrna/
   DEPENDS makesrna
 )
 
 # Build bf_rna
-SET(SRC rna_access.c rna_dependency.c rna.c)
+SET(SRC rna_access.c rna_dependency.c ${GENSRC})
 BLENDERLIB(bf_rna "${SRC}" "${INC}")
 
 MESSAGE(STATUS "Configuring makesrna")
+
index e844d74decf8788396940ca726bffc7acec0020b..aad4acdbf388036088f86e0babfb7c573ece2054 100644 (file)
 
 LIBNAME = rna
 DIR = $(OCGDIR)/blender/makesrna
-CSRCS = RNA.c $(wildcard rna_*.c)
+
+ALLRNA = $(wildcard rna_*.c)
+DEFRNA = $(filter-out %rna_define.c, $(filter-out %rna_dependency.c, $(filter-out %rna_access.c, $(ALLRNA))))
+
+GENSRCS = $(patsubst rna_%.c, rna_%_gen.c, $(DEFRNA))
+GENTARGET = $(patsubst %.c, $(DIR)/$(DEBUG_DIR)%.c, $(GENSRCS))
+
+MAKESRCS = $(DEFRNA) makesrna.c rna_define.c
+MAKEOBJS = $(patsubst %.c, $(DIR)/$(DEBUG_DIR)%.o, $(MAKESRCS))
+
+CSRCS = $(GENSRCS) rna_access.c rna_dependency.c
 
 include nan_compile.mk
 
@@ -53,8 +63,8 @@ ifeq ($(OS),windows)
 endif
 
 clean::
-       @$(RM) $(DIR)/makesrna* $(DIR)/RNA.c
-       @$(RM) $(DIR)/debug/makesrna* $(DIR)/debug/RNA.c
+       @$(RM) $(DIR)/makesrna* $(DIR)/rna*
+       @$(RM) $(DIR)/debug/makesrna* $(DIR)/debug/rna*
 
 # TODO include right .mk for ldflags
 
@@ -62,18 +72,19 @@ clean::
 # is done quite intentionally. If there is a bug in that lib, it needs
 # to be fixed by the module maintainer.
 
-RNAOBJS = $(filter-out %rna_dependency.o, $(filter-out %rna_access.o, $(filter-out %RNA.o, $(OBJS))))
-
-$(DIR)/$(DEBUG_DIR)makesrna: $(RNAOBJS) $(DIR)/$(DEBUG_DIR)makesrna.o $(OCGDIR)/blender/makesdna/$(DEBUG_DIR)libdna.a $(NAN_GUARDEDALLOC)/lib/libguardedalloc.a
+$(DIR)/$(DEBUG_DIR)makesrna: $(MAKEOBJS) $(OCGDIR)/blender/makesdna/$(DEBUG_DIR)libdna.a $(NAN_GUARDEDALLOC)/lib/libguardedalloc.a
        $(CC) $(LDFLAGS) -o $@ $(WINLIBS) $^
 
-$(DIR)/$(DEBUG_DIR)RNA.c: $(DIR)/$(DEBUG_DIR)makesrna
+$(DIR)/$(DEBUG_DIR)rna_phony_gen.c: $(DIR)/$(DEBUG_DIR)makesrna
     ifeq ($(OS),windows)
        $(SRCHOME)/tools/cygwin/cl_wrapper.pl - $(DIR)/$(DEBUG_DIR)makesrna \
-           $(DIR)/$(DEBUG_DIR)RNA.c
+           $(DIR)/$(DEBUG_DIR)
     else
-       $(DIR)/$(DEBUG_DIR)makesrna $(DIR)/$(DEBUG_DIR)RNA.c
+       $(DIR)/$(DEBUG_DIR)makesrna $(DIR)/$(DEBUG_DIR)
     endif
+       @touch $@
+
+$(GENTARGET): $(DIR)/$(DEBUG_DIR)rna_phony_gen.c
 
 $(DIR)/$(DEBUG_DIR)makesrna.o: makesrna.c $(wildcard rna_*.c)
        $(CC) -c $(CFLAGS) $(CPPFLAGS) makesrna.c -o $@
index af0d67a0b9efbe3330ce3125eb2b07c5d915d55a..661f9b91a34c38f70442dcd371b3fab141f91083 100644 (file)
@@ -14,6 +14,12 @@ source_files = env.Glob('*.c')
 source_files.remove('rna_access.c')
 source_files.remove('rna_dependency.c')
 
+generated_files = source_files[:]
+generated_files.remove('rna_define.c')
+generated_files.remove('makesrna.c')
+
+generated_files = [filename[:-2] + '_gen.c' for filename in generated_files]
+
 makesrna_tool = env.Clone()
 rna = env.Clone()
 makesrna_tool.Append(CCFLAGS = '-DBASE_HEADER="\\"source/blender/makesrna/\\"" ')
@@ -59,11 +65,19 @@ else:
     makesrna = makesrna_tool.Program (target = targetpath, source = source_files, LIBS=['bf_guardedalloc', 'bf_dna'])
 
 rna_dict = rna.Dictionary()
-rna.Depends ('rna.c', makesrna)
+rna.Depends (generated_files, makesrna)
+
+# this seems bad, how to retrieve it from scons?
+build_dir = root_build_dir + '/source/blender/makesrna/intern/'
+
 if env['OURPLATFORM'] != 'linuxcross':
-    rna.Command ('rna.c', '', root_build_dir+os.sep+"makesrna $TARGET")
+    rna.Command (generated_files, '', root_build_dir+os.sep+"makesrna " + build_dir)
 else:
-    rna.Command ('rna.c', '', root_build_dir+os.sep+"makesrna.exe $TARGET")
-obj = ['intern/rna.c', 'intern/rna_access.c', 'intern/rna_dependency.c']
+    rna.Command (generated_files, '', root_build_dir+os.sep+"makesrna.exe "  + build_dir)
+
+obj = ['intern/rna_access.c', 'intern/rna_dependency.c']
+for generated_file in generated_files:
+       obj += ['intern/' + generated_file]
+
 Return ('obj')
 
index b46696aa80085239d8d45a65469be6276c04ec6e..fad9830549105a31bff980c7f33530c17d8b2ad9 100644 (file)
@@ -598,18 +598,6 @@ static void rna_auto_types()
        }
 }
 
-static void rna_auto_functions(FILE *f)
-{
-       StructDefRNA *ds;
-       PropertyDefRNA *dp;
-
-       fprintf(f, "/* Autogenerated Functions */\n\n");
-
-       for(ds=DefRNA.structs.first; ds; ds=ds->next)
-               for(dp=ds->properties.first; dp; dp=dp->next)
-                       rna_def_property_funcs(f, dp);
-}
-
 static void rna_sort(BlenderRNA *brna)
 {
        StructRNA *srna;
@@ -668,8 +656,13 @@ static void rna_generate_prototypes(BlenderRNA *brna, FILE *f)
        StructRNA *srna;
 
        for(srna=brna->structs.first; srna; srna=srna->next)
-               fprintf(f, "StructRNA RNA_%s;\n", srna->identifier);
+               fprintf(f, "extern StructRNA RNA_%s;\n", srna->identifier);
        fprintf(f, "\n");
+}
+
+static void rna_generate_blender(BlenderRNA *brna, FILE *f)
+{
+       StructRNA *srna;
 
        fprintf(f, "BlenderRNA BLENDER_RNA = {");
 
@@ -957,18 +950,15 @@ RNAProcessItem PROCESS_ITEMS[]= {
        {"rna_world.c", RNA_def_world}, 
        {NULL, NULL}};
 
-static int rna_preprocess(char *basedirectory, FILE *f)
+static void rna_generate(BlenderRNA *brna, char *basedirectory, FILE *f, char *filename)
 {
-       BlenderRNA *brna;
-       StructRNA *srna;
-       int i, status;
+       StructDefRNA *ds;
+       PropertyDefRNA *dp;
        
        fprintf(f, "\n/* Automatically generated struct definitions for the Data API.\n"
                        "   Do not edit manually, changes will be overwritten */\n\n"
                        "#define RNA_RUNTIME\n\n");
 
-       brna= RNA_create();
-
        fprintf(f, "#include <float.h>\n");
        fprintf(f, "#include <limits.h>\n");
        fprintf(f, "#include <string.h>\n\n");
@@ -981,29 +971,89 @@ static int rna_preprocess(char *basedirectory, FILE *f)
        fprintf(f, "#include \"RNA_types.h\"\n");
        fprintf(f, "#include \"rna_internal.h\"\n\n");
 
-       /* this is ugly, but we cannot have c files compiled for both
-        * makesrna and blender with some build systems at the moment */
-       fprintf(f, "#include \"rna_define.c\"\n\n");
+       rna_generate_prototypes(brna, f);
+
+       fprintf(f, "#include \"%s\"\n\n", filename);
+
+       fprintf(f, "/* Autogenerated Functions */\n\n");
+
+       for(ds=DefRNA.structs.first; ds; ds=ds->next)
+               if(!filename || ds->filename == filename)
+                       for(dp=ds->properties.first; dp; dp=dp->next)
+                               rna_def_property_funcs(f, dp);
+
+       for(ds=DefRNA.structs.first; ds; ds=ds->next)
+               if(!filename || ds->filename == filename)
+                       rna_generate_struct(brna, ds->srna, f);
+
+       if(strcmp(filename, "rna_ID.c") == 0) {
+               /* this is ugly, but we cannot have c files compiled for both
+                * makesrna and blender with some build systems at the moment */
+               fprintf(f, "#include \"rna_define.c\"\n\n");
+
+               rna_generate_blender(brna, f);
+       }
+}
+
+static void make_bad_file(char *file)
+{
+       FILE *fp= fopen(file, "w");
+       fprintf(fp, "ERROR! Cannot make correct RNA file, STUPID!\n");
+       fclose(fp);
+}
+
+static int rna_preprocess(char *basedirectory, char *outfile)
+{
+       BlenderRNA *brna;
+       StructDefRNA *ds;
+       FILE *file;
+       char deffile[4096];
+       int i, status, len;
+
+       /* define rna */
+       brna= RNA_create();
 
-       for(i=0; PROCESS_ITEMS[i].filename; i++)
-               if(PROCESS_ITEMS[i].define)
+       for(i=0; PROCESS_ITEMS[i].filename; i++) {
+               if(PROCESS_ITEMS[i].define) {
                        PROCESS_ITEMS[i].define(brna);
 
+                       for(ds=DefRNA.structs.first; ds; ds=ds->next)
+                               if(!ds->filename)
+                                       ds->filename= PROCESS_ITEMS[i].filename;
+               }
+       }
+
        rna_sort(brna);
        rna_auto_types();
-       
-       rna_generate_prototypes(brna, f);
 
-       for(i=0; PROCESS_ITEMS[i].filename; i++)
-               fprintf(f, "#include \"%s\"\n", PROCESS_ITEMS[i].filename);
-       fprintf(f, "\n");
+       status= (DefRNA.error != 0);
 
-       rna_auto_functions(f);
+       len= strlen(outfile);
 
-       for(srna=brna->structs.first; srna; srna=srna->next)
-               rna_generate_struct(brna, srna, f);
-       
-       status= DefRNA.error;
+       for(i=0; PROCESS_ITEMS[i].filename; i++) {
+               strcpy(deffile, outfile);
+               strcat(deffile, PROCESS_ITEMS[i].filename);
+               deffile[strlen(deffile)-2] = '\0';
+               strcat(deffile, "_gen.c");
+
+               if(status) {
+                       make_bad_file(deffile);
+               }
+               else {
+                       file = fopen(deffile, "w");
+
+                       if(!file) {
+                               printf ("Unable to open file: %s\n", deffile);
+                               status = 1;
+                       }
+                       else {
+                               rna_generate(brna, basedirectory, file, PROCESS_ITEMS[i].filename);
+                               fclose(file);
+
+                               status= (DefRNA.error != 0);
+                       }
+               }
+       }
 
        RNA_define_free(brna);
        RNA_free(brna);
@@ -1011,52 +1061,29 @@ static int rna_preprocess(char *basedirectory, FILE *f)
        return status;
 }
 
-static void make_bad_file(char *file)
-{
-       FILE *fp= fopen(file, "w");
-       fprintf(fp, "ERROR! Cannot make correct RNA.c file, STUPID!\n");
-       fclose(fp);
-}
-
 #ifndef BASE_HEADER
 #define BASE_HEADER "../"
 #endif
 
 int main(int argc, char **argv)
 {
-       FILE *file;
        int totblock, return_status = 0;
 
        if (argc!=2 && argc!=3) {
-               printf("Usage: %s outfile.c [base directory]\n", argv[0]);
+               printf("Usage: %s outdirectory/ [base directory]\n", argv[0]);
                return_status = 1;
        }
        else {
-               file = fopen(argv[1], "w");
-
-               if (!file) {
-                       printf ("Unable to open file: %s\n", argv[1]);
-                       return_status = 1;
-               }
-               else {
-                       char baseDirectory[256];
+               char baseDirectory[256];
 
-                       printf("Running makesrna, program versions %s\n",  RNA_VERSION_DATE);
+               printf("Running makesrna, program versions %s\n",  RNA_VERSION_DATE);
 
-                       if (argc==3)
-                               strcpy(baseDirectory, argv[2]);
-                       else
-                               strcpy(baseDirectory, BASE_HEADER);
-
-                       return_status= (rna_preprocess(baseDirectory, file));
-                       fclose(file);
+               if (argc==3)
+                       strcpy(baseDirectory, argv[2]);
+               else
+                       strcpy(baseDirectory, BASE_HEADER);
 
-                       if(return_status) {
-                               /* error */
-                               make_bad_file(argv[1]);
-                               return_status = 1;
-                       }
-               }
+               return_status= rna_preprocess(baseDirectory, argv[1]);
        }
 
        totblock= MEM_get_memory_blocks_in_use();
index bb7fe7be526d2a990e6bf64ba5233510aed48867..7ea2952d9fc8123a247dd1bdd4143d237cc3ab25 100644 (file)
 #include "BKE_idprop.h"
 
 /* name functions that ignore the first two ID characters */
-static void rna_ID_name_get(PointerRNA *ptr, char *value)
+void rna_ID_name_get(PointerRNA *ptr, char *value)
 {
        ID *id= (ID*)ptr->data;
        BLI_strncpy(value, id->name+2, sizeof(id->name)-2);
 }
 
-static int rna_ID_name_length(PointerRNA *ptr)
+int rna_ID_name_length(PointerRNA *ptr)
 {
        ID *id= (ID*)ptr->data;
        return strlen(id->name+2);
 }
 
-static void rna_ID_name_set(PointerRNA *ptr, const char *value)
+void rna_ID_name_set(PointerRNA *ptr, const char *value)
 {
        ID *id= (ID*)ptr->data;
        BLI_strncpy(id->name+2, value, sizeof(id->name)-2);
 }
 
-static StructRNA *rna_ID_refine(PointerRNA *ptr)
+StructRNA *rna_ID_refine(PointerRNA *ptr)
 {
        ID *id= (ID*)ptr->data;
 
@@ -87,7 +87,7 @@ static StructRNA *rna_ID_refine(PointerRNA *ptr)
        }
 }
 
-static void rna_ID_fake_user_set(PointerRNA *ptr, int value)
+void rna_ID_fake_user_set(PointerRNA *ptr, int value)
 {
        ID *id= (ID*)ptr->data;
 
index cc8d9b6ac040f7024d046a228a3d622a9007b058..32c545131bab966ca70642548d4cd64cba7e0730 100644 (file)
@@ -64,6 +64,7 @@ typedef struct StructDefRNA {
        struct StructDefRNA *next, *prev;
 
        struct StructRNA *srna;
+       const char *filename;
 
        const char *dnaname;
 
@@ -142,6 +143,12 @@ void RNA_def_world(struct BlenderRNA *brna);
 void rna_def_ipo_common(struct StructRNA *srna);
 void rna_def_texmat_common(struct StructRNA *srna, const char *texspace_editable);
 
+void rna_ID_name_get(struct PointerRNA *ptr, char *value);
+int rna_ID_name_length(struct PointerRNA *ptr);
+void rna_ID_name_set(struct PointerRNA *ptr, const char *value);
+struct StructRNA *rna_ID_refine(struct PointerRNA *ptr);
+void rna_ID_fake_user_set(struct PointerRNA *ptr, int value);
+
 void rna_object_vgroup_name_index_get(struct PointerRNA *ptr, char *value, int index);
 int rna_object_vgroup_name_index_length(struct PointerRNA *ptr, int index);
 void rna_object_vgroup_name_index_set(struct PointerRNA *ptr, const char *value, short *index);
index e48a462b69a29ced63577ca99b22530936e7fd8d..6610cf895b49759bde373c1ed1876b22ded3048e 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "rna_internal.h"
 
+#include "DNA_curve_types.h"
 #include "DNA_key_types.h"
 #include "DNA_lattice_types.h"
 #include "DNA_meshdata_types.h"
index 043f99326227a4ff43c866f5c7427c17314a834f..7da778979216e54e0291cfdab59d374ffc99c3b6 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "rna_internal.h"
 
+#include "DNA_mesh_types.h"
 #include "DNA_meta_types.h"
 
 #ifdef RNA_RUNTIME
index b079262d54962a5350bafe2686687f62ce7083d3..a5ba31e2280ca471f2f57534d862a0ba2f681de2 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "DNA_armature_types.h"
 #include "DNA_modifier_types.h"
+#include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 
 #include "BKE_bmesh.h" /* For BevelModifierData */
@@ -284,7 +285,6 @@ static void rna_def_modifier_subsurf(BlenderRNA *brna)
 static void rna_def_modifier_multires(BlenderRNA *brna)
 {
        StructRNA *srna;
-       PropertyRNA *prop;
 
        srna= RNA_def_struct(brna, "MultiresModifier", "Modifier");
        RNA_def_struct_ui_text(srna, "Multires Modifier", "");
index 3e4474dba8e78b3242e9dafef3c5dbe860056e39..0ae76a2097296f39015d2935ae790fead11ffc20 100644 (file)
@@ -29,6 +29,8 @@
 
 #include "rna_internal.h"
 
+#include "DNA_customdata_types.h"
+#include "DNA_mesh_types.h"
 #include "DNA_object_types.h"
 #include "DNA_property_types.h"
 #include "DNA_scene_types.h"
index aead0ca54c0d8bed42f4dcd2a225427c0248fe3b..069f344b290f24bf6fbb76f341147b926bcf551a 100644 (file)
@@ -24,6 +24,9 @@
 
 #include <stdlib.h>
 
+#include "DNA_ID.h"
+
+#include "RNA_access.h"
 #include "RNA_define.h"
 #include "RNA_types.h"
 
index 353db5248d9ad1c1a510ce64970eaabaa94c9f4d..f87636bf4e1d07089c0d473e6492ed6115487f7c 100644 (file)
@@ -35,6 +35,7 @@
 
 #ifdef RNA_RUNTIME
 
+#include "BKE_context.h"
 #include "BKE_global.h"
 
 void *rna_Scene_objects_get(CollectionPropertyIterator *iter)
index 7834775c4b98f1a871da53db3ed126b5a896dc12..af04b396584c4efc5aeaa9ac89d51d362b515760 100644 (file)
@@ -25,6 +25,8 @@
 #include <stdlib.h>
 #include <limits.h>
 
+#include "MEM_guardedalloc.h"
+
 #include "BKE_text.h"
 
 #include "RNA_define.h"