Skip to content

Commit

Permalink
Rewrite Mainframer in Rust. (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-zinnatullin committed Mar 1, 2018
1 parent 2fb903e commit 118611d
Show file tree
Hide file tree
Showing 38 changed files with 740 additions and 217 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
.DS_Store
build/

# Rust
target

# Share code style.
!.idea/codeStyleSettings.xml
4 changes: 4 additions & 0 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "mainframer"
version = "2.1.0"
authors = ["Artem Zinnatullin <artem.zinnatullin@gmail.com>", "Artur Dryomov <artur.dryomov@gmail.com>", "Mainframer Developers and Contributors"]

[dependencies]
3 changes: 0 additions & 3 deletions ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ if [ "$USER_ID" == "0" ]; then
echo "Warning: running as r00t."
fi

# Run shellcheck.
docker run --rm --env SHELLCHECK_OPTS="--exclude SC2088" --volume `"pwd"`:/scripts:ro koalaman/shellcheck:v0.4.6 /scripts/mainframer

docker build -t mainframer:latest .

# Command will run inside a container.
Expand Down
18 changes: 11 additions & 7 deletions ci/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ FROM ubuntu:16.04
MAINTAINER Mainframer Team

# "sudo": switch user in entrypoint.
# "curl rustup": build Mainframer and sample Rust project.
# "openssh-server": testing.
# "openjdk-8-jdk": build sample Gradle, Maven, Buck projects.
# "golang": build sample Go project.
# "clang": build sample Clang project.
# "build-essential": build sample GCC project.
# "lib32stdc++6 lib32z1 unzip": build sample Android project.
# "ant python git": build sample Buck project.
# "curl rustup": build sample Rust project.
RUN apt-get update --quiet && \
RUN apt-get update --quiet > /dev/null && \
apt-get --assume-yes --quiet install sudo openssh-server openjdk-8-jdk \
golang clang build-essential lib32stdc++6 lib32z1 unzip ant python git curl && \
curl -sf -L https://static.rust-lang.org/rustup.sh | sh
Expand All @@ -22,14 +22,18 @@ ENV ANDROID_HOME /opt/android-sdk-linux
ENV PATH ${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools
ENV ANDROID_SDK_INSTALL_COMPONENT "echo \"y\" | \"$ANDROID_HOME\"/tools/bin/sdkmanager --verbose"

# Give all users access to Android SDK (otherwise build_user won't be able to access it).
RUN mkdir -p $ANDROID_HOME && \
curl https://dl.google.com/android/repository/$ANDROID_SDK_FILE_NAME --progress-bar --location --output $ANDROID_SDK_FILE_NAME && \
unzip $ANDROID_SDK_FILE_NAME -d $ANDROID_HOME && \
echo "Unzipping Android SDK" && \
unzip -qq $ANDROID_SDK_FILE_NAME -d $ANDROID_HOME && \
rm $ANDROID_SDK_FILE_NAME && \
eval $ANDROID_SDK_INSTALL_COMPONENT '"tools"' && \
eval $ANDROID_SDK_INSTALL_COMPONENT '"platform-tools"' && \
eval $ANDROID_SDK_INSTALL_COMPONENT '"build-tools;25.0.2"' && \
eval $ANDROID_SDK_INSTALL_COMPONENT '"platforms;android-25"'
echo "Installing Android SDK components" && \
eval $ANDROID_SDK_INSTALL_COMPONENT '"tools"' > /dev/null && \
eval $ANDROID_SDK_INSTALL_COMPONENT '"platform-tools"' > /dev/null && \
eval $ANDROID_SDK_INSTALL_COMPONENT '"build-tools;25.0.2"' > /dev/null && \
eval $ANDROID_SDK_INSTALL_COMPONENT '"platforms;android-25"' > /dev/null && \
chmod -R a+rwx "$ANDROID_HOME"

# Entrypoint script will allow us run as non-root in the container.
COPY ci/docker/entrypoint.sh /usr/local/bin/entrypoint.sh
Expand Down
3 changes: 0 additions & 3 deletions ci/docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ echo "Starting with UID : $USER_ID"
groupadd --gid $USER_ID build_user
useradd --shell /bin/bash --uid $USER_ID --gid $USER_ID --comment "User for container" --create-home build_user

# Grant build_user access to Android SDK.
chown -R build_user:build_user $ANDROID_HOME

# Start ssh server for tests.
service ssh start

Expand Down
176 changes: 0 additions & 176 deletions mainframer

This file was deleted.

38 changes: 38 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#[derive(Debug, PartialEq, Eq)]
pub struct Args {
pub command: String
}

impl Args {
pub fn parse(raw_args: Vec<String>) -> Result<Args, String> {
match raw_args.len() {
0 => Err(String::from("Please pass remote command.")), // TODO more user friendly message, for now it's consistent with Bash version.
_ => Ok(Args {
command: raw_args.join(" ").trim().into()
})
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn parse_command_passed_as_single_parameter() {
let raw_args = vec![String::from("test command")];
assert_eq!(Args::parse(raw_args), Ok(Args { command: String::from("test command") }));
}

#[test]
fn parse_empty() {
let raw_args: Vec<String> = vec![];
assert_eq!(Args::parse(raw_args), Err(String::from("Please pass remote command.")));
}

#[test]
fn parse_command_passed_as_multiple_parameters() {
let raw_args = vec![String::from("test"), String::from("command")];
assert_eq!(Args::parse(raw_args), Ok(Args { command: String::from("test command") }));
}
}
Loading

0 comments on commit 118611d

Please sign in to comment.