From 35301621dc1792bc67e0d4c4c722511e795ebe03 Mon Sep 17 00:00:00 2001 From: starkos Date: Fri, 2 May 2008 13:51:44 +0000 Subject: [PATCH] GNU C++ project makefile generation (placeholder); refactoring and code cleanup (r346:349) --- samples/gmake/CppExe/Makefile | 7 + src/action/make/gmake.c | 20 ++ src/action/make/make_project.c | 236 ++++++++++++++++++ src/action/make/make_project.h | 30 +++ src/action/make/tests/gmake_project_tests.cpp | 158 ++++++++++++ src/action/tests/action_tests.h | 1 + .../vs200x/tests/vs200x_project_tests.cpp | 1 - src/action/vs200x/vs2002.c | 2 +- src/action/vs200x/vs2002_solution.c | 23 -- src/action/vs200x/vs2003.c | 2 +- src/action/vs200x/vs2005.c | 2 +- src/action/vs200x/vs2008.c | 2 +- src/action/vs200x/vs200x_project.c | 3 - src/action/vs200x/vs200x_solution.c | 33 +++ src/action/vs200x/vs200x_solution.h | 3 +- src/base/tests/xml_tests.cpp | 64 ----- src/base/xml.c | 120 --------- src/base/xml.h | 19 -- 18 files changed, 491 insertions(+), 235 deletions(-) create mode 100644 src/action/make/make_project.c create mode 100644 src/action/make/make_project.h create mode 100644 src/action/make/tests/gmake_project_tests.cpp create mode 100644 src/action/vs200x/vs200x_solution.c delete mode 100644 src/base/tests/xml_tests.cpp delete mode 100644 src/base/xml.c delete mode 100644 src/base/xml.h diff --git a/samples/gmake/CppExe/Makefile b/samples/gmake/CppExe/Makefile index ee1101a6..1f5ab33e 100644 --- a/samples/gmake/CppExe/Makefile +++ b/samples/gmake/CppExe/Makefile @@ -41,6 +41,8 @@ OBJECTS := \ RESOURCES := \ +# Can I have premake check the OS type instead of doing this here? + MKDIR_TYPE := msdos CMD := $(subst \,\\,$(ComSpec)$(COMSPEC)) ifeq (,$(CMD)) @@ -63,6 +65,8 @@ endif .PHONY: clean +# I really only need to create OUTDIR; that's the only one that matters! + $(OUTDIR)/$(TARGET): $(OBJECTS) $(LDDEPS) $(RESOURCES) @echo Linking CppExe -@$(CMD_MKBINDIR) @@ -81,6 +85,9 @@ else -@if exist $(subst /,\,$(OBJDIR)) rmdir /s /q $(subst /,\,$(OBJDIR)) endif +# add an "objdir" as first dependency to target and create directories there (or maybe +# call it outdirs and do all required output directories + $(OBJDIR)/Hello.o: Hello.cpp -@$(CMD_MKOBJDIR) @echo $(notdir $<) diff --git a/src/action/make/gmake.c b/src/action/make/gmake.c index 54a31721..4ec2a45e 100644 --- a/src/action/make/gmake.c +++ b/src/action/make/gmake.c @@ -9,6 +9,7 @@ #include "action/action.h" #include "make.h" #include "make_solution.h" +#include "make_project.h" /** The GNU make solution writing process, for session_enumerate_objects() */ @@ -27,6 +28,14 @@ static SessionSolutionCallback SolutionCallbacks[] = /** The GNU make project writing process, for session_enumerate_objects() */ static SessionProjectCallback ProjectCallbacks[] = { + make_project_create, + make_project_signature, + session_enumerate_configurations, + make_project_objects, + make_project_resources, + make_project_phony_rule, + make_project_target, + make_project_include_dependencies, NULL }; @@ -34,6 +43,17 @@ static SessionProjectCallback ProjectCallbacks[] = /** The GNU make configuration writing process, for session_enumerate_configurations() */ static SessionProjectCallback ConfigCallbacks[] = { + make_project_config_conditional, + make_project_config_outdir, + make_project_config_outfile, + make_project_config_objdir, + make_project_config_cppflags, + make_project_config_cflags, + make_project_config_cxxflags, + make_project_config_ldflags, + make_project_config_lddeps, + make_project_config_resflags, + make_project_config_end, NULL }; diff --git a/src/action/make/make_project.c b/src/action/make/make_project.c new file mode 100644 index 00000000..9b845d03 --- /dev/null +++ b/src/action/make/make_project.c @@ -0,0 +1,236 @@ +/** + * \file make_project.c + * \brief Makefile project generation functions. + * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project + */ + +#include +#include "premake.h" +#include "action/make/make.h" +#include "action/make/make_project.h" +#include "base/error.h" + + +/** + * Write the opening conditional for a configuration block. + */ +int make_project_config_conditional(Session sess, Project prj, Stream strm) +{ + const char* cfg_name = project_get_configuration_filter(prj); + UNUSED(sess); + return stream_writeline(strm, "ifeq ($(CONFIG),%s)", cfg_name); +} + + +/** + * Write the CFLAGS configuration variable. + */ +int make_project_config_cflags(Session sess, Project prj, Stream strm) +{ + UNUSED(sess); + UNUSED(prj); + return stream_writeline(strm, " CFLAGS += $(CPPFLAGS) $(ARCHFLAGS)"); +} + + +/** + * Write the CPPFLAGS configuration variable. + */ +int make_project_config_cppflags(Session sess, Project prj, Stream strm) +{ + UNUSED(sess); + UNUSED(prj); + return stream_writeline(strm, " CPPFLAGS += -MMD"); +} + + +/** + * Write the CXXFLAGS configuration variable. + */ +int make_project_config_cxxflags(Session sess, Project prj, Stream strm) +{ + UNUSED(sess); + UNUSED(prj); + return stream_writeline(strm, " CXXFLAGS += $(CFLAGS)"); +} + + +/** + * Write the opening conditional for a configuration block. + */ +int make_project_config_end(Session sess, Project prj, Stream strm) +{ + int z; + UNUSED(sess); + UNUSED(prj); + z = stream_writeline(strm, "endif"); + z |= stream_writeline(strm, ""); + return z; +} + + +/** + * Write the LDDEPS configuration variable. + */ +int make_project_config_lddeps(Session sess, Project prj, Stream strm) +{ + UNUSED(sess); + UNUSED(prj); + return stream_writeline(strm, " LDDEPS :="); +} + + +/** + * Write the LDFLAGS configuration variable. + */ +int make_project_config_ldflags(Session sess, Project prj, Stream strm) +{ + UNUSED(sess); + UNUSED(prj); + return stream_writeline(strm, " LDFLAGS +="); +} + + +/** + * Write the OBJDIR configuration variable. + */ +int make_project_config_objdir(Session sess, Project prj, Stream strm) +{ + const char* cfg_name = project_get_configuration_filter(prj); + UNUSED(sess); + return stream_writeline(strm, " OBJDIR := obj/%s", cfg_name); +} + + +/** + * Write the OUTDIR configuration variable. + */ +int make_project_config_outdir(Session sess, Project prj, Stream strm) +{ + UNUSED(sess); + UNUSED(prj); + return stream_writeline(strm, " OUTDIR := ."); +} + + +/** + * Write the OUTFILE configuration variable. + */ +int make_project_config_outfile(Session sess, Project prj, Stream strm) +{ + UNUSED(sess); + UNUSED(prj); + return stream_writeline(strm, " OUTFILE := MyApp"); +} + + +/** + * Write the RESFLAGS configuration variable. + */ +int make_project_config_resflags(Session sess, Project prj, Stream strm) +{ + UNUSED(sess); + UNUSED(prj); + return stream_writeline(strm, " RESFLAGS +="); +} + + +/** + * Create a new output stream for a project , and make it active for subsequent writes. + */ +int make_project_create(Session sess, Project prj, Stream strm) +{ + /* create the makefile */ + const char* filename = make_get_project_makefile(sess, prj); + strm = stream_create_file(filename); + if (!strm) + { + return !OKAY; + } + + /* make the stream active for the functions that come after */ + session_set_active_stream(sess, strm); + return OKAY; +} + + +/** + * Include the auto-generated dependencies into the project makefile. + */ +int make_project_include_dependencies(Session sess, Project prj, Stream strm) +{ + UNUSED(sess); + UNUSED(prj); + return stream_writeline(strm, "-include $(OBJECTS:%%.o=%%.d)"); +} + + +/** + * Write the OBJECTS project variable. + */ +int make_project_objects(Session sess, Project prj, Stream strm) +{ + int z; + UNUSED(sess); + UNUSED(prj); + z = stream_writeline(strm, "OBJECTS := \\"); + z |= stream_writeline(strm, ""); + return z; +} + + +/** + * Write the .PHONY rule for a project. + */ +int make_project_phony_rule(Session sess, Project prj, Stream strm) +{ + int z; + UNUSED(sess); + UNUSED(prj); + z = stream_writeline(strm, ".PHONY: clean"); + z |= stream_writeline(strm, ""); + return z; +} + + +/** + * Write the RESOURCES project variable. + */ +int make_project_resources(Session sess, Project prj, Stream strm) +{ + int z; + UNUSED(sess); + UNUSED(prj); + z = stream_writeline(strm, "RESOURCES := \\"); + z |= stream_writeline(strm, ""); + return z; +} + + +/** + * Write the project makefile signature. + */ +int make_project_signature(Session sess, Project prj, Stream strm) +{ + int z; + UNUSED(sess); + UNUSED(prj); + z = stream_writeline(strm, "# GNU Makefile autogenerated by Premake"); + z |= stream_writeline(strm, ""); + return z; +} + + +/** + * Write the project output target rule. + */ +int make_project_target(Session sess, Project prj, Stream strm) +{ + int z; + UNUSED(sess); + z = stream_writeline(strm, "$(OUTDIR)/$(OUTFILE): $(OBJECTS) $(LDDEPS) $(RESOURCES)"); + z |= stream_writeline(strm, "\t@echo Linking %s", project_get_name(prj)); + z |= stream_writeline(strm, "\t$(CXX) -o $@ $(LDFLAGS) $(ARCHFLAGS) $(OBJECTS) $(RESOURCES)"); + z |= stream_writeline(strm, ""); + return z; +} diff --git a/src/action/make/make_project.h b/src/action/make/make_project.h new file mode 100644 index 00000000..30191097 --- /dev/null +++ b/src/action/make/make_project.h @@ -0,0 +1,30 @@ +/** + * \file make_project.h + * \brief Makefile project generation functions. + * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project + */ +#if !defined(PREMAKE_MAKE_PROJECT_H) +#define PREMAKE_MAKE_PROJECT_H + +#include "engine/session.h" + +int make_project_config_conditional(Session sess, Project prj, Stream strm); +int make_project_config_cflags(Session sess, Project prj, Stream strm); +int make_project_config_cppflags(Session sess, Project prj, Stream strm); +int make_project_config_cxxflags(Session sess, Project prj, Stream strm); +int make_project_config_end(Session sess, Project prj, Stream strm); +int make_project_config_lddeps(Session sess, Project prj, Stream strm); +int make_project_config_ldflags(Session sess, Project prj, Stream strm); +int make_project_config_objdir(Session sess, Project prj, Stream strm); +int make_project_config_outdir(Session sess, Project prj, Stream strm); +int make_project_config_outfile(Session sess, Project prj, Stream strm); +int make_project_config_resflags(Session sess, Project prj, Stream strm); +int make_project_create(Session sess, Project prj, Stream strm); +int make_project_include_dependencies(Session sess, Project prj, Stream strm); +int make_project_objects(Session sess, Project prj, Stream strm); +int make_project_phony_rule(Session sess, Project prj, Stream strm); +int make_project_resources(Session sess, Project prj, Stream strm); +int make_project_signature(Session sess, Project prj, Stream strm); +int make_project_target(Session sess, Project prj, Stream strm); + +#endif diff --git a/src/action/make/tests/gmake_project_tests.cpp b/src/action/make/tests/gmake_project_tests.cpp new file mode 100644 index 00000000..3ec77510 --- /dev/null +++ b/src/action/make/tests/gmake_project_tests.cpp @@ -0,0 +1,158 @@ +/** + * \file gmake_project_tests.cpp + * \brief Automated tests for GNU makefile project processing. + * \author Copyright (c) 2008 Jason Perkins and the Premake project + */ + +#include "premake.h" +#include "action/tests/action_tests.h" +extern "C" { +#include "action/make/make_project.h" +} + +SUITE(action) +{ + TEST_FIXTURE(FxAction, MakeProject_Signature) + { + make_project_signature(sess, prj, strm); + CHECK_EQUAL( + "# GNU Makefile autogenerated by Premake\n" + "\n", + buffer); + } + + TEST_FIXTURE(FxAction, MakeProject_Config_Conditional) + { + make_project_config_conditional(sess, prj, strm); + CHECK_EQUAL( + "ifeq ($(CONFIG),Debug)\n", + buffer); + } + + TEST_FIXTURE(FxAction, MakeProject_Config_End) + { + make_project_config_end(sess, prj, strm); + CHECK_EQUAL( + "endif\n" + "\n", + buffer); + } + + TEST_FIXTURE(FxAction, MakeProject_Config_CFlags) + { + make_project_config_cflags(sess, prj, strm); + CHECK_EQUAL( + " CFLAGS += $(CPPFLAGS) $(ARCHFLAGS)\n", + buffer); + } + + TEST_FIXTURE(FxAction, MakeProject_Config_CppFlags) + { + make_project_config_cppflags(sess, prj, strm); + CHECK_EQUAL( + " CPPFLAGS += -MMD\n", + buffer); + } + + TEST_FIXTURE(FxAction, MakeProject_Config_CxxFlags) + { + make_project_config_cxxflags(sess, prj, strm); + CHECK_EQUAL( + " CXXFLAGS += $(CFLAGS)\n", + buffer); + } + + TEST_FIXTURE(FxAction, MakeProject_Config_LdDeps) + { + make_project_config_lddeps(sess, prj, strm); + CHECK_EQUAL( + " LDDEPS :=\n", + buffer); + } + + TEST_FIXTURE(FxAction, MakeProject_Config_LdFlags) + { + make_project_config_ldflags(sess, prj, strm); + CHECK_EQUAL( + " LDFLAGS +=\n", + buffer); + } + + TEST_FIXTURE(FxAction, MakeProject_Config_ObjDir) + { + make_project_config_objdir(sess, prj, strm); + CHECK_EQUAL( + " OBJDIR := obj/Debug\n", + buffer); + } + + TEST_FIXTURE(FxAction, MakeProject_Config_OutFile) + { + make_project_config_outfile(sess, prj, strm); + CHECK_EQUAL( + " OUTFILE := MyApp\n", + buffer); + } + + TEST_FIXTURE(FxAction, MakeProject_Config_OutDir) + { + make_project_config_outdir(sess, prj, strm); + CHECK_EQUAL( + " OUTDIR := .\n", + buffer); + } + + TEST_FIXTURE(FxAction, MakeProject_Config_ResFlags) + { + make_project_config_resflags(sess, prj, strm); + CHECK_EQUAL( + " RESFLAGS +=\n", + buffer); + } + + TEST_FIXTURE(FxAction, MakeProject_Objects) + { + make_project_objects(sess, prj, strm); + CHECK_EQUAL( + "OBJECTS := \\\n" + "\n", + buffer); + } + + TEST_FIXTURE(FxAction, MakeProject_Resources) + { + make_project_resources(sess, prj, strm); + CHECK_EQUAL( + "RESOURCES := \\\n" + "\n", + buffer); + } + + TEST_FIXTURE(FxAction, MakeProject_PhonyRule) + { + make_project_phony_rule(sess, prj, strm); + CHECK_EQUAL( + ".PHONY: clean\n" + "\n", + buffer); + } + + TEST_FIXTURE(FxAction, MakeProject_OutputTarget) + { + make_project_target(sess, prj, strm); + CHECK_EQUAL( + "$(OUTDIR)/$(OUTFILE): $(OBJECTS) $(LDDEPS) $(RESOURCES)\n" + "\t@echo Linking MyProject\n" + "\t$(CXX) -o $@ $(LDFLAGS) $(ARCHFLAGS) $(OBJECTS) $(RESOURCES)\n" + "\n", + buffer); + } + + TEST_FIXTURE(FxAction, MakeProject_IncludeDependencies) + { + make_project_include_dependencies(sess, prj, strm); + CHECK_EQUAL( + "-include $(OBJECTS:%.o=%.d)\n", + buffer); + } +} diff --git a/src/action/tests/action_tests.h b/src/action/tests/action_tests.h index f2069fb6..17f29d34 100644 --- a/src/action/tests/action_tests.h +++ b/src/action/tests/action_tests.h @@ -40,6 +40,7 @@ struct FxAction project_set_location(prj, "ProjectFolder"); project_set_guid(prj, "AE2461B7-236F-4278-81D3-F0D476F9A4C0"); project_set_language(prj, "c++"); + project_set_configuration_filter(prj, "Debug"); } ~FxAction() diff --git a/src/action/vs200x/tests/vs200x_project_tests.cpp b/src/action/vs200x/tests/vs200x_project_tests.cpp index dd57a2d8..3969f180 100644 --- a/src/action/vs200x/tests/vs200x_project_tests.cpp +++ b/src/action/vs200x/tests/vs200x_project_tests.cpp @@ -16,7 +16,6 @@ struct FxVsProject : FxAction FxVsProject() { session_set_action(sess, "vs2002"); - project_set_configuration_filter(prj, "Debug"); } }; diff --git a/src/action/vs200x/vs2002.c b/src/action/vs200x/vs2002.c index 28958630..c0bbcece 100644 --- a/src/action/vs200x/vs2002.c +++ b/src/action/vs200x/vs2002.c @@ -15,7 +15,7 @@ /** The VS2002 solution writing process, for session_enumerate_objects() */ static SessionSolutionCallback SolutionCallbacks[] = { - vs2002_solution_create, + vs200x_solution_create, vs2002_solution_signature, vs2002_solution_projects, vs2002_solution_configuration, diff --git a/src/action/vs200x/vs2002_solution.c b/src/action/vs200x/vs2002_solution.c index efd85b7c..28d3c887 100644 --- a/src/action/vs200x/vs2002_solution.c +++ b/src/action/vs200x/vs2002_solution.c @@ -40,29 +40,6 @@ int vs2002_solution_configuration(Session sess, Solution sln, Stream strm) } -/** - * Create a new output stream for a solution, and make it active for subsequent writes. - * \param sess The execution session context. - * \param sln The current solution. - * \param strm The currently active stream; set with session_set_active_stream(). - * \returns OKAY if successful. - */ -int vs2002_solution_create(Session sess, Solution sln, Stream strm) -{ - /* create the solution file */ - const char* filename = solution_get_filename(sln, NULL, ".sln"); - strm = stream_create_file(filename); - if (!strm) - { - return !OKAY; - } - - /* make the stream active for the functions that come after */ - session_set_active_stream(sess, strm); - return OKAY; -} - - /** * Create the Visual Studio 2002 project dependencies block. * \param sess The execution session context. diff --git a/src/action/vs200x/vs2003.c b/src/action/vs200x/vs2003.c index 75dc9278..0175fd09 100644 --- a/src/action/vs200x/vs2003.c +++ b/src/action/vs200x/vs2003.c @@ -15,7 +15,7 @@ /** The VS2003 solution writing process, for session_enumerate_objects() */ static SessionSolutionCallback SolutionCallbacks[] = { - vs2002_solution_create, + vs200x_solution_create, vs2003_solution_signature, vs2002_solution_projects, vs2003_solution_configuration, diff --git a/src/action/vs200x/vs2005.c b/src/action/vs200x/vs2005.c index 56894383..adfc5672 100644 --- a/src/action/vs200x/vs2005.c +++ b/src/action/vs200x/vs2005.c @@ -15,7 +15,7 @@ /** The VS2005 solution writing process, for session_enumerate_objects() */ static SessionSolutionCallback SolutionCallbacks[] = { - vs2002_solution_create, + vs200x_solution_create, vs2005_solution_signature, vs2002_solution_projects, vs2005_solution_platforms, diff --git a/src/action/vs200x/vs2008.c b/src/action/vs200x/vs2008.c index 8429819a..6317a2a7 100644 --- a/src/action/vs200x/vs2008.c +++ b/src/action/vs200x/vs2008.c @@ -15,7 +15,7 @@ /** The VS2008 solution writing process, for session_enumerate_objects() */ static SessionSolutionCallback SolutionCallbacks[] = { - vs2002_solution_create, + vs200x_solution_create, vs2008_solution_signature, vs2002_solution_projects, vs2005_solution_platforms, diff --git a/src/action/vs200x/vs200x_project.c b/src/action/vs200x/vs200x_project.c index a906c24c..8e30d38a 100644 --- a/src/action/vs200x/vs200x_project.c +++ b/src/action/vs200x/vs200x_project.c @@ -18,10 +18,7 @@ int vs200x_project_config_element(Session sess, Project prj, Stream strm) { int z; const char* cfg_name = project_get_configuration_filter(prj); - - UNUSED(prj); UNUSED(strm); - z = vs200x_element_start(sess, 2, "Configuration"); z |= vs200x_attribute(sess, 2, "Name", "%s|Win32", cfg_name); z |= vs200x_attribute(sess, 2, "OutputDirectory", "$(SolutionDir)$(ConfigurationName)"); diff --git a/src/action/vs200x/vs200x_solution.c b/src/action/vs200x/vs200x_solution.c new file mode 100644 index 00000000..577155e6 --- /dev/null +++ b/src/action/vs200x/vs200x_solution.c @@ -0,0 +1,33 @@ +/** + * \file vs200x_solution.c + * \brief Visual Studio multiple-version solution generation functions. + * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project + */ + +#include +#include "premake.h" +#include "vs200x.h" +#include "vs200x_solution.h" + + +/** + * Create a new output stream for a solution, and make it active for subsequent writes. + * \param sess The execution session context. + * \param sln The current solution. + * \param strm The currently active stream; set with session_set_active_stream(). + * \returns OKAY if successful. + */ +int vs200x_solution_create(Session sess, Solution sln, Stream strm) +{ + /* create the solution file */ + const char* filename = solution_get_filename(sln, NULL, ".sln"); + strm = stream_create_file(filename); + if (!strm) + { + return !OKAY; + } + + /* make the stream active for the functions that come after */ + session_set_active_stream(sess, strm); + return OKAY; +} diff --git a/src/action/vs200x/vs200x_solution.h b/src/action/vs200x/vs200x_solution.h index 03d8d52c..b6662618 100644 --- a/src/action/vs200x/vs200x_solution.h +++ b/src/action/vs200x/vs200x_solution.h @@ -9,7 +9,6 @@ #include "engine/session.h" int vs2002_solution_configuration(Session sess, Solution sln, Stream strm); -int vs2002_solution_create(Session sess, Solution sln, Stream strm); int vs2002_solution_dependencies(Session sess, Solution sln, Stream strm); int vs2002_solution_extensibility(Session sess, Solution sln, Stream strm); int vs2002_solution_project_configuration(Session sess, Solution sln, Stream strm); @@ -26,4 +25,6 @@ int vs2005_solution_signature(Session sess, Solution sln, Stream strm); int vs2008_solution_signature(Session sess, Solution sln, Stream strm); +int vs200x_solution_create(Session sess, Solution sln, Stream strm); + #endif diff --git a/src/base/tests/xml_tests.cpp b/src/base/tests/xml_tests.cpp deleted file mode 100644 index 11313826..00000000 --- a/src/base/tests/xml_tests.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/** - * \file xml_tests.cpp - * \brief XML output tests. - * \author Copyright (c) 2007-2008 Jason Perkins and the Premake project - */ - -#include "premake.h" -#include "testing/testing.h" -extern "C" { -#include "base/stream.h" -#include "base/xml.h" -} - -struct FxXml -{ - Stream strm; - Xml xml; - char buffer[1024]; - - FxXml() - { - strm = stream_create_null(); - stream_set_buffer(strm, buffer); - - xml = xml_create(strm); - } - - ~FxXml() - { - xml_destroy(xml); - stream_destroy(strm); - } -}; - - -SUITE(base) -{ - TEST_FIXTURE(FxXml, EndElement_Short) - { - xml_element_start(xml, "MyElement"); - xml_element_end(xml, "MyElement"); - CHECK_EQUAL("\n", buffer); - } - - TEST_FIXTURE(FxXml, EndElement_Full) - { - xml_element_start(xml, "MyElement"); - xml_element_end_full(xml, "MyElement"); - CHECK_EQUAL("\n\n", buffer); - } - - TEST_FIXTURE(FxXml, ElementNesting_OneDeep) - { - xml_element_start(xml, "Element0"); - xml_element_start(xml, "Element1"); - xml_element_end(xml, "Element1"); - xml_element_end(xml, "Element0"); - CHECK_EQUAL( - "\n" - "\t\n" - "\n", - buffer); - } -} \ No newline at end of file diff --git a/src/base/xml.c b/src/base/xml.c deleted file mode 100644 index 2d09f4a9..00000000 --- a/src/base/xml.c +++ /dev/null @@ -1,120 +0,0 @@ -/** - * \file xml.c - * \brief XML output handling. - * \author Copyright (c) 2007-2008 Jason Perkins and the Premake project - */ - -#include -#include -#include "premake.h" -#include "xml.h" - - -DEFINE_CLASS(Xml) -{ - Stream strm; - int element_depth; - int has_children; -}; - - -/** - * Create a new XML output object around a stream. - * \param strm The stream to which to write XML output. - * \returns A new XML output object. - */ -Xml xml_create(Stream strm) -{ - Xml xml; - assert(strm); - xml = ALLOC_CLASS(Xml); - xml->strm = strm; - xml->element_depth = 0; - xml->has_children = 0; - return xml; -} - - -/** - * Destroy an XML output object and release the associated memory. The stream associated - * with the object is left intact, and not closed or destroyed. - * \param xml The XML output object to destroy. - */ -void xml_destroy(Xml xml) -{ - assert(xml); - free(xml); -} - - -/** - * Close the current element tag. - * \param xml The XML output object. - * \param element_name The name of the element being ended. - * \returns OKAY if successful. - */ -int xml_element_end(Xml xml, const char* element_name) -{ - int z = OKAY; - - assert(xml); - assert(element_name); - - if (xml->has_children) - { - z |= stream_writeline(xml->strm, "", element_name); - } - else - { - z |= stream_writeline(xml->strm, "/>"); - } - - xml->element_depth--; - xml->has_children = 1; - return z; -} - - -/** - * Close the current element tag, using the full () form. - * \param xml The XML output object. - * \param element_name The name of the element being ended. - * \returns OKAY if successful. - */ -int xml_element_end_full(Xml xml, const char* element_name) -{ - int z; - assert(xml); - z = stream_writeline(xml->strm, ">"); - z |= stream_writeline(xml->strm, "", element_name); - return z; -} - - -/** - * Start writing a new element tag. - * \param xml The XML output object. - * \param element_name The name of the new element. - * \returns OKAY if successful. - */ -int xml_element_start(Xml xml, const char* element_name) -{ - int i, z = OKAY; - - assert(xml); - assert(element_name); - - if (xml->element_depth > 0) - { - z |= stream_writeline(xml->strm, ">"); - } - - for (i = 0; i < xml->element_depth; ++i) - { - z |= stream_write(xml->strm, "\t"); - } - - xml->element_depth++; - z |= stream_write(xml->strm, "<%s", element_name); - return z; -} diff --git a/src/base/xml.h b/src/base/xml.h deleted file mode 100644 index ed1d1d8f..00000000 --- a/src/base/xml.h +++ /dev/null @@ -1,19 +0,0 @@ -/** - * \file xml.h - * \brief XML output handling. - * \author Copyright (c) 2007-2008 Jason Perkins and the Premake project - */ -#if !defined(PREMAKE_XML_H) -#define PREMAKE_XML_H - -#include "base/stream.h" - -DECLARE_CLASS(Xml); - -Xml xml_create(Stream strm); -void xml_destroy(Xml xml); -int xml_element_end(Xml xml, const char* element_name); -int xml_element_end_full(Xml xml, const char* element_name); -int xml_element_start(Xml xml, const char* element_name); - -#endif