Skip to content

Revert "[Diag] Create frontend flags for localization and write tests #32615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions include/swift/AST/DiagnosticEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -740,10 +740,9 @@ namespace swift {
}

void setLocalization(std::string locale, std::string path) {
assert(!locale.empty());
assert(!path.empty());
localization =
std::make_unique<diag::YAMLLocalizationProducer>(locale, path);
if (!locale.empty() && !path.empty())
localization =
std::make_unique<diag::YAMLLocalizationProducer>(locale, path);
}

void ignoreDiagnostic(DiagID id) {
Expand Down
7 changes: 0 additions & 7 deletions include/swift/AST/DiagnosticsFrontend.def
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ ERROR(error_unknown_arg,none,
"unknown argument: '%0'", (StringRef))
ERROR(error_invalid_arg_value,none,
"invalid value '%1' in '%0'", (StringRef, StringRef))
ERROR(error_invalid_locale_code,none,
"unsupported locale code; supported locale codes are: '%0'", (StringRef))
WARNING(warning_locale_path_not_found,none,
"specified localization directory '%0' does not exist, "
"translation is disabled", (StringRef))
WARNING(warning_cannot_find_locale_file,none,
"cannot find translations for '%0' at '%1': no such file", (StringRef, StringRef))
WARNING(warning_cannot_multithread_batch_mode,none,
"ignoring -num-threads argument; cannot multithread batch mode", ())
ERROR(error_unsupported_option_argument,none,
Expand Down
207 changes: 0 additions & 207 deletions include/swift/AST/LocalizationLanguages.def

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,3 @@
#
#===----------------------------------------------------------------------===#

- id: "lex_unterminated_string"
msg: "chaîne non terminée littérale"

- id: "var_init_self_referential"
msg: "variable utilisée dans sa propre valeur initiale"

- id: "cannot_find_in_scope"
msg: "impossible %select{de trouver|de trouver opérateur}1 %0 portée"

- id: "error_invalid_locale_code"
msg: "code de paramètres régionaux non pris en charge; les codes pris en charge sont '%0'"
5 changes: 0 additions & 5 deletions include/swift/Basic/DiagnosticOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ class DiagnosticOptions {

std::string DiagnosticDocumentationPath = "";

std::string LocalizationCode = "";

// Diagnostic messages directory path.
std::string LocalizationPath = "";

/// Return a hash code of any components from these options that should
/// contribute to a Swift Bridging PCH hash.
llvm::hash_code getPCHHashComponents() const {
Expand Down
8 changes: 0 additions & 8 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,6 @@ def diagnostic_style : Separate<["-"], "diagnostic-style">,
def diagnostic_style_EQ : Joined<["-"], "diagnostic-style=">,
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
MetaVarName<"<style>">, Alias<diagnostic_style>;
def locale : Separate<["-"], "locale">,
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
HelpText<"Choose a language for diagnostic messages">,
MetaVarName<"<locale-code>">;
def localization_path : Separate<["-"], "localization-path">,
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, ArgumentIsPath]>,
HelpText<"Path to localized diagnostic messages directory">,
MetaVarName<"<path>">;

def module_cache_path : Separate<["-"], "module-cache-path">,
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, ArgumentIsPath]>,
Expand Down
2 changes: 0 additions & 2 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,6 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
inputArgs.AddLastArg(arguments,
options::OPT_emit_fine_grained_dependency_sourcefile_dot_files);
inputArgs.AddLastArg(arguments, options::OPT_package_description_version);
inputArgs.AddLastArg(arguments, options::OPT_locale);
inputArgs.AddLastArg(arguments, options::OPT_localization_path);
inputArgs.AddLastArg(arguments, options::OPT_serialize_diagnostics_path);
inputArgs.AddLastArg(arguments, options::OPT_debug_diagnostic_names);
inputArgs.AddLastArg(arguments, options::OPT_print_educational_notes);
Expand Down
50 changes: 0 additions & 50 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ using namespace llvm::opt;
/// The path for Swift libraries in the OS on Darwin.
#define DARWIN_OS_LIBRARY_PATH "/usr/lib/swift"

static constexpr const char *const localeCodes[] = {
#define SUPPORTED_LOCALE(Code, Language) #Code,
#include "swift/AST/LocalizationLanguages.def"
};

swift::CompilerInvocation::CompilerInvocation() {
setTargetTriple(llvm::sys::getDefaultTargetTriple());
}
Expand All @@ -62,14 +57,6 @@ void CompilerInvocation::setMainExecutablePath(StringRef Path) {
llvm::sys::path::append(DiagnosticDocsPath, "share", "doc", "swift",
"diagnostics");
DiagnosticOpts.DiagnosticDocumentationPath = std::string(DiagnosticDocsPath.str());

// Compute the path of the YAML diagnostic messages directory files
// in the toolchain.
llvm::SmallString<128> DiagnosticMessagesDir(Path);
llvm::sys::path::remove_filename(DiagnosticMessagesDir); // Remove /swift
llvm::sys::path::remove_filename(DiagnosticMessagesDir); // Remove /bin
llvm::sys::path::append(DiagnosticMessagesDir, "share", "swift");
DiagnosticOpts.LocalizationPath = std::string(DiagnosticMessagesDir.str());
}

void CompilerInvocation::setDefaultPrebuiltCacheIfNecessary() {
Expand Down Expand Up @@ -941,43 +928,6 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
if (Arg *A = Args.getLastArg(OPT_diagnostic_documentation_path)) {
Opts.DiagnosticDocumentationPath = A->getValue();
}
if (Arg *A = Args.getLastArg(OPT_locale)) {
std::string localeCode = A->getValue();

// Check if the locale code is available.
if (llvm::none_of(localeCodes, [&](const char *locale) {
return localeCode == locale;
})) {
std::string availableLocaleCodes = "";
llvm::interleave(
std::begin(localeCodes), std::end(localeCodes),
[&](std::string locale) { availableLocaleCodes += locale; },
[&] { availableLocaleCodes += ", "; });

Diags.diagnose(SourceLoc(), diag::error_invalid_locale_code,
availableLocaleCodes);
return true;
}
Opts.LocalizationCode = localeCode;
}
if (Arg *A = Args.getLastArg(OPT_localization_path)) {
if (!llvm::sys::fs::exists(A->getValue())) {
Diags.diagnose(SourceLoc(), diag::warning_locale_path_not_found,
A->getValue());
} else if (!Opts.LocalizationCode.empty()) {
// Check if the localization path exists but it doesn't have a file
// for the specified locale code.
llvm::SmallString<128> localizationPath(A->getValue());
llvm::sys::path::append(localizationPath, Opts.LocalizationCode);
llvm::sys::path::replace_extension(localizationPath, ".yaml");
if (!llvm::sys::fs::exists(localizationPath)) {
Diags.diagnose(SourceLoc(), diag::warning_cannot_find_locale_file,
Opts.LocalizationCode, localizationPath);
}

Opts.LocalizationPath = A->getValue();
}
}
assert(!(Opts.WarningsAsErrors && Opts.SuppressWarnings) &&
"conflicting arguments; should have been caught by driver");

Expand Down
5 changes: 0 additions & 5 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,6 @@ void CompilerInstance::setUpDiagnosticOptions() {
}
Diagnostics.setDiagnosticDocumentationPath(
Invocation.getDiagnosticOptions().DiagnosticDocumentationPath);
if (!Invocation.getDiagnosticOptions().LocalizationCode.empty()) {
Diagnostics.setLocalization(
Invocation.getDiagnosticOptions().LocalizationCode,
Invocation.getDiagnosticOptions().LocalizationPath);
}
}

// The ordering of ModuleLoaders is important!
Expand Down
Loading