diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ab116e8..80b17293 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6efb8c6d..c1068c82 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 diff --git a/Headers/xcexecution/Executor.h b/Headers/xcexecution/Executor.h index 7838d6ab..b8cf75f7 100644 --- a/Headers/xcexecution/Executor.h +++ b/Headers/xcexecution/Executor.h @@ -11,7 +11,7 @@ #define __xcexecution_Executor_h #include -#include +#include #include namespace pbxbuild { @@ -31,12 +31,12 @@ class Parameters; */ class Executor { protected: - std::shared_ptr _formatter; - bool _dryRun; - bool _generate; + std::shared_ptr _formatter; + bool _dryRun; + bool _generate; protected: - Executor(std::shared_ptr const &formatter, bool dryRun, bool generate); + Executor(std::shared_ptr const &formatter, bool dryRun, bool generate); public: virtual ~Executor(); diff --git a/Headers/xcexecution/NinjaExecutor.h b/Headers/xcexecution/NinjaExecutor.h index 1f8acae4..a7fe3c2c 100644 --- a/Headers/xcexecution/NinjaExecutor.h +++ b/Headers/xcexecution/NinjaExecutor.h @@ -21,7 +21,7 @@ namespace xcexecution { */ class NinjaExecutor : public Executor { public: - NinjaExecutor(std::shared_ptr const &formatter, bool dryRun, bool generate); + NinjaExecutor(std::shared_ptr const &formatter, bool dryRun, bool generate); ~NinjaExecutor(); public: @@ -53,7 +53,7 @@ private: public: static std::unique_ptr - Create(std::shared_ptr const &formatter, bool dryRun, bool generate); + Create(std::shared_ptr const &formatter, bool dryRun, bool generate); }; } diff --git a/Headers/xcexecution/SimpleExecutor.h b/Headers/xcexecution/SimpleExecutor.h index e1e8aa46..f23d604b 100644 --- a/Headers/xcexecution/SimpleExecutor.h +++ b/Headers/xcexecution/SimpleExecutor.h @@ -24,7 +24,7 @@ private: builtin::Registry _builtins; public: - SimpleExecutor(std::shared_ptr const &formatter, bool dryRun, builtin::Registry const &builtins); + SimpleExecutor(std::shared_ptr const &formatter, bool dryRun, builtin::Registry const &builtins); ~SimpleExecutor(); public: @@ -49,7 +49,7 @@ private: public: static std::unique_ptr - Create(std::shared_ptr const &formatter, bool dryRun, builtin::Registry const &builtins); + Create(std::shared_ptr const &formatter, bool dryRun, builtin::Registry const &builtins); }; } diff --git a/Headers/xcexecution/DefaultFormatter.h b/Headers/xcformatter/DefaultFormatter.h similarity index 92% rename from Headers/xcexecution/DefaultFormatter.h rename to Headers/xcformatter/DefaultFormatter.h index 678069bc..4c2ace8c 100644 --- a/Headers/xcexecution/DefaultFormatter.h +++ b/Headers/xcformatter/DefaultFormatter.h @@ -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 +#include -namespace xcexecution { +namespace xcformatter { /* * Formats output with the default format. @@ -64,4 +64,4 @@ public: } -#endif // !__xcexecution_DefaultFormatter_h +#endif // !__xcformatter_DefaultFormatter_h diff --git a/Headers/xcexecution/Formatter.h b/Headers/xcformatter/Formatter.h similarity index 93% rename from Headers/xcexecution/Formatter.h rename to Headers/xcformatter/Formatter.h index 3c3693b4..291a7ff0 100644 --- a/Headers/xcexecution/Formatter.h +++ b/Headers/xcformatter/Formatter.h @@ -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 -#include +#include 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 diff --git a/Sources/xcdriver/BuildAction.cpp b/Sources/xcdriver/BuildAction.cpp index f613d2b3..971297c1 100644 --- a/Sources/xcdriver/BuildAction.cpp +++ b/Sources/xcdriver/BuildAction.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include @@ -31,15 +31,15 @@ BuildAction:: { } -static std::shared_ptr +static std::shared_ptr 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(formatter); + auto formatter = xcformatter::DefaultFormatter::Create(color); + return std::static_pointer_cast(formatter); } return nullptr; @@ -48,7 +48,7 @@ CreateFormatter(std::string const &formatter) static std::unique_ptr CreateExecutor( std::string const &executor, - std::shared_ptr const &formatter, + std::shared_ptr 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 formatter = CreateFormatter(options.formatter()); + std::shared_ptr formatter = CreateFormatter(options.formatter()); if (formatter == nullptr) { fprintf(stderr, "error: unknown formatter %s\n", options.formatter().c_str()); return -1; diff --git a/Sources/xcexecution/Executor.cpp b/Sources/xcexecution/Executor.cpp index 03287362..f7ac695c 100644 --- a/Sources/xcexecution/Executor.cpp +++ b/Sources/xcexecution/Executor.cpp @@ -12,7 +12,7 @@ using xcexecution::Executor; Executor:: -Executor(std::shared_ptr const &formatter, bool dryRun, bool generate) : +Executor(std::shared_ptr const &formatter, bool dryRun, bool generate) : _formatter(formatter), _dryRun (dryRun), _generate (generate) diff --git a/Sources/xcexecution/NinjaExecutor.cpp b/Sources/xcexecution/NinjaExecutor.cpp index 319025a7..743820ff 100644 --- a/Sources/xcexecution/NinjaExecutor.cpp +++ b/Sources/xcexecution/NinjaExecutor.cpp @@ -35,7 +35,7 @@ using libutil::Subprocess; using libutil::SysUtil; NinjaExecutor:: -NinjaExecutor(std::shared_ptr const &formatter, bool dryRun, bool generate) : +NinjaExecutor(std::shared_ptr const &formatter, bool dryRun, bool generate) : Executor(formatter, dryRun, generate) { } @@ -812,7 +812,7 @@ buildTargetInvocations( } std::unique_ptr NinjaExecutor:: -Create(std::shared_ptr const &formatter, bool dryRun, bool generate) +Create(std::shared_ptr const &formatter, bool dryRun, bool generate) { return std::unique_ptr(new NinjaExecutor( formatter, diff --git a/Sources/xcexecution/SimpleExecutor.cpp b/Sources/xcexecution/SimpleExecutor.cpp index f1d4f2bb..ecc32b2e 100644 --- a/Sources/xcexecution/SimpleExecutor.cpp +++ b/Sources/xcexecution/SimpleExecutor.cpp @@ -24,7 +24,7 @@ using libutil::FSUtil; using libutil::Subprocess; SimpleExecutor:: -SimpleExecutor(std::shared_ptr const &formatter, bool dryRun, builtin::Registry const &builtins) : +SimpleExecutor(std::shared_ptr 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> 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 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 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 sortedEnvironment = std::map(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 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({ 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({ 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({ 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()); @@ -262,9 +262,9 @@ buildTarget( return std::make_pair(false, std::vector()); } - Formatter::Print(_formatter->beginCreateProductStructure(target)); + xcformatter::Formatter::Print(_formatter->beginCreateProductStructure(target)); std::pair> 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:: -Create(std::shared_ptr const &formatter, bool dryRun, builtin::Registry const &builtins) +Create(std::shared_ptr const &formatter, bool dryRun, builtin::Registry const &builtins) { return std::unique_ptr(new SimpleExecutor( formatter, diff --git a/Sources/xcexecution/DefaultFormatter.cpp b/Sources/xcformatter/DefaultFormatter.cpp similarity index 99% rename from Sources/xcexecution/DefaultFormatter.cpp rename to Sources/xcformatter/DefaultFormatter.cpp index dd6f903a..b5ea7012 100644 --- a/Sources/xcexecution/DefaultFormatter.cpp +++ b/Sources/xcformatter/DefaultFormatter.cpp @@ -7,11 +7,11 @@ of patent rights can be found in the PATENTS file in the same directory. */ -#include +#include #include #include -using xcexecution::DefaultFormatter; +using xcformatter::DefaultFormatter; DefaultFormatter:: DefaultFormatter(bool color) : diff --git a/Sources/xcexecution/Formatter.cpp b/Sources/xcformatter/Formatter.cpp similarity index 87% rename from Sources/xcexecution/Formatter.cpp rename to Sources/xcformatter/Formatter.cpp index 32d28276..a8b36c82 100644 --- a/Sources/xcexecution/Formatter.cpp +++ b/Sources/xcformatter/Formatter.cpp @@ -7,9 +7,9 @@ of patent rights can be found in the PATENTS file in the same directory. */ -#include +#include -using xcexecution::Formatter; +using xcformatter::Formatter; Formatter:: Formatter()