From bebe874a5b80a1e698b3a9dc6aec0870540aed4b Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 8 Jan 2009 13:57:29 +0000 Subject: RNA * 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. --- source/blender/makesrna/RNA_types.h | 3 +- source/blender/makesrna/intern/CMakeLists.txt | 66 +++++++++-- source/blender/makesrna/intern/Makefile | 29 +++-- source/blender/makesrna/intern/SConscript | 22 +++- source/blender/makesrna/intern/makesrna.c | 157 +++++++++++++++----------- source/blender/makesrna/intern/rna_ID.c | 10 +- source/blender/makesrna/intern/rna_internal.h | 7 ++ source/blender/makesrna/intern/rna_lattice.c | 1 + source/blender/makesrna/intern/rna_meta.c | 1 + source/blender/makesrna/intern/rna_modifier.c | 2 +- source/blender/makesrna/intern/rna_object.c | 2 + source/blender/makesrna/intern/rna_rna.c | 3 + source/blender/makesrna/intern/rna_scene.c | 1 + source/blender/makesrna/intern/rna_text.c | 2 + 14 files changed, 213 insertions(+), 93 deletions(-) (limited to 'source/blender') diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h index e4aceb0a81b..fc98a0ad594 100644 --- a/source/blender/makesrna/RNA_types.h +++ b/source/blender/makesrna/RNA_types.h @@ -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; diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt index 4a537d031a0..5eaef1ab246 100644 --- a/source/blender/makesrna/intern/CMakeLists.txt +++ b/source/blender/makesrna/intern/CMakeLists.txt @@ -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") + diff --git a/source/blender/makesrna/intern/Makefile b/source/blender/makesrna/intern/Makefile index e844d74decf..aad4acdbf38 100644 --- a/source/blender/makesrna/intern/Makefile +++ b/source/blender/makesrna/intern/Makefile @@ -24,7 +24,17 @@ 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 $@ diff --git a/source/blender/makesrna/intern/SConscript b/source/blender/makesrna/intern/SConscript index af0d67a0b9e..661f9b91a34 100644 --- a/source/blender/makesrna/intern/SConscript +++ b/source/blender/makesrna/intern/SConscript @@ -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') diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index b46696aa800..fad98305491 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -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 \n"); fprintf(f, "#include \n"); fprintf(f, "#include \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(); diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index bb7fe7be526..7ea2952d9fc 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -35,25 +35,25 @@ #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; diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index cc8d9b6ac04..32c545131ba 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -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); diff --git a/source/blender/makesrna/intern/rna_lattice.c b/source/blender/makesrna/intern/rna_lattice.c index e48a462b69a..6610cf895b4 100644 --- a/source/blender/makesrna/intern/rna_lattice.c +++ b/source/blender/makesrna/intern/rna_lattice.c @@ -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" diff --git a/source/blender/makesrna/intern/rna_meta.c b/source/blender/makesrna/intern/rna_meta.c index 043f9932622..7da77897921 100644 --- a/source/blender/makesrna/intern/rna_meta.c +++ b/source/blender/makesrna/intern/rna_meta.c @@ -29,6 +29,7 @@ #include "rna_internal.h" +#include "DNA_mesh_types.h" #include "DNA_meta_types.h" #ifdef RNA_RUNTIME diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index b079262d549..a5ba31e2280 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -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", ""); diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index 3e4474dba8e..0ae76a20972 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -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" diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c index aead0ca54c0..069f344b290 100644 --- a/source/blender/makesrna/intern/rna_rna.c +++ b/source/blender/makesrna/intern/rna_rna.c @@ -24,6 +24,9 @@ #include +#include "DNA_ID.h" + +#include "RNA_access.h" #include "RNA_define.h" #include "RNA_types.h" diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 353db5248d9..f87636bf4e1 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -35,6 +35,7 @@ #ifdef RNA_RUNTIME +#include "BKE_context.h" #include "BKE_global.h" void *rna_Scene_objects_get(CollectionPropertyIterator *iter) diff --git a/source/blender/makesrna/intern/rna_text.c b/source/blender/makesrna/intern/rna_text.c index 7834775c4b9..af04b396584 100644 --- a/source/blender/makesrna/intern/rna_text.c +++ b/source/blender/makesrna/intern/rna_text.c @@ -25,6 +25,8 @@ #include #include +#include "MEM_guardedalloc.h" + #include "BKE_text.h" #include "RNA_define.h" -- cgit v1.2.3