[ros-diffs] [cwittich] 27440: -added msbuild target to rbuild to be able to test drivers with PREfast

cwittich at svn.reactos.org cwittich at svn.reactos.org
Sat Jul 7 02:39:00 CEST 2007


Author: cwittich
Date: Sat Jul  7 04:38:59 2007
New Revision: 27440

URL: http://svn.reactos.org/svn/reactos?rev=27440&view=rev
Log:
-added msbuild target to rbuild to be able to test drivers with PREfast

Added:
    trunk/reactos/tools/rbuild/backend/msbuild/
    trunk/reactos/tools/rbuild/backend/msbuild/msbuild.cpp
    trunk/reactos/tools/rbuild/backend/msbuild/msbuild.h
Modified:
    trunk/reactos/Makefile
    trunk/reactos/tools/rbuild/rbuild.mak

Modified: trunk/reactos/Makefile
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/Makefile?rev=27440&r1=27439&r2=27440&view=diff
==============================================================================
--- trunk/reactos/Makefile (original)
+++ trunk/reactos/Makefile Sat Jul  7 04:38:59 2007
@@ -472,6 +472,16 @@
 	$(ECHO_RBUILD)
 	$(Q)$(RBUILD_TARGET) $(ROS_RBUILDFLAGS) cb
 
+.PHONY: msbuild
+msbuild: $(RBUILD_TARGET)
+	$(ECHO_RBUILD)
+	$(Q)$(RBUILD_TARGET) $(ROS_RBUILDFLAGS) msbuild
+
+.PHONY: msbuild_clean
+msbuild_clean: $(RBUILD_TARGET)
+	$(ECHO_RBUILD)
+	$(Q)$(RBUILD_TARGET) $(ROS_RBUILDFLAGS) -c msbuild
+
 .PHONY: depmap
 depmap: $(RBUILD_TARGET)
 	$(ECHO_RBUILD)

Added: trunk/reactos/tools/rbuild/backend/msbuild/msbuild.cpp
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/rbuild/backend/msbuild/msbuild.cpp?rev=27440&view=auto
==============================================================================
--- trunk/reactos/tools/rbuild/backend/msbuild/msbuild.cpp (added)
+++ trunk/reactos/tools/rbuild/backend/msbuild/msbuild.cpp Sat Jul  7 04:38:59 2007
@@ -1,0 +1,274 @@
+/*
+ * Copyright (C) 2007 Christoph von Wittich
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+#ifdef _MSC_VER
+#pragma warning ( disable : 4786 )
+#endif//_MSC_VER
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <vector>
+
+#include <stdio.h>
+
+#include "msbuild.h"
+#include "../mingw/mingw.h"
+
+using std::string;
+using std::vector;
+using std::map;
+using std::ifstream;
+
+#ifdef OUT
+#undef OUT
+#endif//OUT
+
+
+static class MsBuildFactory : public Backend::Factory
+{
+	public:
+
+		MsBuildFactory() : Factory("MsBuild", "Ms Build") {}
+		Backend *operator() (Project &project,
+		                     Configuration& configuration)
+		{
+			return new MsBuildBackend(project, configuration);
+		}
+		
+} factory;
+
+
+MsBuildBackend::MsBuildBackend(Project &project,
+	Configuration& configuration) : Backend(project, configuration)
+{
+
+}
+
+void MsBuildBackend::Process()
+{
+	if ( configuration.CleanAsYouGo ) {
+		_clean_project_files();
+		return;
+	}
+
+	ProcessModules();
+}
+
+void
+MsBuildBackend::_generate_makefile ( const Module& module )
+{
+	string makefile = module.GetBasePath() + "\\makefile";
+	FILE* OUT = fopen ( makefile.c_str(), "wb" );
+	fprintf ( OUT, "!INCLUDE $(NTMAKEENV)\\makefile.def\r\n" );
+	fclose ( OUT );
+}
+
+void
+MsBuildBackend::_generate_sources ( const Module& module )
+{
+	size_t i;
+
+	string module_type = GetExtension(module.GetTargetName());
+	vector<string> source_files, resource_files, includes, libraries;
+	vector<string> header_files, common_defines, compiler_flags;
+	vector<string> vars, values;
+	string sourcesfile = module.GetBasePath() + "\\sources";
+	string proj_path = module.GetBasePath();	
+
+	FILE* OUT = fopen ( sourcesfile.c_str(), "wb" );
+	fprintf ( OUT, "TARGETNAME=%s\r\n", module.name.c_str() );
+
+	vector<const IfableData*> ifs_list;
+	ifs_list.push_back ( &module.project.non_if_data );
+	ifs_list.push_back ( &module.non_if_data );
+	while ( ifs_list.size() )
+	{
+		const IfableData& data = *ifs_list.back();
+		ifs_list.pop_back();
+		for ( i = 0; i < data.ifs.size(); i++ )
+		{
+			const Property* property = _lookup_property( module, data.ifs[i]->property );
+			if ( property != NULL )
+			{
+				if ( data.ifs[i]->value == property->value && data.ifs[i]->negated == false ||
+					data.ifs[i]->value != property->value && data.ifs[i]->negated)
+					ifs_list.push_back ( &data.ifs[i]->data );
+			}
+		}
+		const vector<File*>& files = data.files;
+		for ( i = 0; i < files.size(); i++ )
+		{
+			string file = &files[i]->name[proj_path.size()+1];
+			source_files.push_back ( file );
+		}
+		const vector<Include*>& incs = data.includes;
+		for ( i = 0; i < incs.size(); i++ )
+		{
+			string path = Path::RelativeFromDirectory (
+				incs[i]->directory,
+				module.GetBasePath() );
+
+			includes.push_back ( path );
+		}
+		const vector<Library*>& libs = data.libraries;
+		for ( i = 0; i < libs.size(); i++ )
+		{
+			libraries.push_back ( libs[i]->name );
+		}
+		const vector<CompilerFlag*>& cflags = data.compilerFlags;
+		for ( i = 0; i < cflags.size(); i++ )
+		{
+			compiler_flags.push_back ( cflags[i]->flag );
+		}
+		const vector<Define*>& defs = data.defines;
+		for ( i = 0; i < defs.size(); i++ )
+		{
+			if ( defs[i]->value[0] )
+			{
+				const string& escaped = _replace_str(defs[i]->value, "\"","&quot;");
+				common_defines.push_back( defs[i]->name + "=" + escaped );
+			}
+			else
+			{
+				common_defines.push_back( defs[i]->name );
+			}
+		}
+	}
+
+
+	if (module_type == ".sys")
+		fprintf ( OUT, "TARGETTYPE=DRIVER\r\n" );
+
+	fprintf ( OUT, "\r\nMSC_WARNING_LEVEL=/W3 /WX\r\n\r\n" );
+
+	/* Disable deprecated function uage warnings */
+	fprintf ( OUT, "C_DEFINES=$(C_DEFINES) /wd4996\r\n" );
+	
+
+	/* includes */
+	fprintf ( OUT, "INCLUDES=.; \\\r\n" );
+	for ( i = 1; i < includes.size() -1; i++ )
+	{
+		const string& include = includes[i];
+		
+		/* don't include psdk / ddk */
+		std::string::size_type pos = include.find("ddk");
+		std::string::size_type pos2 = include.find("psdk");
+		if ((std::string::npos == pos) && (std::string::npos == pos2))
+			fprintf ( OUT, "\t%s; \\\r\n", include.c_str() );
+	}
+	if (includes.size() > 1)
+	{
+		const string& include = includes[includes.size()-1];
+		fprintf ( OUT, "\t%s \r\n\r\n", include.c_str() );
+	}
+
+	fprintf ( OUT, "TARGETLIBS= $(DDK_LIB_PATH)\\ntstrsafe.lib\r\n\r\n" );
+
+	string source_file = "";
+	if (source_files.size() > 0)
+	{
+		source_file = DosSeparator(source_files[0]);
+		fprintf ( OUT, "SOURCES=%s \\\r\n", source_file.c_str() );
+	
+		for ( size_t isrcfile = 1; isrcfile < source_files.size()-1; isrcfile++ )
+		{
+			source_file = DosSeparator(source_files[isrcfile]);
+			fprintf ( OUT, "\t%s \\\r\n", source_file.c_str() );
+		}
+	}
+	if (source_files.size() > 1)
+	{
+		source_file = DosSeparator(source_files[source_files.size()-1]);
+		fprintf ( OUT, "\t%s \r\n", source_file.c_str() );
+	}
+
+	fprintf ( OUT, "TARGET_DESTINATION=retail\r\n" );
+	
+
+	fclose ( OUT );
+}
+
+void MsBuildBackend::ProcessModules()
+{
+	for(size_t i = 0; i < ProjectNode.modules.size(); i++)
+	{
+		Module &module = *ProjectNode.modules[i];
+		_generate_makefile ( module );
+		_generate_sources ( module );
+	}
+}
+
+void
+MsBuildBackend::_clean_project_files ( void )
+{
+	for ( size_t i = 0; i < ProjectNode.modules.size(); i++ )
+	{
+		Module& module = *ProjectNode.modules[i];
+		printf("Cleaning project %s %s\n", module.name.c_str (), module.GetBasePath ().c_str () );
+		
+		string makefile = module.GetBasePath() + "\\makefile";
+		string sourcesfile = module.GetBasePath() + "\\sources";
+
+		string basepath = module.GetBasePath ();
+		remove ( makefile.c_str() );	
+		remove ( sourcesfile.c_str() );	
+	}
+}
+
+MsBuildConfiguration::MsBuildConfiguration ( const std::string &name )
+{
+	/* nothing to do here */
+}
+
+const Property* 
+MsBuildBackend::_lookup_property ( const Module& module, const std::string& name ) const
+{
+	/* Check local values */
+	for ( size_t i = 0; i < module.non_if_data.properties.size(); i++ )
+	{
+		const Property& property = *module.non_if_data.properties[i];
+		if ( property.name == name )
+			return &property;
+	}
+	// TODO FIXME - should we check local if-ed properties?
+	for ( size_t i = 0; i < module.project.non_if_data.properties.size(); i++ )
+	{
+		const Property& property = *module.project.non_if_data.properties[i];
+		if ( property.name == name )
+			return &property;
+	}
+	// TODO FIXME - should we check global if-ed properties?
+	return NULL;
+}
+
+std::string
+MsBuildBackend::_replace_str(std::string string1, const std::string &find_str, const std::string &replace_str)
+{
+	std::string::size_type pos = string1.find(find_str, 0);
+	int intLen = find_str.length();
+
+	while(std::string::npos != pos)
+	{
+		string1.replace(pos, intLen, replace_str);
+		pos = string1.find(find_str, intLen + pos);
+	}
+
+	return string1;
+}
+

Added: trunk/reactos/tools/rbuild/backend/msbuild/msbuild.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/rbuild/backend/msbuild/msbuild.h?rev=27440&view=auto
==============================================================================
--- trunk/reactos/tools/rbuild/backend/msbuild/msbuild.h (added)
+++ trunk/reactos/tools/rbuild/backend/msbuild/msbuild.h Sat Jul  7 04:38:59 2007
@@ -1,0 +1,72 @@
+/*
+ * Copyright (C) 2007 Christoph von Wittich
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+#ifndef __MSBUILD_H__
+#define __MSBUILD_H__
+
+#include <fstream>
+#include <vector>
+#include <string>
+
+#include "../backend.h"
+
+class MsBuildConfiguration
+{
+	public:
+		MsBuildConfiguration(const std::string &name = "");
+		virtual ~MsBuildConfiguration() {}
+		std::string name;
+};
+
+class MsBuildBackend : public Backend
+{
+	public:
+
+		MsBuildBackend(Project &project,
+		              Configuration& configuration);
+		virtual ~MsBuildBackend() {}
+
+		virtual void Process();
+
+	private:
+
+		FILE* m_MsBuildFile;
+
+		std::vector<MsBuildConfiguration*> m_configurations;
+		void _generate_makefile ( const Module& module );
+		void _generate_sources ( const Module& module );
+		void _clean_project_files ( void );
+		void ProcessModules();
+		const Property* _lookup_property ( const Module& module, const std::string& name ) const;
+		std::string _replace_str(std::string string1, const std::string &find_str, const std::string &replace_str);
+
+		struct module_data
+		{
+			std::vector <std::string> libraries;
+			std::vector <std::string> references;
+		
+			module_data()
+			{}
+			~module_data()
+			{}
+		};
+
+};
+
+
+#endif // __MsBuild_H__
+

Modified: trunk/reactos/tools/rbuild/rbuild.mak
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/rbuild/rbuild.mak?rev=27440&r1=27439&r2=27440&view=diff
==============================================================================
--- trunk/reactos/tools/rbuild/rbuild.mak (original)
+++ trunk/reactos/tools/rbuild/rbuild.mak Sat Jul  7 04:38:59 2007
@@ -119,6 +119,24 @@
 	${mkdir} $@
 endif
 
+
+RBUILD_MSBUILD_BASE = $(RBUILD_BACKEND_BASE_)msbuild
+RBUILD_MSBUILD_BASE_ = $(RBUILD_MSBUILD_BASE)$(SEP)
+RBUILD_MSBUILD_INT = $(INTERMEDIATE_)$(RBUILD_MSBUILD_BASE)
+RBUILD_MSBUILD_INT_ = $(RBUILD_MSBUILD_INT)$(SEP)
+RBUILD_MSBUILD_OUT = $(OUTPUT_)$(RBUILD_MSBUILD_BASE)
+RBUILD_MSBUILD_OUT_ = $(RBUILD_MSBUILD_OUT)$(SEP)
+
+$(RBUILD_MSBUILD_INT): | $(RBUILD_BACKEND_INT)
+	$(ECHO_MKDIR)
+	${mkdir} $@
+
+ifneq ($(INTERMEDIATE),$(OUTPUT))
+$(RBUILD_MSBUILD_OUT): | $(RBUILD_BACKEND_OUT)
+	$(ECHO_MKDIR)
+	${mkdir} $@
+endif
+
 RBUILD_DEPMAP_BASE = $(RBUILD_BACKEND_BASE_)dependencymap
 RBUILD_DEPMAP_BASE_ = $(RBUILD_DEPMAP_BASE)$(SEP)
 RBUILD_DEPMAP_INT = $(INTERMEDIATE_)$(RBUILD_DEPMAP_BASE)
@@ -179,6 +197,9 @@
 	dependencymap.cpp \
 	)
 
+RBUILD_BACKEND_MSBUILD_BASE_SOURCES = $(addprefix $(RBUILD_MSBUILD_BASE_), \
+	msbuild.cpp \
+	)
 
 RBUILD_BACKEND_MSVC_BASE_SOURCES = $(addprefix $(RBUILD_MSVC_BASE_), \
 	genguid.cpp \
@@ -193,6 +214,7 @@
 	$(RBUILD_BACKEND_MSVC_BASE_SOURCES) \
 	$(RBUILD_BACKEND_CODEBLOCKS_BASE_SOURCES) \
 	$(RBUILD_BACKEND_DEPMAP_BASE_SOURCES) \
+	$(RBUILD_BACKEND_MSBUILD_BASE_SOURCES) \
 	$(RBUILD_BACKEND_BASE_)backend.cpp
 
 RBUILD_COMMON_SOURCES = \
@@ -251,6 +273,9 @@
 RBUILD_BACKEND_DEPMAP_HEADERS = \
 	dependencymap.h
 
+RBUILD_BACKEND_MSBUILD_HEADERS = \
+	msbuild.h
+
 RBUILD_BACKEND_MINGW_HEADERS = \
 	mingw.h \
 	modulehandler.h
@@ -261,6 +286,7 @@
 	$(addprefix msvc$(SEP), $(RBUILD_BACKEND_MSVC_HEADERS)) \
 	$(addprefix mingw$(SEP), $(RBUILD_BACKEND_MINGW_HEADERS)) \
 	$(addprefix codeblocks$(SEP), $(RBUILD_BACKEND_CODEBLOCKS_HEADERS)) \
+	$(addprefix msbuild$(SEP), $(RBUILD_BACKEND_MSBUILD_HEADERS)) \
 	$(addprefix dependencymap$(SEP), $(RBUILD_BACKEND_DEPMAP_HEADERS))
 
 RBUILD_HEADERS = \
@@ -434,6 +460,10 @@
 	$(ECHO_CC)
 	${host_gpp} $(RBUILD_HOST_CXXFLAGS) -c $< -o $@
 
+$(RBUILD_MSBUILD_INT_)msbuild.o: $(RBUILD_MSBUILD_BASE_)msbuild.cpp $(RBUILD_HEADERS) | $(RBUILD_MSBUILD_INT)
+	$(ECHO_CC)
+	${host_gpp} $(RBUILD_HOST_CXXFLAGS) -c $< -o $@
+
 $(RBUILD_MSVC_INT_)genguid.o: $(RBUILD_MSVC_BASE_)genguid.cpp $(RBUILD_HEADERS) | $(RBUILD_MSVC_INT)
 	$(ECHO_CC)
 	${host_gpp} $(RBUILD_HOST_CXXFLAGS) -c $< -o $@




More information about the Ros-diffs mailing list