diff --git a/include/swift/Option/FrontendOptions.td b/include/swift/Option/FrontendOptions.td index 58636ee107e2d..304969fbca60b 100644 --- a/include/swift/Option/FrontendOptions.td +++ b/include/swift/Option/FrontendOptions.td @@ -14,48 +14,31 @@ // //===----------------------------------------------------------------------===// -let Flags = [FrontendOption, NoDriverOption] in { - -def triple : Separate<["-"], "triple">, Alias; - -def primary_file : Separate<["-"], "primary-file">, - HelpText<"Produce output for this file, not the whole module">; +let Flags = [FrontendOption, NoDriverOption, ArgumentIsFileList] in { def filelist : Separate<["-"], "filelist">, HelpText<"Specify source inputs in a file rather than on the command line">; def primary_filelist : Separate<["-"], "primary-filelist">, HelpText<"Specify primary inputs in a file rather than on the command line">; + +} // end let Flags = [FrontendOption, NoDriverOption, ArgumentIsFileList] + + +let Flags = [FrontendOption, NoDriverOption, CacheInvariant] in { + def output_filelist : Separate<["-"], "output-filelist">, HelpText<"Specify outputs in a file rather than on the command line">; def supplementary_output_file_map : Separate<["-"], "supplementary-output-file-map">, HelpText<"Specify supplementary outputs in a file rather than on the command line">; +def index_unit_output_path_filelist : Separate<["-"], "index-unit-output-path-filelist">, + HelpText<"Specify index unit output paths in a file rather than on the command line">; -def frontend_parseable_output : Flag<["-"], "frontend-parseable-output">, - HelpText<"Emit textual output in a parseable format">; - -def emit_module_doc : Flag<["-"], "emit-module-doc">, - HelpText<"Emit a module documentation file based on documentation " - "comments">; def emit_module_doc_path : Separate<["-"], "emit-module-doc-path">, MetaVarName<"">, HelpText<"Output module documentation file ">; - -def emit_module_source_info : Flag<["-"], "emit-module-source-info">, - HelpText<"Output module source info file">; - -def ignore_module_source_info : Flag<["-"], "ignore-module-source-info">, - HelpText<"Avoid getting source location from .swiftsourceinfo files">; - -def merge_modules - : Flag<["-"], "merge-modules">, ModeOpt, - HelpText<"Merge the input modules without otherwise processing them">; - def emit_dependencies_path : Separate<["-"], "emit-dependencies-path">, MetaVarName<"">, HelpText<"Output basic Make-compatible dependencies file to ">; - -def emit_reference_dependencies : Flag<["-"], "emit-reference-dependencies">, - HelpText<"Emit a Swift-style dependencies file">; def emit_reference_dependencies_path : Separate<["-"], "emit-reference-dependencies-path">, MetaVarName<"">, HelpText<"Output Swift-style dependencies file to ">; @@ -63,15 +46,65 @@ def emit_reference_dependencies_path def emit_fixits_path : Separate<["-"], "emit-fixits-path">, MetaVarName<"">, HelpText<"Output compiler fixits as source edits to ">; - def emit_abi_descriptor_path : Separate<["-"], "emit-abi-descriptor-path">, MetaVarName<"">, HelpText<"Output the ABI descriptor of current module to ">; - def emit_module_semantic_info_path : Separate<["-"], "emit-module-semantic-info-path">, MetaVarName<"">, HelpText<"Output semantic info of current module to ">; +def diagnostic_documentation_path + : Separate<["-"], "diagnostic-documentation-path">, MetaVarName<"">, + HelpText<"Path to diagnostic documentation resources">; + +def dump_api_path : Separate<["-"], "dump-api-path">, + HelpText<"The path to output swift interface files for the compiled source files">; + +def group_info_path : Separate<["-"], "group-info-path">, + HelpText<"The path to collect the group information of the compiled module">; + +def prebuilt_module_cache_path : + Separate<["-"], "prebuilt-module-cache-path">, + HelpText<"Directory of prebuilt modules for loading module interfaces">; +def prebuilt_module_cache_path_EQ : + Joined<["-"], "prebuilt-module-cache-path=">, + Alias; + +def backup_module_interface_path : + Separate<["-"], "backup-module-interface-path">, + HelpText<"Directory of module interfaces as backups to those from SDKs">; +def backup_module_interface_path_EQ : + Joined<["-"], "backup-module-interface-path=">, + Alias; + +} // end let Flags = [FrontendOption, NoDriverOption, CacheInvariant] + + +let Flags = [FrontendOption, NoDriverOption] in { + +def triple : Separate<["-"], "triple">, Alias; + +def primary_file : Separate<["-"], "primary-file">, + HelpText<"Produce output for this file, not the whole module">; + +def frontend_parseable_output : Flag<["-"], "frontend-parseable-output">, + HelpText<"Emit textual output in a parseable format">; + +def emit_module_doc : Flag<["-"], "emit-module-doc">, + HelpText<"Emit a module documentation file based on documentation " + "comments">; + +def emit_module_source_info : Flag<["-"], "emit-module-source-info">, + HelpText<"Output module source info file">; +def ignore_module_source_info : Flag<["-"], "ignore-module-source-info">, + HelpText<"Avoid getting source location from .swiftsourceinfo files">; + +def merge_modules + : Flag<["-"], "merge-modules">, ModeOpt, + HelpText<"Merge the input modules without otherwise processing them">; +def emit_reference_dependencies : Flag<["-"], "emit-reference-dependencies">, + HelpText<"Emit a Swift-style dependencies file">; + def serialize_module_interface_dependency_hashes : Flag<["-"], "serialize-module-interface-dependency-hashes">, Flags<[HelpHidden]>; @@ -127,10 +160,6 @@ def enable_cross_import_overlays : Flag<["-"], "enable-cross-import-overlays">, def disable_cross_import_overlays : Flag<["-"], "disable-cross-import-overlays">, HelpText<"Do not automatically import declared cross-import overlays.">; -def diagnostic_documentation_path - : Separate<["-"], "diagnostic-documentation-path">, MetaVarName<"">, - HelpText<"Path to diagnostic documentation resources">; - def enable_testable_attr_requires_testable_module : Flag<["-"], "enable-testable-attr-requires-testable-module">, HelpText<"Enable checking of @testable">; @@ -895,9 +924,6 @@ def index_ignore_stdlib : Flag<["-"], "index-ignore-stdlib">, HelpText<"Avoid emitting index data for the standard library.">; -def index_unit_output_path_filelist : Separate<["-"], "index-unit-output-path-filelist">, - HelpText<"Specify index unit output paths in a file rather than on the command line">; - def dump_interface_hash : Flag<["-"], "dump-interface-hash">, HelpText<"Parse input file(s) and dump interface token hash(es)">, ModeOpt; @@ -960,29 +986,9 @@ def experimental_one_way_closure_params : Flag<["-"], "experimental-one-way-closure-params">, HelpText<"Enable experimental support for one-way closure parameters">; -def prebuilt_module_cache_path : - Separate<["-"], "prebuilt-module-cache-path">, - HelpText<"Directory of prebuilt modules for loading module interfaces">; -def prebuilt_module_cache_path_EQ : - Joined<["-"], "prebuilt-module-cache-path=">, - Alias; - -def backup_module_interface_path : - Separate<["-"], "backup-module-interface-path">, - HelpText<"Directory of module interfaces as backups to those from SDKs">; -def backup_module_interface_path_EQ : - Joined<["-"], "backup-module-interface-path=">, - Alias; - def force_public_linkage : Flag<["-"], "force-public-linkage">, HelpText<"Force public linkage for private symbols. Used by LLDB.">; -def dump_api_path : Separate<["-"], "dump-api-path">, - HelpText<"The path to output swift interface files for the compiled source files">; - -def group_info_path : Separate<["-"], "group-info-path">, - HelpText<"The path to collect the group information of the compiled module">; - def diagnostics_editor_mode : Flag<["-"], "diagnostics-editor-mode">, HelpText<"Diagnostics will be used in editor">; diff --git a/include/swift/Option/Options.h b/include/swift/Option/Options.h index 8961283d58909..0f24e0bd7d0df 100644 --- a/include/swift/Option/Options.h +++ b/include/swift/Option/Options.h @@ -43,6 +43,8 @@ namespace options { NewDriverOnlyOption = (1 << 18), ModuleInterfaceOptionIgnorable = (1 << 19), ModuleInterfaceOptionIgnorablePrivate = (1 << 20), + ArgumentIsFileList = (1 << 21), + CacheInvariant = (1 << 22), }; enum ID { diff --git a/include/swift/Option/Options.td b/include/swift/Option/Options.td index a6faf8336f371..31f4b5374125c 100644 --- a/include/swift/Option/Options.td +++ b/include/swift/Option/Options.td @@ -77,6 +77,15 @@ def SwiftAPIDigesterOption : OptionFlag; // The option only functions in the new driver. def NewDriverOnlyOption : OptionFlag; +// The option's argument is a path to a file that contains a list of files. +def ArgumentIsFileList : OptionFlag; + +// The option that is cache invariant. Change this option doesn't affect the +// content of any output file. The candidates are options like: `-o` which only +// affects the location of the output file, or `-emit-module` which defines +// which action is performed. +def CacheInvariant : OptionFlag; + ///////// // Options @@ -255,7 +264,7 @@ def _DASH_DASH : Option<["--"], "", KIND_REMAINING_ARGS>, def o : JoinedOrSeparate<["-"], "o">, Flags<[FrontendOption, AutolinkExtractOption, ModuleWrapOption, NoInteractiveOption, SwiftIndentOption, ArgumentIsPath, - SwiftAPIExtractOption, SwiftAPIDigesterOption]>, + SwiftAPIExtractOption, SwiftAPIDigesterOption, CacheInvariant]>, HelpText<"Write output to ">, MetaVarName<"">; def j : JoinedOrSeparate<["-"], "j">, Flags<[DoesNotAffectIncrementalBuild]>, @@ -360,26 +369,26 @@ def profile_stats_entities: Flag<["-"], "profile-stats-entities">, HelpText<"Profile changes to stats in -stats-output-dir, subdivided by source entity">; def emit_dependencies : Flag<["-"], "emit-dependencies">, - Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput]>, + Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput, CacheInvariant]>, HelpText<"Emit basic Make-compatible dependencies files">; def track_system_dependencies : Flag<["-"], "track-system-dependencies">, Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>, HelpText<"Track system dependencies while emitting Make-style dependencies">; def emit_loaded_module_trace : Flag<["-"], "emit-loaded-module-trace">, - Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput]>, + Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput, CacheInvariant]>, HelpText<"Emit a JSON file containing information about what modules were loaded">; def emit_loaded_module_trace_path : Separate<["-"], "emit-loaded-module-trace-path">, Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath, - SupplementaryOutput]>, + SupplementaryOutput, CacheInvariant]>, HelpText<"Emit the loaded module trace JSON to ">, MetaVarName<"">; def emit_loaded_module_trace_path_EQ : Joined<["-"], "emit-loaded-module-trace-path=">, Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath, - SupplementaryOutput]>, + SupplementaryOutput, CacheInvariant]>, Alias; def emit_cross_import_remarks : Flag<["-"], "Rcross-import">, - Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>, + Flags<[FrontendOption, DoesNotAffectIncrementalBuild, CacheInvariant]>, HelpText<"Emit a remark if a cross-import of a module is triggered.">; def remark_loading_module : Flag<["-"], "Rmodule-loading">, @@ -399,15 +408,15 @@ def remark_skip_explicit_interface_build : Flag<["-"], "Rskip-explicit-interface def emit_tbd : Flag<["-"], "emit-tbd">, HelpText<"Emit a TBD file">, - Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput]>; + Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput, CacheInvariant]>; def emit_tbd_path : Separate<["-"], "emit-tbd-path">, Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath, - SupplementaryOutput]>, + SupplementaryOutput, CacheInvariant]>, HelpText<"Emit the TBD file to ">, MetaVarName<"">; def emit_tbd_path_EQ : Joined<["-"], "emit-tbd-path=">, Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath, - SupplementaryOutput]>, + SupplementaryOutput, CacheInvariant]>, Alias; def embed_tbd_for_module : Separate<["-"], "embed-tbd-for-module">, Flags<[FrontendOption]>, @@ -418,12 +427,12 @@ def serialize_diagnostics : Flag<["-"], "serialize-diagnostics">, HelpText<"Serialize diagnostics in a binary format">; def serialize_diagnostics_path : Separate<["-"], "serialize-diagnostics-path">, Flags<[FrontendOption, SwiftAPIDigesterOption, NoBatchOption, - ArgumentIsPath, SupplementaryOutput]>, + ArgumentIsPath, SupplementaryOutput, CacheInvariant]>, HelpText<"Emit a serialized diagnostics file to ">, MetaVarName<"">; def serialize_diagnostics_path_EQ: Joined<["-"], "serialize-diagnostics-path=">, Flags<[FrontendOption, SwiftAPIDigesterOption, NoBatchOption, - ArgumentIsPath, SupplementaryOutput]>, + ArgumentIsPath, SupplementaryOutput, CacheInvariant]>, Alias; def color_diagnostics : Flag<["-"], "color-diagnostics">, Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>, @@ -536,42 +545,42 @@ def export_as : Separate<["-"], "export-as">, HelpText<"Module name to use when referenced in clients module interfaces">; def emit_module : Flag<["-"], "emit-module">, - Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput]>, + Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput, CacheInvariant]>, HelpText<"Emit an importable module">; def emit_module_path : Separate<["-"], "emit-module-path">, Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath, - SupplementaryOutput]>, + SupplementaryOutput, CacheInvariant]>, HelpText<"Emit an importable module to ">, MetaVarName<"">; def emit_module_path_EQ : Joined<["-"], "emit-module-path=">, Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath, - SupplementaryOutput]>, + SupplementaryOutput, CacheInvariant]>, Alias; def emit_module_summary : Flag<["-"], "emit-module-summary">, - Flags<[NoInteractiveOption, SupplementaryOutput]>, + Flags<[NoInteractiveOption, SupplementaryOutput, CacheInvariant]>, HelpText<"Output module summary file">; def emit_module_summary_path : Separate<["-"], "emit-module-summary-path">, Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath, - SupplementaryOutput]>, + SupplementaryOutput, CacheInvariant]>, MetaVarName<"">, HelpText<"Output module summary file to ">; def emit_module_interface : Flag<["-"], "emit-module-interface">, - Flags<[NoInteractiveOption, SupplementaryOutput]>, + Flags<[NoInteractiveOption, SupplementaryOutput, CacheInvariant]>, HelpText<"Output module interface file">; def emit_module_interface_path : Separate<["-"], "emit-module-interface-path">, Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath, - SupplementaryOutput]>, + SupplementaryOutput, CacheInvariant]>, MetaVarName<"">, HelpText<"Output module interface file to ">; def emit_private_module_interface_path : Separate<["-"], "emit-private-module-interface-path">, Flags<[FrontendOption, NoInteractiveOption, HelpHidden, - ArgumentIsPath, SupplementaryOutput]>, + ArgumentIsPath, SupplementaryOutput, CacheInvariant]>, MetaVarName<"">, HelpText<"Output private module interface file to ">; def verify_emitted_module_interface : @@ -597,27 +606,27 @@ def emit_module_source_info_path : def emit_parseable_module_interface : Flag<["-"], "emit-parseable-module-interface">, Alias, - Flags<[NoInteractiveOption, HelpHidden, SupplementaryOutput]>; + Flags<[NoInteractiveOption, HelpHidden, SupplementaryOutput, CacheInvariant]>; def emit_parseable_module_interface_path : Separate<["-"], "emit-parseable-module-interface-path">, Alias, Flags<[FrontendOption, NoInteractiveOption, HelpHidden, ArgumentIsPath, - SupplementaryOutput]>; + SupplementaryOutput, CacheInvariant]>; def emit_const_values : Flag<["-"], "emit-const-values">, Flags<[NoInteractiveOption, SupplementaryOutput]>; def emit_const_values_path : Separate<["-"], "emit-const-values-path">, Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath, - SupplementaryOutput]>, + SupplementaryOutput, CacheInvariant]>, MetaVarName<"">, HelpText<"Emit the extracted compile-time known values to ">; def emit_objc_header : Flag<["-"], "emit-objc-header">, - Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput]>, + Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput, CacheInvariant]>, HelpText<"Emit an Objective-C header file">; def emit_objc_header_path : Separate<["-"], "emit-objc-header-path">, Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath, - SupplementaryOutput]>, + SupplementaryOutput, CacheInvariant]>, MetaVarName<"">, HelpText<"Emit an Objective-C header file to ">; def emit_clang_header_nonmodular_includes : Flag<["-"], "emit-clang-header-nonmodular-includes">, Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput]>, @@ -625,7 +634,7 @@ def emit_clang_header_nonmodular_includes : Flag<["-"], "emit-clang-header-nonmo def emit_clang_header_path : Separate<["-"], "emit-clang-header-path">, Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath, - SupplementaryOutput]>, + SupplementaryOutput, CacheInvariant]>, HelpText<"Emit an Objective-C and C++ header file to ">, Alias; @@ -1101,45 +1110,39 @@ def modes_Group : OptionGroup<"">, HelpText<"MODES">; class ModeOpt : Group; // Output Modes -def emit_executable : Flag<["-"], "emit-executable">, - HelpText<"Emit a linked executable">, ModeOpt, - Flags<[NoInteractiveOption, DoesNotAffectIncrementalBuild]>; -def emit_library : Flag<["-"], "emit-library">, - HelpText<"Emit a linked library">, ModeOpt, - Flags<[NoInteractiveOption]>; +let Flags = [FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild, CacheInvariant] in { + def emit_object : Flag<["-"], "emit-object">, - HelpText<"Emit object file(s) (-c)">, ModeOpt, - Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>; + HelpText<"Emit object file(s) (-c)">, ModeOpt; def emit_assembly : Flag<["-"], "emit-assembly">, - HelpText<"Emit assembly file(s) (-S)">, ModeOpt, - Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>; + HelpText<"Emit assembly file(s) (-S)">, ModeOpt; def emit_bc : Flag<["-"], "emit-bc">, - HelpText<"Emit LLVM BC file(s)">, ModeOpt, - Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>; + HelpText<"Emit LLVM BC file(s)">, ModeOpt; def emit_irgen : Flag<["-"], "emit-irgen">, - HelpText<"Emit LLVM IR file(s) before LLVM optimizations">, ModeOpt, - Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>; + HelpText<"Emit LLVM IR file(s) before LLVM optimizations">, ModeOpt; def emit_ir : Flag<["-"], "emit-ir">, - HelpText<"Emit LLVM IR file(s) after LLVM optimizations">, ModeOpt, - Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>; + HelpText<"Emit LLVM IR file(s) after LLVM optimizations">, ModeOpt; def emit_sil : Flag<["-"], "emit-sil">, - HelpText<"Emit canonical SIL file(s)">, ModeOpt, - Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>; + HelpText<"Emit canonical SIL file(s)">, ModeOpt; def emit_silgen : Flag<["-"], "emit-silgen">, - HelpText<"Emit raw SIL file(s)">, ModeOpt, - Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>; + HelpText<"Emit raw SIL file(s)">, ModeOpt; def emit_sib : Flag<["-"], "emit-sib">, - HelpText<"Emit serialized AST + canonical SIL file(s)">, ModeOpt, - Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>; + HelpText<"Emit serialized AST + canonical SIL file(s)">, ModeOpt; def emit_sibgen : Flag<["-"], "emit-sibgen">, - HelpText<"Emit serialized AST + raw SIL file(s)">, ModeOpt, - Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>; + HelpText<"Emit serialized AST + raw SIL file(s)">, ModeOpt; def emit_imported_modules : Flag<["-"], "emit-imported-modules">, - HelpText<"Emit a list of the imported modules">, ModeOpt, - Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>; + HelpText<"Emit a list of the imported modules">, ModeOpt; def emit_pcm : Flag<["-"], "emit-pcm">, - HelpText<"Emit a precompiled Clang module from a module map">, ModeOpt, - Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>; + HelpText<"Emit a precompiled Clang module from a module map">, ModeOpt; + +} // end let Flags = [FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild, CacheInvariant] + +def emit_executable : Flag<["-"], "emit-executable">, + HelpText<"Emit a linked executable">, ModeOpt, + Flags<[NoInteractiveOption, DoesNotAffectIncrementalBuild]>; +def emit_library : Flag<["-"], "emit-library">, + HelpText<"Emit a linked library">, ModeOpt, + Flags<[NoInteractiveOption]>; def c : Flag<["-"], "c">, Alias, Flags<[FrontendOption, NoInteractiveOption]>, ModeOpt; @@ -1235,7 +1238,7 @@ def force_single_frontend_invocation : Flags<[FrontendOption, NoInteractiveOption, HelpHidden]>; def num_threads : Separate<["-"], "num-threads">, - Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>, + Flags<[FrontendOption, DoesNotAffectIncrementalBuild, CacheInvariant]>, HelpText<"Enable multi-threading and specify number of threads">, MetaVarName<"">; @@ -1381,7 +1384,7 @@ def index_store_path : Separate<["-"], "index-store-path">, HelpText<"Store indexing data to ">; def index_unit_output_path : Separate<["-"], "index-unit-output-path">, - Flags<[FrontendOption, ArgumentIsPath]>, MetaVarName<"">, + Flags<[FrontendOption, ArgumentIsPath, CacheInvariant]>, MetaVarName<"">, HelpText<"Use as the output path in the produced index data.">; def index_ignore_clang_modules : Flag<["-"], "index-ignore-clang-modules">, @@ -1822,15 +1825,15 @@ def cache_compile_job: Flag<["-"], "cache-compile-job">, HelpText<"Enable compiler caching">; def cache_remarks: Flag<["-"], "Rcache-compile-job">, - Flags<[FrontendOption, NewDriverOnlyOption]>, + Flags<[FrontendOption, NewDriverOnlyOption, CacheInvariant]>, HelpText<"Show remarks for compiler caching">; def cache_disable_replay: Flag<["-"], "cache-disable-replay">, - Flags<[FrontendOption, NewDriverOnlyOption]>, + Flags<[FrontendOption, NewDriverOnlyOption, CacheInvariant]>, HelpText<"Skip loading the compilation result from cache">; def cas_path: Separate<["-"], "cas-path">, - Flags<[FrontendOption, NewDriverOnlyOption]>, + Flags<[FrontendOption, NewDriverOnlyOption, CacheInvariant]>, HelpText<"Path to CAS">, MetaVarName<"">; def cas_plugin_path: Separate<["-"], "cas-plugin-path">, diff --git a/lib/Frontend/CompileJobCacheKey.cpp b/lib/Frontend/CompileJobCacheKey.cpp index a143acd71405e..06b94d82bf789 100644 --- a/lib/Frontend/CompileJobCacheKey.cpp +++ b/lib/Frontend/CompileJobCacheKey.cpp @@ -14,12 +14,15 @@ // //===----------------------------------------------------------------------===// +#include "swift/Option/Options.h" #include #include #include #include "llvm/ADT/STLExtras.h" #include "llvm/CAS/HierarchicalTreeBuilder.h" #include "llvm/CAS/ObjectStore.h" +#include "llvm/Option/ArgList.h" +#include "llvm/Option/OptTable.h" #include "llvm/Support/Error.h" #include "llvm/Support/MemoryBuffer.h" @@ -28,52 +31,37 @@ using namespace swift; // TODO: Rewrite this into CASNodeSchema. llvm::Expected swift::createCompileJobBaseCacheKey( llvm::cas::ObjectStore &CAS, ArrayRef Args) { - SmallString<256> CommandLine; - - // TODO: Improve this list. - static const std::vector removeArgAndNext = { - "-o", - "-output-filelist", - "-supplementary-output-file-map", - "-index-unit-output-path", - "-index-unit-output-path-filelist", - "-serialize-diagnostics-path", - "-num-threads", - "-cas-path"}; - // Don't count the `-frontend` in the first location since only frontend // invocation can have a cache key. if (Args.size() > 1 && StringRef(Args.front()) == "-frontend") Args = Args.drop_front(); - for (unsigned I = 0, IE =Args.size(); I < IE; ++I) { - StringRef Arg = Args[I]; - if (llvm::is_contained(removeArgAndNext, Arg)) { - ++I; - continue; - } - // FIXME: Use a heuristic to remove all the flags that affect output paths. - // Those should not affect compile cache key. - if (Arg.startswith("-emit-")) { - if (Arg.endswith("-path")) - ++I; + unsigned MissingIndex; + unsigned MissingCount; + std::unique_ptr Table = createSwiftOptTable(); + llvm::opt::InputArgList ParsedArgs = Table->ParseArgs( + Args, MissingIndex, MissingCount, options::FrontendOption); + + SmallString<256> CommandLine; + for (auto *Arg : ParsedArgs) { + const auto &Opt = Arg->getOption(); + + // Skip the options that doesn't affect caching. + if (Opt.hasFlag(options::CacheInvariant)) continue; - } - // Handle -file-list option. Need to drop the option but adds the file - // content instead. - // FIXME: will be nice if the same list of files gets the same key no matter - // going through command-line or filelist. - if (Arg == "-filelist" || Arg == "-primary-filelist") { - auto FileList = llvm::MemoryBuffer::getFile(Args[++I]); + + if (Opt.hasFlag(options::ArgumentIsFileList)) { + auto FileList = llvm::MemoryBuffer::getFile(Arg->getValue()); if (!FileList) return llvm::errorCodeToError(FileList.getError()); - CommandLine.append(Arg); + CommandLine.append(Opt.getRenderName()); CommandLine.push_back(0); CommandLine.append((*FileList)->getBuffer()); CommandLine.push_back(0); continue; } - CommandLine.append(Arg); + + CommandLine.append(Arg->getAsString(ParsedArgs)); CommandLine.push_back(0); }