Merged configuration check logic and global eol-settings (r405:413)

This commit is contained in:
starkos 2008-06-17 18:45:11 +00:00
parent 79d8f8026c
commit a99ff72d9f
147 changed files with 13419 additions and 13397 deletions

View File

@ -1,56 +0,0 @@
/**
* \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);
}
}

View File

@ -10,12 +10,9 @@
#include "base/error.h"
static int fn_accessor(lua_State* L);
static int fn_accessor_object_has_field(struct FieldInfo* fields, const char* field_name);
static int fn_accessor_register(lua_State* L, struct FieldInfo* fields);
static int fn_accessor_register_field(lua_State* L, struct FieldInfo* field);
static int fn_accessor_set_string_value(lua_State* L, struct FieldInfo* field);
static int fn_accessor_set_list_value(lua_State* L, struct FieldInfo* field);
static void fn_accessor_append_value(lua_State* L, struct FieldInfo* field, int tbl, int idx);
@ -103,7 +100,7 @@ static int fn_accessor_object_has_field(struct FieldInfo* fields, const char* fi
* work gets done to get or set an object property or list.
* \returns The current value of the field.
*/
static int fn_accessor(lua_State* L)
int fn_accessor(lua_State* L)
{
struct FieldInfo* field;
int container_type;
@ -141,7 +138,7 @@ static int fn_accessor(lua_State* L)
* Sets a string field to the value on the bottom of the Lua stack.
* \returns OKAY if successful.
*/
static int fn_accessor_set_string_value(lua_State* L, struct FieldInfo* field)
int fn_accessor_set_string_value(lua_State* L, struct FieldInfo* field)
{
/* can't set lists to simple fields */
if (lua_istable(L, 1))
@ -172,7 +169,7 @@ static int fn_accessor_set_string_value(lua_State* L, struct FieldInfo* field)
* Appends the value or list at the bottom of the Lua stack to the specified list field.
* \returns OKAY if successful.
*/
static int fn_accessor_set_list_value(lua_State* L, struct FieldInfo* field)
int fn_accessor_set_list_value(lua_State* L, struct FieldInfo* field)
{
/* get the current value of the field */
lua_getfield(L, -1, field->name);

View File

@ -0,0 +1,43 @@
/**
* \file fn_configurations.c
* \brief Specify the build configurations.
* \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
*/
#include "premake.h"
#include "script_internal.h"
/**
* Specify the build configurations for a solution.
*/
int fn_configurations(lua_State* L)
{
struct FieldInfo* field;
if (!script_internal_get_active_object(L, SolutionObject, REQUIRED))
{
return 0;
}
/* configurations may not be modified once projects are defined */
lua_getfield(L, -1, PROJECTS_KEY);
if (luaL_getn(L, -1) > 0)
{
luaL_error(L, "configurations may not be modified after projects are defined");
}
lua_pop(L, 1);
/* get information about the field being accessed */
field = (struct FieldInfo*)lua_touserdata(L, lua_upvalueindex(2));
/* if a value is provided, set the field */
if (lua_gettop(L) > 1)
{
fn_accessor_set_list_value(L, &SolutionFieldInfo[SolutionConfigurations]);
}
/* return the current value of the field */
lua_getfield(L, -1, SolutionFieldInfo[SolutionConfigurations].name);
return 1;
}

View File

@ -38,6 +38,15 @@ int fn_project(lua_State* L)
lua_getfield(L, -1, name);
if (lua_isnil(L, -1))
{
/* this is a new project; check to be sure the configurations have been set */
lua_getfield(L, -3, SolutionFieldInfo[SolutionConfigurations].name);
if (luaL_getn(L, -1) == 0)
{
luaL_error(L, "no configurations defined");
return 0;
}
lua_pop(L, 1);
/* project does not exists, create it */
lua_newtable(L);

View File

@ -15,6 +15,7 @@
/** Functions to add to the global namespace */
static const luaL_Reg global_funcs[] = {
{ "configurations", fn_configurations },
{ "dofile", fn_dofile },
{ "include", fn_include },
{ "match", fn_match },
@ -55,10 +56,6 @@ Script script_create(void)
/* register all the standard Lua libraries */
luaL_openlibs(L);
/* register the Premake non-configuration related functions */
luaL_register(L, "_G", global_funcs);
luaL_register(L, "os", os_funcs);
/* create an empty list of solutions in the script environment */
lua_newtable(L);
lua_setglobal(L, SOLUTIONS_KEY);
@ -66,6 +63,10 @@ Script script_create(void)
/* register the project object accessor functions */
fn_accessor_register_all(L);
/* register the Premake non-configuration related functions */
luaL_register(L, "_G", global_funcs);
luaL_register(L, "os", os_funcs);
script = ALLOC_CLASS(Script);
script->L = L;
return script;

View File

@ -46,8 +46,12 @@ void script_internal_populate_object(lua_State* L, struct FieldInfo* fiel
/* Generic project object field getter/setter API */
int fn_accessor_register_all(lua_State* L);
int fn_accessor_set_string_value(lua_State* L, struct FieldInfo* field);
int fn_accessor_set_list_value(lua_State* L, struct FieldInfo* field);
/* script function handlers */
int fn_accessor(lua_State* L);
int fn_configurations(lua_State* L);
int fn_dofile(lua_State* L);
int fn_error(lua_State* L);
int fn_getcwd(lua_State* L);

View File

@ -9,14 +9,14 @@
SUITE(script)
{
TEST_FIXTURE(FxAccessor, Configurations_Exists_OnStartup)
TEST_FIXTURE(FxScript, Configurations_Exists_OnStartup)
{
const char* result = script_run_string(script,
"return (configurations ~= nil)");
CHECK_EQUAL("true", result);
}
TEST_FIXTURE(FxAccessor, Configurations_Error_OnNoActiveSolution)
TEST_FIXTURE(FxScript, Configurations_Error_OnNoActiveSolution)
{
Script script = script_create();
const char* result = script_run_string(script, "configurations {'Debug'}");
@ -24,11 +24,23 @@ SUITE(script)
script_destroy(script);
}
TEST_FIXTURE(FxAccessor, Configurations_CanRoundtrip)
TEST_FIXTURE(FxScript, Configurations_CanRoundtrip)
{
const char* result = script_run_string(script,
"configurations {'Debug'};"
"solution 'MySolution';"
" configurations {'Debug','Release'};"
"return configurations()[1]");
CHECK_EQUAL("Debug", result);
}
TEST_FIXTURE(FxScript, Configurations_RaisesError_OnProjectDefined)
{
const char* result = script_run_string(script,
"solution 'MySolution';"
" configurations {'Debug','Release'};"
"project 'MyProject';"
" configurations {'DebugDLL','ReleaseDLL'}");
CHECK_EQUAL("configurations may not be modified after projects are defined", result);
}
}

View File

@ -14,6 +14,7 @@ struct FnProject : FxScript
{
script_run_string(script,
"sln = solution('MySolution');"
" configurations {'Debug','Release'};"
"prj = project('MyProject')");
}
};
@ -91,7 +92,15 @@ SUITE(script)
"return (prj == project('MyProject'))");
CHECK_EQUAL("true", result);
}
/*
TEST_FIXTURE(FxScript, Project_RaisesError_OnNoConfigurations)
{
const char* result = script_run_string(script,
"sln = solution('MySolution');"
"prj = project('MyProject')");
CHECK_EQUAL("no configurations defined", result);
}
*/
/**************************************************************************
* Initial object state tests

View File

@ -34,6 +34,7 @@ struct FxAccessor : FxScript
{
script_run_string(script,
"sln = solution 'MySolution';"
" configurations {'Debug','Release'};"
"prj = project 'MyProject';");
}
};

View File

@ -26,6 +26,7 @@ struct FxUnloadProject
script_run_string(script,
"solution('MySolution');"
" configurations {'Debug','Release'};"
"prj = project('MyProject');"
" guid '0C202E43-B9AF-4972-822B-5A42F0BF008C';"
" language 'c++';"

View File

@ -78,6 +78,7 @@ struct FxUnload2 : FxUnload
{
script_run_string(script,
"solution 'MySolution';"
" configurations{'Debug','Release'};"
" project 'MyProject';"
" project 'MyProject2';"
"solution 'MySolution2';");