mirror of
https://github.com/reactos/CMake.git
synced 2024-12-04 09:54:15 +00:00
cmSourceFileLocation: allow skipping ambiguous extensions
The ambiguous extension logic is an old behavior that ends up taking lots of extra compute cycles to execute. This is triggered by various CMake codepaths which pass extension-less paths down when CMake actually knows that they are not ambiguous. These codepaths will be indicated in upcoming changes. Various APIs have gained a cmSourceFileLocationKind parameter, but they are all optional and default to the existing behavior.
This commit is contained in:
parent
ddc4f9a3c0
commit
b0716fbcc5
@ -327,6 +327,7 @@ set(SRCS
|
||||
cmSourceFile.h
|
||||
cmSourceFileLocation.cxx
|
||||
cmSourceFileLocation.h
|
||||
cmSourceFileLocationKind.h
|
||||
cmSourceGroup.cxx
|
||||
cmSourceGroup.h
|
||||
cmState.cxx
|
||||
|
@ -3132,9 +3132,10 @@ void cmMakefile::SetArgcArgv(const std::vector<std::string>& args)
|
||||
}
|
||||
}
|
||||
|
||||
cmSourceFile* cmMakefile::GetSource(const std::string& sourceName) const
|
||||
cmSourceFile* cmMakefile::GetSource(const std::string& sourceName,
|
||||
cmSourceFileLocationKind kind) const
|
||||
{
|
||||
cmSourceFileLocation sfl(this, sourceName);
|
||||
cmSourceFileLocation sfl(this, sourceName, kind);
|
||||
auto name = this->GetCMakeInstance()->StripExtension(sfl.GetName());
|
||||
#if defined(_WIN32) || defined(__APPLE__)
|
||||
name = cmSystemTools::LowerCase(name);
|
||||
@ -3151,9 +3152,10 @@ cmSourceFile* cmMakefile::GetSource(const std::string& sourceName) const
|
||||
}
|
||||
|
||||
cmSourceFile* cmMakefile::CreateSource(const std::string& sourceName,
|
||||
bool generated)
|
||||
bool generated,
|
||||
cmSourceFileLocationKind kind)
|
||||
{
|
||||
cmSourceFile* sf = new cmSourceFile(this, sourceName);
|
||||
cmSourceFile* sf = new cmSourceFile(this, sourceName, kind);
|
||||
if (generated) {
|
||||
sf->SetProperty("GENERATED", "1");
|
||||
}
|
||||
@ -3170,12 +3172,13 @@ cmSourceFile* cmMakefile::CreateSource(const std::string& sourceName,
|
||||
}
|
||||
|
||||
cmSourceFile* cmMakefile::GetOrCreateSource(const std::string& sourceName,
|
||||
bool generated)
|
||||
bool generated,
|
||||
cmSourceFileLocationKind kind)
|
||||
{
|
||||
if (cmSourceFile* esf = this->GetSource(sourceName)) {
|
||||
if (cmSourceFile* esf = this->GetSource(sourceName, kind)) {
|
||||
return esf;
|
||||
}
|
||||
return this->CreateSource(sourceName, generated);
|
||||
return this->CreateSource(sourceName, generated, kind);
|
||||
}
|
||||
|
||||
void cmMakefile::AddTargetObject(std::string const& tgtName,
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "cmListFileCache.h"
|
||||
#include "cmNewLineStyle.h"
|
||||
#include "cmPolicies.h"
|
||||
#include "cmSourceFileLocationKind.h"
|
||||
#include "cmStateSnapshot.h"
|
||||
#include "cmStateTypes.h"
|
||||
#include "cmTarget.h"
|
||||
@ -387,22 +388,26 @@ public:
|
||||
/** Get a cmSourceFile pointer for a given source name, if the name is
|
||||
* not found, then a null pointer is returned.
|
||||
*/
|
||||
cmSourceFile* GetSource(const std::string& sourceName) const;
|
||||
cmSourceFile* GetSource(
|
||||
const std::string& sourceName,
|
||||
cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous) const;
|
||||
|
||||
/** Create the source file and return it. generated
|
||||
* indicates if it is a generated file, this is used in determining
|
||||
* how to create the source file instance e.g. name
|
||||
*/
|
||||
cmSourceFile* CreateSource(const std::string& sourceName,
|
||||
bool generated = false);
|
||||
cmSourceFile* CreateSource(
|
||||
const std::string& sourceName, bool generated = false,
|
||||
cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous);
|
||||
|
||||
/** Get a cmSourceFile pointer for a given source name, if the name is
|
||||
* not found, then create the source file and return it. generated
|
||||
* indicates if it is a generated file, this is used in determining
|
||||
* how to create the source file instance e.g. name
|
||||
*/
|
||||
cmSourceFile* GetOrCreateSource(const std::string& sourceName,
|
||||
bool generated = false);
|
||||
cmSourceFile* GetOrCreateSource(
|
||||
const std::string& sourceName, bool generated = false,
|
||||
cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous);
|
||||
|
||||
void AddTargetObject(std::string const& tgtName, std::string const& objFile);
|
||||
|
||||
|
@ -12,8 +12,9 @@
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmake.h"
|
||||
|
||||
cmSourceFile::cmSourceFile(cmMakefile* mf, const std::string& name)
|
||||
: Location(mf, name)
|
||||
cmSourceFile::cmSourceFile(cmMakefile* mf, const std::string& name,
|
||||
cmSourceFileLocationKind kind)
|
||||
: Location(mf, name, kind)
|
||||
{
|
||||
this->CustomCommand = nullptr;
|
||||
this->FindFullPathFailed = false;
|
||||
|
@ -27,7 +27,9 @@ public:
|
||||
* Construct with the makefile storing the source and the initial
|
||||
* name referencing it.
|
||||
*/
|
||||
cmSourceFile(cmMakefile* mf, const std::string& name);
|
||||
cmSourceFile(
|
||||
cmMakefile* mf, const std::string& name,
|
||||
cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous);
|
||||
|
||||
~cmSourceFile();
|
||||
|
||||
|
@ -27,7 +27,8 @@ cmSourceFileLocation::cmSourceFileLocation(const cmSourceFileLocation& loc)
|
||||
}
|
||||
|
||||
cmSourceFileLocation::cmSourceFileLocation(cmMakefile const* mf,
|
||||
const std::string& name)
|
||||
const std::string& name,
|
||||
cmSourceFileLocationKind kind)
|
||||
: Makefile(mf)
|
||||
{
|
||||
this->AmbiguousDirectory = !cmSystemTools::FileIsFullPath(name.c_str());
|
||||
@ -37,7 +38,12 @@ cmSourceFileLocation::cmSourceFileLocation(cmMakefile const* mf,
|
||||
this->Directory = cmSystemTools::CollapseFullPath(this->Directory);
|
||||
}
|
||||
this->Name = cmSystemTools::GetFilenameName(name);
|
||||
this->UpdateExtension(name);
|
||||
if (kind == cmSourceFileLocationKind::Known) {
|
||||
this->DirectoryUseSource();
|
||||
this->AmbiguousExtension = false;
|
||||
} else {
|
||||
this->UpdateExtension(name);
|
||||
}
|
||||
}
|
||||
|
||||
void cmSourceFileLocation::Update(cmSourceFileLocation const& loc)
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "cmSourceFileLocationKind.h"
|
||||
|
||||
class cmMakefile;
|
||||
|
||||
/** \class cmSourceFileLocation
|
||||
@ -26,7 +28,9 @@ public:
|
||||
* Construct for a source file created in a given cmMakefile
|
||||
* instance with an initial name.
|
||||
*/
|
||||
cmSourceFileLocation(cmMakefile const* mf, const std::string& name);
|
||||
cmSourceFileLocation(
|
||||
cmMakefile const* mf, const std::string& name,
|
||||
cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous);
|
||||
cmSourceFileLocation();
|
||||
cmSourceFileLocation(const cmSourceFileLocation& loc);
|
||||
|
||||
|
15
Source/cmSourceFileLocationKind.h
Normal file
15
Source/cmSourceFileLocationKind.h
Normal file
@ -0,0 +1,15 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
#ifndef cmSourceFileLocationKind_h
|
||||
#define cmSourceFileLocationKind_h
|
||||
|
||||
enum class cmSourceFileLocationKind
|
||||
{
|
||||
// The location is user-specified and may be ambiguous.
|
||||
Ambiguous,
|
||||
// The location is known to be at the given location; do not try to guess at
|
||||
// extensions or absolute path.
|
||||
Known
|
||||
};
|
||||
|
||||
#endif
|
@ -23,6 +23,7 @@
|
||||
#include "cmProperty.h"
|
||||
#include "cmSourceFile.h"
|
||||
#include "cmSourceFileLocation.h"
|
||||
#include "cmSourceFileLocationKind.h"
|
||||
#include "cmState.h"
|
||||
#include "cmStateDirectory.h"
|
||||
#include "cmStateSnapshot.h"
|
||||
|
Loading…
Reference in New Issue
Block a user