From 708a965fcd526361a6705f7ab3ebe09c967978fe Mon Sep 17 00:00:00 2001 From: starkos Date: Wed, 9 Apr 2008 20:02:25 +0000 Subject: [PATCH] Merged with dev branch: generation of stub solution files for VS and gmake (r292:300) --- CHANGES.txt | 326 +++++++++--------- premake4.lua | 1 - samples/gmake/CppExe/Makefile | 90 +++++ samples/gmake/Makefile | 24 ++ samples/vs2003/EmptySolution.sln | 11 + samples/vs2005/EmptySolution.sln | 8 + src/action/make/gmake.c | 1 + src/action/make/make_solution.c | 23 ++ src/action/make/make_solution.h | 1 + .../make_solution_tests.cpp | 56 +++ .../vs200x/tests/vs200x_solution_tests.cpp | 73 ++++ src/action/vs200x/tests/vs200x_tests.cpp | 54 +++ src/action/vs200x/vs2005.c | 1 + src/action/vs200x/vs200x.c | 38 ++ src/action/vs200x/vs200x.h | 14 + src/action/vs200x/vs200x_solution.c | 41 ++- src/action/vs200x/vs200x_solution.h | 1 + src/base/stream.c | 10 + src/base/stream.h | 1 + src/engine/internals.h | 1 + src/engine/session.c | 33 +- src/engine/session.h | 2 + src/engine/tests/engine_tests.cpp | 2 - src/engine/tests/session_tests.cpp | 25 ++ src/host/host.c | 34 +- src/host/host.h | 3 +- src/host/tests/host_args_tests.cpp | 10 +- src/host/tests/host_tests.cpp | 1 + src/host/tests/host_validate_tests.cpp | 63 ++++ src/premake.c | 12 +- src/premake4.lua | 5 - 31 files changed, 782 insertions(+), 183 deletions(-) create mode 100644 samples/gmake/CppExe/Makefile create mode 100644 samples/gmake/Makefile create mode 100644 samples/vs2003/EmptySolution.sln create mode 100644 samples/vs2005/EmptySolution.sln create mode 100644 src/action/make/tests/make_solution_tests.cpp/make_solution_tests.cpp create mode 100644 src/action/vs200x/tests/vs200x_solution_tests.cpp create mode 100644 src/action/vs200x/tests/vs200x_tests.cpp create mode 100644 src/action/vs200x/vs200x.c create mode 100644 src/action/vs200x/vs200x.h create mode 100644 src/host/tests/host_validate_tests.cpp delete mode 100644 src/premake4.lua diff --git a/CHANGES.txt b/CHANGES.txt index 173e8dd3..30484874 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -3,288 +3,288 @@ -------------------- This version is a complete rewrite of Premake. -* New, more readable syntax for project information -* Better validation of command-line arguments -* Standardized path handling across all project settings -* Upgraded to Lua 5.1.2 +- New, more readable syntax for project information +- Better validation of command-line arguments +- Standardized path handling across all project settings +- Upgraded to Lua 5.1.2 -------------------- 3.5 -------------------- -* Prevent creation of import libraries on OS X -* Improved handling of dylibs on OS X -* Patch 1771977: Ability to compile C source as C++ in Code::Blocks (Ryan Pusztai) -* Patch 1771168: luaL_getn speed optimization (Richard O'Grady) -* Bug 1804810: out-implib not present in linux gnu compler toolchain -* Bug 1806949: .Net reference paths are broken when bindir is specified -* Bug 1806960: Make clean does not remove .mdb files -* Bug 1831389: Makefiles stored in subdirs contain no targets on first run +- Prevent creation of import libraries on OS X +- Improved handling of dylibs on OS X +- Patch 1771977: Ability to compile C source as C++ in Code::Blocks (Ryan Pusztai) +- Patch 1771168: luaL_getn speed optimization (Richard O'Grady) +- Bug 1804810: out-implib not present in linux gnu compler toolchain +- Bug 1806949: .Net reference paths are broken when bindir is specified +- Bug 1806960: Make clean does not remove .mdb files +- Bug 1831389: Makefiles stored in subdirs contain no targets on first run -------------------- 3.4 -------------------- -* Added `no-pch` flag to suppress precompiled headers -* Added App.config support to GNU makefiles -* Add os.mkdir() to script environment -* Makefile now creates target directory before copying .NET references -* Feature 1520182: Enhanced file-handling functions -* Bug 531878: Problems with relative paths -* Bug 1723867: Config-specific post-build on GNU target (Benoit Miller) -* Bug 1596826: XML targets doesn't escape xml entities -* Bug 1600155: Core dump due to newpackage() and matchfiles() -* Bug 1608895: resgen command shown -* Bug 1639730: Output filename is not set -* Bug 1729227: non-portable executable with relative library path -* Bug 1559951: default clean rule removes package dir -* Patch 1733674: PCH support for Code::Block targets (Ryan Pusztai) -* Patch 1746563: Ability to specify GUID for VS targets (Ryan Pusztai) -* Patch 1754867: Creating import lib of different name (Ryan Pusztai) +- Added `no-pch` flag to suppress precompiled headers +- Added App.config support to GNU makefiles +- Add os.mkdir() to script environment +- Makefile now creates target directory before copying .NET references +- Feature 1520182: Enhanced file-handling functions +- Bug 531878: Problems with relative paths +- Bug 1723867: Config-specific post-build on GNU target (Benoit Miller) +- Bug 1596826: XML targets doesn't escape xml entities +- Bug 1600155: Core dump due to newpackage() and matchfiles() +- Bug 1608895: resgen command shown +- Bug 1639730: Output filename is not set +- Bug 1729227: non-portable executable with relative library path +- Bug 1559951: default clean rule removes package dir +- Patch 1733674: PCH support for Code::Block targets (Ryan Pusztai) +- Patch 1746563: Ability to specify GUID for VS targets (Ryan Pusztai) +- Patch 1754867: Creating import lib of different name (Ryan Pusztai) -------------------- 3.3 -------------------- -* Added support for prebuild, prelink, and postbuild commands -* Added `target` global variable to script environment -* Added build flag `no-edit-and-continue` -* Added build flags `native-wchar` and `no-native-wchar` -* Added build flag `no-manifest` -* Added build flag `seh-exceptions` (VS2005 only) -* Added `resdefines`, `respaths`, and `resoptions` -* Added `prebuildcommands`, `prelinkcommands`, and `postbuildcommands` -* Added `pchheader` and `pchsource` (Visual Studio only) -* Feature 1337547: Package-level bindir and libdir -* Bug 1565755: Generated makefiles do not work with MSYS -* Bug 1587955: Target path ignored for libs -* Bug 1574725: Static library extension for "gnu" target -* Bug 1522861: Fixed by using "ar -rcs" instead of "ar -cr && ranlib" -* Bug 1656816: Mkdir set wrong directory rights -* Bug 1655595: Compile/build problem on FreeBSD -* Bug: "gnu" clean rule doesn't work in cmd.exe -* Improved behavior of Linux findlib() -* Updated Code::Blocks support to latest project version (major="1" minor="6") -* Patch 1681666: GNU targets always show the console if kind = 'winexe' +- Added support for prebuild, prelink, and postbuild commands +- Added `target` global variable to script environment +- Added build flag `no-edit-and-continue` +- Added build flags `native-wchar` and `no-native-wchar` +- Added build flag `no-manifest` +- Added build flag `seh-exceptions` (VS2005 only) +- Added `resdefines`, `respaths`, and `resoptions` +- Added `prebuildcommands`, `prelinkcommands`, and `postbuildcommands` +- Added `pchheader` and `pchsource` (Visual Studio only) +- Feature 1337547: Package-level bindir and libdir +- Bug 1565755: Generated makefiles do not work with MSYS +- Bug 1587955: Target path ignored for libs +- Bug 1574725: Static library extension for "gnu" target +- Bug 1522861: Fixed by using "ar -rcs" instead of "ar -cr && ranlib" +- Bug 1656816: Mkdir set wrong directory rights +- Bug 1655595: Compile/build problem on FreeBSD +- Bug: "gnu" clean rule doesn't work in cmd.exe +- Improved behavior of Linux findlib() +- Updated Code::Blocks support to latest project version (major="1" minor="6") +- Patch 1681666: GNU targets always show the console if kind = 'winexe' -------------------- 3.2 -------------------- -* Added support for Code::Blocks -* Updated MonoDevelop support -* Upgraded Lua to 5.0.3 -* Added new matchdirs() to Lua script environment -* Expose list of packages as _PACKAGES global in Lua -* Turn off edit-and-continue in release builds with symbols -* Bug 1559873: libpaths inserts extra space after -L +- Added support for Code::Blocks +- Updated MonoDevelop support +- Upgraded Lua to 5.0.3 +- Added new matchdirs() to Lua script environment +- Expose list of packages as _PACKAGES global in Lua +- Turn off edit-and-continue in release builds with symbols +- Bug 1559873: libpaths inserts extra space after -L -------------------- 3.1 -------------------- -* Added support for Visual Studio 2005 -* Added support for Windows resources to GNU make target -* Added path handling functions to Lua environment -* Added matchrecursive() for recursive file searches -* Added os.fileexists() function to Lua environment -* Added os.appendfile() function to Lua environment -* Changed `monoresgen` to `resgen` to keep up with Mono project -* Added `mono2` .NET compiler set for Mono .NET 2.0 support -* Feature 1096677: exclude files from matchfiles (package.excludes) -* Bug 1439463: VS2003 RTTI problem -* Bug 1439446: GNU Makefile problem under Mingw32 -* Bug 1422068: package.path="." causes bad makefiles -* Bug 1431530: makefile target fails when project path specified +- Added support for Visual Studio 2005 +- Added support for Windows resources to GNU make target +- Added path handling functions to Lua environment +- Added matchrecursive() for recursive file searches +- Added os.fileexists() function to Lua environment +- Added os.appendfile() function to Lua environment +- Changed `monoresgen` to `resgen` to keep up with Mono project +- Added `mono2` .NET compiler set for Mono .NET 2.0 support +- Feature 1096677: exclude files from matchfiles (package.excludes) +- Bug 1439463: VS2003 RTTI problem +- Bug 1439446: GNU Makefile problem under Mingw32 +- Bug 1422068: package.path="." causes bad makefiles +- Bug 1431530: makefile target fails when project path specified -------------------- 3.0 -------------------- -* Upgraded Lua interpreter to version 5.0.1 -* The options table now stores simple values, rather than tables -* Completed MonoDevelop support -* Improved .NET resource handling for GNU generator -* Added unit test suite -* Merged Scott Graham unicode build flag patch -* Removed package.warninglevel in favor of extra-warnings flag -* Added package.targetprefix -* Overhauled structure of generated GNU makefiles -* Added --os command line option -* Fixed bug 1268588: Use gcc to link C packages -* Fixed bug 1363306: GNU C# should copy referenced DLLs +- Upgraded Lua interpreter to version 5.0.1 +- The options table now stores simple values, rather than tables +- Completed MonoDevelop support +- Improved .NET resource handling for GNU generator +- Added unit test suite +- Merged Scott Graham unicode build flag patch +- Removed package.warninglevel in favor of extra-warnings flag +- Added package.targetprefix +- Overhauled structure of generated GNU makefiles +- Added --os command line option +- Fixed bug 1268588: Use gcc to link C packages +- Fixed bug 1363306: GNU C# should copy referenced DLLs -------------------- 2.4 -------------------- -* Added chdir() to Lua script environment -* Merged Thomas Harning's patch for .NET resources on GNU -* Fixed bug 1194702: Can't put multiple packages in same directory -* Fixed bug in GNU shared library builds (doh!) -* Added target 'vs2002' to replace 'vs7' +- Added chdir() to Lua script environment +- Merged Thomas Harning's patch for .NET resources on GNU +- Fixed bug 1194702: Can't put multiple packages in same directory +- Fixed bug in GNU shared library builds (doh!) +- Added target 'vs2002' to replace 'vs7' -------------------- 2.3 -------------------- -* Added 'project.config[]' with 'bindir' and 'libdir' -* Merged Scott Graham's "warninglevel" patch. -* Fixed bug 1153484: Import lib in wrong directory. -* Fixed bug 1013352: Stack overflow with large projects. -* Fixed bug 945406: package.files, bad value = crash +- Added 'project.config[]' with 'bindir' and 'libdir' +- Merged Scott Graham's "warninglevel" patch. +- Fixed bug 1153484: Import lib in wrong directory. +- Fixed bug 1013352: Stack overflow with large projects. +- Fixed bug 945406: package.files, bad value = crash -------------------- 2.2 -------------------- -* Worked around VS.NET bug for .NET assemblies > 64K. -* Added --very-verbose flag to GNU generator. -* GNU generator now supports assembly sources. +- Worked around VS.NET bug for .NET assemblies > 64K. +- Added --very-verbose flag to GNU generator. +- GNU generator now supports assembly sources. -------------------- 2.1 -------------------- -* File extension of generated binaries can now be set +- File extension of generated binaries can now be set with config.targetextension. -* Windows targets now handle .def files for DLLs. +- Windows targets now handle .def files for DLLs. -------------------- 2.0 -------------------- -* Can now specify build actions per file -* Include paths are now passed to VC7 resource compiler -* Removed _WIN32 define from Cygwin makefiles -* Added package.objdir to set intermediates directory -* Added rmdir() to Lua script environment -* A big bag of bug fixes +- Can now specify build actions per file +- Include paths are now passed to VC7 resource compiler +- Removed _WIN32 define from Cygwin makefiles +- Added package.objdir to set intermediates directory +- Added rmdir() to Lua script environment +- A big bag of bug fixes -------------------- 1.9 -------------------- -* Made verbose mode even more verbose. -* posix.c now builds properly as C. -* Fixed package dependency generation for GNU and VS2003. -* Display Lua version number in usage text. -* Fixed VS link between *.aspx and *.aspx.cs files. -* Fixed VS link between *.resx and *.cs files. -* Fixed *.d file generation for gcc 2.9x. -* Unified various help options under '--help'. -* Bin and Lib paths can now be arbitrarily long. -* linkoptions are now applied in VC6 and VC7 projects. +- Made verbose mode even more verbose. +- posix.c now builds properly as C. +- Fixed package dependency generation for GNU and VS2003. +- Display Lua version number in usage text. +- Fixed VS link between *.aspx and *.aspx.cs files. +- Fixed VS link between *.resx and *.cs files. +- Fixed *.d file generation for gcc 2.9x. +- Unified various help options under '--help'. +- Bin and Lib paths can now be arbitrarily long. +- linkoptions are now applied in VC6 and VC7 projects. -------------------- 1.8 -------------------- -* Added support for ASP.NET projects. -* Fixed a bug in VC6 support for static libraries. -* matchfiles() now uses package path instead of script path. -* Added --verbose option. -* No longer apply no-rtti and no-exceptions to *.c files. +- Added support for ASP.NET projects. +- Fixed a bug in VC6 support for static libraries. +- matchfiles() now uses package path instead of script path. +- Added --verbose option. +- No longer apply no-rtti and no-exceptions to *.c files. -------------------- 1.7 -------------------- -* Location of generated project files can now be specified with +- Location of generated project files can now be specified with the project.path variable. -* Inter-package dependencies are fixed for GNU makefiles. -* No longer need to execute in same directory as project script. -* Added "c" language specifier. -* Added support for .resx and .config files to C# projects. -* Added support for full assembly names in .NET references. -* Fixed handling of paths in package.target variable. -* Improved support for SharpDevelop. -* Started support for OS X. -* Added support for Digital Mars compiler. +- Inter-package dependencies are fixed for GNU makefiles. +- No longer need to execute in same directory as project script. +- Added "c" language specifier. +- Added support for .resx and .config files to C# projects. +- Added support for full assembly names in .NET references. +- Fixed handling of paths in package.target variable. +- Improved support for SharpDevelop. +- Started support for OS X. +- Added support for Digital Mars compiler. -------------------- 1.6 -------------------- -* VS7 generator crashed if a package was built before one of its +- VS7 generator crashed if a package was built before one of its dependencies. Now immediately assigns UUID before processing. -* Added support for Visual Studio 2003 and SharpDevelop. -* Added binaries directory as a reference path for VS7. +- Added support for Visual Studio 2003 and SharpDevelop. +- Added binaries directory as a reference path for VS7. -------------------- 1.5 -------------------- -* Added initial support for building static libraries. -* Added "no-main" flag, prevents overriding WinMain() on +- Added initial support for building static libraries. +- Added "no-main" flag, prevents overriding WinMain() on Windows builds. -* Added "--no-rtti" and "no-exceptions" build flags to +- Added "--no-rtti" and "no-exceptions" build flags to disable those C++ features. -* Display error message when project has no packages. -* Moved VC7 *.pdb files into intermediates directory. +- Display error message when project has no packages. +- Moved VC7 *.pdb files into intermediates directory. -------------------- 1.4 -------------------- -* Bug fixes to the path manipulation routines. -* GNU makefiles are regenerated when premake scripts change. +- Bug fixes to the path manipulation routines. +- GNU makefiles are regenerated when premake scripts change. -------------------- 1.3 -------------------- -* Added support for the Cygwin environment. -* Added "static-runtime" build flag to statically link against C/C++ +- Added support for the Cygwin environment. +- Added "static-runtime" build flag to statically link against C/C++ standard runtime libraries. -* Bug fixes to Visual Studio 6 and 7 generators and path reversing +- Bug fixes to Visual Studio 6 and 7 generators and path reversing algorithm. -------------------- 1.2 -------------------- -* Standardized format of command-line options. -* Can now handle custom command-line options in script. -* Added new function findlib(). -* Added new C++ build flag "managed" for writing C++ .NET code. -* Can now use open-source C# compilers in VS6 generator. -* Several bug fixes to the VS7 generator. +- Standardized format of command-line options. +- Can now handle custom command-line options in script. +- Added new function findlib(). +- Added new C++ build flag "managed" for writing C++ .NET code. +- Can now use open-source C# compilers in VS6 generator. +- Several bug fixes to the VS7 generator. -------------------- 1.1 -------------------- -* Added support for custom build configurations. Added "optimize", +- Added support for custom build configurations. Added "optimize", "optimize-size", "optimize-speed", and "no-symbols" flags to control build settings. -* Added matchfiles() to select files using wildcards. -* Added "unsafe" flag for C# projects. -* Added newpackage() function for creating new package objects inline, +- Added matchfiles() to select files using wildcards. +- Added "unsafe" flag for C# projects. +- Added newpackage() function for creating new package objects inline, instead of creating separate scripts. -* Changed include() to dopackage() and option() to addoption(). The old +- Changed include() to dopackage() and option() to addoption(). The old versions have been kept for compatibility, but will be deprecated eventually. -* Major cleanup of the source code. +- Major cleanup of the source code. -------------------- 1.0 -------------------- -* Fixed a bug related to the reference paths in VS7 C# projects. -* Display a warning message if a reference path can't be found. -* Automatically create bin and lib directories if they do not exist. -* GNU C# projects will now properly use the configured library paths. -* Added --with-mono and --with-pnet options. -* VS7 C# projects will now properly use the configured library paths. -* Switched to Lua (http://www.lua.org/) for project script parsing. -* Add support for custom project options. -* Changed 'type' to 'kind' to avoid conflict with Lua function of the same name. -* Changed 'conexe' to 'exe' because I liked it better. -* Changed 'library' to 'dll' for C# projects to keep things consistent. +- Fixed a bug related to the reference paths in VS7 C# projects. +- Display a warning message if a reference path can't be found. +- Automatically create bin and lib directories if they do not exist. +- GNU C# projects will now properly use the configured library paths. +- Added --with-mono and --with-pnet options. +- VS7 C# projects will now properly use the configured library paths. +- Switched to Lua (http://www.lua.org/) for project script parsing. +- Add support for custom project options. +- Changed 'type' to 'kind' to avoid conflict with Lua function of the same name. +- Changed 'conexe' to 'exe' because I liked it better. +- Changed 'library' to 'dll' for C# projects to keep things consistent. -------------------- 0.9 -------------------- -* Initial public release. +- Initial public release. diff --git a/premake4.lua b/premake4.lua index 02aba03e..8a975d8b 100644 --- a/premake4.lua +++ b/premake4.lua @@ -5,7 +5,6 @@ solution "Premake4" -include "src" diff --git a/samples/gmake/CppExe/Makefile b/samples/gmake/CppExe/Makefile new file mode 100644 index 00000000..ee1101a6 --- /dev/null +++ b/samples/gmake/CppExe/Makefile @@ -0,0 +1,90 @@ +# GNU Makefile autogenerated by Premake +# Please build using the solution Makefile at: +# ../Makefile + +ifndef CONFIG + CONFIG=Debug +endif + +ifeq ($(CONFIG),Debug) + BINDIR := .. + LIBDIR := .. + OBJDIR := obj/Debug + OUTDIR := .. + CPPFLAGS := -MMD + CFLAGS += $(CPPFLAGS) $(TARGET_ARCH) -g + CXXFLAGS := $(CFLAGS) + LDFLAGS += -L$(BINDIR) -L$(LIBDIR) + LDDEPS := + RESFLAGS := + TARGET := CppExe.exe + BLDCMD = $(CXX) -o $(OUTDIR)/$(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(TARGET_ARCH) +endif + +ifeq ($(CONFIG),Release) + BINDIR := .. + LIBDIR := .. + OBJDIR := obj/Release + OUTDIR := .. + CPPFLAGS := -MMD + CFLAGS += $(CPPFLAGS) $(TARGET_ARCH) -O2 + CXXFLAGS := $(CFLAGS) + LDFLAGS += -L$(BINDIR) -L$(LIBDIR) -s + LDDEPS := + RESFLAGS := + TARGET := CppExe.exe + BLDCMD = $(CXX) -o $(OUTDIR)/$(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(TARGET_ARCH) +endif + +OBJECTS := \ + $(OBJDIR)/Hello.o \ + +RESOURCES := \ + +MKDIR_TYPE := msdos +CMD := $(subst \,\\,$(ComSpec)$(COMSPEC)) +ifeq (,$(CMD)) + MKDIR_TYPE := posix +endif +ifeq (/bin/sh.exe,$(SHELL)) + MKDIR_TYPE := posix +endif +ifeq ($(MKDIR_TYPE),posix) + CMD_MKBINDIR := mkdir -p $(BINDIR) + CMD_MKLIBDIR := mkdir -p $(LIBDIR) + CMD_MKOUTDIR := mkdir -p $(OUTDIR) + CMD_MKOBJDIR := mkdir -p $(OBJDIR) +else + CMD_MKBINDIR := $(CMD) /c if not exist $(subst /,\\,$(BINDIR)) mkdir $(subst /,\\,$(BINDIR)) + CMD_MKLIBDIR := $(CMD) /c if not exist $(subst /,\\,$(LIBDIR)) mkdir $(subst /,\\,$(LIBDIR)) + CMD_MKOUTDIR := $(CMD) /c if not exist $(subst /,\\,$(OUTDIR)) mkdir $(subst /,\\,$(OUTDIR)) + CMD_MKOBJDIR := $(CMD) /c if not exist $(subst /,\\,$(OBJDIR)) mkdir $(subst /,\\,$(OBJDIR)) +endif + +.PHONY: clean + +$(OUTDIR)/$(TARGET): $(OBJECTS) $(LDDEPS) $(RESOURCES) + @echo Linking CppExe + -@$(CMD_MKBINDIR) + -@$(CMD_MKLIBDIR) + -@$(CMD_MKOUTDIR) + @$(BLDCMD) + +clean: + @echo Cleaning CppExe +ifeq ($(MKDIR_TYPE),posix) + -@rm -f $(OUTDIR)/$(TARGET) + -@rm -rf $(OBJDIR) +else + -@if exist $(subst /,\,$(OUTDIR)/$(TARGET)) del /q $(subst /,\,$(OUTDIR)/$(TARGET)) + -@if exist $(subst /,\,$(OBJDIR)) del /q $(subst /,\,$(OBJDIR)) + -@if exist $(subst /,\,$(OBJDIR)) rmdir /s /q $(subst /,\,$(OBJDIR)) +endif + +$(OBJDIR)/Hello.o: Hello.cpp + -@$(CMD_MKOBJDIR) + @echo $(notdir $<) + @$(CXX) $(CXXFLAGS) -o $@ -c $< + +-include $(OBJECTS:%.o=%.d) + diff --git a/samples/gmake/Makefile b/samples/gmake/Makefile new file mode 100644 index 00000000..af4ce8dd --- /dev/null +++ b/samples/gmake/Makefile @@ -0,0 +1,24 @@ +# GNU Makefile autogenerated by Premake +# Usage: make [ CONFIG=config_name ] +# Where {config_name} is one of: +# Debug, Release + +ifndef CONFIG + CONFIG=Debug +endif +export CONFIG + +.PHONY: all clean CppExe + +all: CppExe + +Makefile: premake.lua CppExe/premake.lua + @echo ==== Regenerating Makefiles ==== + @premake --file $^ --target gnu + +CppExe: + @echo ==== Building CppExe ==== + @$(MAKE) --no-print-directory -C CppExe + +clean: + @$(MAKE) --no-print-directory -C CppExe clean diff --git a/samples/vs2003/EmptySolution.sln b/samples/vs2003/EmptySolution.sln new file mode 100644 index 00000000..ff0f832b --- /dev/null +++ b/samples/vs2003/EmptySolution.sln @@ -0,0 +1,11 @@ +Microsoft Visual Studio Solution File, Format Version 8.00 +Global + GlobalSection(SolutionConfiguration) = preSolution + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/samples/vs2005/EmptySolution.sln b/samples/vs2005/EmptySolution.sln new file mode 100644 index 00000000..634e232c --- /dev/null +++ b/samples/vs2005/EmptySolution.sln @@ -0,0 +1,8 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Global + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/action/make/gmake.c b/src/action/make/gmake.c index d56be2a9..9dad4084 100644 --- a/src/action/make/gmake.c +++ b/src/action/make/gmake.c @@ -14,6 +14,7 @@ static SessionSolutionCallback GmakeSolutionCallbacks[] = { make_solution_create, + make_solution_signature, NULL }; diff --git a/src/action/make/make_solution.c b/src/action/make/make_solution.c index d74e54f5..5304e3f6 100644 --- a/src/action/make/make_solution.c +++ b/src/action/make/make_solution.c @@ -4,6 +4,7 @@ * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project */ +#include #include "premake.h" #include "action/make/make.h" #include "action/make/make_solution.h" @@ -32,3 +33,25 @@ int make_solution_create(Session sess, Solution sln, Stream strm) return OKAY; } + +/** + * Write the solution file signature block. + * \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 make_solution_signature(Session sess, Solution sln, Stream strm) +{ + int z = OKAY; + + assert(strm); + sess = 0; /* unused */ + sln = 0; /* unused */ + + z |= stream_writeline(strm, "# GNU Makefile autogenerated by Premake"); + z |= stream_writeline(strm, "# Usage: make [ CONFIG=config_name ]"); + z |= stream_writeline(strm, "# Where {config_name} is one of:"); + + return z; +} diff --git a/src/action/make/make_solution.h b/src/action/make/make_solution.h index 9d5f6c5e..fa279f20 100644 --- a/src/action/make/make_solution.h +++ b/src/action/make/make_solution.h @@ -9,5 +9,6 @@ #include "engine/session.h" int make_solution_create(Session sess, Solution sln, Stream strm); +int make_solution_signature(Session sess, Solution sln, Stream strm); #endif diff --git a/src/action/make/tests/make_solution_tests.cpp/make_solution_tests.cpp b/src/action/make/tests/make_solution_tests.cpp/make_solution_tests.cpp new file mode 100644 index 00000000..62ff1fc1 --- /dev/null +++ b/src/action/make/tests/make_solution_tests.cpp/make_solution_tests.cpp @@ -0,0 +1,56 @@ +/** + * \file make_solution_tests.cpp + * \brief Automated tests for makefile solution processing. + * \author Copyright (c) 2008 Jason Perkins and the Premake project + */ + +#include "premake.h" +#include "testing/testing.h" +extern "C" { +#include "action/make/make_solution.h" +} + +struct FxMakeSln +{ + Session sess; + Stream strm; + Solution sln; + char buffer[8192]; + + FxMakeSln() + { + sess = session_create(); + + strm = stream_create_null(); + stream_set_buffer(strm, buffer); + + sln = solution_create(); + } + + ~FxMakeSln() + { + solution_destroy(sln); + stream_destroy(strm); + session_destroy(sess); + } +}; + + +SUITE(action) +{ + /********************************************************************** + * Signature tests + **********************************************************************/ + + TEST_FIXTURE(FxMakeSln, Signature_IsCorrect_OnGnuMake) + { + session_set_action(sess, "gmake"); + make_solution_signature(sess, sln, strm); + CHECK_EQUAL( + "# GNU Makefile autogenerated by Premake\n" + "# Usage: make [ CONFIG=config_name ]\n" + "# Where {config_name} is one of:\n", + buffer); + } + +} diff --git a/src/action/vs200x/tests/vs200x_solution_tests.cpp b/src/action/vs200x/tests/vs200x_solution_tests.cpp new file mode 100644 index 00000000..86eb1683 --- /dev/null +++ b/src/action/vs200x/tests/vs200x_solution_tests.cpp @@ -0,0 +1,73 @@ +/** + * \file vs200x_solution_tests.cpp + * \brief Automated tests for VS200x solution processing. + * \author Copyright (c) 2008 Jason Perkins and the Premake project + */ + +#include "premake.h" +#include "testing/testing.h" +extern "C" { +#include "action/vs200x/vs200x_solution.h" +} + +struct FxVs200xSln +{ + Session sess; + Stream strm; + Solution sln; + char buffer[8192]; + + FxVs200xSln() + { + sess = session_create(); + + strm = stream_create_null(); + stream_set_buffer(strm, buffer); + + sln = solution_create(); + } + + ~FxVs200xSln() + { + solution_destroy(sln); + stream_destroy(strm); + session_destroy(sess); + } +}; + + +SUITE(action) +{ + /********************************************************************** + * Signature tests + **********************************************************************/ + + TEST_FIXTURE(FxVs200xSln, Signature_IsCorrect_OnVs2002) + { + session_set_action(sess, "vs2002"); + vs200x_solution_signature(sess, sln, strm); + CHECK_EQUAL( + "\357\273\277Microsoft Visual Studio Solution File, Format Version 7.00\r\n", + buffer); + } + + TEST_FIXTURE(FxVs200xSln, Signature_IsCorrect_OnVs2003) + { + session_set_action(sess, "vs2003"); + vs200x_solution_signature(sess, sln, strm); + CHECK_EQUAL( + "\357\273\277Microsoft Visual Studio Solution File, Format Version 8.00\r\n", + buffer); + } + + TEST_FIXTURE(FxVs200xSln, Signature_IsCorrect_OnVs2005) + { + session_set_action(sess, "vs2005"); + vs200x_solution_signature(sess, sln, strm); + CHECK_EQUAL( + "\357\273\277\r\n" + "Microsoft Visual Studio Solution File, Format Version 9.00\r\n" + "# Visual Studio 2005\r\n", + buffer); + } +} diff --git a/src/action/vs200x/tests/vs200x_tests.cpp b/src/action/vs200x/tests/vs200x_tests.cpp new file mode 100644 index 00000000..0228717d --- /dev/null +++ b/src/action/vs200x/tests/vs200x_tests.cpp @@ -0,0 +1,54 @@ +/** + * \file vs200x_tests.cpp + * \brief Automated tests for VS200x support functions. + * \author Copyright (c) 2008 Jason Perkins and the Premake project + */ + +#include "premake.h" +#include "testing/testing.h" +extern "C" { +#include "action/vs200x/vs200x.h" +} + +struct FxVs200x +{ + Session sess; + + FxVs200x() + { + sess = session_create(); + } + + ~FxVs200x() + { + session_destroy(sess); + } +}; + +SUITE(action) +{ + /********************************************************************** + * Version identification tests + **********************************************************************/ + + TEST_FIXTURE(FxVs200x, GetTargetVersion_Returns2002_OnVs2002) + { + session_set_action(sess, "vs2002"); + int result = vs200x_get_target_version(sess); + CHECK(result == 2002); + } + + TEST_FIXTURE(FxVs200x, GetTargetVersion_Returns2003_OnVs2003) + { + session_set_action(sess, "vs2003"); + int result = vs200x_get_target_version(sess); + CHECK(result == 2003); + } + + TEST_FIXTURE(FxVs200x, GetTargetVersion_Returns2005_OnVs2005) + { + session_set_action(sess, "vs2005"); + int result = vs200x_get_target_version(sess); + CHECK(result == 2005); + } +} diff --git a/src/action/vs200x/vs2005.c b/src/action/vs200x/vs2005.c index 196113b0..8df792d5 100644 --- a/src/action/vs200x/vs2005.c +++ b/src/action/vs200x/vs2005.c @@ -14,6 +14,7 @@ static SessionSolutionCallback Vs2005SolutionCallbacks[] = { vs200x_solution_create, + vs200x_solution_signature, NULL }; diff --git a/src/action/vs200x/vs200x.c b/src/action/vs200x/vs200x.c new file mode 100644 index 00000000..eaf61763 --- /dev/null +++ b/src/action/vs200x/vs200x.c @@ -0,0 +1,38 @@ +/** + * \file vs200x.c + * \brief General purpose Visual Studio support functions. + * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project + */ + +#include +#include "premake.h" +#include "vs200x.h" +#include "base/cstr.h" + + +/** + * Converts the session action string to a Visual Studio version number. + * \param sess The current execution session. + * \returns The Visual Studio version number corresponding to the current action. + */ +int vs200x_get_target_version(Session sess) +{ + const char* action = session_get_action(sess); + if (cstr_eq(action, "vs2002")) + { + return 2002; + } + else if (cstr_eq(action, "vs2003")) + { + return 2003; + } + else if (cstr_eq(action, "vs2005")) + { + return 2005; + } + else + { + assert(0); + return 0; + } +} diff --git a/src/action/vs200x/vs200x.h b/src/action/vs200x/vs200x.h new file mode 100644 index 00000000..5053551b --- /dev/null +++ b/src/action/vs200x/vs200x.h @@ -0,0 +1,14 @@ +/** + * \file vs200x.h + * \brief General purpose Visual Studio support functions. + * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project + */ +#if !defined(PREMAKE_VS200X_H) +#define PREMAKE_VS200X_H + +#include "engine/session.h" + +int vs200x_get_target_version(Session sess); + +#endif + diff --git a/src/action/vs200x/vs200x_solution.c b/src/action/vs200x/vs200x_solution.c index f48360a1..bce1f4b0 100644 --- a/src/action/vs200x/vs200x_solution.c +++ b/src/action/vs200x/vs200x_solution.c @@ -4,10 +4,12 @@ * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project */ +#include #include #include "premake.h" +#include "vs200x.h" +#include "vs200x_solution.h" #include "base/error.h" -#include "action/vs200x/vs200x_solution.h" /** @@ -32,3 +34,40 @@ int vs200x_solution_create(Session sess, Solution sln, Stream strm) return OKAY; } + +/** + * Write the solution file signature block. + * \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_signature(Session sess, Solution sln, Stream strm) +{ + int version, z; + + assert(sess); + assert(strm); + sln = 0; /* unused */ + + stream_set_newline(strm, "\r\n"); + z = stream_write_unicode_marker(strm); + + version = vs200x_get_target_version(sess); + switch (version) + { + case 2002: + z |= stream_writeline(strm, "Microsoft Visual Studio Solution File, Format Version 7.00"); + break; + case 2003: + z |= stream_writeline(strm, "Microsoft Visual Studio Solution File, Format Version 8.00"); + break; + case 2005: + z |= stream_writeline(strm, ""); + z |= stream_writeline(strm, "Microsoft Visual Studio Solution File, Format Version 9.00"); + z |= stream_writeline(strm, "# Visual Studio 2005"); + break; + } + + return z; +} diff --git a/src/action/vs200x/vs200x_solution.h b/src/action/vs200x/vs200x_solution.h index 446f7619..8ef0971a 100644 --- a/src/action/vs200x/vs200x_solution.h +++ b/src/action/vs200x/vs200x_solution.h @@ -9,5 +9,6 @@ #include "engine/session.h" int vs200x_solution_create(Session sess, Solution sln, Stream strm); +int vs200x_solution_signature(Session sess, Solution sln, Stream strm); #endif diff --git a/src/base/stream.c b/src/base/stream.c index 3b3de4d7..7f10b199 100644 --- a/src/base/stream.c +++ b/src/base/stream.c @@ -170,6 +170,16 @@ int stream_write(Stream strm, const char* value, ...) } +/** + * Writes the Unicode encoding marker sequence into the stream. + * \param strm The stream to which to write. + */ +int stream_write_unicode_marker(Stream strm) +{ + return stream_write(strm, "\357\273\277"); +} + + /** * Write a string value, followed by a newline, to a stream. * \param strm The stream. diff --git a/src/base/stream.h b/src/base/stream.h index c414ad56..11d4ee62 100644 --- a/src/base/stream.h +++ b/src/base/stream.h @@ -16,6 +16,7 @@ void stream_destroy(Stream stream); void stream_set_buffer(Stream strm, char* buffer); void stream_set_newline(Stream strm, const char* newline); int stream_write(Stream strm, const char* value, ...); +int stream_write_unicode_marker(Stream strm); int stream_writeline(Stream strm, const char* value, ...); #endif diff --git a/src/engine/internals.h b/src/engine/internals.h index 342d861f..953ef68f 100644 --- a/src/engine/internals.h +++ b/src/engine/internals.h @@ -15,6 +15,7 @@ /* string constants for script variables and functions */ +#define ACTION_KEY "_ACTION" #define CONFIGURATION_KEY "configuration" #define FILE_KEY "_FILE" #define PROJECT_KEY "project" diff --git a/src/engine/session.c b/src/engine/session.c index 83052e8f..48348707 100644 --- a/src/engine/session.c +++ b/src/engine/session.c @@ -140,7 +140,7 @@ int session_enumerate_objects(Session sess, SessionSolutionCallback* sln_funcs, Solution sln = session_get_solution(sess, si); for (sfi = 0; result == OKAY && sln_funcs[sfi] != NULL; ++sfi) { - result = sln_funcs[sfi](sess, sln, NULL); + result = sln_funcs[sfi](sess, sln, sess->active_stream); } } @@ -154,6 +154,23 @@ int session_enumerate_objects(Session sess, SessionSolutionCallback* sln_funcs, } +/** + * Get the action name to be performed by this execution run. + * \param sess The session object. + * \returns The action name if set, or NULL. + */ +const char* session_get_action(Session sess) +{ + const char* action; + + assert(sess); + lua_getglobal(sess->L, ACTION_KEY); + action = lua_tostring(sess->L, -1); + lua_pop(sess->L, 1); + return action; +} + + /** * Retrieve the Lua engine state for this session; used for internal testing. */ @@ -286,6 +303,20 @@ const char* session_run_string(Session sess, const char* script) } +/** + * Set the action name to be performed on this execution pass. The action name will + * be placed in the _ACTION script environment global. + * \param sess The current execution session context. + * \param action The name of the action to be performed. + */ +void session_set_action(Session sess, const char* action) +{ + assert(sess); + lua_pushstring(sess->L, action); + lua_setglobal(sess->L, ACTION_KEY); +} + + /** * Set the active output stream, which will be passed to subsequent callbacks during * object processing by session_enumerate_objects(). If there is an existing active diff --git a/src/engine/session.h b/src/engine/session.h index 97761681..460f0496 100644 --- a/src/engine/session.h +++ b/src/engine/session.h @@ -60,10 +60,12 @@ Session session_create(void); void session_destroy(Session sess); void session_add_solution(Session sess, Solution sln); int session_enumerate_objects(Session sess, SessionSolutionCallback* sln_funcs, SessionProjectCallback* prj_funcs); +const char* session_get_action(Session sess); Solution session_get_solution(Session sess, int index); int session_num_solutions(Session sess); const char* session_run_file(Session sess, const char* filename); const char* session_run_string(Session sess, const char* script); +void session_set_action(Session sess, const char* action); void session_set_active_stream(Session sess, Stream strm); int session_unload(Session sess); diff --git a/src/engine/tests/engine_tests.cpp b/src/engine/tests/engine_tests.cpp index 94e8771c..f7c992f3 100644 --- a/src/engine/tests/engine_tests.cpp +++ b/src/engine/tests/engine_tests.cpp @@ -10,7 +10,6 @@ extern "C" { #include "base/base.h" #include "project/project.h" #include "engine/engine.h" -#include "action/action.h" } @@ -26,6 +25,5 @@ int engine_tests() if (status == OKAY) status = tests_run_suite("session"); if (status == OKAY) status = tests_run_suite("engine"); if (status == OKAY) status = tests_run_suite("unload"); - if (status == OKAY) status = tests_run_suite("action"); return status; } diff --git a/src/engine/tests/session_tests.cpp b/src/engine/tests/session_tests.cpp index ea87d4b9..d2767609 100644 --- a/src/engine/tests/session_tests.cpp +++ b/src/engine/tests/session_tests.cpp @@ -97,6 +97,31 @@ SUITE(session) } + /********************************************************************** + * Action handling tests + **********************************************************************/ + + TEST_FIXTURE(FxSession, SetAction_SetScriptVar) + { + session_set_action(sess, "MyAction"); + const char* result = session_run_string(sess, "return _ACTION"); + CHECK_EQUAL("MyAction", result); + } + + TEST_FIXTURE(FxSession, GetAction_ReturnsNull_OnNoAction) + { + const char* result = session_get_action(sess); + CHECK(result == NULL); + } + + TEST_FIXTURE(FxSession, GetAction_GetsFromScriptVar) + { + session_run_string(sess, "_ACTION = 'SomeAction'"); + const char* result = session_get_action(sess); + CHECK_EQUAL("SomeAction", result); + } + + /********************************************************************** * Solution containment tests **********************************************************************/ diff --git a/src/host/host.c b/src/host/host.c index ceea97b6..58f69b98 100644 --- a/src/host/host.c +++ b/src/host/host.c @@ -17,6 +17,18 @@ static const char** Args = NULL; +/** + * Initial processing and validation of the command line arguments. + * \param sess The current execution session. + * \returns OKAY on success. + */ +int host_parse_argv(Session sess) +{ + session_set_action(sess, Args[0]); + return OKAY; +} + + /** * Display the results of the application run. * Any errors returned during the run will be written to stderr; otherwise, a @@ -49,9 +61,8 @@ int host_run_action(Session sess) assert(sess); - /* identify the action */ + /* find the action in the master list and execute the associated callback */ action = Args[0]; - for (i = 0; Actions[i].name != NULL; ++i) { if (cstr_eq(Actions[i].name, action)) @@ -146,3 +157,22 @@ int host_show_help(Session sess) return OKAY; } + + +/** + * Make sure that the session contains a valid set of project objects: at least + * one solution, each solution contains at least one project, etc. + * \param sess The current execution session context. + * \returns OKAY if the session is valid. + */ +int host_validate_session(Session sess) +{ + assert(sess); + if (session_num_solutions(sess) == 0) + { + error_set("no solutions defined"); + return !OKAY; + } + + return OKAY; +} diff --git a/src/host/host.h b/src/host/host.h index af55be69..be097c73 100644 --- a/src/host/host.h +++ b/src/host/host.h @@ -23,7 +23,7 @@ typedef int (*HostExecutionStep)(Session sess); -int host_process_args(Session sess); +int host_parse_argv(Session sess); int host_report_results(Session sess); int host_run_action(Session sess); int host_run_script(Session sess); @@ -31,5 +31,6 @@ int host_run_steps(Session sess, HostExecutionStep* steps); void host_set_argv(const char** argv); int host_show_help(Session sess); int host_tests(void); +int host_validate_session(Session sess); #endif diff --git a/src/host/tests/host_args_tests.cpp b/src/host/tests/host_args_tests.cpp index 9f171ae9..b13e9702 100644 --- a/src/host/tests/host_args_tests.cpp +++ b/src/host/tests/host_args_tests.cpp @@ -1,6 +1,6 @@ /** * \file host_args_tests.cpp - * \brief Automated test for application command line argument processing. + * \brief Automated tests for application command line argument processing. * \author Copyright (c) 2008 Jason Perkins and the Premake project */ @@ -34,5 +34,11 @@ struct FxHostArgs SUITE(host) { - /* coming soon */ + TEST_FIXTURE(FxHostArgs, ParseArgv_SetsAction_OnAction) + { + const char* argv[] = { "premake", "action", NULL }; + host_set_argv(argv); + host_parse_argv(sess); + CHECK_EQUAL("action", session_get_action(sess)); + } } diff --git a/src/host/tests/host_tests.cpp b/src/host/tests/host_tests.cpp index 5ddad416..773a2362 100644 --- a/src/host/tests/host_tests.cpp +++ b/src/host/tests/host_tests.cpp @@ -20,6 +20,7 @@ extern "C" { int host_tests() { int status = engine_tests(); + if (status == OKAY) status = tests_run_suite("action"); if (status == OKAY) status = tests_run_suite("host"); return status; } diff --git a/src/host/tests/host_validate_tests.cpp b/src/host/tests/host_validate_tests.cpp new file mode 100644 index 00000000..7b832232 --- /dev/null +++ b/src/host/tests/host_validate_tests.cpp @@ -0,0 +1,63 @@ +/** + * \file host_validate_tests.cpp + * \brief Automated tests for session validation. + * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project + */ + +#include "premake.h" +#include "testing/testing.h" +extern "C" { +#include "host/host.h" +#include "base/error.h" +} + +struct FxHostValidate +{ + Session sess; + Solution sln; + char buffer[8192]; + + FxHostValidate() + { + sess = session_create(); + stream_set_buffer(Console, buffer); + } + + ~FxHostValidate() + { + session_destroy(sess); + error_clear(); + host_set_argv(NULL); + } + + void AddSolution() + { + sln = solution_create(); + session_add_solution(sess, sln); + } +}; + + +SUITE(host) +{ + TEST_FIXTURE(FxHostValidate, Validate_ReturnsOkay_OnValidSession) + { + AddSolution(); + int result = host_validate_session(sess); + CHECK(result == OKAY); + } + + + TEST_FIXTURE(FxHostValidate, Validate_ReturnsNotOkay_OnNoSolutions) + { + int result = host_validate_session(sess); + CHECK(result != OKAY); + } + + + TEST_FIXTURE(FxHostValidate, Validate_SetsError_OnNoSolutions) + { + host_validate_session(sess); + CHECK_EQUAL("no solutions defined", error_get()); + } +} diff --git a/src/premake.c b/src/premake.c index 703dfba5..54f92b69 100644 --- a/src/premake.c +++ b/src/premake.c @@ -15,11 +15,13 @@ */ static HostExecutionStep Steps[] = { - host_run_script, /* run the main script (i.e. premake4.lua) */ - session_unload, /* unload the objects built by the script into more accessible C data structures */ - host_show_help, /* show help and version messages as appropriate; may end processing here */ - host_run_action, /* run the action specified on the command line */ - NULL /* all done! */ + host_parse_argv, /* process the command line arguments */ + host_run_script, /* run the main script (i.e. premake4.lua) */ + session_unload, /* unload the objects built by the script into more accessible C data structures */ + host_show_help, /* show help and version messages as appropriate; may end processing here */ + host_validate_session, /* make sure script defined required project objects */ + host_run_action, /* run the action specified on the command line */ + NULL /* all done! */ }; diff --git a/src/premake4.lua b/src/premake4.lua deleted file mode 100644 index 4a0cbdeb..00000000 --- a/src/premake4.lua +++ /dev/null @@ -1,5 +0,0 @@ ---------------------------------------------------------------------------- --- Premake4 project script for Premake4 --- Copyright (c) 2002-2008 Jason Perkins and the Premake project ---------------------------------------------------------------------------- -