Split xcformatter out of xcexecution.

Because xcexecution creates driver commands, it is much more closely
tied to the driver than xcformatter. Split that out in order to make
it more reusable outside xcdriver.
This commit is contained in:
Grant Paul 2016-02-29 19:40:40 -08:00
parent d9d6aff53b
commit cd7fc82b52
13 changed files with 67 additions and 61 deletions

View File

@ -315,13 +315,16 @@ set(libpbxbuild_SOURCES
Sources/pbxbuild/Build/DependencyResolver.cpp
)
set(libxcformatter_SOURCES
Sources/xcformatter/Formatter.cpp
Sources/xcformatter/DefaultFormatter.cpp
)
set(libxcexecution_SOURCES
Sources/xcexecution/Parameters.cpp
Sources/xcexecution/Executor.cpp
Sources/xcexecution/SimpleExecutor.cpp
Sources/xcexecution/NinjaExecutor.cpp
Sources/xcexecution/Formatter.cpp
Sources/xcexecution/DefaultFormatter.cpp
)
set(libxcdriver_SOURCES
@ -375,11 +378,14 @@ target_link_libraries(pbxspec pbxsetting util plist)
add_library(pbxbuild SHARED ${libpbxbuild_SOURCES})
target_link_libraries(pbxbuild xcsdk xcworkspace xcscheme pbxproj pbxspec dependency ext)
add_library(xcformatter SHARED ${libxcformatter_SOURCES})
target_link_libraries(xcformatter pbxbuild pbxproj)
add_library(xcexecution SHARED ${libxcexecution_SOURCES})
target_link_libraries(xcexecution pbxbuild dependency ninja builtin)
target_link_libraries(xcexecution xcformatter pbxbuild dependency ninja builtin)
add_library(xcdriver SHARED ${libxcdriver_SOURCES})
target_link_libraries(xcdriver xcexecution pbxbuild xcworkspace xcsdk pbxsetting util plist builtin)
target_link_libraries(xcdriver xcexecution xcformatter pbxbuild xcworkspace xcsdk pbxsetting util plist builtin)
add_executable(plutil Tools/plutil.cpp)
target_link_libraries(plutil plist util)

View File

@ -31,7 +31,8 @@ High level overview of each component library:
- `Target`: Creates the build environment and settings for each target.
- `Phase`: Implementations for the various build phases (compile, link, copy, etc).
- `Tool`: Tool implementations for generating command line invocations.
- `xcexecution`: Build execution engines and log formatting.
- `xcformatter`: Build log formatting styles.
- `xcexecution`: Build execution engines.
- `xcdriver`: Parses command line options and drives the build.
## Style

View File

@ -11,7 +11,7 @@
#define __xcexecution_Executor_h
#include <xcexecution/Base.h>
#include <xcexecution/Formatter.h>
#include <xcformatter/Formatter.h>
#include <pbxbuild/DirectedGraph.h>
namespace pbxbuild {
@ -31,12 +31,12 @@ class Parameters;
*/
class Executor {
protected:
std::shared_ptr<Formatter> _formatter;
bool _dryRun;
bool _generate;
std::shared_ptr<xcformatter::Formatter> _formatter;
bool _dryRun;
bool _generate;
protected:
Executor(std::shared_ptr<Formatter> const &formatter, bool dryRun, bool generate);
Executor(std::shared_ptr<xcformatter::Formatter> const &formatter, bool dryRun, bool generate);
public:
virtual ~Executor();

View File

@ -21,7 +21,7 @@ namespace xcexecution {
*/
class NinjaExecutor : public Executor {
public:
NinjaExecutor(std::shared_ptr<Formatter> const &formatter, bool dryRun, bool generate);
NinjaExecutor(std::shared_ptr<xcformatter::Formatter> const &formatter, bool dryRun, bool generate);
~NinjaExecutor();
public:
@ -53,7 +53,7 @@ private:
public:
static std::unique_ptr<NinjaExecutor>
Create(std::shared_ptr<Formatter> const &formatter, bool dryRun, bool generate);
Create(std::shared_ptr<xcformatter::Formatter> const &formatter, bool dryRun, bool generate);
};
}

View File

@ -24,7 +24,7 @@ private:
builtin::Registry _builtins;
public:
SimpleExecutor(std::shared_ptr<Formatter> const &formatter, bool dryRun, builtin::Registry const &builtins);
SimpleExecutor(std::shared_ptr<xcformatter::Formatter> const &formatter, bool dryRun, builtin::Registry const &builtins);
~SimpleExecutor();
public:
@ -49,7 +49,7 @@ private:
public:
static std::unique_ptr<SimpleExecutor>
Create(std::shared_ptr<Formatter> const &formatter, bool dryRun, builtin::Registry const &builtins);
Create(std::shared_ptr<xcformatter::Formatter> const &formatter, bool dryRun, builtin::Registry const &builtins);
};
}

View File

@ -7,12 +7,12 @@
of patent rights can be found in the PATENTS file in the same directory.
*/
#ifndef __xcexecution_DefaultFormatter_h
#define __xcexecution_DefaultFormatter_h
#ifndef __xcformatter_DefaultFormatter_h
#define __xcformatter_DefaultFormatter_h
#include <xcexecution/Formatter.h>
#include <xcformatter/Formatter.h>
namespace xcexecution {
namespace xcformatter {
/*
* Formats output with the default format.
@ -64,4 +64,4 @@ public:
}
#endif // !__xcexecution_DefaultFormatter_h
#endif // !__xcformatter_DefaultFormatter_h

View File

@ -7,18 +7,17 @@
of patent rights can be found in the PATENTS file in the same directory.
*/
#ifndef __xcexecution_Formatter_h
#define __xcexecution_Formatter_h
#ifndef __xcformatter_Formatter_h
#define __xcformatter_Formatter_h
#include <xcexecution/Base.h>
#include <pbxproj/pbxproj.h>
#include <pbxproj/PBX/Target.h>
namespace pbxbuild {
namespace Build { class Context; }
namespace Tool { class Invocation; }
}
namespace xcexecution {
namespace xcformatter {
/*
* Abstract formatter for build output.
@ -68,4 +67,4 @@ public:
}
#endif // !__xcexecution_Formatter_h
#endif // !__xcformatter_Formatter_h

View File

@ -12,7 +12,7 @@
#include <xcdriver/Options.h>
#include <xcexecution/NinjaExecutor.h>
#include <xcexecution/SimpleExecutor.h>
#include <xcexecution/DefaultFormatter.h>
#include <xcformatter/DefaultFormatter.h>
#include <builtin/builtin.h>
#include <unistd.h>
@ -31,15 +31,15 @@ BuildAction::
{
}
static std::shared_ptr<xcexecution::Formatter>
static std::shared_ptr<xcformatter::Formatter>
CreateFormatter(std::string const &formatter)
{
if (formatter == "default" || formatter.empty()) {
/* Only use color if attached to a terminal. */
bool color = isatty(fileno(stdout));
auto formatter = xcexecution::DefaultFormatter::Create(color);
return std::static_pointer_cast<xcexecution::Formatter>(formatter);
auto formatter = xcformatter::DefaultFormatter::Create(color);
return std::static_pointer_cast<xcformatter::Formatter>(formatter);
}
return nullptr;
@ -48,7 +48,7 @@ CreateFormatter(std::string const &formatter)
static std::unique_ptr<xcexecution::Executor>
CreateExecutor(
std::string const &executor,
std::shared_ptr<xcexecution::Formatter> const &formatter,
std::shared_ptr<xcformatter::Formatter> const &formatter,
bool dryRun,
bool generate)
{
@ -114,7 +114,7 @@ Run(Options const &options)
/*
* Create the formatter to format the build log.
*/
std::shared_ptr<xcexecution::Formatter> formatter = CreateFormatter(options.formatter());
std::shared_ptr<xcformatter::Formatter> formatter = CreateFormatter(options.formatter());
if (formatter == nullptr) {
fprintf(stderr, "error: unknown formatter %s\n", options.formatter().c_str());
return -1;

View File

@ -12,7 +12,7 @@
using xcexecution::Executor;
Executor::
Executor(std::shared_ptr<Formatter> const &formatter, bool dryRun, bool generate) :
Executor(std::shared_ptr<xcformatter::Formatter> const &formatter, bool dryRun, bool generate) :
_formatter(formatter),
_dryRun (dryRun),
_generate (generate)

View File

@ -35,7 +35,7 @@ using libutil::Subprocess;
using libutil::SysUtil;
NinjaExecutor::
NinjaExecutor(std::shared_ptr<Formatter> const &formatter, bool dryRun, bool generate) :
NinjaExecutor(std::shared_ptr<xcformatter::Formatter> const &formatter, bool dryRun, bool generate) :
Executor(formatter, dryRun, generate)
{
}
@ -812,7 +812,7 @@ buildTargetInvocations(
}
std::unique_ptr<NinjaExecutor> NinjaExecutor::
Create(std::shared_ptr<Formatter> const &formatter, bool dryRun, bool generate)
Create(std::shared_ptr<xcformatter::Formatter> const &formatter, bool dryRun, bool generate)
{
return std::unique_ptr<NinjaExecutor>(new NinjaExecutor(
formatter,

View File

@ -24,7 +24,7 @@ using libutil::FSUtil;
using libutil::Subprocess;
SimpleExecutor::
SimpleExecutor(std::shared_ptr<Formatter> const &formatter, bool dryRun, builtin::Registry const &builtins) :
SimpleExecutor(std::shared_ptr<xcformatter::Formatter> const &formatter, bool dryRun, builtin::Registry const &builtins) :
Executor (formatter, dryRun, false),
_builtins(builtins)
{
@ -50,7 +50,7 @@ build(
return false;
}
Formatter::Print(_formatter->begin(*buildContext));
xcformatter::Formatter::Print(_formatter->begin(*buildContext));
ext::optional<pbxbuild::DirectedGraph<pbxproj::PBX::Target::shared_ptr>> targetGraph = buildParameters.resolveDependencies(buildEnvironment, *buildContext);
if (!targetGraph) {
@ -64,31 +64,31 @@ build(
}
for (pbxproj::PBX::Target::shared_ptr const &target : *orderedTargets) {
Formatter::Print(_formatter->beginTarget(*buildContext, target));
xcformatter::Formatter::Print(_formatter->beginTarget(*buildContext, target));
ext::optional<pbxbuild::Target::Environment> targetEnvironment = buildContext->targetEnvironment(buildEnvironment, target);
if (!targetEnvironment) {
fprintf(stderr, "error: couldn't create target environment for %s\n", target->name().c_str());
Formatter::Print(_formatter->finishTarget(*buildContext, target));
xcformatter::Formatter::Print(_formatter->finishTarget(*buildContext, target));
continue;
}
Formatter::Print(_formatter->beginCheckDependencies(target));
xcformatter::Formatter::Print(_formatter->beginCheckDependencies(target));
pbxbuild::Phase::Environment phaseEnvironment = pbxbuild::Phase::Environment(buildEnvironment, *buildContext, target, *targetEnvironment);
pbxbuild::Phase::PhaseInvocations phaseInvocations = pbxbuild::Phase::PhaseInvocations::Create(phaseEnvironment, target);
Formatter::Print(_formatter->finishCheckDependencies(target));
xcformatter::Formatter::Print(_formatter->finishCheckDependencies(target));
auto result = buildTarget(target, *targetEnvironment, phaseInvocations.invocations());
if (!result.first) {
Formatter::Print(_formatter->finishTarget(*buildContext, target));
Formatter::Print(_formatter->failure(*buildContext, result.second));
xcformatter::Formatter::Print(_formatter->finishTarget(*buildContext, target));
xcformatter::Formatter::Print(_formatter->failure(*buildContext, result.second));
return false;
}
Formatter::Print(_formatter->finishTarget(*buildContext, target));
xcformatter::Formatter::Print(_formatter->finishTarget(*buildContext, target));
}
Formatter::Print(_formatter->success(*buildContext));
xcformatter::Formatter::Print(_formatter->success(*buildContext));
return true;
}
@ -145,12 +145,12 @@ writeAuxiliaryFiles(
pbxbuild::Target::Environment const &targetEnvironment,
std::vector<pbxbuild::Tool::Invocation> const &invocations)
{
Formatter::Print(_formatter->beginWriteAuxiliaryFiles(target));
xcformatter::Formatter::Print(_formatter->beginWriteAuxiliaryFiles(target));
for (pbxbuild::Tool::Invocation const &invocation : invocations) {
for (pbxbuild::Tool::Invocation::AuxiliaryFile const &auxiliaryFile : invocation.auxiliaryFiles()) {
std::string directory = FSUtil::GetDirectoryName(auxiliaryFile.path());
if (!FSUtil::TestForDirectory(directory)) {
Formatter::Print(_formatter->createAuxiliaryDirectory(directory));
xcformatter::Formatter::Print(_formatter->createAuxiliaryDirectory(directory));
if (!_dryRun) {
if (!FSUtil::CreateDirectory(directory)) {
@ -159,7 +159,7 @@ writeAuxiliaryFiles(
}
}
Formatter::Print(_formatter->writeAuxiliaryFile(auxiliaryFile.path()));
xcformatter::Formatter::Print(_formatter->writeAuxiliaryFile(auxiliaryFile.path()));
if (!_dryRun) {
std::ofstream out;
@ -173,7 +173,7 @@ writeAuxiliaryFiles(
}
if (auxiliaryFile.executable() && !FSUtil::TestForExecute(auxiliaryFile.path())) {
Formatter::Print(_formatter->setAuxiliaryExecutable(auxiliaryFile.path()));
xcformatter::Formatter::Print(_formatter->setAuxiliaryExecutable(auxiliaryFile.path()));
if (!_dryRun) {
if (::chmod(auxiliaryFile.path().c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) != 0) {
@ -183,7 +183,7 @@ writeAuxiliaryFiles(
}
}
}
Formatter::Print(_formatter->finishWriteAuxiliaryFiles(target));
xcformatter::Formatter::Print(_formatter->finishWriteAuxiliaryFiles(target));
return true;
}
@ -207,7 +207,7 @@ performInvocations(
std::map<std::string, std::string> sortedEnvironment = std::map<std::string, std::string>(invocation.environment().begin(), invocation.environment().end());
Formatter::Print(_formatter->beginInvocation(invocation, invocation.executable().displayName(), createProductStructure));
xcformatter::Formatter::Print(_formatter->beginInvocation(invocation, invocation.executable().displayName(), createProductStructure));
if (!_dryRun) {
for (std::string const &output : invocation.outputs()) {
@ -222,25 +222,25 @@ performInvocations(
/* For built-in tools, run them in-process. */
std::shared_ptr<builtin::Driver> driver = _builtins.driver(invocation.executable().builtin());
if (driver == nullptr) {
Formatter::Print(_formatter->finishInvocation(invocation, invocation.executable().displayName(), createProductStructure));
xcformatter::Formatter::Print(_formatter->finishInvocation(invocation, invocation.executable().displayName(), createProductStructure));
return std::make_pair(false, std::vector<pbxbuild::Tool::Invocation>({ invocation }));
}
if (driver->run(invocation.arguments(), invocation.environment(), invocation.workingDirectory()) != 0) {
Formatter::Print(_formatter->finishInvocation(invocation, invocation.executable().displayName(), createProductStructure));
xcformatter::Formatter::Print(_formatter->finishInvocation(invocation, invocation.executable().displayName(), createProductStructure));
return std::make_pair(false, std::vector<pbxbuild::Tool::Invocation>({ invocation }));
}
} else {
/* External tool, run the tool externally. */
Subprocess process;
if (!process.execute(invocation.executable().path(), invocation.arguments(), invocation.environment(), invocation.workingDirectory()) || process.exitcode() != 0) {
Formatter::Print(_formatter->finishInvocation(invocation, invocation.executable().displayName(), createProductStructure));
xcformatter::Formatter::Print(_formatter->finishInvocation(invocation, invocation.executable().displayName(), createProductStructure));
return std::make_pair(false, std::vector<pbxbuild::Tool::Invocation>({ invocation }));
}
}
}
Formatter::Print(_formatter->finishInvocation(invocation, invocation.executable().displayName(), createProductStructure));
xcformatter::Formatter::Print(_formatter->finishInvocation(invocation, invocation.executable().displayName(), createProductStructure));
}
return std::make_pair(true, std::vector<pbxbuild::Tool::Invocation>());
@ -262,9 +262,9 @@ buildTarget(
return std::make_pair(false, std::vector<pbxbuild::Tool::Invocation>());
}
Formatter::Print(_formatter->beginCreateProductStructure(target));
xcformatter::Formatter::Print(_formatter->beginCreateProductStructure(target));
std::pair<bool, std::vector<pbxbuild::Tool::Invocation>> structureResult = performInvocations(target, targetEnvironment, *orderedInvocations, true);
Formatter::Print(_formatter->finishCreateProductStructure(target));
xcformatter::Formatter::Print(_formatter->finishCreateProductStructure(target));
if (!structureResult.first) {
return structureResult;
}
@ -278,7 +278,7 @@ buildTarget(
}
std::unique_ptr<SimpleExecutor> SimpleExecutor::
Create(std::shared_ptr<Formatter> const &formatter, bool dryRun, builtin::Registry const &builtins)
Create(std::shared_ptr<xcformatter::Formatter> const &formatter, bool dryRun, builtin::Registry const &builtins)
{
return std::unique_ptr<SimpleExecutor>(new SimpleExecutor(
formatter,

View File

@ -7,11 +7,11 @@
of patent rights can be found in the PATENTS file in the same directory.
*/
#include <xcexecution/DefaultFormatter.h>
#include <xcformatter/DefaultFormatter.h>
#include <pbxbuild/Tool/Invocation.h>
#include <pbxbuild/Build/Context.h>
using xcexecution::DefaultFormatter;
using xcformatter::DefaultFormatter;
DefaultFormatter::
DefaultFormatter(bool color) :

View File

@ -7,9 +7,9 @@
of patent rights can be found in the PATENTS file in the same directory.
*/
#include <xcexecution/Formatter.h>
#include <xcformatter/Formatter.h>
using xcexecution::Formatter;
using xcformatter::Formatter;
Formatter::
Formatter()