Skip to content
This repository has been archived by the owner on Nov 8, 2019. It is now read-only.

Commit

Permalink
Merge pull request #17 from spontoreau/feature/manifestPath
Browse files Browse the repository at this point in the history
Feature/manifest path
  • Loading branch information
spontoreau authored Feb 22, 2019
2 parents bbd2050 + 7d1908e commit e7784fc
Show file tree
Hide file tree
Showing 26 changed files with 136 additions and 72 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,10 @@ tmp/

# tfx
dist/
.taskkey
.taskkey

# rust
debug/**/target/

#macOS
.DS_Store
1 change: 1 addition & 0 deletions DETAILS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ By default, the task will install the latest stable version. You can also instal
Parameters:

- **Command**: Cargo subcommand to execute (example: build, test, update, install, doc...).
- **Working directory**: Working folder that contains Cargo.toml (optional).
- **Options**: Subcommand options (optional).

## Other tasks
Expand Down
8 changes: 4 additions & 4 deletions debug/cargo/noOptions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import debug from "../common/debug";

const cargoCommandInput = {
name: "cargoCommand",
value: "help"
const cargoCommandInput = {
name: "cargoCommand",
value: "help"
};

debug("cargo.js", cargoCommandInput);
debug("cargo.js", cargoCommandInput);
25 changes: 18 additions & 7 deletions debug/cargo/options.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import debug from "../common/debug";
import { join } from "path";

const cargoCommandInput = {
name: "cargoCommand",
value: "search"
const cargoCommandInput = {
name: "cargoCommand",
value: "build"
};

const cargoCommandOptionsInput = {
name: "cargoCommandOptions",
value: "rocket --limit 1"
const cargoCommandOptionsInput = {
name: "cargoCommandOptions",
value: "--release"
};

debug("cargo.js", cargoCommandInput, cargoCommandOptionsInput);
const cargoCommandWorkingDirectory = {
name: "cargoWorkingDir",
value: join(__dirname, "sample")
};

debug(
"cargo.js",
cargoCommandInput,
cargoCommandOptionsInput,
cargoCommandWorkingDirectory
);
6 changes: 6 additions & 0 deletions debug/cargo/sample/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions debug/cargo/sample/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "factorial"
version = "0.1.0"
authors = ["spontoreau <[email protected]>"]

[dependencies]
11 changes: 11 additions & 0 deletions debug/cargo/sample/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fn main() {
println!("Factorial of 0: {}", factorial(0));
println!("Factorial of 1: {}", factorial(1));
println!("Factorial of 2: {}", factorial(2));
println!("Factorial of 5: {}", factorial(5));
println!("Factorial of 9: {}", factorial(9));
}

fn factorial(n: u32) -> u32 {
return if n >= 1 { n * factorial(n - 1) } else { 1 };
}
11 changes: 5 additions & 6 deletions debug/common/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import { TaskMockRunner } from "azure-pipelines-task-lib/mock-run";
import { Input } from "./input";

export default (file: string, ...input: Input[]) => {
const taskPath = join(__dirname, "../../src", file);
const taskMockRunner = new TaskMockRunner(taskPath);
input.forEach(i => taskMockRunner.setInput(i.name, i.value));
taskMockRunner.run();
}

const taskPath = join(__dirname, "../../src", file);
const taskMockRunner = new TaskMockRunner(taskPath);
input.forEach(i => taskMockRunner.setInput(i.name, i.value));
taskMockRunner.run();
};
6 changes: 3 additions & 3 deletions debug/common/input.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface Input {
name: string,
value: string
}
name: string;
value: string;
}
8 changes: 4 additions & 4 deletions debug/install/default.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import debug from "../common/debug";

const installNightlyInput = {
name: "installNightly",
value: "false"
const installNightlyInput = {
name: "installNightly",
value: "false"
};

debug("install.js", installNightlyInput);
debug("install.js", installNightlyInput);
8 changes: 4 additions & 4 deletions debug/install/nigthly.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import debug from "../common/debug";

const installNightlyInput = {
name: "installNightly",
value: "true"
const installNightlyInput = {
name: "installNightly",
value: "true"
};

debug("install.js", installNightlyInput);
debug("install.js", installNightlyInput);
8 changes: 4 additions & 4 deletions debug/rustc/noOptions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import debug from "../common/debug";
import { join } from "path";

const rustcInput = {
name: "rustcInput",
value: join(__dirname, "test.rs")
const rustcInput = {
name: "rustcInput",
value: join(__dirname, "test.rs")
};

debug("rustc.js", rustcInput);
debug("rustc.js", rustcInput);
14 changes: 7 additions & 7 deletions debug/rustc/options.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import debug from "../common/debug";
import { join } from "path";

const rustcInput = {
name: "rustcInput",
value: join(__dirname, "test.rs")
const rustcInput = {
name: "rustcInput",
value: join(__dirname, "test.rs")
};

const rustcOptions = {
name: "rustcOptions",
value: "-o azure-devops-rustc-debug"
const rustcOptions = {
name: "rustcOptions",
value: "-o azure-devops-rustc-debug"
};

debug("rustc.js", rustcOptions, rustcInput);
debug("rustc.js", rustcOptions, rustcInput);
14 changes: 7 additions & 7 deletions debug/rustup/args.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import debug from "../common/debug";

const rustupCommandInput = {
name: "rustupCommand",
value: "target"
const rustupCommandInput = {
name: "rustupCommand",
value: "target"
};

const rustupCommandArgsInput = {
name: "rustupCommandArguments",
value: "list"
const rustupCommandArgsInput = {
name: "rustupCommandArguments",
value: "list"
};

debug("rustup.js", rustupCommandInput, rustupCommandArgsInput);
debug("rustup.js", rustupCommandInput, rustupCommandArgsInput);
8 changes: 4 additions & 4 deletions debug/rustup/noArgs.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import debug from "../common/debug";

const rustupCommandInput = {
name: "rustupCommand",
value: "show"
const rustupCommandInput = {
name: "rustupCommand",
value: "show"
};

debug("rustup.js", rustupCommandInput);
debug("rustup.js", rustupCommandInput);
Binary file modified images/doc-cargo-task.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build": "npm run format && gulp",
"package": "gulp pre-package && tfx extension create --root ./tmp --manifest-globs ./vss-extension.json --output-path ./dist",
"deploy": "tfx extension publish",
"format": "prettier --write \"{src, test}/**/*.ts\""
"format": "prettier --write \"src/**/*.ts\""
},
"repository": {
"type": "git",
Expand Down
10 changes: 8 additions & 2 deletions src/cargo.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { getInput } from "azure-pipelines-task-lib";
import { executeCommand, createCommand } from "./common/command";
import { join } from "path";
import { createCommand, executeCommand } from "./common/command";
import { launch } from "./common/launch";

const workingDir = getInput("cargoWorkingDir");
const manifestPath = !workingDir
? ""
: `--manifest-path ${join(workingDir, "Cargo.toml")}`;

const command = createCommand(
"cargo",
getInput("cargoCommand"),
getInput("cargoCommandOptions")
`${getInput("cargoCommandOptions")} ${manifestPath}`
);

launch(async () => await executeCommand(command));
22 changes: 13 additions & 9 deletions src/common/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ const executeCommand = async (
: Promise.reject(new Error("Rust toolchains are not available."));
};

const getToolArgs = (command: Command | InputCommand) => {
return isInputCommand(command)
const getToolArgs = (command: Command | InputCommand): string => {
const fullCommand = isInputCommand(command)
? [...command.args, command.input]
: [command.name, command.args];
: [command.name, ...command.args];
return fullCommand
.filter(p => p !== null && !p.includes("null"))
.reduce((p, n) => `${p} ${n}`)
.trim();
};

const isInputCommand = (command: any): command is InputCommand => {
Expand All @@ -43,9 +47,9 @@ const createCommand = (
options: string
): Command => {
return {
args: options.split(" "),
name: name,
tool: tool
args: !!options ? options.split(" ") : [],
name,
tool
};
};

Expand All @@ -55,9 +59,9 @@ const createInputCommand = (
options: string
): InputCommand => {
return {
args: options.split(" "),
input: input,
tool: tool
args: !!options ? options.split(" ") : [],
input,
tool
};
};

Expand Down
2 changes: 1 addition & 1 deletion src/common/path.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { homedir } from "os";
import { delimiter, join } from "path";
import process from "process";
import { homedir } from "os";

const addRustToolToPath = () => {
const toolPath = getToolPath();
Expand Down
8 changes: 5 additions & 3 deletions src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
tool,
which
} from "azure-pipelines-task-lib";
import { addRustToolToPath } from "./common/path";
import { executeCommand, createCommand } from "./common/command";
import { createCommand, executeCommand } from "./common/command";
import { launch } from "./common/launch";
import { addRustToolToPath } from "./common/path";

const nightly = getBoolInput("installNightly");

Expand Down Expand Up @@ -39,7 +39,9 @@ const installNightly = async () => {

const checkUpdateResult = (returnCode: Readonly<number>) => {
debug(`Return code: ${returnCode}`);
if (returnCode !== 0) throw new Error("Rustup update failed.");
if (returnCode !== 0) {
throw new Error("Rustup update failed.");
}
return "Rust updated";
};

Expand Down
2 changes: 1 addition & 1 deletion src/rustc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getInput } from "azure-pipelines-task-lib";
import { executeCommand, createInputCommand } from "./common/command";
import { createInputCommand, executeCommand } from "./common/command";
import { launch } from "./common/launch";

const command = createInputCommand(
Expand Down
2 changes: 1 addition & 1 deletion src/rustup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getInput } from "azure-pipelines-task-lib";
import { executeCommand, createCommand } from "./common/command";
import { createCommand, executeCommand } from "./common/command";
import { launch } from "./common/launch";

const command = createCommand(
Expand Down
8 changes: 8 additions & 0 deletions tasks/cargo/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
"defaultValue": "",
"required": true
},
{
"name": "cargoWorkingDir",
"type": "filePath",
"label": "Working folder that contains Cargo.toml",
"helpMarkDown": "Path to the folder containing the Cargo.toml file.",
"defaultValue": "",
"required": false
},
{
"name": "cargoCommandOptions",
"type": "string",
Expand Down
8 changes: 6 additions & 2 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"defaultSeverity": "error",
"extends": ["tslint:recommended"],
"extends": [
"tslint:recommended",
"tslint-config-prettier"
],
"jsRules": {},
"rules": {
"interface-name": [true, "never-prefix"],
"member-access": [true, "no-public"]
"member-access": [true, "no-public"],
"interface-over-type-literal": false
},
"rulesDirectory": []
}
2 changes: 1 addition & 1 deletion vss-extension.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifestVersion": 1,
"id": "rust-vsts",
"version": "1.0.{patch}",
"version": "1.1.{patch}",
"name": "Rust",
"description": "Rust extension for Azure DevOps",
"publisher": "spontoreau",
Expand Down

0 comments on commit e7784fc

Please sign in to comment.