Skip to content

Commit

Permalink
First public release
Browse files Browse the repository at this point in the history
  • Loading branch information
valff committed Sep 20, 2019
1 parent ef66d23 commit 94f25b8
Show file tree
Hide file tree
Showing 24 changed files with 268 additions and 129 deletions.
112 changes: 55 additions & 57 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ members = ["config"]

[package]
name = "drone"
version = "0.9.0"
version = "0.10.0"
authors = ["Valentine Valyaeff <[email protected]>"]
edition = "2018"
default-run = "drone"
repository = "https://github.com/drone-os/drone"
homepage = "https://www.drone-os.com/"
readme = "README.md"
license = "MIT OR Apache-2.0"
keywords = [
Expand All @@ -32,7 +33,7 @@ CLI utility for Drone, an Embedded Operating System.
maintenance = { status = "actively-developed" }

[dependencies.drone-config]
version = "=0.9.0"
version = "=0.10.0"
path = "config"

[dependencies]
Expand Down
14 changes: 11 additions & 3 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,23 @@ doc-open: doc
test:
cargo test

# Install the binaries
install:
cargo install --path . --debug --force

# Update README.md
readme:
cargo readme -o README.md

# Install the binaries
install:
cargo install --path . --debug --force
# Bump crate versions
version-bump version:
sed -i '/\[.*\]/h;/version = ".*"/{x;s/\[package\]/version = "{{version}}"/;t;x}' \
Cargo.toml config/Cargo.toml
sed -i '/\[.*\]/h;/version = "=.*"/{x;s/\[.*drone-.*\]/version = "={{version}}"/;t;x}' \
Cargo.toml

# Publish to crates.io
publish:
cd config && cargo publish
sleep 5
cargo publish
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
[![Crates.io](https://img.shields.io/crates/v/drone.svg)](https://crates.io/crates/drone)
[![crates.io](https://img.shields.io/crates/v/drone.svg)](https://crates.io/crates/drone)
![maintenance](https://img.shields.io/badge/maintenance-actively--developed-brightgreen.svg)

# drone

CLI utility for Drone, an Embedded Operating System.

## Documentation

Refer to the [Drone Book](https://book.drone-os.com/) for documentation.

## Usage

The program requires Nightly channel of Rust. Make sure you have it
installed:

```shell
$ rustup toolchain install nightly
```

Install the latest version from crates.io:

```shell
$ cargo +nightly install drone
```

Check the built-in help:

```shell
$ drone help
```

## License

Licensed under either of
Expand Down
3 changes: 2 additions & 1 deletion README.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![Crates.io](https://img.shields.io/crates/v/{{crate}}.svg)](https://crates.io/crates/{{crate}})
[![crates.io](https://img.shields.io/crates/v/{{crate}}.svg)](https://crates.io/crates/{{crate}})
![maintenance](https://img.shields.io/badge/maintenance-actively--developed-brightgreen.svg)

# {{crate}}

Expand Down
3 changes: 2 additions & 1 deletion config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[package]
name = "drone-config"
version = "0.9.0"
version = "0.10.0"
authors = ["Valentine Valyaeff <[email protected]>"]
edition = "2018"
repository = "https://github.com/drone-os/drone"
homepage = "https://www.drone-os.com/"
license = "MIT OR Apache-2.0"
description = """
Configuration for Drone, an Embedded Operating System.
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2019-08-26
nightly-2019-09-13
13 changes: 9 additions & 4 deletions src/bmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
utils::{mask_signals, run_command, temp_dir},
};
use drone_config as config;
use failure::Error;
use failure::{format_err, Error};
use std::{
ffi::CString,
fs::OpenOptions,
Expand Down Expand Up @@ -101,11 +101,14 @@ impl BmpItmCmd {
let dir = tempdir_in(temp_dir())?;
let pipe = make_fifo(&dir)?;
let script = registry.bmp_itm(&config, ports, *reset, &pipe)?;
let mut gdb = Command::new(&config.bmp()?.gdb_command);
let gdb_command = &config.bmp()?.gdb_command;
let mut gdb = Command::new(gdb_command);
gdb.arg("--nx");
gdb.arg("--batch");
gdb.arg("--command").arg(script.path());
let mut gdb = gdb.spawn()?;
let mut gdb = gdb
.spawn()
.map_err(|err| format_err!("`{}` command failed to start: {}", gdb_command, err))?;

let mut packet = [0];
OpenOptions::new()
Expand All @@ -117,7 +120,9 @@ impl BmpItmCmd {
let mut itmsink = Command::new("itmsink");
itmsink.arg("--input").arg(&config.bmp()?.uart_endpoint);
itmsink.args(itmsink_args);
let mut itmsink = itmsink.spawn()?;
let mut itmsink = itmsink
.spawn()
.map_err(|err| format_err!("`itmsink` command failed to start: {}", err))?;

shell.set_color(ColorSpec::new().set_bold(true).set_fg(Some(Color::Cyan)))?;
writeln!(shell)?;
Expand Down
3 changes: 3 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ pub struct NewCmd {
/// Set the resulting package name, defaults to the directory name
#[structopt(long)]
pub name: Option<String>,
/// Toolchain name, such as 'nightly' or 'nightly-2019-09-05'
#[structopt(long, default_value = "nightly")]
pub toolchain: String,
}

#[derive(Debug, StructOpt)]
Expand Down
22 changes: 22 additions & 0 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,26 @@ impl Device {
| Self::Stm32L4S9 => 0x2000_0000,
}
}

/// Returns a list of features for the `drone-stm32-map` dependency.
pub fn drone_stm32_map_features(&self) -> &[&str] {
match self {
Self::Stm32F100
| Self::Stm32F101
| Self::Stm32F102
| Self::Stm32F103
| Self::Stm32F107 => &[],
Self::Stm32L4X1
| Self::Stm32L4X2
| Self::Stm32L4X3
| Self::Stm32L4X5
| Self::Stm32L4X6
| Self::Stm32L4R5
| Self::Stm32L4R7
| Self::Stm32L4R9
| Self::Stm32L4S5
| Self::Stm32L4S7
| Self::Stm32L4S9 => &["fpu"],
}
}
}
26 changes: 25 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
//! CLI utility for Drone, an Embedded Operating System.
//!
//! # Documentation
//!
//! Refer to the [Drone Book](https://book.drone-os.com/) for documentation.
//!
//! # Usage
//!
//! The program requires Nightly channel of Rust. Make sure you have it
//! installed:
//!
//! ```shell
//! $ rustup toolchain install nightly
//! ```
//!
//! Install the latest version from crates.io:
//!
//! ```shell
//! $ cargo +nightly install drone
//! ```
//!
//! Check the built-in help:
//!
//! ```shell
//! $ drone help
//! ```
#![feature(generator_trait)]
#![feature(generators)]
Expand All @@ -10,7 +35,6 @@
clippy::cast_possible_truncation,
clippy::cast_precision_loss,
clippy::cast_sign_loss,
clippy::module_name_repetitions,
clippy::similar_names
)]

Expand Down
70 changes: 48 additions & 22 deletions src/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
};
use failure::{bail, format_err, Error};
use std::{
fs::{create_dir, read_to_string, File, OpenOptions},
fs::{create_dir, read_to_string, remove_file, File, OpenOptions},
io::Write,
path::Path,
};
Expand All @@ -23,6 +23,7 @@ impl NewCmd {
flash_size,
ram_size,
name,
toolchain,
} = self;
let registry = Registry::new()?;
let name = name.as_ref().map(String::as_str).map_or_else(
Expand All @@ -49,38 +50,47 @@ impl NewCmd {
.collect::<String>();
mask_signals();

cargo_new(path)?;
src_main_rs(path, &underscore_name, &registry, shell)?;
cargo_new(path, &toolchain)?;
src_main_rs(path, shell)?;
src_bin_rs(path, &underscore_name, &registry, shell)?;
src_lib_rs(path, &registry, shell)?;
src_thr_mod_rs(path, &registry, shell)?;
src_thr_trunk_rs(path, &registry, shell)?;
src_thr_rs(path, &registry, shell)?;
src_tasks_mod_rs(path, &registry, shell)?;
src_tasks_root_rs(path, &registry, shell)?;
cargo_toml(path, &name, &device, &registry, shell)?;
drone_toml(path, &device, *flash_size, *ram_size, &registry, shell)?;
justfile(path, &device, &registry, shell)?;
rust_toolchain(path, &registry, shell)?;
rust_toolchain(path, &toolchain, &registry, shell)?;
cargo_config(path, &registry, shell)?;
gitignore(path, &registry, shell)?;

Ok(())
}
}

fn cargo_new(path: &Path) -> Result<(), Error> {
run_command(Path::new("cargo"), |cargo| {
cargo.arg("+nightly").arg("new").arg("--bin").arg(path);
fn cargo_new(path: &Path, toolchain: &str) -> Result<(), Error> {
run_command(Path::new("rustup"), |rustup| {
rustup.arg("run").arg(toolchain);
rustup.arg("cargo").arg("new").arg("--bin").arg(path);
})
}

fn src_main_rs(
fn src_main_rs(path: &Path, shell: &mut StandardStream) -> Result<(), Error> {
let path = path.join("src/main.rs");
remove_file(path)?;
print_removed(shell, "src/main.rs")
}

fn src_bin_rs(
path: &Path,
name: &str,
registry: &Registry,
shell: &mut StandardStream,
) -> Result<(), Error> {
let path = path.join("src/main.rs");
let path = path.join("src/bin.rs");
let mut file = File::create(&path)?;
file.write_all(registry.new_src_main_rs(name)?.as_bytes())?;
print_patched(shell, "src/main.rs")
file.write_all(registry.new_src_bin_rs(name)?.as_bytes())?;
print_created(shell, "src/bin.rs")
}

fn src_lib_rs(path: &Path, registry: &Registry, shell: &mut StandardStream) -> Result<(), Error> {
Expand All @@ -90,28 +100,35 @@ fn src_lib_rs(path: &Path, registry: &Registry, shell: &mut StandardStream) -> R
print_created(shell, "src/lib.rs")
}

fn src_thr_mod_rs(
fn src_thr_rs(path: &Path, registry: &Registry, shell: &mut StandardStream) -> Result<(), Error> {
let path = path.join("src/thr.rs");
let mut file = File::create(&path)?;
file.write_all(registry.new_src_thr_rs()?.as_bytes())?;
print_created(shell, "src/thr.rs")
}

fn src_tasks_mod_rs(
path: &Path,
registry: &Registry,
shell: &mut StandardStream,
) -> Result<(), Error> {
let path = path.join("src/thr");
let path = path.join("src/tasks");
create_dir(&path)?;
let path = path.join("mod.rs");
let mut file = File::create(&path)?;
file.write_all(registry.new_src_thr_mod_rs()?.as_bytes())?;
print_created(shell, "src/thr/mod.rs")
file.write_all(registry.new_src_tasks_mod_rs()?.as_bytes())?;
print_created(shell, "src/tasks/mod.rs")
}

fn src_thr_trunk_rs(
fn src_tasks_root_rs(
path: &Path,
registry: &Registry,
shell: &mut StandardStream,
) -> Result<(), Error> {
let path = path.join("src/thr/trunk.rs");
let path = path.join("src/tasks/root.rs");
let mut file = File::create(&path)?;
file.write_all(registry.new_src_thr_trunk_rs()?.as_bytes())?;
print_created(shell, "src/thr/trunk.rs")
file.write_all(registry.new_src_tasks_root_rs()?.as_bytes())?;
print_created(shell, "src/tasks/root.rs")
}

fn cargo_toml(
Expand Down Expand Up @@ -166,12 +183,13 @@ fn justfile(

fn rust_toolchain(
path: &Path,
toolchain: &str,
registry: &Registry,
shell: &mut StandardStream,
) -> Result<(), Error> {
let path = path.join("rust-toolchain");
let mut file = File::create(&path)?;
file.write_all(registry.new_rust_toolchain()?.as_bytes())?;
file.write_all(registry.new_rust_toolchain(toolchain)?.as_bytes())?;
print_created(shell, "rust-toolchain")
}

Expand Down Expand Up @@ -206,3 +224,11 @@ fn print_patched(shell: &mut StandardStream, message: &str) -> Result<(), Error>
writeln!(shell, " {}", message)?;
Ok(())
}

fn print_removed(shell: &mut StandardStream, message: &str) -> Result<(), Error> {
shell.set_color(ColorSpec::new().set_bold(true).set_fg(Some(Color::Green)))?;
write!(shell, " Removed")?;
shell.reset()?;
writeln!(shell, " {}", message)?;
Ok(())
}
2 changes: 1 addition & 1 deletion src/templates/layout.ld.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ SECTIONS

.data ADDR(.bss) + SIZEOF(.bss) :
{
DATA_CONST = LOADADDR(.data);
DATA_LOAD = LOADADDR(.data);
DATA_START = .;
*(.data.*);
. = ALIGN(4);
Expand Down
Loading

0 comments on commit 94f25b8

Please sign in to comment.