Split session and scripting components (r354:358)
@ -6,7 +6,7 @@
|
||||
#if !defined(PREMAKE_ACTION_H)
|
||||
#define PREMAKE_ACTION_H
|
||||
|
||||
#include "engine/session.h"
|
||||
#include "session/session.h"
|
||||
|
||||
extern SessionAction Actions[];
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
#if !defined(PREMAKE_MAKE_H)
|
||||
#define PREMAKE_MAKE_H
|
||||
|
||||
#include "engine/session.h"
|
||||
#include "session/session.h"
|
||||
|
||||
const char* make_get_project_makefile(Session sess, Project prj);
|
||||
const char* make_get_solution_makefile(Session sess, Solution sln);
|
||||
|
@ -6,7 +6,7 @@
|
||||
#if !defined(PREMAKE_MAKE_PROJECT_H)
|
||||
#define PREMAKE_MAKE_PROJECT_H
|
||||
|
||||
#include "engine/session.h"
|
||||
#include "session/session.h"
|
||||
|
||||
int make_project_config_conditional(Session sess, Project prj, Stream strm);
|
||||
int make_project_config_cflags(Session sess, Project prj, Stream strm);
|
||||
|
@ -6,7 +6,7 @@
|
||||
#if !defined(PREMAKE_MAKE_SOLUTION_H)
|
||||
#define PREMAKE_MAKE_SOLUTION_H
|
||||
|
||||
#include "engine/session.h"
|
||||
#include "session/session.h"
|
||||
|
||||
int make_solution_create(Session sess, Solution sln, Stream strm);
|
||||
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include "premake.h"
|
||||
#include "testing/testing.h"
|
||||
extern "C" {
|
||||
#include "engine/engine.h"
|
||||
#include "action/make/make.h"
|
||||
#include "base/error.h"
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include "testing/testing.h"
|
||||
extern "C" {
|
||||
#include "engine/session.h"
|
||||
#include "session/session.h"
|
||||
#include "project/project.h"
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
#if !defined(PREMAKE_VS200X_H)
|
||||
#define PREMAKE_VS200X_H
|
||||
|
||||
#include "engine/session.h"
|
||||
#include "session/session.h"
|
||||
|
||||
int vs200x_attribute(Session sess, int level, const char* name, const char* value, ...);
|
||||
int vs200x_element(Session sess, int level, const char* name);
|
||||
|
@ -6,7 +6,7 @@
|
||||
#if !defined(PREMAKE_VS200X_CONFIG_H)
|
||||
#define PREMAKE_VS200X_CONFIG_H
|
||||
|
||||
#include "engine/session.h"
|
||||
#include "session/session.h"
|
||||
|
||||
int vs200x_config_character_set(Session sess);
|
||||
int vs200x_config_detect_64bit_portability(Session sess, Project prj);
|
||||
|
@ -6,7 +6,7 @@
|
||||
#if !defined(PREMAKE_VS200X_PROJECT_H)
|
||||
#define PREMAKE_VS200X_PROJECT_H
|
||||
|
||||
#include "engine/session.h"
|
||||
#include "session/session.h"
|
||||
|
||||
int vs200x_project_config_element(Session sess, Project prj, Stream strm);
|
||||
int vs200x_project_config_end(Session sess, Project prj, Stream strm);
|
||||
|
@ -6,7 +6,7 @@
|
||||
#if !defined(PREMAKE_VS200X_SOLUTION_H)
|
||||
#define PREMAKE_VS200X_SOLUTION_H
|
||||
|
||||
#include "engine/session.h"
|
||||
#include "session/session.h"
|
||||
|
||||
int vs2002_solution_configuration(Session sess, Solution sln, Stream strm);
|
||||
int vs2002_solution_dependencies(Session sess, Solution sln, Stream strm);
|
||||
|
@ -1,164 +0,0 @@
|
||||
/**
|
||||
* \file accessor.c
|
||||
* \brief A generic getter/setter for project fields.
|
||||
* \author Copyright (c) 2007-2008 Jason Perkins and the Premake project
|
||||
*/
|
||||
|
||||
#include "premake.h"
|
||||
#include "internals.h"
|
||||
#include "base/cstr.h"
|
||||
#include "base/error.h"
|
||||
|
||||
|
||||
static int accessor_object_has_field(struct FieldInfo* fields, const char* field_name);
|
||||
static int accessor_register(lua_State* L, struct FieldInfo* fields);
|
||||
static int accessor_register_field(lua_State* L, struct FieldInfo* field);
|
||||
static int accessor_set_string_value(lua_State* L, struct FieldInfo* field);
|
||||
static int fn_accessor(lua_State* L);
|
||||
|
||||
|
||||
/**
|
||||
* Register all of the accessors listed in the project object field information.
|
||||
* \param L The Lua scripting state.
|
||||
* \returns OKAY if successful.
|
||||
*/
|
||||
int accessor_register_all(lua_State* L)
|
||||
{
|
||||
int z = OKAY;
|
||||
if (z == OKAY) z = accessor_register(L, SolutionFieldInfo);
|
||||
if (z == OKAY) z = accessor_register(L, ProjectFieldInfo);
|
||||
return z;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register accessor functions for a set of fields.
|
||||
* \param L The Lua scripting state.
|
||||
* \param fields The list of fields to register.
|
||||
* \returns OKAY if successful.
|
||||
*/
|
||||
int accessor_register(lua_State* L, struct FieldInfo* fields)
|
||||
{
|
||||
int i, z = OKAY;
|
||||
|
||||
for (i = 0; z == OKAY && fields[i].name != NULL; ++i)
|
||||
{
|
||||
z = accessor_register_field(L, &fields[i]);
|
||||
}
|
||||
|
||||
return z;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register a single accessor function.
|
||||
* \param L The Lua scripting state.
|
||||
* \param field The field to register.
|
||||
* \returns OKAY if successful.
|
||||
*/
|
||||
int accessor_register_field(lua_State* L, struct FieldInfo* field)
|
||||
{
|
||||
int container_type, z;
|
||||
|
||||
/* has this accessor already been registered? If so, skip it now */
|
||||
lua_getglobal(L, field->name);
|
||||
z = lua_isnil(L, -1);
|
||||
lua_pop(L, 1);
|
||||
if (!z) return OKAY;
|
||||
|
||||
/* figure out what object types this accessor applies to */
|
||||
container_type = 0;
|
||||
if (accessor_object_has_field(SolutionFieldInfo, field->name)) container_type |= SolutionObject;
|
||||
if (accessor_object_has_field(ProjectFieldInfo, field->name)) container_type |= ProjectObject;
|
||||
|
||||
/* register the accessor function */
|
||||
lua_pushnumber(L, container_type);
|
||||
lua_pushlightuserdata(L, field);
|
||||
lua_pushcclosure(L, fn_accessor, 2);
|
||||
lua_setglobal(L, field->name);
|
||||
return OKAY;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine if a field list contains a field with a particular name.
|
||||
* \param fields The list of fields to check.
|
||||
* \param field_name The field to look for.
|
||||
* \returns True if the field is contained by the list.
|
||||
*/
|
||||
int accessor_object_has_field(struct FieldInfo* fields, const char* field_name)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; fields[i].name != NULL; ++i)
|
||||
{
|
||||
if (cstr_eq(fields[i].name, field_name))
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets a string field, using the value on the stack.
|
||||
* \param L The Lua state.
|
||||
* \param field The field to set.
|
||||
* \returns OKAY if successful.
|
||||
*/
|
||||
int accessor_set_string_value(lua_State* L, struct FieldInfo* field)
|
||||
{
|
||||
/* can't set lists to simple fields */
|
||||
if (lua_istable(L, 1))
|
||||
{
|
||||
luaL_error(L, "the field '%s' does not support lists of values", field->name);
|
||||
return !OKAY;
|
||||
}
|
||||
|
||||
/* if a validator function is present, call it */
|
||||
if (field->validator != NULL)
|
||||
{
|
||||
const char* value = luaL_checkstring(L, 1);
|
||||
if (!field->validator(value))
|
||||
{
|
||||
luaL_error(L, "invalid value '%s'", value);
|
||||
return !OKAY;
|
||||
}
|
||||
}
|
||||
|
||||
/* set the field */
|
||||
lua_pushvalue(L, 1);
|
||||
lua_setfield(L, -2, field->name);
|
||||
return OKAY;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The accessor function; this is what gets called by Lua when an accessor
|
||||
* function is called in a script.
|
||||
* \param L The Lua state.
|
||||
* \returns The current value of the field.
|
||||
*/
|
||||
int fn_accessor(lua_State* L)
|
||||
{
|
||||
struct FieldInfo* field;
|
||||
int container_type;
|
||||
|
||||
/* get the required container object */
|
||||
container_type = lua_tointeger(L, lua_upvalueindex(1));
|
||||
if (!engine_get_active_object(L, container_type, REQUIRED))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* get field information */
|
||||
field = (struct FieldInfo*)lua_touserdata(L, lua_upvalueindex(2));
|
||||
|
||||
/* if a value is provided, set the field */
|
||||
if (lua_gettop(L) > 1)
|
||||
{
|
||||
accessor_set_string_value(L, field);
|
||||
}
|
||||
|
||||
/* return the current value of the field */
|
||||
lua_getfield(L, -1, field->name);
|
||||
return 1;
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
/**
|
||||
* \file engine.h
|
||||
* \brief Project scripting system API.
|
||||
* \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
|
||||
*/
|
||||
#if !defined(PREMAKE_ENGINE_H)
|
||||
#define PREMAKE_ENGINE_H
|
||||
|
||||
int engine_tests(void);
|
||||
|
||||
#endif
|
@ -1,31 +0,0 @@
|
||||
/**
|
||||
* \file accessor_tests.h
|
||||
* \brief Common fixture for accessor function tests.
|
||||
* \author Copyright (c) 2008 Jason Perkins and the Premake project
|
||||
*/
|
||||
|
||||
#include "testing/testing.h"
|
||||
extern "C" {
|
||||
#include "engine/session.h"
|
||||
#include "base/error.h"
|
||||
}
|
||||
|
||||
|
||||
struct FxAccessor
|
||||
{
|
||||
Session sess;
|
||||
|
||||
FxAccessor()
|
||||
{
|
||||
sess = session_create();
|
||||
session_run_string(sess,
|
||||
"sln = solution 'MySolution';"
|
||||
"prj = project 'MyProject';");
|
||||
}
|
||||
|
||||
~FxAccessor()
|
||||
{
|
||||
session_destroy(sess);
|
||||
error_clear();
|
||||
}
|
||||
};
|
@ -1,29 +0,0 @@
|
||||
/**
|
||||
* \file engine_tests.cpp
|
||||
* \brief Automated tests for the project scripting engine.
|
||||
* \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
|
||||
*/
|
||||
|
||||
#include "premake.h"
|
||||
#include "testing/testing.h"
|
||||
extern "C" {
|
||||
#include "base/base.h"
|
||||
#include "project/project.h"
|
||||
#include "engine/engine.h"
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Run the engine automated tests.
|
||||
* \returns OKAY if all tests completed successfully.
|
||||
* \note Also runs the tests for all dependencies (everything but the host executable).
|
||||
*/
|
||||
int engine_tests()
|
||||
{
|
||||
int status = base_tests();
|
||||
if (status == OKAY) status = project_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");
|
||||
return status;
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/**
|
||||
* \file fn_error_tests.cpp
|
||||
* \brief Automated test for the error() function.
|
||||
* \author Copyright (c) 2007-2008 Jason Perkins and the Premake project
|
||||
*/
|
||||
|
||||
#include "premake.h"
|
||||
#include "testing/testing.h"
|
||||
extern "C" {
|
||||
#include "engine/session.h"
|
||||
#include "base/error.h"
|
||||
}
|
||||
|
||||
struct FnError
|
||||
{
|
||||
Session sess;
|
||||
|
||||
FnError()
|
||||
{
|
||||
sess = session_create();
|
||||
}
|
||||
|
||||
~FnError()
|
||||
{
|
||||
session_destroy(sess);
|
||||
error_clear();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
SUITE(engine)
|
||||
{
|
||||
TEST_FIXTURE(FnError, Error_Exists_OnStartup)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return (error ~= nil)");
|
||||
CHECK_EQUAL("true", result);
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FnError, Error_SetsSessionError_OnCall)
|
||||
{
|
||||
session_run_string(sess,
|
||||
"error('an error message')");
|
||||
CHECK_EQUAL("[string \"error('an error message')\"]:1: an error message", error_get());
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/**
|
||||
* \file fn_getcwd_tests.cpp
|
||||
* \brief Automated test for the getcwd() function.
|
||||
* \author Copyright (c) 2007-2008 Jason Perkins and the Premake project
|
||||
*/
|
||||
|
||||
#include "premake.h"
|
||||
#include "testing/testing.h"
|
||||
extern "C" {
|
||||
#include "engine/session.h"
|
||||
#include "base/cstr.h"
|
||||
}
|
||||
|
||||
|
||||
struct FnGetCwd
|
||||
{
|
||||
Session sess;
|
||||
|
||||
FnGetCwd()
|
||||
{
|
||||
sess = session_create();
|
||||
}
|
||||
|
||||
~FnGetCwd()
|
||||
{
|
||||
session_destroy(sess);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
SUITE(engine)
|
||||
{
|
||||
TEST_FIXTURE(FnGetCwd, GetCwd_Exists_OnStartup)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return (os.getcwd ~= nil)");
|
||||
CHECK_EQUAL("true", result);
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FnGetCwd, GetCwd_ReturnsCwd)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return os.getcwd()");
|
||||
CHECK(cstr_ends_with(result, "/src"));
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
/**
|
||||
* \file fn_include_tests.cpp
|
||||
* \brief Automated test for the include() function.
|
||||
* \author Copyright (c) 2008 Jason Perkins and the Premake project
|
||||
*/
|
||||
|
||||
#include "premake.h"
|
||||
#include "testing/testing.h"
|
||||
extern "C" {
|
||||
#include "engine/session.h"
|
||||
#include "base/cstr.h"
|
||||
#include "base/error.h"
|
||||
}
|
||||
|
||||
struct FnInclude
|
||||
{
|
||||
Session sess;
|
||||
|
||||
FnInclude()
|
||||
{
|
||||
sess = session_create();
|
||||
}
|
||||
|
||||
~FnInclude()
|
||||
{
|
||||
session_destroy(sess);
|
||||
error_clear();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
SUITE(engine)
|
||||
{
|
||||
TEST_FIXTURE(FnInclude, Include_Exists_OnStartup)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return (include ~= nil)");
|
||||
CHECK_EQUAL("true", result);
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FnInclude, Include_ReturnsValue_OnPremake4Found)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return include('testing/test_files')");
|
||||
CHECK_EQUAL("true", result);
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FnInclude, Include_SetsError_OnFileNotFound)
|
||||
{
|
||||
session_run_string(sess,
|
||||
"include('testing')");
|
||||
CHECK(cstr_ends_with(error_get(), "No such file or directory"));
|
||||
}
|
||||
}
|
@ -1,145 +0,0 @@
|
||||
/**
|
||||
* \file fn_project_tests.cpp
|
||||
* \brief Automated tests for the project() function.
|
||||
* \author Copyright (c) 2008 Jason Perkins and the Premake project
|
||||
*/
|
||||
|
||||
#include "premake.h"
|
||||
#include "testing/testing.h"
|
||||
extern "C" {
|
||||
#include "engine/session.h"
|
||||
#include "base/error.h"
|
||||
}
|
||||
|
||||
struct FnProject
|
||||
{
|
||||
Session sess;
|
||||
|
||||
FnProject()
|
||||
{
|
||||
sess = session_create();
|
||||
}
|
||||
|
||||
~FnProject()
|
||||
{
|
||||
session_destroy(sess);
|
||||
error_clear();
|
||||
}
|
||||
};
|
||||
|
||||
struct FnProject2
|
||||
{
|
||||
Session sess;
|
||||
|
||||
FnProject2()
|
||||
{
|
||||
sess = session_create();
|
||||
session_run_string(sess,
|
||||
"sln = solution('MySolution');"
|
||||
"prj = project('MyProject')");
|
||||
}
|
||||
|
||||
~FnProject2()
|
||||
{
|
||||
session_destroy(sess);
|
||||
error_clear();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
SUITE(engine)
|
||||
{
|
||||
/**************************************************************************
|
||||
* Initial state tests
|
||||
**************************************************************************/
|
||||
|
||||
TEST_FIXTURE(FnProject, Project_Exists_OnStartup)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return (project ~= nil)");
|
||||
CHECK_EQUAL("true", result);
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FnProject, Project_ReturnsNil_OnNoActiveProject)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return (project() == nil)");
|
||||
CHECK_EQUAL("true", result);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* Object creation tests
|
||||
**************************************************************************/
|
||||
|
||||
TEST_FIXTURE(FnProject, Project_Fails_OnNoActiveSolution)
|
||||
{
|
||||
const char* result = session_run_string(sess, "project('MyProject')");
|
||||
CHECK_EQUAL("no active solution", result);
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FnProject2, Project_ReturnsNewObject_OnNewName)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return (prj ~= nil)");
|
||||
CHECK_EQUAL("true", result);
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FnProject2, Project_ReturnsObject_OnActiveProject)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return (prj == project())");
|
||||
CHECK_EQUAL("true", result);
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FnProject2, Project_AddsToKeyList_OnNewName)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return (prj == sln.projects['MyProject']);");
|
||||
CHECK_EQUAL("true", result);
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FnProject2, Project_AddsToIndexList_OnNewName)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return (prj == sln.projects[1]);");
|
||||
CHECK_EQUAL("true", result);
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FnProject2, Project_IncrementsTableSize_OnNewName)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return #sln.projects");
|
||||
CHECK_EQUAL("1", result);
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FnProject2, Project_ReturnsSameObject_OnExistingName)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"prj1 = project('SecondProject');"
|
||||
"return (prj == project('MyProject'))");
|
||||
CHECK_EQUAL("true", result);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Initial object state tests
|
||||
**************************************************************************/
|
||||
|
||||
TEST_FIXTURE(FnProject2, Project_SetsName)
|
||||
{
|
||||
const char* result = session_run_string(sess, "return prj.name");
|
||||
CHECK_EQUAL("MyProject", result);
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FnProject2, Project_SetsBaseDir)
|
||||
{
|
||||
const char* result = session_run_string(sess, "return prj.basedir");
|
||||
CHECK_EQUAL("(string)", result);
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FnProject2, Project_SetsGuid)
|
||||
{
|
||||
const char* result = session_run_string(sess, "return prj.guid");
|
||||
CHECK(result != NULL && strlen(result) == 36);
|
||||
}
|
||||
}
|
@ -1,141 +0,0 @@
|
||||
/**
|
||||
* \file fn_solution_tests.cpp
|
||||
* \brief Automated tests for the solution() function.
|
||||
* \author Copyright (c) 2007-2008 Jason Perkins and the Premake project
|
||||
*/
|
||||
|
||||
#include "premake.h"
|
||||
#include "testing/testing.h"
|
||||
extern "C" {
|
||||
#include "engine/session.h"
|
||||
}
|
||||
|
||||
struct FnSolution1
|
||||
{
|
||||
Session sess;
|
||||
|
||||
FnSolution1()
|
||||
{
|
||||
sess = session_create();
|
||||
}
|
||||
|
||||
~FnSolution1()
|
||||
{
|
||||
session_destroy(sess);
|
||||
}
|
||||
};
|
||||
|
||||
struct FnSolution2 : FnSolution1
|
||||
{
|
||||
FnSolution2()
|
||||
{
|
||||
session_run_string(sess, "sln = solution('MySolution');");
|
||||
}
|
||||
|
||||
~FnSolution2()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
SUITE(engine)
|
||||
{
|
||||
/**************************************************************************
|
||||
* Initial state tests
|
||||
**************************************************************************/
|
||||
|
||||
TEST_FIXTURE(FnSolution1, Solution_Exists_OnStartup)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return (solution ~= nil)");
|
||||
CHECK_EQUAL("true", result);
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FnSolution1, Solution_ReturnsNil_OnNoActiveSolution)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return (solution() == nil)");
|
||||
CHECK_EQUAL("true", result);
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FnSolution1, Solutions_Exists_OnStartup)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return #_SOLUTIONS");
|
||||
CHECK_EQUAL("0", result);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Object creation tests
|
||||
**************************************************************************/
|
||||
|
||||
TEST_FIXTURE(FnSolution2, Solution_ReturnsNewObject_OnNewName)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return (sln ~= nil)");
|
||||
CHECK_EQUAL("true", result);
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FnSolution2, Solution_ReturnsObject_OnActiveSolution)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return (sln == solution())");
|
||||
CHECK_EQUAL("true", result);
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FnSolution2, Solution_AddsToKeyList_OnNewName)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return (sln == _SOLUTIONS['MySolution']);");
|
||||
CHECK_EQUAL("true", result);
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FnSolution2, Solution_AddsToIndexList_OnNewName)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return (sln == _SOLUTIONS[1]);");
|
||||
CHECK_EQUAL("true", result);
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FnSolution2, Solution_IncrementsTableSize_OnNewName)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return #_SOLUTIONS;");
|
||||
CHECK_EQUAL("1", result);
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FnSolution2, Solution_ReturnsSameObject_OnExistingName)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"sln1 = solution('SecondSolution');"
|
||||
"return (sln == solution('MySolution'))");
|
||||
CHECK_EQUAL("true", result);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Initial object state tests
|
||||
**************************************************************************/
|
||||
|
||||
TEST_FIXTURE(FnSolution2, Solution_SetsName)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return sln.name");
|
||||
CHECK_EQUAL("MySolution", result);
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FnSolution2, Solution_SetsBaseDir)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return sln.basedir");
|
||||
CHECK_EQUAL("(string)", result);
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FnSolution2, Solution_HasEmptyProjectsList)
|
||||
{
|
||||
const char* result = session_run_string(sess,
|
||||
"return #sln.projects");
|
||||
CHECK_EQUAL("0", result);
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
#if !defined(PREMAKE_HOST_H)
|
||||
#define PREMAKE_HOST_H
|
||||
|
||||
#include "engine/session.h"
|
||||
#include "session/session.h"
|
||||
|
||||
/**
|
||||
* The short help message, displayed if Premake is run with no arguments.
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include "premake.h"
|
||||
#include "testing/testing.h"
|
||||
extern "C" {
|
||||
#include "engine/engine.h"
|
||||
#include "host/host.h"
|
||||
}
|
||||
|
||||
@ -19,8 +18,9 @@ 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;
|
||||
int z = OKAY;
|
||||
if (z == OKAY) z = session_tests();
|
||||
if (z == OKAY) z = tests_run_suite("action");
|
||||
if (z == OKAY) z = tests_run_suite("host");
|
||||
return z;
|
||||
}
|
||||
|
@ -11,7 +11,8 @@ local subsystems =
|
||||
"action",
|
||||
"action/make",
|
||||
"action/vs200x",
|
||||
"engine",
|
||||
"script",
|
||||
"session",
|
||||
"host"
|
||||
}
|
||||
|
||||
@ -63,7 +64,7 @@ local subsystems =
|
||||
|
||||
-- Lua scripting engine
|
||||
|
||||
local lua = "engine/lua-5.1.2/src"
|
||||
local lua = "script/lua-5.1.2/src"
|
||||
table.insert(package.includepaths, lua)
|
||||
table.insert(package.files, matchfiles(lua.."/*.h", lua.."/*.c"))
|
||||
table.insert(package.excludes, {lua.."/lua.c", lua.."/luac.c"})
|
||||
|
159
src/script/fn_accessor.c
Normal file
@ -0,0 +1,159 @@
|
||||
/**
|
||||
* \file fn_accessor.c
|
||||
* \brief A generic getter/setter for project fields.
|
||||
* \author Copyright (c) 2007-2008 Jason Perkins and the Premake project
|
||||
*/
|
||||
|
||||
#include "premake.h"
|
||||
#include "script_internal.h"
|
||||
#include "base/cstr.h"
|
||||
#include "base/error.h"
|
||||
|
||||
|
||||
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(lua_State* L);
|
||||
|
||||
|
||||
/**
|
||||
* Using the field information lists for each of the project objects (solution, project,
|
||||
* and configuration) register accessor functions in the script environment. Examples of
|
||||
* accessor functions include location(), language(), kind(), and so on; function that
|
||||
* get and set the project object properties.
|
||||
* \returns OKAY if successful.
|
||||
*/
|
||||
int fn_accessor_register_all(lua_State* L)
|
||||
{
|
||||
int z = OKAY;
|
||||
if (z == OKAY) z = fn_accessor_register(L, SolutionFieldInfo);
|
||||
if (z == OKAY) z = fn_accessor_register(L, ProjectFieldInfo);
|
||||
return z;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register the accessor functions for a particular set of fields.
|
||||
* \returns OKAY if successful.
|
||||
*/
|
||||
static int fn_accessor_register(lua_State* L, struct FieldInfo* fields)
|
||||
{
|
||||
int i, z = OKAY;
|
||||
|
||||
for (i = 0; z == OKAY && fields[i].name != NULL; ++i)
|
||||
{
|
||||
z = fn_accessor_register_field(L, &fields[i]);
|
||||
}
|
||||
|
||||
return z;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register a single accessor function.
|
||||
* \returns OKAY if successful.
|
||||
*/
|
||||
static int fn_accessor_register_field(lua_State* L, struct FieldInfo* field)
|
||||
{
|
||||
int container_type, z;
|
||||
|
||||
/* has this accessor already been registered? This will happen if two object
|
||||
* types (ie. solution and project) define the same property. If so, skip it */
|
||||
lua_getglobal(L, field->name);
|
||||
z = lua_isnil(L, -1);
|
||||
lua_pop(L, 1);
|
||||
if (!z) return OKAY;
|
||||
|
||||
/* figure out what object types this accessor applies to; may be more than one */
|
||||
container_type = 0;
|
||||
if (fn_accessor_object_has_field(SolutionFieldInfo, field->name)) container_type |= SolutionObject;
|
||||
if (fn_accessor_object_has_field(ProjectFieldInfo, field->name)) container_type |= ProjectObject;
|
||||
|
||||
/* register the accessor function */
|
||||
lua_pushnumber(L, container_type);
|
||||
lua_pushlightuserdata(L, field);
|
||||
lua_pushcclosure(L, fn_accessor, 2);
|
||||
lua_setglobal(L, field->name);
|
||||
return OKAY;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine if a field list contains a field with a particular name.
|
||||
* \returns True if the field is contained by the list.
|
||||
*/
|
||||
static int fn_accessor_object_has_field(struct FieldInfo* fields, const char* field_name)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; fields[i].name != NULL; ++i)
|
||||
{
|
||||
if (cstr_eq(fields[i].name, field_name))
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The accessor script function; all of the individually registered accessors
|
||||
* (location(), language(), etc.) point to here, and this is where all of the
|
||||
* 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)
|
||||
{
|
||||
struct FieldInfo* field;
|
||||
int container_type;
|
||||
|
||||
/* get the required container object */
|
||||
container_type = lua_tointeger(L, lua_upvalueindex(1));
|
||||
if (!script_internal_get_active_object(L, container_type, REQUIRED))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 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_string_value(L, field);
|
||||
}
|
||||
|
||||
/* return the current value of the field */
|
||||
lua_getfield(L, -1, field->name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets a string field to the value on the top of the Lua stack.
|
||||
* \returns OKAY if successful.
|
||||
*/
|
||||
static int fn_accessor_set_string_value(lua_State* L, struct FieldInfo* field)
|
||||
{
|
||||
/* can't set lists to simple fields */
|
||||
if (lua_istable(L, 1))
|
||||
{
|
||||
luaL_error(L, "the field '%s' does not support lists of values", field->name);
|
||||
return !OKAY;
|
||||
}
|
||||
|
||||
/* if a validator function is present, call it */
|
||||
if (field->validator != NULL)
|
||||
{
|
||||
const char* value = luaL_checkstring(L, 1);
|
||||
if (!field->validator(value))
|
||||
{
|
||||
luaL_error(L, "invalid value '%s'", value);
|
||||
return !OKAY;
|
||||
}
|
||||
}
|
||||
|
||||
/* set the field */
|
||||
lua_pushvalue(L, 1);
|
||||
lua_setfield(L, -2, field->name);
|
||||
return OKAY;
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "premake.h"
|
||||
#include "internals.h"
|
||||
#include "script_internal.h"
|
||||
#include "base/dir.h"
|
||||
#include "base/path.h"
|
||||
#include "base/string.h"
|
||||
@ -32,7 +32,8 @@ int fn_dofile(lua_State* L)
|
||||
|
||||
/* set the _FILE global to the full path of the script being run */
|
||||
full_path = path_absolute(filename);
|
||||
engine_set_script_file(L, full_path);
|
||||
lua_pushstring(L, full_path);
|
||||
lua_setglobal(L, FILE_KEY);
|
||||
|
||||
/* make the script directory the current directory */
|
||||
script_dir = path_directory(full_path);
|
@ -5,9 +5,8 @@
|
||||
*/
|
||||
|
||||
#include "premake.h"
|
||||
#include "script_internal.h"
|
||||
#include "base/error.h"
|
||||
#include "engine/session.h"
|
||||
#include "internals.h"
|
||||
|
||||
|
||||
int fn_error(lua_State* L)
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "premake.h"
|
||||
#include "internals.h"
|
||||
#include "script_internal.h"
|
||||
#include "base/dir.h"
|
||||
|
||||
int fn_getcwd(lua_State* L)
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "premake.h"
|
||||
#include "internals.h"
|
||||
#include "script_internal.h"
|
||||
#include "base/path.h"
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "premake.h"
|
||||
#include "internals.h"
|
||||
#include "script_internal.h"
|
||||
#include "base/guid.h"
|
||||
|
||||
|
||||
@ -19,12 +19,12 @@ int fn_project(lua_State* L)
|
||||
/* if there are no parameters, return the active project */
|
||||
if (lua_gettop(L) == 0)
|
||||
{
|
||||
engine_get_active_object(L, ProjectObject, OPTIONAL);
|
||||
script_internal_get_active_object(L, ProjectObject, OPTIONAL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* get the active solution, which will contain this project */
|
||||
if (!engine_get_active_object(L, SolutionObject, REQUIRED))
|
||||
if (!script_internal_get_active_object(L, SolutionObject, REQUIRED))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -46,15 +46,15 @@ int fn_project(lua_State* L)
|
||||
lua_setfield(L, -2, ProjectFieldInfo[ProjectName].name);
|
||||
|
||||
/* set the base directory */
|
||||
lua_pushstring(L, engine_get_script_dir(L));
|
||||
lua_pushstring(L, script_internal_script_dir(L));
|
||||
lua_setfield(L, -2, ProjectFieldInfo[ProjectBaseDirectory].name);
|
||||
|
||||
/* set a default GUID */
|
||||
lua_pushstring(L, guid_create());
|
||||
lua_setfield(L, -2, ProjectFieldInfo[ProjectGuid].name);
|
||||
|
||||
/* finish the configuration */
|
||||
engine_configure_project_object(L, ProjectFieldInfo);
|
||||
/* use the list of fields to populate the object properties and accessor functions */
|
||||
script_internal_populate_object(L, ProjectFieldInfo);
|
||||
|
||||
/* add it to solution's list of projects, keyed by name */
|
||||
lua_pushvalue(L, -1);
|
||||
@ -66,7 +66,7 @@ int fn_project(lua_State* L)
|
||||
}
|
||||
|
||||
/* activate and return the solution object */
|
||||
engine_set_active_object(L, ProjectObject);
|
||||
script_internal_set_active_object(L, ProjectObject);
|
||||
return 1;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "premake.h"
|
||||
#include "internals.h"
|
||||
#include "script_internal.h"
|
||||
|
||||
|
||||
/**
|
||||
@ -18,7 +18,7 @@ int fn_solution(lua_State* L)
|
||||
/* if there are no parameters, return the active solution */
|
||||
if (lua_gettop(L) == 0)
|
||||
{
|
||||
engine_get_active_object(L, SolutionObject, OPTIONAL);
|
||||
script_internal_get_active_object(L, SolutionObject, OPTIONAL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -37,15 +37,15 @@ int fn_solution(lua_State* L)
|
||||
lua_setfield(L, -2, SolutionFieldInfo[SolutionName].name);
|
||||
|
||||
/* set the base directory */
|
||||
lua_pushstring(L, engine_get_script_dir(L));
|
||||
lua_pushstring(L, script_internal_script_dir(L));
|
||||
lua_setfield(L, -2, SolutionFieldInfo[SolutionBaseDirectory].name);
|
||||
|
||||
/* create an empty list of projects */
|
||||
lua_newtable(L);
|
||||
lua_setfield(L, -2, PROJECTS_KEY);
|
||||
|
||||
/* finish the configuration */
|
||||
engine_configure_project_object(L, SolutionFieldInfo);
|
||||
/* use the list of fields to populate the object properties and accessor functions */
|
||||
script_internal_populate_object(L, SolutionFieldInfo);
|
||||
|
||||
/* add it to the master list of solutions, keyed by name */
|
||||
lua_pushvalue(L, -1);
|
||||
@ -57,6 +57,6 @@ int fn_solution(lua_State* L)
|
||||
}
|
||||
|
||||
/* activate and return the solution object */
|
||||
engine_set_active_object(L, SolutionObject);
|
||||
script_internal_set_active_object(L, SolutionObject);
|
||||
return 1;
|
||||
}
|
Before Width: | Height: | Size: 797 B After Width: | Height: | Size: 797 B |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |