1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124
//! # types
//!
//! Defines the various types and aliases used by cargo-make.
//!
#[cfg(test)]
#[path = "./types_test.rs"]
mod types_test;
use ci_info::types::CiInfo;
use indexmap::IndexMap;
use rust_info::types::RustInfo;
/// Returns the platform name
pub fn get_platform_name() -> String {
if cfg!(windows) {
"windows".to_string()
} else if cfg!(target_os = "macos") || cfg!(target_os = "ios") {
"mac".to_string()
} else {
"linux".to_string()
}
}
#[derive(Debug, Clone)]
/// Holds CLI args
pub struct CliArgs {
/// The command name
pub command: String,
/// The external Makefile.toml path
pub build_file: Option<String>,
/// The task to invoke
pub task: String,
/// Log level name
pub log_level: String,
/// Current working directory
pub cwd: Option<String>,
/// Environment variables
pub env: Option<Vec<String>>,
/// Environment variables file
pub env_file: Option<String>,
/// Prevent workspace support
pub disable_workspace: bool,
/// Prevent on error flow even if defined in config section
pub disable_on_error: bool,
/// Only print the execution plan
pub print_only: bool,
/// List all known steps
pub list_all_steps: bool,
/// Disables the update check during startup
pub disable_check_for_updates: bool,
/// Allows access unsupported experimental predefined tasks
pub experimental: bool,
/// additional command line arguments
pub arguments: Option<Vec<String>>,
/// Output format
pub output_format: String,
}
impl CliArgs {
/// Creates and returns a new instance.
pub fn new() -> CliArgs {
CliArgs {
command: "".to_string(),
build_file: None,
task: "default".to_string(),
log_level: "info".to_string(),
cwd: None,
env: None,
env_file: None,
disable_workspace: false,
disable_on_error: false,
print_only: false,
list_all_steps: false,
disable_check_for_updates: false,
experimental: false,
arguments: None,
output_format: "default".to_string(),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Holds persisted data used by cargo-make
pub struct Cache {
/// File from which the cache file was loaded from
#[serde(skip)]
pub file_name: Option<String>,
/// Holds last update check with returned no updates result
pub last_update_check: Option<u64>,
}
impl Cache {
/// Returns new instance
pub fn new() -> Cache {
Cache {
file_name: None,
last_update_check: None,
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Holds configuration info for cargo-make
pub struct GlobalConfig {
/// File from which the global config was loaded from
#[serde(skip)]
pub file_name: Option<String>,
/// Default log level
pub log_level: Option<String>,
/// Default task name
pub default_task_name: Option<String>,
/// Update check minimum time from the previous check (always, daily, weekly, monthly)
pub update_check_minimum_interval: Option<String>,
/// True to search for project root in parent directories if current cwd is not a project root
pub search_project_root: Option<bool>,
}
impl GlobalConfig {
/// Returns new instance
pub fn new() -> GlobalConfig {
GlobalConfig {
file_name: None,
log_level: None,
default_task_name: None,
update_check_minimum_interval: None,
search_project_root: Some(false),
}
}
}
#[derive(Debug, Clone)]
/// Holds git info for the given repo directory
pub struct GitInfo {
/// branch name
pub branch: Option<String>,
/// user.name
pub user_name: Option<String>,
/// user.email
pub user_email: Option<String>,
}
impl GitInfo {
/// Returns new instance
pub fn new() -> GitInfo {
GitInfo {
branch: None,
user_name: None,
user_email: None,
}
}
}
#[derive(Deserialize, Debug, Clone)]
/// Holds crate workspace info, see http://doc.crates.io/manifest.html#the-workspace-section
pub struct Workspace {
/// members paths
pub members: Option<Vec<String>>,
/// exclude paths
pub exclude: Option<Vec<String>>,
}
impl Workspace {
/// Creates and returns a new instance.
pub fn new() -> Workspace {
Workspace {
members: None,
exclude: None,
}
}
}
#[derive(Deserialize, Debug, Clone)]
/// Holds crate package information loaded from the Cargo.toml file package section.
pub struct PackageInfo {
/// name
pub name: Option<String>,
/// version
pub version: Option<String>,
/// description
pub description: Option<String>,
/// license
pub license: Option<String>,
/// documentation link
pub documentation: Option<String>,
/// homepage link
pub homepage: Option<String>,
/// repository link
pub repository: Option<String>,
}
impl PackageInfo {
/// Creates and returns a new instance.
pub fn new() -> PackageInfo {
PackageInfo {
name: None,
version: None,
description: None,
license: None,
documentation: None,
homepage: None,
repository: None,
}
}
}
#[derive(Deserialize, Debug, Clone)]
/// Holds crate dependency info.
pub struct CrateDependencyInfo {
/// Holds the dependency path
pub path: Option<String>,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(untagged)]
/// Holds crate dependency info.
pub enum CrateDependency {
/// Holds the dependency version
Version(String),
/// Hold dependency info
Info(CrateDependencyInfo),
}
#[derive(Deserialize, Debug, Clone)]
/// Holds crate information loaded from the Cargo.toml file.
pub struct CrateInfo {
/// package info
pub package: Option<PackageInfo>,
/// workspace info
pub workspace: Option<Workspace>,
/// crate dependencies
pub dependencies: Option<IndexMap<String, CrateDependency>>,
}
impl CrateInfo {
/// Creates and returns a new instance.
pub fn new() -> CrateInfo {
CrateInfo {
package: None,
workspace: None,
dependencies: None,
}
}
}
#[derive(Debug, Clone)]
/// Holds env information
pub struct EnvInfo {
/// Rust info
pub rust_info: RustInfo,
/// Crate info
pub crate_info: CrateInfo,
/// Git info
pub git_info: GitInfo,
/// CI info
pub ci_info: CiInfo,
}
#[derive(Debug, Clone)]
/// Holds flow information
pub struct FlowInfo {
/// The flow config object
pub config: Config,
/// The main task of the flow
pub task: String,
/// The env info
pub env_info: EnvInfo,
/// Prevent workspace support
pub disable_workspace: bool,
/// Prevent on error flow even if defined in config section
pub disable_on_error: bool,
/// additional command line arguments
pub cli_arguments: Option<Vec<String>>,
}
#[derive(Deserialize, Debug, Clone)]
/// Rust version condition structure
pub struct RustVersionCondition {
/// min version number
pub min: Option<String>,
/// max version number
pub max: Option<String>,
/// specific version number
pub equal: Option<String>,
}
#[derive(Deserialize, Debug, Clone)]
/// Holds condition attributes
pub struct TaskCondition {
/// Platform names (linux, windows, mac)
pub platforms: Option<Vec<String>>,
/// Channel names (stable, beta, nightly)
pub channels: Option<Vec<String>>,
/// Environment variables which must be defined
pub env_set: Option<Vec<String>>,
/// Environment variables which must not be defined
pub env_not_set: Option<Vec<String>>,
/// Environment variables and their values
pub env: Option<IndexMap<String, String>>,
/// Rust version condition
pub rust_version: Option<RustVersionCondition>,
}
#[derive(Deserialize, Debug, Clone)]
/// Holds a single task configuration such as command and dependencies list
pub struct EnvValueInfo {
/// The script to execute to get the env value
pub script: Vec<String>,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(untagged)]
/// Holds the env value or script
pub enum EnvValue {
/// The value as string
Value(String),
/// Script which will return the value
Info(EnvValueInfo),
}
#[derive(Deserialize, Debug, Clone)]
/// Holds instructions how to install the crate
pub struct InstallCrateInfo {
/// The provided crate to install
pub crate_name: String,
/// If defined, the component to install via rustup
pub rustup_component_name: Option<String>,
/// The binary file name to be used to test if the crate is already installed
pub binary: String,
/// Test argument that will be used to check that the crate is installed
pub test_arg: String,
}
impl PartialEq for InstallCrateInfo {
fn eq(&self, other: &InstallCrateInfo) -> bool {
if self.crate_name != other.crate_name
|| self.binary != other.binary
|| self.test_arg != other.test_arg
{
false
} else {
match self.rustup_component_name {
Some(ref value) => match other.rustup_component_name {
Some(ref other_value) => value == other_value,
None => false,
},
None => match other.rustup_component_name {
None => true,
_ => false,
},
}
}
}
}
#[derive(Deserialize, Debug, Clone)]
/// Holds instructions how to install a rustup component
pub struct InstallRustupComponentInfo {
/// The component to install via rustup
pub rustup_component_name: String,
/// The binary file name to be used to test if the crate is already installed
pub binary: Option<String>,
/// Test argument that will be used to check that the crate is installed
pub test_arg: Option<String>,
}
impl PartialEq for InstallRustupComponentInfo {
fn eq(&self, other: &InstallRustupComponentInfo) -> bool {
if self.rustup_component_name != other.rustup_component_name {
false
} else {
let same = match self.binary {
Some(ref value) => match other.binary {
Some(ref other_value) => value == other_value,
None => false,
},
None => match other.binary {
None => true,
_ => false,
},
};
if same {
match self.test_arg {
Some(ref value) => match other.test_arg {
Some(ref other_value) => value == other_value,
None => false,
},
None => match other.test_arg {
None => true,
_ => false,
},
}
} else {
false
}
}
}
}
#[derive(Deserialize, Debug, Clone)]
#[serde(untagged)]
/// Install crate name or params
pub enum InstallCrate {
/// The value as string
Value(String),
/// Install crate params
CrateInfo(InstallCrateInfo),
/// Install rustup component params
RustupComponentInfo(InstallRustupComponentInfo),
}
impl PartialEq for InstallCrate {
fn eq(&self, other: &InstallCrate) -> bool {
match self {
InstallCrate::Value(value) => match other {
InstallCrate::Value(other_value) => value == other_value,
_ => false,
},
InstallCrate::CrateInfo(info) => match other {
InstallCrate::CrateInfo(other_info) => info == other_info,
_ => false,
},
InstallCrate::RustupComponentInfo(info) => match other {
InstallCrate::RustupComponentInfo(other_info) => info == other_info,
_ => false,
},
}
}
}
#[derive(Deserialize, Debug, Clone)]
/// Holds a single task configuration such as command and dependencies list
pub struct Task {
/// if true, it should ignore all data in base task
pub clear: Option<bool>,
/// Task description
pub description: Option<String>,
/// Category name used to document the task
pub category: Option<String>,
/// if true, the command/script of this task will not be invoked, dependencies however will be
pub disabled: Option<bool>,
/// if true, the task is hidden from the list of available tasks and also cannot be invoked directly from cli
pub private: Option<bool>,
/// set to false to notify cargo-make that this is not a workspace and should not call task for every member (same as --no-workspace CLI flag)
pub workspace: Option<bool>,
/// if provided all condition values must be met in order for the task to be invoked (will not stop dependencies)
pub condition: Option<TaskCondition>,
/// if script exit code is not 0, the command/script of this task will not be invoked, dependencies however will be
pub condition_script: Option<Vec<String>>,
/// if true, any error while executing the task will be printed but will not break the build
pub force: Option<bool>,
/// The env vars to setup before running the task commands
pub env: Option<IndexMap<String, EnvValue>>,
/// The working directory for the task to execute its command/script
pub cwd: Option<String>,
/// if defined, task points to another task and all other properties are ignored
pub alias: Option<String>,
/// acts like alias if runtime OS is Linux (takes precedence over alias)
pub linux_alias: Option<String>,
/// acts like alias if runtime OS is Windows (takes precedence over alias)
pub windows_alias: Option<String>,
/// acts like alias if runtime OS is Mac (takes precedence over alias)
pub mac_alias: Option<String>,
/// if defined, the provided crate will be installed (if needed) before running the task
pub install_crate: Option<InstallCrate>,
/// additional cargo install arguments
pub install_crate_args: Option<Vec<String>>,
/// if defined, the provided script will be executed before running the task
pub install_script: Option<Vec<String>>,
/// The command to execute
pub command: Option<String>,
/// The command args
pub args: Option<Vec<String>>,
/// If command is not defined, and script is defined, the provided script will be executed
pub script: Option<Vec<String>>,
/// The script runner (defaults to cmd in windows and sh for other platforms)
pub script_runner: Option<String>,
/// The script file extension
pub script_extension: Option<String>,
/// The task name to execute
pub run_task: Option<String>,
/// A list of tasks to execute before this task
pub dependencies: Option<Vec<String>>,
/// The rust toolchain used to invoke the command or install the needed crates/components
pub toolchain: Option<String>,
/// override task if runtime OS is Linux (takes precedence over alias)
pub linux: Option<PlatformOverrideTask>,
/// override task if runtime OS is Windows (takes precedence over alias)
pub windows: Option<PlatformOverrideTask>,
/// override task if runtime OS is Mac (takes precedence over alias)
pub mac: Option<PlatformOverrideTask>,
}
impl Task {
/// Creates and returns a new instance.
pub fn new() -> Task {
Task {
clear: None,
description: None,
category: None,
disabled: None,
private: None,
workspace: None,
condition: None,
condition_script: None,
force: None,
env: None,
cwd: None,
alias: None,
linux_alias: None,
windows_alias: None,
mac_alias: None,
install_crate: None,
install_crate_args: None,
install_script: None,
command: None,
args: None,
script: None,
script_runner: None,
script_extension: None,
run_task: None,
dependencies: None,
toolchain: None,
linux: None,
windows: None,
mac: None,
}
}
/// Copies values from the task into self.
///
/// # Arguments
///
/// * `task` - The task to copy from
pub fn extend(self: &mut Task, task: &Task) {
let override_values = match task.clear {
Some(value) => value,
None => false,
};
if task.clear.is_some() {
self.clear = task.clear.clone();
}
if task.description.is_some() {
self.description = task.description.clone();
} else if override_values {
self.description = None;
}
if task.category.is_some() {
self.category = task.category.clone();
} else if override_values {
self.category = None;
}
if task.disabled.is_some() {
self.disabled = task.disabled.clone();
} else if override_values {
self.disabled = None;
}
if task.private.is_some() {
self.private = task.private.clone();
} else if override_values {
self.private = None;
}
if task.workspace.is_some() {
self.workspace = task.workspace.clone();
} else if override_values {
self.workspace = None;
}
if task.condition.is_some() {
self.condition = task.condition.clone();
} else if override_values {
self.condition = None;
}
if task.condition_script.is_some() {
self.condition_script = task.condition_script.clone();
} else if override_values {
self.condition_script = None;
}
if task.force.is_some() {
self.force = task.force.clone();
} else if override_values {
self.force = None;
}
if task.env.is_some() {
self.env = task.env.clone();
} else if override_values {
self.env = None;
}
if task.cwd.is_some() {
self.cwd = task.cwd.clone();
} else if override_values {
self.cwd = None;
}
if task.alias.is_some() {
self.alias = task.alias.clone();
} else if override_values {
self.alias = None;
}
if task.linux_alias.is_some() {
self.linux_alias = task.linux_alias.clone();
} else if override_values {
self.linux_alias = None;
}
if task.windows_alias.is_some() {
self.windows_alias = task.windows_alias.clone();
} else if override_values {
self.windows_alias = None;
}
if task.mac_alias.is_some() {
self.mac_alias = task.mac_alias.clone();
} else if override_values {
self.mac_alias = None;
}
if task.install_crate.is_some() {
self.install_crate = task.install_crate.clone();
} else if override_values {
self.install_crate = None;
}
if task.install_crate_args.is_some() {
self.install_crate_args = task.install_crate_args.clone();
} else if override_values {
self.install_crate_args = None;
}
if task.install_script.is_some() {
self.install_script = task.install_script.clone();
} else if override_values {
self.install_script = None;
}
if task.command.is_some() {
self.command = task.command.clone();
} else if override_values {
self.command = None;
}
if task.args.is_some() {
self.args = task.args.clone();
} else if override_values {
self.args = None;
}
if task.script.is_some() {
self.script = task.script.clone();
} else if override_values {
self.script = None;
}
if task.script_runner.is_some() {
self.script_runner = task.script_runner.clone();
} else if override_values {
self.script_runner = None;
}
if task.script_extension.is_some() {
self.script_extension = task.script_extension.clone();
} else if override_values {
self.script_extension = None;
}
if task.run_task.is_some() {
self.run_task = task.run_task.clone();
} else if override_values {
self.run_task = None;
}
if task.dependencies.is_some() {
self.dependencies = task.dependencies.clone();
} else if override_values {
self.dependencies = None;
}
if task.toolchain.is_some() {
self.toolchain = task.toolchain.clone();
} else if override_values {
self.toolchain = None;
}
if task.linux.is_some() {
self.linux = task.linux.clone();
} else if override_values {
self.linux = None;
}
if task.windows.is_some() {
self.windows = task.windows.clone();
} else if override_values {
self.windows = None;
}
if task.mac.is_some() {
self.mac = task.mac.clone();
} else if override_values {
self.mac = None;
}
}
/// Returns true if the task force attribute is defined and true
pub fn is_force(self: &Task) -> bool {
self.force.unwrap_or(false)
}
/// Returns the override task definition based on the current platform.
fn get_override(self: &Task) -> Option<PlatformOverrideTask> {
let platform_name = get_platform_name();
if platform_name == "windows" {
match self.windows {
Some(ref value) => Some(value.clone()),
_ => None,
}
} else if platform_name == "mac" {
match self.mac {
Some(ref value) => Some(value.clone()),
_ => None,
}
} else {
match self.linux {
Some(ref value) => Some(value.clone()),
_ => None,
}
}
}
/// Returns a new task based on the override information and current platform.
pub fn get_normalized_task(self: &mut Task) -> Task {
match self.get_override() {
Some(ref mut override_task) => {
override_task.extend(self);
Task {
clear: self.clear.clone(),
description: self.description.clone(),
category: self.category.clone(),
disabled: override_task.disabled.clone(),
private: override_task.private.clone(),
workspace: self.workspace.clone(),
condition: override_task.condition.clone(),
condition_script: override_task.condition_script.clone(),
force: override_task.force.clone(),
env: override_task.env.clone(),
cwd: override_task.cwd.clone(),
alias: None,
linux_alias: None,
windows_alias: None,
mac_alias: None,
install_crate: override_task.install_crate.clone(),
install_crate_args: override_task.install_crate_args.clone(),
install_script: override_task.install_script.clone(),
command: override_task.command.clone(),
args: override_task.args.clone(),
script: override_task.script.clone(),
script_runner: override_task.script_runner.clone(),
script_extension: override_task.script_extension.clone(),
run_task: override_task.run_task.clone(),
dependencies: override_task.dependencies.clone(),
toolchain: override_task.toolchain.clone(),
linux: None,
windows: None,
mac: None,
}
}
None => self.clone(),
}
}
/// Returns the alias value based on the current platform and task definition.
pub fn get_alias(self: &Task) -> Option<String> {
let alias = if cfg!(windows) {
match self.windows_alias {
Some(ref value) => Some(value),
_ => None,
}
} else if cfg!(target_os = "macos") || cfg!(target_os = "ios") {
match self.mac_alias {
Some(ref value) => Some(value),
_ => None,
}
} else {
match self.linux_alias {
Some(ref value) => Some(value),
_ => None,
}
};
match alias {
Some(os_alias) => Some(os_alias.clone()),
_ => match self.alias {
Some(ref alias) => Some(alias.clone()),
_ => None,
},
}
}
/// Returns true if the task is valid
pub fn is_valid(self: &Task) -> bool {
let mut actions_count = 0;
if self.run_task.is_some() {
actions_count = actions_count + 1;
}
if self.command.is_some() {
actions_count = actions_count + 1;
}
if self.script.is_some() {
actions_count = actions_count + 1;
}
if actions_count <= 1 {
true
} else {
false
}
}
}
#[derive(Deserialize, Debug, Clone)]
/// Holds a single task configuration for a specific platform as an override of another task
pub struct PlatformOverrideTask {
/// if true, it should ignore all data in base task
pub clear: Option<bool>,
/// if true, the command/script of this task will not be invoked, dependencies however will be
pub disabled: Option<bool>,
/// if true, the task is hidden from the list of available tasks and also cannot be invoked directly from cli
pub private: Option<bool>,
/// if provided all condition values must be met in order for the task to be invoked (will not stop dependencies)
pub condition: Option<TaskCondition>,
/// if script exit code is not 0, the command/script of this task will not be invoked, dependencies however will be
pub condition_script: Option<Vec<String>>,
/// if true, any error while executing the task will be printed but will not break the build
pub force: Option<bool>,
/// The env vars to setup before running the task commands
pub env: Option<IndexMap<String, EnvValue>>,
/// The working directory for the task to execute its command/script
pub cwd: Option<String>,
/// if defined, the provided crate will be installed (if needed) before running the task
pub install_crate: Option<InstallCrate>,
/// additional cargo install arguments
pub install_crate_args: Option<Vec<String>>,
/// if defined, the provided script will be executed before running the task
pub install_script: Option<Vec<String>>,
/// The command to execute
pub command: Option<String>,
/// The command args
pub args: Option<Vec<String>>,
/// If command is not defined, and script is defined, the provided script will be executed
pub script: Option<Vec<String>>,
/// The script runner (defaults to cmd in windows and sh for other platforms)
pub script_runner: Option<String>,
/// The script file extension
pub script_extension: Option<String>,
/// The task name to execute
pub run_task: Option<String>,
/// A list of tasks to execute before this task
pub dependencies: Option<Vec<String>>,
/// The rust toolchain used to invoke the command or install the needed crates/components
pub toolchain: Option<String>,
}
impl PlatformOverrideTask {
/// Copies values from the task into self.
///
/// # Arguments
///
/// * `task` - The task to copy from
pub fn extend(self: &mut PlatformOverrideTask, task: &mut Task) {
let copy_values = match self.clear {
Some(value) => !value,
None => true,
};
if copy_values {
if self.disabled.is_none() && task.disabled.is_some() {
self.disabled = task.disabled.clone();
}
if self.private.is_none() && task.private.is_some() {
self.private = task.private.clone();
}
if self.condition.is_none() && task.condition.is_some() {
self.condition = task.condition.clone();
}
if self.condition_script.is_none() && task.condition_script.is_some() {
self.condition_script = task.condition_script.clone();
}
if self.force.is_none() && task.force.is_some() {
self.force = task.force.clone();
}
if self.env.is_none() && task.env.is_some() {
self.env = task.env.clone();
}
if self.cwd.is_none() && task.cwd.is_some() {
self.cwd = task.cwd.clone();
}
if self.install_crate.is_none() && task.install_crate.is_some() {
self.install_crate = task.install_crate.clone();
}
if self.install_crate_args.is_none() && task.install_crate_args.is_some() {
self.install_crate_args = task.install_crate_args.clone();
}
if self.install_script.is_none() && task.install_script.is_some() {
self.install_script = task.install_script.clone();
}
if self.command.is_none() && task.command.is_some() {
self.command = task.command.clone();
}
if self.args.is_none() && task.args.is_some() {
self.args = task.args.clone();
}
if self.script.is_none() && task.script.is_some() {
self.script = task.script.clone();
}
if self.script_runner.is_none() && task.script_runner.is_some() {
self.script_runner = task.script_runner.clone();
}
if self.script_extension.is_none() && task.script_extension.is_some() {
self.script_extension = task.script_extension.clone();
}
if self.run_task.is_none() && task.run_task.is_some() {
self.run_task = task.run_task.clone();
}
if self.dependencies.is_none() && task.dependencies.is_some() {
self.dependencies = task.dependencies.clone();
}
if self.toolchain.is_none() && task.toolchain.is_some() {
self.toolchain = task.toolchain.clone();
}
}
}
}
#[derive(Deserialize, Debug, Clone)]
/// Holds the configuration found in the makefile toml config section.
pub struct ConfigSection {
/// If true, the default core tasks will not be loaded
pub skip_core_tasks: Option<bool>,
/// Init task name which will be invoked at the start of every run
pub init_task: Option<String>,
/// End task name which will be invoked at the end of every run
pub end_task: Option<String>,
/// The name of the task to run in case of any error during the invocation of the flow
pub on_error_task: Option<String>,
/// Invoked while loading the descriptor file but before loading any extended descriptor
pub load_script: Option<Vec<String>>,
/// acts like load_script if runtime OS is Linux (takes precedence over load_script)
pub linux_load_script: Option<Vec<String>>,
/// acts like load_script if runtime OS is Windows (takes precedence over load_script)
pub windows_load_script: Option<Vec<String>>,
/// acts like load_script if runtime OS is Mac (takes precedence over load_script)
pub mac_load_script: Option<Vec<String>>,
}
impl ConfigSection {
/// Creates and returns a new instance.
pub fn new() -> ConfigSection {
ConfigSection {
skip_core_tasks: None,
init_task: None,
end_task: None,
on_error_task: None,
load_script: None,
linux_load_script: None,
windows_load_script: None,
mac_load_script: None,
}
}
/// Copies values from the config section into self.
///
/// # Arguments
///
/// * `task` - The task to copy from
pub fn extend(self: &mut ConfigSection, extended: &mut ConfigSection) {
if extended.skip_core_tasks.is_some() {
self.skip_core_tasks = extended.skip_core_tasks.clone();
}
if extended.init_task.is_some() {
self.init_task = extended.init_task.clone();
}
if extended.end_task.is_some() {
self.end_task = extended.end_task.clone();
}
if extended.on_error_task.is_some() {
self.on_error_task = extended.on_error_task.clone();
}
if extended.load_script.is_some() {
self.load_script = extended.load_script.clone();
}
if extended.linux_load_script.is_some() {
self.linux_load_script = extended.linux_load_script.clone();
}
if extended.windows_load_script.is_some() {
self.windows_load_script = extended.windows_load_script.clone();
}
if extended.mac_load_script.is_some() {
self.mac_load_script = extended.mac_load_script.clone();
}
}
/// Returns the load script based on the current platform
pub fn get_load_script(self: &ConfigSection) -> Option<Vec<String>> {
let platform_name = get_platform_name();
if platform_name == "windows" {
if self.windows_load_script.is_some() {
self.windows_load_script.clone()
} else {
self.load_script.clone()
}
} else if platform_name == "mac" {
if self.mac_load_script.is_some() {
self.mac_load_script.clone()
} else {
self.load_script.clone()
}
} else {
if self.linux_load_script.is_some() {
self.linux_load_script.clone()
} else {
self.load_script.clone()
}
}
}
}
#[derive(Deserialize, Debug, Clone)]
/// Holds the entire configuration such as task definitions and env vars
pub struct Config {
/// Runtime config
pub config: ConfigSection,
/// The env vars to setup before running the tasks
pub env: IndexMap<String, EnvValue>,
/// All task definitions
pub tasks: IndexMap<String, Task>,
}
#[derive(Deserialize, Debug, Clone)]
/// Holds the entire externally read configuration such as task definitions and env vars where all values are optional
pub struct ExternalConfig {
/// Path to another toml file to extend
pub extend: Option<String>,
/// Runtime config
pub config: Option<ConfigSection>,
/// The env vars to setup before running the tasks
pub env: Option<IndexMap<String, EnvValue>>,
/// All task definitions
pub tasks: Option<IndexMap<String, Task>>,
}
impl ExternalConfig {
/// Creates and returns a new instance.
pub fn new() -> ExternalConfig {
ExternalConfig {
extend: None,
config: None,
env: None,
tasks: None,
}
}
}
#[derive(Debug)]
/// Execution plan step to execute
pub struct Step {
/// The task name
pub name: String,
/// The task config
pub config: Task,
}
#[derive(Debug)]
/// Execution plan which defines all steps to run and the order to run them
pub struct ExecutionPlan {
/// A list of steps to execute
pub steps: Vec<Step>,
}
#[derive(Debug)]
/// Command info
pub struct CommandSpec {
/// The command to execute
pub command: String,
/// The command args
pub args: Option<Vec<String>>,
}