mirror of
https://github.com/darlinghq/xcbuild.git
synced 2024-11-27 05:50:27 +00:00
Use optionals for potentially missing properties of resolved files.
This commit is contained in:
parent
8d2b9879b7
commit
1d20089aa3
@ -13,6 +13,9 @@
|
||||
#include <pbxbuild/Base.h>
|
||||
#include <pbxbuild/Target/BuildRules.h>
|
||||
|
||||
#include <string>
|
||||
#include <ext/optional>
|
||||
|
||||
namespace libutil { class Filesystem; }
|
||||
namespace pbxsetting { class Environment; }
|
||||
|
||||
@ -32,8 +35,8 @@ private:
|
||||
|
||||
private:
|
||||
std::string _path;
|
||||
std::string _localization;
|
||||
std::string _fileNameDisambiguator;
|
||||
ext::optional<std::string> _localization;
|
||||
ext::optional<std::string> _fileNameDisambiguator;
|
||||
|
||||
public:
|
||||
File(
|
||||
@ -41,8 +44,8 @@ public:
|
||||
Target::BuildRules::BuildRule::shared_ptr const &buildRule,
|
||||
pbxspec::PBX::FileType::shared_ptr const &fileType,
|
||||
std::string const &path,
|
||||
std::string const &localization,
|
||||
std::string const &fileNameDisambiguator);
|
||||
ext::optional<std::string> const &localization,
|
||||
ext::optional<std::string> const &fileNameDisambiguator);
|
||||
~File();
|
||||
|
||||
public:
|
||||
@ -75,7 +78,7 @@ public:
|
||||
* The localization this file is for. This is relevant for variant groups,
|
||||
* which contain many versions of the same file for different lproj outputs.
|
||||
*/
|
||||
std::string const &localization() const
|
||||
ext::optional<std::string> const &localization() const
|
||||
{ return _localization; }
|
||||
|
||||
/*
|
||||
@ -83,7 +86,7 @@ public:
|
||||
* same base name within a target. This should be used for the output
|
||||
* path in order to avoid overwriting outputs.
|
||||
*/
|
||||
std::string const &fileNameDisambiguator() const
|
||||
ext::optional<std::string> const &fileNameDisambiguator() const
|
||||
{ return _fileNameDisambiguator; }
|
||||
|
||||
public:
|
||||
|
@ -222,7 +222,7 @@ Group(std::vector<Phase::File> const &files)
|
||||
// TODO: group strings files with a base name matching a sticker pack in an asset catalog. how?
|
||||
} else if (grouping == "ib-base-region-and-strings") {
|
||||
/* Only "Base" region files. See below for finding additional grouped files. */
|
||||
if (file.localization() == "Base") {
|
||||
if (file.localization() && *file.localization() == "Base") {
|
||||
groupedBaseRegion.push_back(file);
|
||||
} else {
|
||||
ungrouped.push_back(file);
|
||||
@ -304,8 +304,8 @@ resolveBuildFiles(
|
||||
Phase::File const &first = files.front();
|
||||
|
||||
std::string fileOutputDirectory = outputDirectory;
|
||||
if (!first.localization().empty()) {
|
||||
fileOutputDirectory += "/" + first.localization() + ".lproj";
|
||||
if (first.localization()) {
|
||||
fileOutputDirectory += "/" + *first.localization() + ".lproj";
|
||||
}
|
||||
|
||||
Target::BuildRules::BuildRule::shared_ptr const &buildRule = first.buildRule();
|
||||
|
@ -27,8 +27,8 @@ File(
|
||||
Target::BuildRules::BuildRule::shared_ptr const &buildRule,
|
||||
pbxspec::PBX::FileType::shared_ptr const &fileType,
|
||||
std::string const &path,
|
||||
std::string const &localization,
|
||||
std::string const &fileNameDisambiguator) :
|
||||
ext::optional<std::string> const &localization,
|
||||
ext::optional<std::string> const &fileNameDisambiguator) :
|
||||
_buildFile (buildFile),
|
||||
_buildRule (buildRule),
|
||||
_fileType (fileType),
|
||||
@ -73,7 +73,7 @@ ResolveBuildFiles(Filesystem const *filesystem, Phase::Environment const &phaseE
|
||||
pbxspec::PBX::FileType::shared_ptr fileType = FileTypeResolver::Resolve(filesystem, buildEnvironment.specManager(), { pbxspec::Manager::AnyDomain() }, fileReference, path);
|
||||
|
||||
Target::BuildRules::BuildRule::shared_ptr buildRule = buildRules.resolve(fileType, path);
|
||||
Phase::File file = Phase::File(buildFile, buildRule, fileType, path, std::string(), fileNameDisambiguator);
|
||||
Phase::File file = Phase::File(buildFile, buildRule, fileType, path, ext::nullopt, fileNameDisambiguator);
|
||||
result.push_back(file);
|
||||
break;
|
||||
}
|
||||
@ -101,7 +101,7 @@ ResolveBuildFiles(Filesystem const *filesystem, Phase::Environment const &phaseE
|
||||
pbxspec::PBX::FileType::shared_ptr fileType = FileTypeResolver::Resolve(filesystem, buildEnvironment.specManager(), { pbxspec::Manager::AnyDomain() }, fileReference, path);
|
||||
|
||||
Target::BuildRules::BuildRule::shared_ptr buildRule = buildRules.resolve(fileType, path);
|
||||
Phase::File file = Phase::File(buildFile, buildRule, fileType, path, std::string(), std::string());
|
||||
Phase::File file = Phase::File(buildFile, buildRule, fileType, path, ext::nullopt, ext::nullopt);
|
||||
result.push_back(file);
|
||||
break;
|
||||
}
|
||||
@ -131,7 +131,7 @@ ResolveBuildFiles(Filesystem const *filesystem, Phase::Environment const &phaseE
|
||||
pbxspec::PBX::FileType::shared_ptr fileType = FileTypeResolver::Resolve(filesystem, buildEnvironment.specManager(), { pbxspec::Manager::AnyDomain() }, versionGroup, path);
|
||||
|
||||
Target::BuildRules::BuildRule::shared_ptr buildRule = buildRules.resolve(fileType, path);
|
||||
Phase::File file = Phase::File(buildFile, buildRule, fileType, path, std::string(), fileNameDisambiguator);
|
||||
Phase::File file = Phase::File(buildFile, buildRule, fileType, path, ext::nullopt, fileNameDisambiguator);
|
||||
result.push_back(file);
|
||||
break;
|
||||
|
||||
|
@ -215,8 +215,8 @@ resolveSource(
|
||||
std::string outputExtension = _compiler->outputFileExtension().value_or("o");
|
||||
|
||||
std::string outputBaseName = FSUtil::GetBaseNameWithoutExtension(input.path());
|
||||
if (!input.fileNameDisambiguator().empty()) {
|
||||
outputBaseName = input.fileNameDisambiguator();
|
||||
if (input.fileNameDisambiguator()) {
|
||||
outputBaseName = *input.fileNameDisambiguator();
|
||||
}
|
||||
std::string output = resolvedOutputDirectory + "/" + outputBaseName + "." + outputExtension;
|
||||
|
||||
|
@ -57,12 +57,15 @@ namespace Tool {
|
||||
*/
|
||||
class Input {
|
||||
private:
|
||||
std::string _path;
|
||||
std::string _localization;
|
||||
std::string _uniquefier;
|
||||
std::string _path;
|
||||
ext::optional<std::string> _localization;
|
||||
ext::optional<std::string> _uniquefier;
|
||||
|
||||
public:
|
||||
Input(std::string const &path, std::string const &localization, std::string const &uniquefier) :
|
||||
Input(
|
||||
std::string const &path,
|
||||
ext::optional<std::string> const &localization,
|
||||
ext::optional<std::string> const &uniquefier) :
|
||||
_path (path),
|
||||
_localization(localization),
|
||||
_uniquefier (uniquefier)
|
||||
@ -72,9 +75,9 @@ public:
|
||||
public:
|
||||
std::string const &path() const
|
||||
{ return _path; }
|
||||
std::string const &localization() const
|
||||
ext::optional<std::string> const &localization() const
|
||||
{ return _localization; }
|
||||
std::string const &uniquefier() const
|
||||
ext::optional<std::string> const &uniquefier() const
|
||||
{ return _uniquefier; }
|
||||
};
|
||||
|
||||
@ -95,7 +98,7 @@ InputLevel(Tool::Input const &input, std::string const &workingDirectory)
|
||||
pbxsetting::Setting::Parse("InputFileBase", "$(InputFile:base)"),
|
||||
pbxsetting::Setting::Parse("InputFileSuffix", "$(InputFile:suffix)"),
|
||||
pbxsetting::Setting::Create("InputFileRelativePath", relativeInputPath),
|
||||
pbxsetting::Setting::Create("InputFileBaseUniquefier", input.uniquefier()),
|
||||
pbxsetting::Setting::Create("InputFileBaseUniquefier", input.uniquefier().value_or("")),
|
||||
pbxsetting::Setting::Create("InputFileTextEncoding", ""), // TODO(grp): Text encoding.
|
||||
});
|
||||
}
|
||||
@ -140,8 +143,8 @@ CreateInternal(
|
||||
std::string tempResourcesDirectory = environment.resolve("TARGET_TEMP_DIR");
|
||||
if (!inputs.empty()) {
|
||||
Tool::Input const &input = inputs.front();
|
||||
if (!input.localization().empty()) {
|
||||
std::string localizationPath = input.localization() + ".lproj";
|
||||
if (input.localization()) {
|
||||
std::string localizationPath = *input.localization() + ".lproj";
|
||||
productResourcesDirectory += "/" + localizationPath;
|
||||
tempResourcesDirectory += "/" + localizationPath;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ resolve(
|
||||
for (Phase::File const &input : inputs) {
|
||||
if (input.fileType()->identifier() == "text.plist.strings") {
|
||||
/* The format here is as expected by ibtool. */
|
||||
localizationStringsFiles.push_back(input.localization() + ":" + input.path());
|
||||
localizationStringsFiles.push_back(input.localization().value_or("") + ":" + input.path());
|
||||
} else {
|
||||
primaryInputs.push_back(input);
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ resolve(
|
||||
pbxsetting::Setting::Parse("INPUT_FILE_NAME", "$(INPUT_FILE_PATH:file)"),
|
||||
pbxsetting::Setting::Parse("INPUT_FILE_BASE", "$(INPUT_FILE_PATH:base)"),
|
||||
pbxsetting::Setting::Parse("INPUT_FILE_SUFFIX", "$(INPUT_FILE_PATH:suffix)"),
|
||||
pbxsetting::Setting::Create("INPUT_FILE_REGION_PATH_COMPONENT", input.localization()), // TODO(grp): Verify format of this.
|
||||
pbxsetting::Setting::Create("INPUT_FILE_REGION_PATH_COMPONENT", input.localization().value_or("")), // TODO(grp): Verify format of this.
|
||||
});
|
||||
|
||||
pbxsetting::Environment ruleEnvironment = pbxsetting::Environment(environment);
|
||||
|
Loading…
Reference in New Issue
Block a user