Added filtering by toolset and OS, and pattern matching (r453:460)
This commit is contained in:
parent
ea6a7d7be2
commit
21882c1218
@ -42,7 +42,7 @@ struct FxAction
|
||||
project_set_guid(prj, "AE2461B7-236F-4278-81D3-F0D476F9A4C0");
|
||||
project_set_language(prj, "c++");
|
||||
|
||||
flt = filter_create();
|
||||
flt = session_get_filter(sess);
|
||||
filter_set_value(flt, FilterConfig, "Debug");
|
||||
project_set_filter(prj, flt);
|
||||
}
|
||||
@ -51,7 +51,6 @@ struct FxAction
|
||||
{
|
||||
stream_destroy(strm);
|
||||
session_destroy(sess);
|
||||
filter_destroy(flt);
|
||||
}
|
||||
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
* \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include "premake.h"
|
||||
#include "platform.h"
|
||||
|
||||
@ -28,6 +29,26 @@ enum Platform platform_get()
|
||||
}
|
||||
|
||||
|
||||
const char* platform_get_name(void)
|
||||
{
|
||||
enum Platform id = platform_get();
|
||||
switch (id)
|
||||
{
|
||||
case BSD:
|
||||
return "BSD";
|
||||
case Linux:
|
||||
return "Linux";
|
||||
case MacOSX:
|
||||
return "MacOSX";
|
||||
case Windows:
|
||||
return "Windows";
|
||||
default:
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void platform_set(enum Platform id)
|
||||
{
|
||||
CurrentPlatform = id;
|
||||
|
@ -78,6 +78,12 @@ int platform_dir_set_current(const char* path);
|
||||
enum Platform platform_get(void);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the current platform identifier as a string value.
|
||||
*/
|
||||
const char* platform_get_name(void);
|
||||
|
||||
|
||||
/**
|
||||
* Create a new platform file search context.
|
||||
*/
|
||||
|
@ -14,14 +14,16 @@
|
||||
DEFINE_CLASS(Filter)
|
||||
{
|
||||
const char* values[NumFilters];
|
||||
Script script;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create and initialize a new configuration filter.
|
||||
* \param script A scripting object; used for script_is_match().
|
||||
* \returns A new configuration filter.
|
||||
*/
|
||||
Filter filter_create(void)
|
||||
Filter filter_create(Script script)
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -30,6 +32,7 @@ Filter filter_create(void)
|
||||
{
|
||||
flt->values[i] = NULL;
|
||||
}
|
||||
flt->script = script;
|
||||
return flt;
|
||||
}
|
||||
|
||||
@ -81,7 +84,8 @@ int filter_is_match(Filter flt, Strings terms)
|
||||
const char* term = strings_item(terms, ti);
|
||||
for (ki = 0; ki < NumFilters; ++ki)
|
||||
{
|
||||
if (cstr_eq(flt->values[ki], term))
|
||||
const char* key = flt->values[ki];
|
||||
if (key != NULL && script_is_match(flt->script, key, term))
|
||||
{
|
||||
is_match = 1;
|
||||
break;
|
||||
|
@ -10,6 +10,7 @@
|
||||
#define PREMAKE_FILTER_H
|
||||
|
||||
#include "base/strings.h"
|
||||
#include "script/script.h"
|
||||
|
||||
|
||||
/**
|
||||
@ -17,14 +18,16 @@
|
||||
*/
|
||||
enum FilterKey
|
||||
{
|
||||
FilterAction,
|
||||
FilterConfig,
|
||||
FilterOS,
|
||||
NumFilters
|
||||
};
|
||||
|
||||
|
||||
DECLARE_CLASS(Filter)
|
||||
|
||||
Filter filter_create(void);
|
||||
Filter filter_create(Script script);
|
||||
void filter_destroy(Filter flt);
|
||||
|
||||
const char* filter_get_value(Filter flt, enum FilterKey key);
|
||||
|
@ -7,26 +7,26 @@
|
||||
#include "premake.h"
|
||||
#include "testing/testing.h"
|
||||
extern "C" {
|
||||
#include "project/solution.h"
|
||||
#include "project/filter.h"
|
||||
#include "session/session.h"
|
||||
}
|
||||
|
||||
|
||||
struct FxFilter
|
||||
{
|
||||
Session sess;
|
||||
Filter flt;
|
||||
Strings terms;
|
||||
|
||||
FxFilter()
|
||||
{
|
||||
flt = filter_create();
|
||||
sess = session_create();
|
||||
flt = session_get_filter(sess);
|
||||
terms = strings_create();
|
||||
strings_add(terms, "Debug");
|
||||
}
|
||||
|
||||
~FxFilter()
|
||||
{
|
||||
filter_destroy(flt);
|
||||
session_destroy(sess);
|
||||
strings_destroy(terms);
|
||||
}
|
||||
};
|
||||
@ -49,19 +49,36 @@ SUITE(project)
|
||||
TEST_FIXTURE(FxFilter, IsMatch_ReturnsTrue_OnValueMatch)
|
||||
{
|
||||
filter_set_value(flt, FilterConfig, "Debug");
|
||||
strings_add(terms, "Debug");
|
||||
CHECK(filter_is_match(flt, terms));
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FxFilter, IsMatch_ReturnsFalse_OnNullKey)
|
||||
{
|
||||
strings_add(terms, "Debug");
|
||||
CHECK(!filter_is_match(flt, terms));
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FxFilter, IsMatch_ReturnsFalse_OnValueMismatch)
|
||||
{
|
||||
filter_set_value(flt, FilterConfig, "Release");
|
||||
strings_add(terms, "Debug");
|
||||
CHECK(!filter_is_match(flt, terms));
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FxFilter, IsMatch_ReturnsTrue_OnWildcardMatch)
|
||||
{
|
||||
filter_set_value(flt, FilterConfig, "DebugDLL");
|
||||
strings_add(terms, "Debug.*");
|
||||
CHECK(filter_is_match(flt, terms));
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FxFilter, IsMatch_ReturnsTrue_OnSetMatch)
|
||||
{
|
||||
filter_set_value(flt, FilterAction, "vs2008");
|
||||
strings_add(terms, "vs200[58]");
|
||||
CHECK(filter_is_match(flt, terms));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -115,6 +115,38 @@ lua_State* script_get_lua(Script script)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Uses Lua's pattern matching functions to test match a value. This is used by
|
||||
* the configuration filter functions (see filter.c).
|
||||
* \param script The script engine instance.
|
||||
* \param str The string to test match.
|
||||
* \param pattern The Lua pattern to match against.
|
||||
* \returns True if the string value matches the pattern.
|
||||
*/
|
||||
int script_is_match(Script script, const char* str, const char* pattern)
|
||||
{
|
||||
const char* match;
|
||||
int top, z;
|
||||
assert(script);
|
||||
assert(str);
|
||||
assert(pattern);
|
||||
|
||||
top = lua_gettop(script->L);
|
||||
|
||||
lua_getglobal(script->L, "string");
|
||||
lua_getfield(script->L, -1, "match");
|
||||
lua_pushstring(script->L, str);
|
||||
lua_pushstring(script->L, pattern);
|
||||
lua_call(script->L, 2, 1);
|
||||
|
||||
match = lua_tostring(script->L, -1);
|
||||
z = cstr_eq(str, match);
|
||||
|
||||
lua_settop(script->L, top);
|
||||
return z;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Internal shared implementation for script_run_file() and script_run_string().
|
||||
* \param L The Lua scripting environment.
|
||||
|
@ -19,6 +19,7 @@ DECLARE_CLASS(Script)
|
||||
Script script_create(void);
|
||||
void script_destroy(Script script);
|
||||
const char* script_get_action(Script script);
|
||||
int script_is_match(Script script, const char* str, const char* pattern);
|
||||
const char* script_run_file(Script script, const char* filename);
|
||||
const char* script_run_string(Script script, const char* code);
|
||||
void script_set_action(Script script, const char* action);
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "base/array.h"
|
||||
#include "base/cstr.h"
|
||||
#include "base/error.h"
|
||||
#include "platform/platform.h"
|
||||
|
||||
|
||||
DEFINE_CLASS(Session)
|
||||
@ -41,12 +42,16 @@ Session session_create(void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* create and return the session object */
|
||||
/* create the session object */
|
||||
sess = ALLOC_CLASS(Session);
|
||||
sess->script = script;
|
||||
sess->solutions = array_create();
|
||||
sess->filter = filter_create();
|
||||
sess->filter = filter_create(script);
|
||||
sess->active_stream = NULL;
|
||||
|
||||
/* initialize the filter */
|
||||
filter_set_value(sess->filter, FilterOS, platform_get_name());
|
||||
|
||||
return sess;
|
||||
}
|
||||
|
||||
@ -209,6 +214,18 @@ Stream session_get_active_stream(Session sess)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the active configuration filter.
|
||||
* \param sess The session object.
|
||||
* \returns The active configuration filter.
|
||||
*/
|
||||
Filter session_get_filter(Session sess)
|
||||
{
|
||||
assert(sess);
|
||||
return sess->filter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the contained solution at the given index in the solution list.
|
||||
* \param sess The session object.
|
||||
@ -274,6 +291,7 @@ void session_set_action(Session sess, const char* action)
|
||||
{
|
||||
assert(sess);
|
||||
script_set_action(sess->script, action);
|
||||
filter_set_value(sess->filter, FilterAction, action);
|
||||
}
|
||||
|
||||
|
||||
|
@ -84,6 +84,7 @@ int session_enumerate_configurations(Session sess, Project prj, Stream s
|
||||
int session_enumerate_objects(Session sess, SessionSolutionCallback* sln_funcs, SessionProjectCallback* prj_funcs, SessionProjectCallback* cfg_funcs);
|
||||
const char* session_get_action(Session sess);
|
||||
Stream session_get_active_stream(Session sess);
|
||||
Filter session_get_filter(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);
|
||||
|
@ -11,6 +11,7 @@ extern "C" {
|
||||
#include "script/script.h"
|
||||
#include "base/base.h"
|
||||
#include "base/error.h"
|
||||
#include "platform/platform.h"
|
||||
}
|
||||
|
||||
|
||||
@ -187,6 +188,24 @@ SUITE(session)
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* Configuration filtering tests
|
||||
**********************************************************************/
|
||||
|
||||
TEST_FIXTURE(FxSession, SetAction_UpdatesFilter)
|
||||
{
|
||||
session_set_action(sess, "MyAction");
|
||||
Filter filter = session_get_filter(sess);
|
||||
CHECK_EQUAL("MyAction", filter_get_value(filter, FilterAction));
|
||||
}
|
||||
|
||||
TEST_FIXTURE(FxSession, Ctor_SetsOSFilter)
|
||||
{
|
||||
Filter filter = session_get_filter(sess);
|
||||
CHECK_EQUAL(platform_get_name(), filter_get_value(filter, FilterOS));
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* Solution containment tests
|
||||
**********************************************************************/
|
||||
|
Reference in New Issue
Block a user