#compdef nact nact3

# Copyright (C)Nintendo All rights reserved.
#
# These coded instructions, statements, and computer programs contain proprietary
# information of Nintendo and/or its licensed developers and are protected by
# national and international copyright laws. They may not be disclosed to third
# parties or copied or duplicated in any form, in whole or in part, without the
# prior written consent of Nintendo.
#
# The content herein is highly confidential and should be handled accordingly.

GIT_TOPLEVEL=`git rev-parse --show-toplevel`
ROOT=`cygpath -am ${GIT_TOPLEVEL}`

function _nact_specs {
    _values -s , 'specs' \
        `cat ${ROOT}/Common/Build/Nact/Target/Specs.narl \
        | awk 'spec == 1 && /".+?"/ { gsub(/[\",]/, "", $1); print $1; spec = 0} /ConfigSpecMap = / || /\},/ { spec=1; }'`
}

function _nact_outputs {
    _values -s ',' 'outputs' \
        `cat ${ROOT}/Common/Build/Nact/BuildOutputRules.narl \
        | awk '/"(.+)", BuildOutput/ { print $1 }' | sed -e 's/[",]//g' \
        | paste -sd " "`
}

function _nact_platforms {
    _values -s ',' 'platforms' \
         `cat ${ROOT}/Common/Build/Nact/Target/Specs.narl \
         | awk 'spec == 1 && /\);/ { spec = 0 } spec == 1 { gsub(/[\",]/, "", $1); print $1;} /CapablePlatforms = / { spec=1; }' \
         | paste -sd " "`
}

function _nact_builds {
    if [[ $words[-1] == *full* ]]; then
        _values 'builds' \
            full
    else
        _values -s ',' 'builds' \
            Debug Develop Release full
    fi
}

function _nact_boolean {
    _values boolean true false
}

function _nact {
    flag_specs=(
        '*'{-d,-C,--build_directory}'[Build the directory specified by Path <param>.]:directory:->dir'
        '--build_source_directory[Build the source specified by Path <param>.]:directory:->dir'
        '--build_source_file[Build the source file specified by Path <param>.]:file:->file'
        '*'--target_directory'[Build the product in the directory specified by Path <param>.]:directory:->dir'
        '*'{-f,--target_file}'[Build the file specified by Path <param>.]:file:->file'
        '*'--target_file_search_string'[Build the files whose paths contain the string <param>.]:search string'
        '*'{-F,--target_file_pattern}'[Build the files whose paths match the regular expression <param>.]:regular expression'
        '--also_build_inactive_rules[Build also inactive rules.]'
        '(-P --build_forever)'{-P,--build_forever}'[Build forever]'
        '--no_use_database[Do not use database]'
        '--enable_jit_debug[Enable JIT debug]'
        '--ignore_dostartup[Rules with DoStartup being true do not build.]'
        '--no_execute[Do not build]'
        '--skip_exists[Do not build rules that have all files specified in the results.]'
        '--ignore_external_dependencies[Ignore rules outside of the directories to build.]'
        '(-u --user_rule_file)'{-u,--user_rule_file}'[Read the file specified by Path <param> as a user rule file.]:file:->file'
        '(-j --execute_parallel)'{-j,--execute_parallel}'[Execute maximum <param> of multiple rules in parallel.]:number'
        '(-s -B --ignore_skip_if)'{-s,-B,--ignore_skip_if}'[Ignore SkipIfNotModified to not prevent building.]'
        '--ignore_skip_if_test''[Process SkipIfNotModified; ignore the test result.]'
        '(-h --help)'{-h,--help}'[Display a help message; then, exit.]'
        '--ignore_error[Execute other executable rules even if a rule fails to build.]'
        '--continue_on_error[Continue to run other executable rules even if a rule fails to build.]'
        '(-v --version)'{-v,--version}'[Display the version.]'
        '(-8 --utf8)'{-8,--utf8}'[Output logs in UTF8.]'
        '(-m --no_utf8)'{-m,--no_utf8}'[Output a log according to the default encoding (SJIS in the JP environment) of the system.]'
        '--print_timestamp[Add a log-output time at the top of each line in the log.]'
        '--print_time_elapsed[Add the time elapsed from the execution start time to the top of each line in the log.]'
        '--print_progress[Output the build progress status every <param> integer second.]:sedonds'
        '--no_print_progress[Do not output the build progress status.]'
        '--print_time_summary[Display the processing time when build is successul.]'
        '--print_time_detail[Display the processing time per rule and directory when build is successful.]'
        '--limit_program_lines[Limit the output display from the program to Line <param>.]:number of lines'
        '--print_process_id[Output Process ID at the top of each line output from the program.]'
        '--print_build_log_summary[Output build log summary.]'
        '--ui_culture[Specify the culture used to print UI messages.]:culture:(932 1252)'
        '--diagnostics_format[Output build log summary.]:style:(Clang Msvc)'
        '--output_active_rule_results[Output executing rule results.]:result'
        '--print_rule_files[Output the reading of rule files into a log.]'
        '--print_actions[Output executing action information to the log.]'
        '--print_results[Output the first one of the executing rule results into a log.]'
        '--print_objects[Output the dump of all instances into a log.]'
        '--print_objects_target_rule_file[Limit instances to output into a log by using --print-objects together.]:file:->file'
        '--print_objects_time[Output the time required to evaluate each instance member by using --print_objects together.]'
        '--print_rules[Output the dump of all rules into the log.]'
        '--print_rules_target[Limit rules to output into a log by using --print_rules together.]:regular expression'
        '--print_dependencies[Output the dump of dependent trees into a log.]'
        '--test_skip_if[Output whether results that match the regular expression <param> should be built and the decision factors.]:regular expression'
        '--print_includes[Output information on the result of processing an include instruction into a log.]'
        '--print_active_chain[Output active chains]'
        '--print_stage[Display the progress of nact processing.]'
        '--print_execute_info[When outputting a log for program execution, display the program execution environment.]'
        '--print_eval_trace[Display nact rule evaluation trace at the time of processing failure.]'
        '--print_executing_task_count[Include the number of active rules in the build status display.]'
        '--print_alias_tags[Display list of tags defined in Alias instances.]'
        '--print_alias_tags_target[Limit Alias tags to display when using --print_alias_tags.]:regular expression'
        '--output_perf_log[Output event tracing file (*.etl) specified by Path <param>.]:output file:->file'
        '--open_perf_monitor[Open Windows Performance Analayzer (WPA) by using --output_perf_log together.]'
        '--output_perf_json[Output build summary JSON to path <param> by using --output_perf_log together.]:output file:->file'
        '--perf_json_data_count[Specify the number of output tasks to build summary JSON.]:number of task'
    )

    param_specs=(
        'specs[Specify the development platform.]: :_nact_specs'
        'platforms[Specify the operating platform.]: :_nact_platforms'
        'BUILD[Specify build type for SDK.]: :_nact_builds'
        'outputs[Specify the build output.]: :_nact_outputs'
        'print-siglo-config[Specify whether to display the target platform information.]: :_nact_boolean'
        'generate-debug-info[Specify whether to generate the debug information. (only VC++)]: :_nact_boolean'
        'generate-dasm[(Tentative, subject to change) Specify whether to generate .dasm files. (GCC & Clang)]: :_nact_boolean'
        'generate-map[(Tentative, subject to change) Specify whether to generate .map files. (GCC & Clang)]: :_nact_boolean'
        'rynda-version[Specify the version of Rynda.]: :'
        'print-siglo-outputs[Specify whether to display the output information.]: :_nact_boolean'
        'documents-make-vs-help[Specify whether to build the API reference by the Visual Studio Help format.]: :_nact_boolean'
        'expanded-packages-root[Specify the target directory path on the output "expanded-packages".]: :_files -/'
        'packages-build-all[Specify whether to run forcefully all build rule of the outputs in the package before the creation of package.]: :_nact_boolean'
        'skip-download-prebuilt-results[Skip downloading of the prebuilt output.]: :_nact_boolean'
        'prebuilt-base-revision:[Specify which commit is the base point to trace back for the prebuilt output.]:revision'
        'prebuilt-search-ancestor-count[Specify how many commits to trace back for the prebuilt output.]:count:'
        'build-only-prebuilt-results[Build only the prebuilt output.]: :_nact_boolean'
        'enable-dmnt-force-debug[Grant "ForceDebug" capability to the dmnt process.]: :_nact_boolean'
        'enable-ssd-force-debug[Grant "ForceDebug" capability to SnapShotDumper.]: :_nact_boolean'
        'make-svc-veneer[Generate .S files for SVC library.]: :_nact_boolean'
        'update-only-dictionary-sources[Specify whether to update only source files without building dictionary libraries.]: :_nact_boolean'
    )

    target_specs=(
        "build[Run the build. When you don't specify the build mode, the build mode is 'build'.]"
        'clean[Remove the files generated by the build.]'
        'help[Display the user option list supported by the build system.]'
        'lint[Specify whether to run C++ coding convention checker.]'
    )

    if [[ $PREFIX == '-' ]]
    then
        _arguments -s $flag_specs
    else
        _arguments -s $flag_specs '*: :->params'
    fi

    case $state in
        (file)
        _description files expl "$state_descr"
        _files
        ;;

        (dir)
        _description directories expl "$state_descr"
        _files -/
        ;;

        (params)
        _values "buildsystem parameters" $param_specs && ret=0
        ;;

        (all)
        _values "" $param_specs $target_specs && ret=0
        ;;
    esac
}

compdef _nact nact nact3

