Some rbuild cleanup:

- Move AutoRegister class to its own file
- Add an enum to replace strings "$(OUTPUT)", "$(INTERMEDIATE)"..., except when writing them to makefile.auto
- Add the FileLocation class to identify a file (root dir, relative path and name)
- Use it to simplify CDFile and InstallFile classes
- Use the FileLocation class when possible
This leads also to good things which were unexpected, like not creating unneeded directories in output directory, removal of some hardcoded strings and a few fixusp in the generated makefile.auto

svn path=/trunk/; revision=28924
This commit is contained in:
Hervé Poussineau 2007-09-07 14:59:23 +00:00
parent 51a42b98f3
commit b1a07a3e6b
17 changed files with 1070 additions and 897 deletions

View file

@ -320,7 +320,10 @@ AutomaticDependency::GetModuleFiles ( const Module& module,
/* FIXME: Collect files in IFs here */
if ( module.pch != NULL )
files.push_back ( &module.pch->file );
{
File *file = new File ( module.pch->file.relative_path + sSep + module.pch->file.name , false, "", true );
files.push_back ( file );
}
}
void

View file

@ -0,0 +1,88 @@
/*
* Copyright (C) 2005 Casper S. Hornstrup
*
* 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.
*/
#include "pch.h"
#include "rbuild.h"
using std::string;
AutoRegister::AutoRegister ( const Project& project_,
const Module* module_,
const XMLElement& node_ )
: XmlNode(project_, node_),
module(module_)
{
Initialize();
}
bool
AutoRegister::IsSupportedModuleType ( ModuleType type )
{
if ( type == Win32DLL ||
type == Win32OCX )
{
return true;
}
else
{
return false;
}
}
AutoRegisterType
AutoRegister::GetAutoRegisterType( const string& type )
{
if ( type == "DllRegisterServer" )
return DllRegisterServer;
if ( type == "DllInstall" )
return DllInstall;
if ( type == "Both" )
return Both;
throw XMLInvalidBuildFileException (
node.location,
"<autoregister> type attribute must be DllRegisterServer, DllInstall or Both." );
}
void
AutoRegister::Initialize ()
{
if ( !IsSupportedModuleType ( module->type ) )
{
throw XMLInvalidBuildFileException (
node.location,
"<autoregister> is not applicable for this module type." );
}
const XMLAttribute* att = node.GetAttribute ( "infsection", true );
if ( !att )
{
throw XMLInvalidBuildFileException (
node.location,
"<autoregister> must have a 'infsection' attribute." );
}
infSection = att->value;
att = node.GetAttribute ( "type", true );
if ( !att )
{
throw XMLInvalidBuildFileException (
node.location,
"<autoregister> must have a 'type' attribute." );
}
type = GetAutoRegisterType ( att->value );
}

View file

@ -34,6 +34,104 @@ using std::map;
typedef set<string> set_string;
string
strDirectory ( const FileLocation *file )
{
MingwModuleHandler::PassThruCacheDirectory ( file );
string directory;
switch ( file->directory )
{
case SourceDirectory:
directory = "";
break;
case IntermediateDirectory:
directory = "$(INTERMEDIATE)";
break;
case OutputDirectory:
directory = "$(OUTPUT)";
break;
case InstallDirectory:
directory = "$(INSTALL)";
break;
case TemporaryDirectory:
directory = "$(TEMPORARY)";
break;
default:
throw InvalidOperationException ( __FILE__,
__LINE__,
"Invalid directory." );
}
if ( file->relative_path.length () > 0 )
{
if ( directory.length () > 0 )
directory += sSep;
directory += file->relative_path;
}
return directory;
}
string
strFile ( const FileLocation *file )
{
string directory;
switch ( file->directory )
{
case SourceDirectory:
directory = "";
break;
case IntermediateDirectory:
directory = "$(INTERMEDIATE)";
break;
case OutputDirectory:
directory = "$(OUTPUT)";
break;
case InstallDirectory:
directory = "$(INSTALL)";
break;
case TemporaryDirectory:
directory = "$(TEMPORARY)";
break;
default:
throw InvalidOperationException ( __FILE__,
__LINE__,
"Invalid directory." );
}
if ( file->relative_path.length () > 0 )
{
if ( directory.length () > 0 )
directory += sSep;
directory += file->relative_path;
}
if ( directory.length () > 0 )
directory += sSep;
return directory + file->name;
}
string
v2s ( const vector<FileLocation>& files, int wrap_at )
{
if ( !files.size() )
return "";
string s;
int wrap_count = 0;
for ( size_t i = 0; i < files.size(); i++ )
{
const FileLocation& file = files[i];
if ( wrap_at > 0 && wrap_count++ == wrap_at )
s += " \\\n\t\t";
else if ( s.size() )
s += " ";
s += strFile ( &file );
}
return s;
}
string
v2s ( const string_list& v, int wrap_at )
@ -1049,22 +1147,18 @@ MingwBackend::DetectPCHSupport ()
void
MingwBackend::GetNonModuleInstallTargetFiles (
vector<string>& out ) const
vector<FileLocation>& out ) const
{
for ( size_t i = 0; i < ProjectNode.installfiles.size (); i++ )
{
const InstallFile& installfile = *ProjectNode.installfiles[i];
string targetFilenameNoFixup = installfile.base + sSep + installfile.newname;
string targetFilename = MingwModuleHandler::PassThruCacheDirectory (
NormalizeFilename ( targetFilenameNoFixup ),
installDirectory );
out.push_back ( targetFilename );
out.push_back ( *installfile.target );
}
}
void
MingwBackend::GetModuleInstallTargetFiles (
vector<string>& out ) const
vector<FileLocation>& out ) const
{
for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )
{
@ -1073,54 +1167,36 @@ MingwBackend::GetModuleInstallTargetFiles (
continue;
if ( module.installName.length () > 0 )
{
string targetFilenameNoFixup;
if ( module.installBase.length () > 0 )
targetFilenameNoFixup = module.installBase + sSep + module.installName;
else
targetFilenameNoFixup = module.installName;
string targetFilename = MingwModuleHandler::PassThruCacheDirectory (
NormalizeFilename ( targetFilenameNoFixup ),
installDirectory );
out.push_back ( targetFilename );
out.push_back ( FileLocation ( InstallDirectory,
module.installBase,
module.installName ) );
}
}
}
void
MingwBackend::GetInstallTargetFiles (
vector<string>& out ) const
vector<FileLocation>& out ) const
{
GetNonModuleInstallTargetFiles ( out );
GetModuleInstallTargetFiles ( out );
}
void
MingwBackend::OutputInstallTarget ( const string& sourceFilename,
const string& targetFilename,
const string& targetDirectory )
MingwBackend::OutputInstallTarget ( const FileLocation& source,
const FileLocation& target )
{
string fullTargetFilename;
if ( targetDirectory.length () > 0)
fullTargetFilename = targetDirectory + sSep + targetFilename;
else
fullTargetFilename = targetFilename;
string normalizedTargetFilename = MingwModuleHandler::PassThruCacheDirectory (
NormalizeFilename ( fullTargetFilename ),
installDirectory );
string normalizedTargetDirectory = MingwModuleHandler::PassThruCacheDirectory (
NormalizeFilename ( targetDirectory ),
installDirectory );
fprintf ( fMakefile,
"%s: %s | %s\n",
normalizedTargetFilename.c_str (),
sourceFilename.c_str (),
normalizedTargetDirectory.c_str () );
strFile( &target ).c_str (),
strFile( &source ).c_str (),
strDirectory( &target ).c_str () );
fprintf ( fMakefile,
"\t$(ECHO_CP)\n" );
fprintf ( fMakefile,
"\t${cp} %s %s 1>$(NUL)\n",
sourceFilename.c_str (),
normalizedTargetFilename.c_str () );
strFile( &source ).c_str (),
strFile( &target ).c_str () );
}
void
@ -1129,9 +1205,7 @@ MingwBackend::OutputNonModuleInstallTargets ()
for ( size_t i = 0; i < ProjectNode.installfiles.size (); i++ )
{
const InstallFile& installfile = *ProjectNode.installfiles[i];
OutputInstallTarget ( installfile.GetPath (),
installfile.newname,
installfile.base );
OutputInstallTarget ( *installfile.source, *installfile.target );
}
}
@ -1159,12 +1233,10 @@ MingwBackend::OutputModuleInstallTargets ()
if ( module.installName.length () > 0 )
{
const Module& aliasedModule = GetAliasedModuleOrModule ( module );
string sourceFilename = MingwModuleHandler::PassThruCacheDirectory (
NormalizeFilename ( aliasedModule.GetPath () ),
outputDirectory );
OutputInstallTarget ( sourceFilename,
module.installName,
module.installBase );
FileLocation source ( OutputDirectory, aliasedModule.GetBasePath (), aliasedModule.GetTargetName () );
FileLocation target ( InstallDirectory, module.installBase, module.installName );
OutputInstallTarget ( source, target );
}
}
}
@ -1182,24 +1254,23 @@ MingwBackend::GetRegistrySourceFiles ()
string
MingwBackend::GetRegistryTargetFiles ()
{
string system32ConfigDirectory = NormalizeFilename (
MingwModuleHandler::PassThruCacheDirectory (
"system32" + sSep + "config" + sSep,
installDirectory ) );
return system32ConfigDirectory + sSep + "default " +
system32ConfigDirectory + sSep + "sam " +
system32ConfigDirectory + sSep + "security " +
system32ConfigDirectory + sSep + "software " +
system32ConfigDirectory + sSep + "system";
string system32ConfigDirectory = "system32" + sSep + "config";
FileLocation system32 ( InstallDirectory, system32ConfigDirectory, "" );
vector<FileLocation> registry_files;
registry_files.push_back ( FileLocation ( InstallDirectory, system32ConfigDirectory, "default" ) );
registry_files.push_back ( FileLocation ( InstallDirectory, system32ConfigDirectory, "sam" ) );
registry_files.push_back ( FileLocation ( InstallDirectory, system32ConfigDirectory, "security" ) );
registry_files.push_back ( FileLocation ( InstallDirectory, system32ConfigDirectory, "software" ) );
registry_files.push_back ( FileLocation ( InstallDirectory, system32ConfigDirectory, "system" ) );
return v2s( registry_files, 6 );
}
void
MingwBackend::OutputRegistryInstallTarget ()
{
string system32ConfigDirectory = NormalizeFilename (
MingwModuleHandler::PassThruCacheDirectory (
"system32" + sSep + "config" + sSep,
installDirectory ) );
FileLocation system32 ( InstallDirectory, "system32" + sSep + "config", "" );
string registrySourceFiles = GetRegistrySourceFiles ();
string registryTargetFiles = GetRegistryTargetFiles ();
@ -1210,12 +1281,12 @@ MingwBackend::OutputRegistryInstallTarget ()
"%s: %s %s $(MKHIVE_TARGET)\n",
registryTargetFiles.c_str (),
registrySourceFiles.c_str (),
system32ConfigDirectory.c_str () );
strDirectory ( &system32 ).c_str () );
fprintf ( fMakefile,
"\t$(ECHO_MKHIVE)\n" );
fprintf ( fMakefile,
"\t$(MKHIVE_TARGET) boot%cbootdata %s boot%cbootdata%chiveinst.inf\n",
cSep, system32ConfigDirectory.c_str (),
cSep, strDirectory ( &system32 ).c_str (),
cSep, cSep );
fprintf ( fMakefile,
"\n" );
@ -1224,7 +1295,7 @@ MingwBackend::OutputRegistryInstallTarget ()
void
MingwBackend::GenerateInstallTarget ()
{
vector<string> vInstallTargetFiles;
vector<FileLocation> vInstallTargetFiles;
GetInstallTargetFiles ( vInstallTargetFiles );
string installTargetFiles = v2s ( vInstallTargetFiles, 5 );
string registryTargetFiles = GetRegistryTargetFiles ();
@ -1232,7 +1303,7 @@ MingwBackend::GenerateInstallTarget ()
fprintf ( fMakefile,
"install: %s %s\n",
installTargetFiles.c_str (),
registryTargetFiles.c_str () );
registryTargetFiles.c_str () );
OutputNonModuleInstallTargets ();
OutputModuleInstallTargets ();
OutputRegistryInstallTarget ();

View file

@ -29,6 +29,8 @@
class Directory;
class MingwModuleHandler;
extern std::string
v2s ( const std::vector<FileLocation>& files, int wrap_at );
extern std::string
v2s ( const string_list& v, int wrap_at );
@ -62,7 +64,7 @@ private:
void GenerateGlobalCFlagsAndProperties ( const char* op,
IfableData& data ) const;
void GenerateProjectGccOptionsMacro ( const char* assignmentOperation,
IfableData& data ) const;
IfableData& data ) const;
void GenerateProjectGccOptions ( const char* assignmentOperation,
IfableData& data ) const;
std::string GenerateProjectLFLAGS () const;
@ -106,12 +108,10 @@ private:
std::string GetInstallDirectories ( const std::string& installDirectory );
void GetNonModuleInstallFiles ( std::vector<std::string>& out ) const;
void GetInstallFiles ( std::vector<std::string>& out ) const;
void GetNonModuleInstallTargetFiles ( std::vector<std::string>& out ) const;
void GetModuleInstallTargetFiles ( std::vector<std::string>& out ) const;
void GetInstallTargetFiles ( std::vector<std::string>& out ) const;
void OutputInstallTarget ( const std::string& sourceFilename,
const std::string& targetFilename,
const std::string& targetDirectory );
void GetNonModuleInstallTargetFiles ( std::vector<FileLocation>& out ) const;
void GetModuleInstallTargetFiles ( std::vector<FileLocation>& out ) const;
void GetInstallTargetFiles ( std::vector<FileLocation>& out ) const;
void OutputInstallTarget ( const FileLocation& source, const FileLocation& target );
void OutputNonModuleInstallTargets ();
void OutputModuleInstallTargets ();
std::string GetRegistrySourceFiles ();

File diff suppressed because it is too large Load diff

View file

@ -41,21 +41,16 @@ public:
static void SetMakefile ( FILE* f );
void EnablePreCompiledHeaderSupport ();
static std::string PassThruCacheDirectory (
const std::string &f,
Directory* directoryTree );
static const FileLocation* PassThruCacheDirectory (const FileLocation* fileLocation );
static std::string PassThruCacheDirectory (const FileLocation* fileLocation );
static Directory* GetTargetDirectoryTree (
static DirectoryLocation GetTargetDirectoryTree (
const Module& module );
static std::string GetTargetFilename (
static const FileLocation* GetTargetFilename (
const Module& module,
string_list* pclean_files );
static std::string
GetImportLibraryFilename (
static const FileLocation* GetImportLibraryFilename (
const Module& module,
string_list* pclean_files );
@ -64,7 +59,7 @@ public:
std::string GetModuleTargets ( const Module& module );
void GetObjectsVector ( const IfableData& data,
std::vector<std::string>& objectFiles ) const;
std::vector<FileLocation>& objectFiles ) const;
void GenerateObjectMacro();
void GenerateTargetMacro();
void GenerateOtherMacros();
@ -83,25 +78,28 @@ public:
void GenerateDependsTarget () const;
static bool ReferenceObjects ( const Module& module );
virtual void AddImplicitLibraries ( Module& module ) { return; }
void OutputCopyCommand ( const FileLocation& source,
const FileLocation& destination );
protected:
virtual void GetModuleSpecificCompilationUnits ( std::vector<CompilationUnit*>& compilationUnits );
std::string GetWorkingDirectory () const;
std::string GetBasename ( const std::string& filename ) const;
FileLocation* GetActualSourceFilename ( const FileLocation* fileLocation ) const;
std::string GetExtraDependencies ( const std::string& filename ) const;
const FileLocation* GetActualSourceFilename ( const FileLocation* file ) const;
std::string GetExtraDependencies ( const FileLocation *file ) const;
std::string GetCompilationUnitDependencies ( const CompilationUnit& compilationUnit ) const;
std::string GetModuleArchiveFilename () const;
const FileLocation* GetModuleArchiveFilename () const;
bool IsGeneratedFile ( const File& file ) const;
std::string GetImportLibraryDependency ( const Module& importedModule );
void GetTargets ( const Module& dependencyModule,
string_list& targets );
void GetModuleDependencies ( string_list& dependencies );
std::string GetAllDependencies () const;
void GetSourceFilenames ( string_list& list,
void GetSourceFilenames ( std::vector<FileLocation>& list,
bool includeGeneratedFiles ) const;
void GetSourceFilenamesWithoutGeneratedFiles ( string_list& list ) const;
std::string GetObjectFilename ( const FileLocation* sourceFileLocation,
string_list* pclean_files ) const;
void GetSourceFilenamesWithoutGeneratedFiles ( std::vector<FileLocation>& list ) const;
const FileLocation* GetObjectFilename ( const FileLocation* sourceFile,
string_list* pclean_files ) const;
std::string GetObjectFilenames ();
@ -121,10 +119,10 @@ protected:
const std::string& libsMacro,
const std::string& pefixupParameters );
void GeneratePhonyTarget() const;
void GenerateBuildMapCode ( const char *mapTarget = NULL );
void GenerateBuildMapCode ( const FileLocation *mapTarget = NULL );
void GenerateRules ();
void GenerateImportLibraryTargetIfNeeded ();
void GetDefinitionDependencies ( string_list& dependencies ) const;
void GetDefinitionDependencies ( std::vector<FileLocation>& dependencies ) const;
std::string GetLinkingDependencies () const;
static MingwBackend* backend;
@ -150,19 +148,19 @@ private:
std::string GenerateGccIncludeParameters () const;
std::string GenerateGccParameters () const;
std::string GenerateNasmParameters () const;
std::string GetPrecompiledHeaderFilename () const;
void GenerateGccCommand ( const FileLocation* sourceFileLocation,
const FileLocation* GetPrecompiledHeaderFilename () const;
void GenerateGccCommand ( const FileLocation* sourceFile,
const std::string& extraDependencies,
const std::string& cc,
const std::string& cflagsMacro );
void GenerateGccAssemblerCommand ( const FileLocation* sourceFileLocation,
void GenerateGccAssemblerCommand ( const FileLocation* sourceFile,
const std::string& cc,
const std::string& cflagsMacro );
void GenerateNasmCommand ( const FileLocation* sourceFileLocation,
void GenerateNasmCommand ( const FileLocation* sourceFile,
const std::string& nasmflagsMacro );
void GenerateWindresCommand ( const FileLocation* sourceFileLocation,
void GenerateWindresCommand ( const FileLocation* sourceFile,
const std::string& windresflagsMacro );
void GenerateWinebuildCommands ( const FileLocation* sourceFileLocation );
void GenerateWinebuildCommands ( const FileLocation* sourceFile );
std::string GetWidlFlags ( const CompilationUnit& compilationUnit );
void GenerateWidlCommandsServer (
const CompilationUnit& compilationUnit,
@ -198,24 +196,23 @@ private:
const std::string& nasmflagsMacro,
const std::string& windresflagsMacro,
const std::string& widlflagsMacro );
std::string GenerateArchiveTarget ( const std::string& ar,
const std::string& objs_macro ) const;
void GetSpecObjectDependencies ( string_list& dependencies,
const std::string& filename ) const;
void GetWidlObjectDependencies ( string_list& dependencies,
const std::string& filename ) const;
const FileLocation* GenerateArchiveTarget ( const std::string& ar,
const std::string& objs_macro ) const;
void GetSpecObjectDependencies ( std::vector<FileLocation>& dependencies,
const FileLocation *file ) const;
void GetWidlObjectDependencies ( std::vector<FileLocation>& dependencies,
const FileLocation *file ) const;
void GetDefaultDependencies ( string_list& dependencies ) const;
void GetInvocationDependencies ( const Module& module, string_list& dependencies );
bool IsWineModule () const;
std::string GetDefinitionFilename () const;
static std::string RemoveVariables ( std::string path);
const FileLocation* GetDefinitionFilename () const;
void GenerateBuildNonSymbolStrippedCode ();
void CleanupCompilationUnitVector ( std::vector<CompilationUnit*>& compilationUnits );
void GetRpcHeaderDependencies ( std::vector<std::string>& dependencies ) const;
void GetRpcHeaderDependencies ( std::vector<FileLocation>& dependencies ) const;
static std::string GetPropertyValue ( const Module& module, const std::string& name );
std::string GetRpcServerHeaderFilename ( std::string basename ) const;
std::string GetRpcClientHeaderFilename ( std::string basename ) const;
std::string GetIdlHeaderFilename ( std::string basename ) const;
const FileLocation* GetRpcServerHeaderFilename ( const FileLocation *base ) const;
const FileLocation* GetRpcClientHeaderFilename ( const FileLocation *base ) const;
const FileLocation* GetIdlHeaderFilename ( const FileLocation *base ) const;
std::string GetModuleCleanTarget ( const Module& module ) const;
void GetReferencedObjectLibraryModuleCleanTargets ( std::vector<std::string>& moduleNames ) const;
public:
@ -427,12 +424,12 @@ public:
virtual void Process ();
private:
void GenerateIsoModuleTarget ();
std::string GetBootstrapCdDirectories ( const std::string& bootcdDirectory );
std::string GetNonModuleCdDirectories ( const std::string& bootcdDirectory );
std::string GetCdDirectories ( const std::string& bootcdDirectory );
void GetBootstrapCdFiles ( std::vector<std::string>& out ) const;
void GetNonModuleCdFiles ( std::vector<std::string>& out ) const;
void GetCdFiles ( std::vector<std::string>& out ) const;
void GetBootstrapCdDirectories ( std::vector<FileLocation>& out, const std::string& bootcdDirectory );
void GetNonModuleCdDirectories ( std::vector<FileLocation>& out, const std::string& bootcdDirectory );
void GetCdDirectories ( std::vector<FileLocation>& out, const std::string& bootcdDirectory );
void GetBootstrapCdFiles ( std::vector<FileLocation>& out ) const;
void GetNonModuleCdFiles ( std::vector<FileLocation>& out ) const;
void GetCdFiles ( std::vector<FileLocation>& out ) const;
void OutputBootstrapfileCopyCommands ( const std::string& bootcdDirectory );
void OutputCdfileCopyCommands ( const std::string& bootcdDirectory );
};
@ -447,9 +444,6 @@ public:
private:
void GenerateLiveIsoModuleTarget ();
void CreateDirectory ( const std::string& directory );
void OutputCopyCommand ( const std::string& sourceFilename,
const std::string& targetFilename,
const std::string& targetDirectory );
void OutputModuleCopyCommands ( std::string& livecdDirectory,
std::string& livecdReactos );
void OutputNonModuleCopyCommands ( std::string& livecdDirectory,

View file

@ -100,7 +100,6 @@ ProxyMakefile::GenerateProxyMakefileForModule ( Module& module,
if ( outputTree.length () > 0 )
{
base = outputTree + sSep + module.GetBasePath ();
Path path;
pathToTopDirectory = working_directory;
}
else
@ -122,7 +121,7 @@ ProxyMakefile::GenerateProxyMakefileForModule ( Module& module,
s = s + sprintf ( s, "DEFAULT = %s\n", defaultTarget.c_str () );
s = s + sprintf ( s, "include $(TOP)/proxy.mak\n" );
FileSupportCode::WriteIfChanged ( buf, proxyMakefile );
FileSupportCode::WriteIfChanged ( buf, proxyMakefile, true );
free ( buf );
}

View file

@ -34,38 +34,24 @@ CDFile::ReplaceVariable ( const string& name,
return path;
}
CDFile::CDFile ( const Project& project_,
const XMLElement& cdfileNode,
const string& path )
: project ( project_ ),
node ( cdfileNode )
CDFile::CDFile ( const Project& project,
const XMLElement& cdfileNode,
const string& path )
: XmlNode ( project, cdfileNode )
{
const XMLAttribute* att = node.GetAttribute ( "base", false );
const XMLAttribute* att = cdfileNode.GetAttribute ( "base", false );
string target_relative_directory;
if ( att != NULL )
base = ReplaceVariable ( "$(CDOUTPUT)", Environment::GetCdOutputPath (), att->value );
target_relative_directory = ReplaceVariable ( "$(CDOUTPUT)", Environment::GetCdOutputPath (), att->value );
else
base = "";
target_relative_directory = "";
att = node.GetAttribute ( "nameoncd", false );
if ( att != NULL )
nameoncd = att->value;
else
nameoncd = node.value;
name = node.value;
this->path = path;
}
const XMLAttribute* nameoncd = cdfileNode.GetAttribute ( "nameoncd", false );
CDFile::~CDFile ()
{
}
string
CDFile::GetPath () const
{
return path + sSep + name;
}
void
CDFile::ProcessXML()
{
source = new FileLocation ( SourceDirectory,
path,
cdfileNode.value );
target = new FileLocation ( OutputDirectory,
target_relative_directory,
nameoncd ? att->value : cdfileNode.value );
}

View file

@ -28,6 +28,7 @@ CompilationUnit::CompilationUnit ( File* file )
module(NULL),
node(NULL)
{
local_name = file->name;
name = file->name;
files.push_back ( file );
}
@ -41,6 +42,7 @@ CompilationUnit::CompilationUnit ( const Project* project,
{
const XMLAttribute* att = node->GetAttribute ( "name", true );
assert(att);
local_name = att->value;
name = module->GetBasePath () + cSep + att->value;
}
@ -92,16 +94,40 @@ CompilationUnit::IsFirstFile () const
return file->first;
}
FileLocation*
CompilationUnit::GetFilename ( Directory* intermediateDirectory ) const
const FileLocation*
CompilationUnit::GetFilename () const
{
if ( files.size () == 0 || files.size () > 1 )
return new FileLocation ( intermediateDirectory, name );
{
return new FileLocation ( IntermediateDirectory,
module ? module->GetBasePath () : "",
local_name );
}
File* file = files[0];
if (file->path_prefix.length() > 0)
return new FileLocation ( intermediateDirectory, file->name );
DirectoryLocation directory;
if ( file->path_prefix.length () == 0 )
directory = SourceDirectory;
else if ( file->path_prefix == "$(INTERMEDIATE)" )
directory = IntermediateDirectory;
else
return new FileLocation ( NULL, file->name );
throw InvalidOperationException ( __FILE__,
__LINE__,
"Invalid path prefix '%s'",
file->path_prefix.c_str () );
size_t pos = file->name.find_last_of ( "/\\" );
assert ( pos != string::npos );
string relative_path = file->name.substr ( 0, pos );
string name = file->name.substr ( pos + 1 );
if ( relative_path.compare ( 0, 15, "$(INTERMEDIATE)") == 0 )
{
directory = IntermediateDirectory;
relative_path.erase ( 0, 16 );
}
return new FileLocation ( directory, relative_path, name );
}
std::string

View file

@ -24,7 +24,8 @@ using std::string;
/* static */ void
FileSupportCode::WriteIfChanged ( char* outbuf,
string filename )
const string& filename,
bool ignoreError )
{
FILE* out;
unsigned int end;
@ -36,7 +37,11 @@ FileSupportCode::WriteIfChanged ( char* outbuf,
{
out = fopen ( filename.c_str (), "wb" );
if ( out == NULL )
{
if ( ignoreError )
return;
throw AccessDeniedException ( filename );
}
fputs ( outbuf, out );
fclose ( out );
return;

View file

@ -22,32 +22,22 @@
using std::string;
InstallFile::InstallFile ( const Project& project_,
InstallFile::InstallFile ( const Project& project,
const XMLElement& installfileNode,
const string& path )
: project ( project_ ),
node ( installfileNode )
: XmlNode(project, installfileNode )
{
const XMLAttribute* att = node.GetAttribute ( "base", false );
if ( att != NULL )
base = att->value;
else
base = "";
const XMLAttribute* base = node.GetAttribute ( "base", false );
const XMLAttribute* newname = node.GetAttribute ( "newname", false );
att = node.GetAttribute ( "newname", false );
if ( att != NULL )
newname = att->value;
else
newname = node.value;
name = node.value;
att = node.GetAttribute ( "root", false );
DirectoryLocation source_directory = SourceDirectory;
const XMLAttribute* att = node.GetAttribute ( "root", false );
if ( att != NULL)
{
if ( att->value == "intermediate" )
this->path = "$(INTERMEDIATE)" + sSep + path;
source_directory = IntermediateDirectory;
else if ( att->value == "output" )
this->path = "$(OUTPUT)" + sSep + path;
source_directory = OutputDirectory;
else
{
throw InvalidAttributeValueException (
@ -56,21 +46,15 @@ InstallFile::InstallFile ( const Project& project_,
att->value );
}
}
else
this->path = path;
}
InstallFile::~InstallFile ()
{
}
string
InstallFile::GetPath () const
{
return path + sSep + name;
}
void
InstallFile::ProcessXML()
{
source = new FileLocation ( source_directory,
path,
node.value );
target = new FileLocation ( InstallDirectory,
base && base->value != "."
? base->value
: "",
newname
? newname->value
: node.value );
}

View file

@ -795,8 +795,19 @@ Module::ProcessXMLSubElement ( const XMLElement& e,
e.location,
"Only one <pch> is valid per module" );
}
pch = new PchFile (
e, *this, File ( FixSeparator ( path + cSep + e.value ), false, "", true ) );
size_t pos = e.value.find_last_of ( "/\\" );
if ( pos == string::npos )
{
pch = new PchFile (
e, *this, FileLocation ( SourceDirectory, path, e.value ) );
}
else
{
string dir = e.value.substr ( 0, pos );
string name = e.value.substr ( pos + 1);
pch = new PchFile (
e, *this, FileLocation ( SourceDirectory, path + sSep + dir, name ) );
}
subs_invalid = true;
}
else if ( e.name == "compilationunit" )
@ -1146,6 +1157,15 @@ Module::GetDependencyPath () const
return GetPath();
}
string
Module::GetDependencyTargetName () const
{
if ( HasImportLibrary () )
return "lib" + name + ".a";
else
return GetTargetName();
}
string
Module::GetBasePath () const
{
@ -1650,7 +1670,7 @@ Property::ProcessXML()
PchFile::PchFile (
const XMLElement& node_,
const Module& module_,
const File file_ )
const FileLocation& file_ )
: node(node_), module(module_), file(file_)
{
}
@ -1659,93 +1679,3 @@ void
PchFile::ProcessXML()
{
}
AutoRegister::AutoRegister ( const Project& project_,
const Module* module_,
const XMLElement& node_ )
: project(project_),
module(module_),
node(node_)
{
Initialize();
}
AutoRegister::~AutoRegister ()
{
}
bool
AutoRegister::IsSupportedModuleType ( ModuleType type )
{
switch ( type )
{
case Win32DLL:
case Win32OCX:
return true;
case Kernel:
case KernelModeDLL:
case NativeDLL:
case NativeCUI:
case Win32CUI:
case Win32GUI:
case Win32SCR:
case KernelModeDriver:
case BootSector:
case BootLoader:
case BootProgram:
case BuildTool:
case StaticLibrary:
case ObjectLibrary:
case Iso:
case LiveIso:
case IsoRegTest:
case LiveIsoRegTest:
case Test:
case RpcServer:
case RpcClient:
case Alias:
case IdlHeader:
case EmbeddedTypeLib:
case ElfExecutable:
return false;
}
throw InvalidOperationException ( __FILE__,
__LINE__ );
}
AutoRegisterType
AutoRegister::GetAutoRegisterType( string type )
{
if ( type == "DllRegisterServer" )
return DllRegisterServer;
if ( type == "DllInstall" )
return DllInstall;
if ( type == "Both" )
return Both;
throw XMLInvalidBuildFileException (
node.location,
"<autoregister> type attribute must be DllRegisterServer, DllInstall or Both." );
}
void
AutoRegister::Initialize ()
{
if ( !IsSupportedModuleType ( module->type ) )
{
throw XMLInvalidBuildFileException (
node.location,
"<autoregister> is not applicable for this module type." );
}
const XMLAttribute* att = node.GetAttribute ( "infsection", true );
infSection = att->value;
att = node.GetAttribute ( "type", true );
type = GetAutoRegisterType ( att->value );
}
void
AutoRegister::ProcessXML()
{
}

View file

@ -99,10 +99,40 @@ ParseContext::ParseContext ()
}
FileLocation::FileLocation ( Directory* directory,
std::string filename )
: directory (directory),
filename (filename)
FileLocation::FileLocation ( const DirectoryLocation directory,
const std::string& relative_path,
const std::string& name )
: directory ( directory ),
relative_path ( NormalizeFilename ( relative_path ) ),
name ( name )
{
if ( relative_path[0] == '/' ||
relative_path[0] == '\\' ||
relative_path.find ( '$' ) != string::npos ||
( relative_path.length () > 1 && ( relative_path[1] == ':' ||
relative_path.find_last_of ( "/\\" ) == relative_path.length () - 1 ) )
)
{
throw InvalidOperationException ( __FILE__,
__LINE__,
"Invalid relative path '%s'",
relative_path.c_str () );
}
if ( strpbrk ( name.c_str (), "/\\:" ) )
{
throw InvalidOperationException ( __FILE__,
__LINE__,
"Invalid file name '%s'",
name.c_str () );
}
}
FileLocation::FileLocation ( const FileLocation& other )
: directory ( other.directory ),
relative_path ( other.relative_path ),
name ( other.name )
{
}

View file

@ -70,6 +70,7 @@ extern char cBadSep;
#define MS_VS_DEF_VERSION "7.10"
class XmlNode;
class Directory;
class Project;
class IfableData;
@ -105,6 +106,20 @@ class Metadata;
typedef std::map<std::string,Directory*> directory_map;
class XmlNode
{
protected:
const Project& project;
const XMLElement& node;
XmlNode ( const Project& project_,
const XMLElement& node_ );
virtual ~XmlNode();
public:
virtual void ProcessXML();
};
class Directory
{
public:
@ -168,7 +183,8 @@ class FileSupportCode
{
public:
static void WriteIfChanged ( char* outbuf,
std::string filename );
const std::string& filename,
bool ignoreError = false );
};
@ -307,7 +323,7 @@ public:
bool isUnicode;
bool isDefaultEntryPoint;
Bootstrap* bootstrap;
AutoRegister* autoRegister;
AutoRegister* autoRegister; // <autoregister> node
IfableData non_if_data;
std::vector<Invoke*> invocations;
std::vector<Dependency*> dependencies;
@ -339,6 +355,7 @@ public:
bool GenerateInOutputTree () const;
std::string GetTargetName () const; // "foo.exe"
std::string GetDependencyPath () const; // "path/foo.exe" or "path/libfoo.a"
std::string GetDependencyTargetName () const; // "foo.exe" or "libfoo.a"
std::string GetBasePath () const; // "path"
std::string GetPath () const; // "path/foo.exe"
std::string GetPathWithPrefix ( const std::string& prefix ) const; // "path/prefixfoo.exe"
@ -814,22 +831,40 @@ private:
};
class CDFile
enum DirectoryLocation
{
SourceDirectory,
IntermediateDirectory,
OutputDirectory,
InstallDirectory,
TemporaryDirectory,
};
class FileLocation
{
public:
const Project& project;
const XMLElement& node;
DirectoryLocation directory;
std::string relative_path;
std::string name;
std::string base;
std::string nameoncd;
std::string path;
FileLocation ( const DirectoryLocation directory,
const std::string& relative_path,
const std::string& name );
FileLocation ( const FileLocation& other );
};
class CDFile : public XmlNode
{
public:
FileLocation *source;
FileLocation *target;
CDFile ( const Project& project,
const XMLElement& bootstrapNode,
const std::string& path );
~CDFile ();
void ProcessXML();
std::string GetPath () const;
private:
static std::string ReplaceVariable ( const std::string& name,
const std::string& value,
@ -837,22 +872,15 @@ private:
};
class InstallFile
class InstallFile : public XmlNode
{
public:
const Project& project;
const XMLElement& node;
std::string name;
std::string base;
std::string newname;
std::string path;
FileLocation *source;
FileLocation *target;
InstallFile ( const Project& project,
const XMLElement& bootstrapNode,
const std::string& path );
~InstallFile ();
void ProcessXML ();
std::string GetPath () const;
};
@ -861,12 +889,12 @@ class PchFile
public:
const XMLElement& node;
const Module& module;
File file;
FileLocation file;
PchFile (
const XMLElement& node,
const Module& module,
const File file );
const FileLocation& file );
void ProcessXML();
};
@ -921,8 +949,10 @@ public:
bool IsGeneratedFile () const;
bool HasFileWithExtension ( const std::string& extension ) const;
bool IsFirstFile () const;
FileLocation* GetFilename ( Directory* intermediateDirectory ) const;
const FileLocation* GetFilename () const;
std::string GetSwitches () const;
private:
std::string local_name;
};
@ -944,16 +974,6 @@ private:
};
class FileLocation
{
public:
Directory* directory;
std::string filename;
FileLocation ( Directory* directory,
std::string filename );
};
enum AutoRegisterType
{
DllRegisterServer,
@ -961,22 +981,18 @@ enum AutoRegisterType
Both
};
class AutoRegister
class AutoRegister : public XmlNode
{
public:
const Project& project;
const Module* module;
const XMLElement& node;
std::string infSection;
AutoRegisterType type;
AutoRegister ( const Project& project_,
const Module* module_,
const XMLElement& node_ );
~AutoRegister ();
void ProcessXML();
private:
bool IsSupportedModuleType ( ModuleType type );
AutoRegisterType GetAutoRegisterType( std::string type );
AutoRegisterType GetAutoRegisterType( const std::string& type );
void Initialize ();
};

View file

@ -244,6 +244,7 @@ RBUILD_COMMON_SOURCES = \
$(addprefix $(RBUILD_BASE_), \
global.cpp \
automaticdependency.cpp \
autoregister.cpp \
bootstrap.cpp \
cdfile.cpp \
compilationunit.cpp \
@ -264,6 +265,7 @@ RBUILD_COMMON_SOURCES = \
syssetupgenerator.cpp \
testsupportcode.cpp \
wineresource.cpp \
xmlnode.cpp \
)
RBUILD_SPECIAL_SOURCES = \
@ -374,6 +376,10 @@ $(RBUILD_INT_)automaticdependency.o: $(RBUILD_BASE_)automaticdependency.cpp $(RB
$(ECHO_CC)
${host_gpp} $(RBUILD_HOST_CXXFLAGS) -c $< -o $@
$(RBUILD_INT_)autoregister.o: $(RBUILD_BASE_)autoregister.cpp $(RBUILD_HEADERS) | $(RBUILD_INT)
$(ECHO_CC)
${host_gpp} $(RBUILD_HOST_CXXFLAGS) -c $< -o $@
$(RBUILD_INT_)bootstrap.o: $(RBUILD_BASE_)bootstrap.cpp $(RBUILD_HEADERS) | $(RBUILD_INT)
$(ECHO_CC)
${host_gpp} $(RBUILD_HOST_CXXFLAGS) -c $< -o $@
@ -454,6 +460,10 @@ $(RBUILD_INT_)wineresource.o: $(RBUILD_BASE_)wineresource.cpp $(RBUILD_HEADERS)
$(ECHO_CC)
${host_gpp} $(RBUILD_HOST_CXXFLAGS) -c $< -o $@
$(RBUILD_INT_)xmlnode.o: $(RBUILD_BASE_)xmlnode.cpp $(RBUILD_HEADERS) | $(RBUILD_INT)
$(ECHO_CC)
${host_gpp} $(RBUILD_HOST_CXXFLAGS) -c $< -o $@
$(RBUILD_INT_)testsupportcode.o: $(RBUILD_BASE_)testsupportcode.cpp $(RBUILD_HEADERS) | $(RBUILD_INT)
$(ECHO_CC)
${host_gpp} $(RBUILD_HOST_CXXFLAGS) -c $< -o $@

View file

@ -297,8 +297,8 @@ TestSupportCode::GetSourceFilenames ( string_list& list,
const vector<CompilationUnit*>& compilationUnits = module.non_if_data.compilationUnits;
for ( i = 0; i < compilationUnits.size (); i++ )
{
FileLocation* sourceFileLocation = compilationUnits[i]->GetFilename ( NULL );
string filename = sourceFileLocation->filename;
const FileLocation* sourceFileLocation = compilationUnits[i]->GetFilename ();
string filename = sourceFileLocation->relative_path + sSep + sourceFileLocation->name;
if ( !compilationUnits[i]->IsGeneratedFile () && IsTestFile ( filename ) )
list.push_back ( filename );
}
@ -317,8 +317,8 @@ TestSupportCode::GetSourceFilenames ( string_list& list,
for ( j = 0; j < compilationUnits.size (); j++ )
{
CompilationUnit& compilationUnit = *compilationUnits[j];
FileLocation* sourceFileLocation = compilationUnits[j]->GetFilename ( NULL );
string filename = sourceFileLocation->filename;
const FileLocation* sourceFileLocation = compilationUnits[j]->GetFilename ();
string filename = sourceFileLocation->relative_path + sSep + sourceFileLocation->name;
if ( !compilationUnit.IsGeneratedFile () && IsTestFile ( filename ) )
list.push_back ( filename );
}

View file

@ -0,0 +1,38 @@
/*
* Copyright (C) 2007 Hervé Poussineau
*
* 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.
*/
#include "pch.h"
#include "rbuild.h"
using std::string;
XmlNode::XmlNode ( const Project& project_,
const XMLElement& node )
: project(project_),
node(node)
{
}
XmlNode::~XmlNode ()
{
}
void
XmlNode::ProcessXML ()
{
}