From 6d307ab6f7384e6d2e6790af7f1639f160c634c3 Mon Sep 17 00:00:00 2001 From: Jason LeBrun Date: Thu, 16 May 2024 00:03:48 +0000 Subject: [PATCH] Remove a bunch of old/unused xtask things Change-Id: I70313a00604b984417c6d990d8a76424ecaf6f5f --- .xtask_bash_completion | 216 +------------------------------------ xtask/src/containers.rs | 163 ---------------------------- xtask/src/examples.rs | 72 ------------- xtask/src/internal.rs | 81 -------------- xtask/src/launcher.rs | 233 ---------------------------------------- xtask/src/lib.rs | 4 - xtask/src/main.rs | 135 +---------------------- xtask/src/testing.rs | 58 ---------- 8 files changed, 3 insertions(+), 959 deletions(-) delete mode 100644 xtask/src/containers.rs delete mode 100644 xtask/src/examples.rs delete mode 100644 xtask/src/launcher.rs delete mode 100644 xtask/src/testing.rs diff --git a/.xtask_bash_completion b/.xtask_bash_completion index af66355fe66..b97799c5ac2 100644 --- a/.xtask_bash_completion +++ b/.xtask_bash_completion @@ -12,9 +12,6 @@ _xtask() { ",$1") cmd="xtask" ;; - xtask,build-enclave-binary) - cmd="xtask__build__enclave__binary" - ;; xtask,check-format) cmd="xtask__check__format" ;; @@ -27,9 +24,6 @@ _xtask() { xtask,help) cmd="xtask__help" ;; - xtask,run-cargo-clean) - cmd="xtask__run__cargo__clean" - ;; xtask,run-cargo-clippy) cmd="xtask__run__cargo__clippy" ;; @@ -39,24 +33,9 @@ _xtask() { xtask,run-cargo-fuzz) cmd="xtask__run__cargo__fuzz" ;; - xtask,run-cargo-tests) - cmd="xtask__run__cargo__tests" - ;; xtask,run-cargo-udeps) cmd="xtask__run__cargo__udeps" ;; - xtask,run-ci) - cmd="xtask__run__ci" - ;; - xtask,run-oak-functions-example) - cmd="xtask__run__oak__functions__example" - ;; - xtask,run-tests) - cmd="xtask__run__tests" - ;; - xtask__help,build-enclave-binary) - cmd="xtask__help__build__enclave__binary" - ;; xtask__help,check-format) cmd="xtask__help__check__format" ;; @@ -69,9 +48,6 @@ _xtask() { xtask__help,help) cmd="xtask__help__help" ;; - xtask__help,run-cargo-clean) - cmd="xtask__help__run__cargo__clean" - ;; xtask__help,run-cargo-clippy) cmd="xtask__help__run__cargo__clippy" ;; @@ -81,21 +57,9 @@ _xtask() { xtask__help,run-cargo-fuzz) cmd="xtask__help__run__cargo__fuzz" ;; - xtask__help,run-cargo-tests) - cmd="xtask__help__run__cargo__tests" - ;; xtask__help,run-cargo-udeps) cmd="xtask__help__run__cargo__udeps" ;; - xtask__help,run-ci) - cmd="xtask__help__run__ci" - ;; - xtask__help,run-oak-functions-example) - cmd="xtask__help__run__oak__functions__example" - ;; - xtask__help,run-tests) - cmd="xtask__help__run__tests" - ;; *) ;; esac @@ -103,7 +67,7 @@ _xtask() { case "${cmd}" in xtask) - opts="-h --dry-run --logs --keep-going --help build-enclave-binary run-oak-functions-example format check-format run-tests run-cargo-clippy run-cargo-tests run-cargo-fuzz run-cargo-deny run-cargo-udeps run-ci run-cargo-clean completion help" + opts="-h --dry-run --logs --keep-going --help format check-format run-cargo-clippy run-cargo-fuzz run-cargo-deny run-cargo-udeps completion help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -116,20 +80,6 @@ _xtask() { COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 ;; - xtask__build__enclave__binary) - opts="-h --help" - if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - fi - case "${prev}" in - *) - COMPREPLY=() - ;; - esac - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - ;; xtask__check__format) opts="-h --help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then @@ -177,7 +127,7 @@ _xtask() { return 0 ;; xtask__help) - opts="build-enclave-binary run-oak-functions-example format check-format run-tests run-cargo-clippy run-cargo-tests run-cargo-fuzz run-cargo-deny run-cargo-udeps run-ci run-cargo-clean completion help" + opts="format check-format run-cargo-clippy run-cargo-fuzz run-cargo-deny run-cargo-udeps completion help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -190,20 +140,6 @@ _xtask() { COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 ;; - xtask__help__build__enclave__binary) - opts="" - if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - fi - case "${prev}" in - *) - COMPREPLY=() - ;; - esac - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - ;; xtask__help__check__format) opts="" if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then @@ -260,20 +196,6 @@ _xtask() { COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 ;; - xtask__help__run__cargo__clean) - opts="" - if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - fi - case "${prev}" in - *) - COMPREPLY=() - ;; - esac - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - ;; xtask__help__run__cargo__clippy) opts="" if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then @@ -316,20 +238,6 @@ _xtask() { COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 ;; - xtask__help__run__cargo__tests) - opts="" - if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - fi - case "${prev}" in - *) - COMPREPLY=() - ;; - esac - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - ;; xtask__help__run__cargo__udeps) opts="" if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then @@ -344,62 +252,6 @@ _xtask() { COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 ;; - xtask__help__run__ci) - opts="" - if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - fi - case "${prev}" in - *) - COMPREPLY=() - ;; - esac - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - ;; - xtask__help__run__oak__functions__example) - opts="" - if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - fi - case "${prev}" in - *) - COMPREPLY=() - ;; - esac - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - ;; - xtask__help__run__tests) - opts="" - if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - fi - case "${prev}" in - *) - COMPREPLY=() - ;; - esac - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - ;; - xtask__run__cargo__clean) - opts="-h --help" - if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - fi - case "${prev}" in - *) - COMPREPLY=() - ;; - esac - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - ;; xtask__run__cargo__clippy) opts="-h --help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then @@ -446,20 +298,6 @@ _xtask() { COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 ;; - xtask__run__cargo__tests) - opts="-h --cleanup --help" - if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - fi - case "${prev}" in - *) - COMPREPLY=() - ;; - esac - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - ;; xtask__run__cargo__udeps) opts="-h --help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then @@ -474,56 +312,6 @@ _xtask() { COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 ;; - xtask__run__ci) - opts="-h --help" - if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - fi - case "${prev}" in - *) - COMPREPLY=() - ;; - esac - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - ;; - xtask__run__oak__functions__example) - opts="-h --example-name --lookup-data-path --help" - if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - fi - case "${prev}" in - --example-name) - COMPREPLY=($(compgen -f "${cur}")) - return 0 - ;; - --lookup-data-path) - COMPREPLY=($(compgen -f "${cur}")) - return 0 - ;; - *) - COMPREPLY=() - ;; - esac - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - ;; - xtask__run__tests) - opts="-h --help" - if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - fi - case "${prev}" in - *) - COMPREPLY=() - ;; - esac - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - ;; esac } diff --git a/xtask/src/containers.rs b/xtask/src/containers.rs deleted file mode 100644 index 433b9aab9db..00000000000 --- a/xtask/src/containers.rs +++ /dev/null @@ -1,163 +0,0 @@ -// -// Copyright 2023 The Project Oak Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -use crate::{ - internal::{Cmd, Runnable, Step}, - workspace_path, -}; - -fn build_kernel() -> Step { - Step::Single { - name: "build kernel".to_string(), - command: Cmd::new("just", vec!["oak_containers_kernel"]), - } -} - -fn build_stage1() -> Step { - Step::Single { - name: "build stage1".to_string(), - command: Cmd::new("just", vec!["stage1_cpio"]), - } -} - -fn build_system_image() -> Step { - Step::Single { - name: "build system image".to_string(), - command: Cmd::new("just", vec!["oak_containers_system_image"]), - } -} - -fn build_oak_functions_bundle() -> Step { - Step::Single { - name: "build Oak Functions bundle".to_string(), - command: Cmd::new("just", vec!["oak_functions_containers_container_bundle_tar"]), - } -} - -fn build_oak_functions_launcher() -> Step { - Step::Single { - name: "build Oak Functions bundle".to_string(), - command: Cmd::new("just", vec!["oak_functions_containers_launcher"]), - } -} - -async fn build_prerequisites() { - // `just` steps can clash with each other, so ensure that we're not trying to - // build things like the system image concurrently. - static BUILD: tokio::sync::OnceCell<()> = tokio::sync::OnceCell::const_new(); - BUILD - .get_or_init(async || { - tokio::join!( - crate::testing::run_step(crate::launcher::build_stage0()), - crate::testing::run_step(build_kernel()), - crate::testing::run_step(build_stage1()), - crate::testing::run_step(build_system_image()), - crate::testing::run_step(build_oak_functions_bundle()), - crate::testing::run_step(build_oak_functions_launcher()) - ); - }) - .await; -} - -pub fn run_oak_functions_launcher_example_with_lookup_data( - wasm_path: &str, - port: u16, - lookup_data_path: &str, - communication_channel: &str, -) -> Box { - let args = vec![ - format!("--vmm-binary={}", which::which("qemu-system-x86_64").unwrap().to_str().unwrap()), - format!( - "--stage0-binary={}", - workspace_path(&[ - "stage0_bin", - "target", - "x86_64-unknown-none", - "release", - "oak_stage0.bin", - ]) - .to_str() - .unwrap() - ), - format!( - "--kernel={}", - workspace_path(&["oak_containers_kernel", "target", "bzImage"]).to_str().unwrap() - ), - format!("--initrd={}", workspace_path(&["target", "stage1.cpio"]).to_str().unwrap()), - format!( - "--system-image={}", - workspace_path(&["oak_containers_system_image", "target", "image.tar.xz"]) - .to_str() - .unwrap() - ), - format!( - "--container-bundle={}", - workspace_path(&[ - "oak_functions_containers_container", - "target", - "oak_functions_container_oci_filesystem_bundle.tar", - ]) - .to_str() - .unwrap() - ), - format!("--ramdrive-size={}", "1000000"), // 1 GiB in KiB - format!("--memory-size={}", "2G"), - format!("--wasm={}", wasm_path), - format!("--port={}", port), - format!("--lookup-data={}", lookup_data_path), - // Use the current thread ID as the CID, as we may have tests that start multiple QEMUs in - // parallel. Starting multiple QEMUs in one thread will fail. - format!("--virtio-guest-cid={}", nix::unistd::gettid()), - format!("--communication-channel={}", communication_channel), - ]; - Cmd::new( - workspace_path(&[ - "target", - "x86_64-unknown-linux-gnu", - "release", - "oak_functions_containers_launcher", - ]) - .to_str() - .unwrap(), - args, - ) -} - -/// Runs the specified example as a background task. Returns a reference to the -/// running server and the port on which the server is listening. -pub async fn run_oak_functions_example_in_background( - wasm_path: &str, - lookup_data_path: &str, - communication_channel: &str, -) -> (crate::testing::BackgroundStep, u16) { - build_prerequisites().await; - - eprintln!("using Wasm module {}", wasm_path); - - let port = portpicker::pick_unused_port().expect("failed to pick a port"); - eprintln!("using port {}", port); - - let background = - crate::testing::run_background(run_oak_functions_launcher_example_with_lookup_data( - wasm_path, - port, - lookup_data_path, - communication_channel, - )) - .await; - - (background, port) -} diff --git a/xtask/src/examples.rs b/xtask/src/examples.rs deleted file mode 100644 index 07932341d3d..00000000000 --- a/xtask/src/examples.rs +++ /dev/null @@ -1,72 +0,0 @@ -// -// Copyright 2021 The Project Oak Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -use crate::{ - internal::*, - launcher, - launcher::{ - build_binary, build_stage0, run_oak_functions_launcher_example_with_lookup_data, - MOCK_LOOKUP_DATA_PATH, - }, -}; - -/// Build the Rust crate that will be used as the Wasm module for the Oak -/// Functions server. -pub fn build_rust_crate_wasm(crate_name: &str) -> Step { - Step::Single { - name: "cargo build Wasm".to_string(), - command: Cmd::new( - "cargo", - vec![ - "build".to_string(), - "--target=wasm32-unknown-unknown".to_string(), - "--release".to_string(), - format!("--package={crate_name}"), - ], - ), - } -} - -pub fn run_oak_functions_example(opt: &RunOakExampleOpt) -> Step { - let app = launcher::App::from_crate_name("oak_functions_enclave_app"); - - let wasm_path = oak_functions_test_utils::rust_crate_wasm_out_path(&opt.example_name); - - Step::Multiple { - name: "run Oak Functions example".to_string(), - steps: vec![ - build_stage0(), - crate::launcher::just_build("oak_restricted_kernel_wrapper"), - build_binary( - "build Oak Restricted Kernel orchestrator", - &launcher::App::from_crate_name("oak_orchestrator").enclave_crate_path(), - ), - build_binary("build Oak Functions enclave app", &app.enclave_crate_path()), - build_rust_crate_wasm(&opt.example_name), - Step::Single { - name: "server".to_string(), - command: run_oak_functions_launcher_example_with_lookup_data( - &app, - &wasm_path, - 8080, - &opt.lookup_data_path - .clone() - .unwrap_or(MOCK_LOOKUP_DATA_PATH.to_str().unwrap().to_string()), - ), - }, - ], - } -} diff --git a/xtask/src/internal.rs b/xtask/src/internal.rs index f0b889cde9e..44a22f30bb8 100644 --- a/xtask/src/internal.rs +++ b/xtask/src/internal.rs @@ -25,7 +25,6 @@ use async_trait::async_trait; use clap::{Parser, Subcommand}; use colored::*; use nix::sys::signal::Signal; -use strum_macros::EnumIter; use tokio::io::{empty, AsyncRead, AsyncReadExt}; use crate::PROCESSES; @@ -44,18 +43,12 @@ pub struct Opt { #[derive(Subcommand, Clone, Debug)] pub enum Command { - BuildEnclaveBinary, - RunOakFunctionsExample(RunOakExampleOpt), Format, CheckFormat, - RunTests, RunCargoClippy, - RunCargoTests(RunTestsOpt), RunCargoFuzz(RunCargoFuzz), RunCargoDeny, RunCargoUdeps, - RunCi, - RunCargoClean, #[command(about = "generate bash completion script to stdout")] Completion(Completion), } @@ -70,80 +63,6 @@ pub struct Completion { pub file_name: PathBuf, } -/// Holds the options for running the example. -#[derive(Parser, Clone, Debug)] -pub struct RunOakExampleOpt { - #[arg( - long, - help = "name of a single example to run (i.e. the Rust crate name of the Wasm module)" - )] - pub example_name: String, - #[arg(long, help = "path to the lookup data file")] - pub lookup_data_path: Option, -} - -#[derive(Parser, Clone, Debug)] -pub struct BuildClient { - #[arg( - long, - help = "client variant: [all, rust, cpp, go, nodejs, none] [default: all]", - default_value = "all" - )] - pub client_variant: String, - #[arg( - long, - help = "rust toolchain override to use for the client compilation [e.g. stable, nightly, stage2]" - )] - pub client_rust_toolchain: Option, - #[arg( - long, - help = "rust target to use for the client compilation [e.g. x86_64-unknown-linux-gnu, x86_64-unknown-linux-musl, x86_64-apple-darwin]" - )] - pub client_rust_target: Option, -} - -#[derive(serde::Deserialize, Default, Debug, Clone, PartialEq, EnumIter)] -pub enum ServerVariant { - /// Production-like server variant, without logging or any of the - /// experimental features enabled - #[default] - Base, -} - -impl std::str::FromStr for ServerVariant { - type Err = String; - fn from_str(variant: &str) -> Result { - match variant { - "base" => Ok(ServerVariant::Base), - _ => Err(format!("couldn't parse functions server variant {}", variant)), - } - } -} - -impl ServerVariant { - // Get path to manifest for the variant. - pub fn path_to_manifest(&self) -> &'static str { - match self { - ServerVariant::Base => "./oak_functions_launcher", - } - } - - /// Get path to the executable server binary for the server variant. - pub fn path_to_executable(&self) -> &'static str { - match self { - ServerVariant::Base => { - "./target/x86_64-unknown-linux-musl/release/oak_functions_launcher" - } - } - } -} - -#[derive(Parser, Clone, Debug)] -pub struct RunTestsOpt { - #[arg(long, help = "Remove generated files after running tests for each crate")] - pub cleanup: bool, -} - #[derive(Parser, Clone, Debug)] pub struct RunCargoFuzz { #[arg(long, help = "name of a specific fuzz-target. If not specified, runs all fuzz targets.")] diff --git a/xtask/src/launcher.rs b/xtask/src/launcher.rs deleted file mode 100644 index 9bdcb5fb118..00000000000 --- a/xtask/src/launcher.rs +++ /dev/null @@ -1,233 +0,0 @@ -// -// Copyright 2020 The Project Oak Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -//! Functionality for testing variants of the enclave binary exposed by the -//! launcher. - -pub static MOCK_LOOKUP_DATA_PATH: Lazy = - Lazy::new(|| workspace_path(&["oak_functions_launcher", "mock_lookup_data"])); -static STAGE_0_DIR: Lazy = Lazy::new(|| workspace_path(&["stage0_bin"])); -static OAK_FUNCTIONS_LAUNCHER_BIN_DIR: Lazy = - Lazy::new(|| workspace_path(&["oak_functions_launcher"])); -static OAK_FUNCTIONS_LAUNCHER_BIN: Lazy = Lazy::new(|| { - workspace_path(&["target", "x86_64-unknown-linux-gnu", "debug", "oak_functions_launcher"]) -}); -pub static OAK_RESTRICTED_KERNEL_WRAPPER_BIN: Lazy = Lazy::new(|| { - workspace_path(&[ - "oak_restricted_kernel_wrapper", - "target", - "x86_64-unknown-none", - "release", - "oak_restricted_kernel_wrapper_bin", - ]) -}); -static OAK_RESTRICTED_KERNEL_ORCHESTRATOR: Lazy = Lazy::new(|| { - workspace_path(&[ - "enclave_apps", - "target", - "x86_64-unknown-none", - "release", - "oak_orchestrator", - ]) -}); - -use std::path::{Path, PathBuf}; - -use once_cell::sync::Lazy; - -use crate::{internal::*, workspace_path}; - -#[derive(Debug, Clone, PartialEq)] -pub struct App { - /// app binary crate name. - crate_name: String, -} - -impl App { - pub fn from_crate_name(crate_name: &str) -> Self { - Self { crate_name: crate_name.to_string() } - } - - /// Get the crate name of respective enclave binary variant - pub fn enclave_crate_name(&self) -> String { - self.crate_name.clone() - } - - /// Get the path to the respective enclave binary variant that should be - /// launched - pub fn enclave_crate_path(&self) -> String { - workspace_path(&["enclave_apps", &self.enclave_crate_name()]).to_str().unwrap().to_string() - } - - /// Get the path to the respective enclave binary variant that should be - /// launched - pub fn enclave_binary_path(&self) -> String { - workspace_path(&[ - "enclave_apps", - "target", - "x86_64-unknown-none", - "debug", - &self.enclave_crate_name(), - ]) - .to_str() - .unwrap() - .to_string() - } - - /// Get the subcommand for launching in this mode - pub fn subcommand(&self) -> Vec { - vec![ - format!("--kernel={}", OAK_RESTRICTED_KERNEL_WRAPPER_BIN.to_str().unwrap()), - format!( - "--vmm-binary={}", - which::which("qemu-system-x86_64").unwrap().to_str().unwrap() - ), - "--memory-size=256M".to_string(), - format!("--app-binary={}", &self.enclave_binary_path()), - format!("--initrd={}", OAK_RESTRICTED_KERNEL_ORCHESTRATOR.to_str().unwrap()), - format!( - "--bios-binary={}", - workspace_path(&[ - "stage0_bin", - "target", - "x86_64-unknown-none", - "release", - "oak_stage0.bin", - ]) - .to_str() - .unwrap() - ), - ] - } -} - -pub fn build_enclave_binary() -> Step { - Step::Single { - name: "Build enclave binary variants".to_string(), - command: Cmd::new_in_dir( - "cargo", - vec!["build", "--release"], - Path::new(&App::from_crate_name("").enclave_crate_path()), - ), - } -} - -pub fn build_stage0() -> Step { - Step::Single { - name: "build stage0".to_string(), - command: Cmd::new_in_dir( - "cargo", - vec![ - "objcopy", - "--release", - "--", - "-O", - "binary", - "target/x86_64-unknown-none/release/oak_stage0.bin", - ], - STAGE_0_DIR.as_path(), - ), - } -} - -pub fn build_binary(name: &str, directory: &str) -> Step { - Step::Single { - name: name.to_string(), - command: Cmd::new_in_dir("cargo", vec!["build"], Path::new(directory)), - } -} - -pub fn just_build(just_command: &str) -> Step { - Step::Single { - name: format!("build {}", just_command), - command: Cmd::new_in_dir("just", vec![just_command], workspace_path(&[]).as_path()), - } -} - -/// Runs the Oak Functions launcher configured with a default Wasm module for -/// key / value lookups and mock lookup data. -pub fn run_oak_functions_launcher_example( - app: &App, - wasm_path: &str, - port: u16, -) -> Box { - run_oak_functions_launcher_example_with_lookup_data( - app, - wasm_path, - port, - MOCK_LOOKUP_DATA_PATH.to_str().unwrap(), - ) -} - -pub fn run_oak_functions_launcher_example_with_lookup_data( - app: &App, - wasm_path: &str, - port: u16, - lookup_data_path: &str, -) -> Box { - let mut args = vec![ - format!("--wasm={}", wasm_path), - format!("--port={}", port), - format!("--lookup-data={}", lookup_data_path), - ]; - args.append(&mut app.subcommand()); - Cmd::new(OAK_FUNCTIONS_LAUNCHER_BIN.to_str().unwrap(), args) -} - -pub fn run_launcher(launcher_bin: &str, app: &App) -> Box { - let mut args = vec![]; - args.append(&mut app.subcommand()); - Cmd::new(launcher_bin, args) -} - -/// Runs the specified example as a background task. Returns a reference to the -/// running server and the port on which the server is listening. -pub async fn run_oak_functions_example_in_background( - wasm_path: &str, - lookup_data_path: &str, -) -> (crate::testing::BackgroundStep, u16) { - crate::testing::run_step(crate::launcher::build_stage0()).await; - crate::testing::run_step(crate::launcher::just_build("oak_restricted_kernel_wrapper")).await; - crate::testing::run_step(crate::launcher::just_build("oak_orchestrator")).await; - crate::testing::run_step(crate::launcher::build_binary( - "build Oak Functions Launcher binary", - crate::launcher::OAK_FUNCTIONS_LAUNCHER_BIN_DIR.to_str().unwrap(), - )) - .await; - let variant = crate::launcher::App::from_crate_name("oak_functions_enclave_app"); - crate::testing::run_step(crate::launcher::build_binary( - "build Oak Functions enclave app", - &variant.enclave_crate_path(), - )) - .await; - - eprintln!("using Wasm module {}", wasm_path); - - let port = portpicker::pick_unused_port().expect("failed to pick a port"); - eprintln!("using port {}", port); - - let background = crate::testing::run_background( - crate::launcher::run_oak_functions_launcher_example_with_lookup_data( - &variant, - wasm_path, - port, - lookup_data_path, - ), - ) - .await; - - (background, port) -} diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index f168a0e0f35..b0357d050f7 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -24,12 +24,8 @@ use once_cell::sync::Lazy; pub mod check_build_licenses; pub mod check_license; pub mod check_todo; -pub mod containers; -pub mod examples; pub mod files; pub mod internal; -pub mod launcher; -pub mod testing; pub static PROCESSES: Lazy>> = Lazy::new(|| Mutex::new(Vec::new())); diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 5433694ee63..9f647ad68fb 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -33,10 +33,9 @@ use xtask::{ check_build_licenses::*, check_license::*, check_todo::*, - examples::*, files::*, internal::{self, *}, - launcher, spread, + spread, }; #[tokio::main] @@ -93,19 +92,13 @@ async fn main() -> Result<(), Box> { fn match_cmd(opt: &Opt) -> Step { match opt.cmd { - Command::BuildEnclaveBinary => launcher::build_enclave_binary(), - Command::RunOakFunctionsExample(ref run_opt) => run_oak_functions_example(run_opt), - Command::RunTests => run_tests(), Command::RunCargoClippy => run_cargo_clippy(), - Command::RunCargoTests(ref run_opt) => run_cargo_tests(run_opt), Command::RunCargoFuzz(ref opt) => run_cargo_fuzz(opt), Command::Format => format(), Command::CheckFormat => check_format(), - Command::RunCi => run_ci(), Command::Completion(ref opt) => run_completion(opt), Command::RunCargoDeny => run_cargo_deny(), Command::RunCargoUdeps => run_cargo_udeps(), - Command::RunCargoClean => run_cargo_clean(), } } @@ -122,20 +115,6 @@ fn cleanup() { } } -fn run_tests() -> Step { - Step::Multiple { - name: "tests".to_string(), - steps: vec![run_cargo_tests(&RunTestsOpt { cleanup: false })], - } -} - -fn run_cargo_tests(opt: &RunTestsOpt) -> Step { - Step::Multiple { - name: "cargo tests".to_string(), - steps: vec![run_cargo_test(opt), run_cargo_doc()], - } -} - pub fn run_cargo_fuzz(opt: &RunCargoFuzz) -> Step { let cargo_manifests: Vec = crate_manifest_files().filter(|path| is_fuzzing_toml_file(path)).collect(); @@ -222,33 +201,6 @@ fn run_completion(completion: &Completion) -> Step { Step::Multiple { name: "cargo completion".to_string(), steps: vec![] } } -fn run_ci() -> Step { - // parse cmds for ./scripts/xtask from ci.yaml to keep them in sync - let path_to_ci_yaml = ".github/workflows/ci.yaml"; - let file = std::fs::File::open(path_to_ci_yaml).expect("couldn't open file"); - let contents: serde_yaml::Value = - serde_yaml::from_reader(file).expect("couldn't read file contents"); - let mut ci_cmds = contents["jobs"]["xtask"]["strategy"]["matrix"]["cmd"] - .as_sequence() - .unwrap() - .iter() - .map(|c| c.as_str().unwrap().split_whitespace().collect()) - .collect::>>(); - - Step::Multiple { - name: "ci".to_string(), - steps: ci_cmds - .iter_mut() - .map(|cmd| { - let mut call = vec!["xtask"]; - call.append(cmd); - let opt = Opt::parse_from(call); - match_cmd(&opt) - }) - .collect(), - } -} - enum FormatMode { Check, Fix, @@ -466,75 +418,6 @@ fn run_cargo_fmt(mode: FormatMode) -> Step { } } -fn run_cargo_test(opt: &RunTestsOpt) -> Step { - Step::Multiple { - name: "cargo test".to_string(), - steps: crate_manifest_files() - // Exclude `fuzz` crates, as there are no tests and binaries should not be executed. - .filter(|path| !is_fuzzing_toml_file(path)) - .map(|entry| { - // Run `cargo test` in the directory of the crate, not the top-level directory. - // This is needed as otherwise any crate-specific `.cargo/config.toml` files - // would be ignored. If a crate does not have a config file, - // Cargo will just backtrack up the tree and pick up the - // `.cargo/config.toml` file from the root directory. - let test_run_step = |name| Step::Single { - name, - command: Cmd::new_in_dir( - "cargo", - [ - "test", - "--all-features", - &format!( - "--manifest-path={}", - entry.file_name().unwrap().to_str().unwrap() - ), - ], - entry.parent().unwrap(), - ), - }; - - // If `cleanup` is enabled, add a cleanup step to remove the generated files. - if opt.cleanup { - Step::Multiple { - name: entry.to_str().unwrap().to_string(), - steps: vec![ - test_run_step("run".to_string()), - Step::Single { - name: "cleanup".to_string(), - command: Cmd::new( - "rm", - ["-rf", entry.with_file_name("target").to_str().unwrap()], - ), - }, - ], - } - } else { - test_run_step(entry.to_str().unwrap().to_string()) - } - }) - .collect(), - } -} - -fn run_cargo_doc() -> Step { - Step::Multiple { - name: "cargo doc".to_string(), - steps: crate_manifest_files() - .map(to_string) - .map(|entry| { - let mut path = PathBuf::from(entry); - path.pop(); - let path = to_string(path).replace("./", ""); - Step::Single { - name: path.clone(), - command: Cmd::new("bash", ["./scripts/check_docs", &path]), - } - }) - .collect(), - } -} - fn run_cargo_clippy() -> Step { Step::Multiple { name: "cargo clippy".to_string(), @@ -608,19 +491,3 @@ fn run_cargo_udeps() -> Step { .collect(), } } - -fn run_cargo_clean() -> Step { - Step::Multiple { - name: "cargo clean".to_string(), - steps: crate_manifest_files() - .map(to_string) - .map(|manifest_path| Step::Single { - name: manifest_path.clone(), - command: Cmd::new( - "cargo", - ["clean", &format!("--manifest-path={}", manifest_path)], - ), - }) - .collect(), - } -} diff --git a/xtask/src/testing.rs b/xtask/src/testing.rs deleted file mode 100644 index 7b918845b9a..00000000000 --- a/xtask/src/testing.rs +++ /dev/null @@ -1,58 +0,0 @@ -// -// Copyright 2023 The Project Oak Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -use crate::internal::{read_to_end, Command, Context, Opt, Runnable, Running, Status, Step}; - -fn opt_for_test() -> Opt { - Opt { dry_run: false, logs: true, keep_going: false, cmd: Command::RunTests } -} - -/// Runs a step, and asserts that it succeeds. -pub async fn run_step(step: Step) { - let context = Context::root(&opt_for_test()); - let run_status = Status::new(usize::MAX); - let result = crate::internal::run_step(&context, step, run_status).await; - assert!(result.success()); -} - -/// Thin wrapper around an inner `Running` that kills the inner `Running` when -/// dropped. -pub struct BackgroundStep { - pub inner: Box, -} - -impl std::ops::Drop for BackgroundStep { - fn drop(&mut self) { - self.inner.kill(); - } -} - -/// Runs a step in the background, and returns a reference to the running -/// process. -/// -/// The running process is killed when the returned `BackgroundStep` is dropped. -pub async fn run_background(step: Box) -> BackgroundStep { - let mut running = step.run(&opt_for_test()); - tokio::spawn(read_to_end(running.stdout())); - tokio::spawn(read_to_end(running.stderr())); - BackgroundStep { inner: running } -} - -/// Whether to skip the test. For instance, GitHub Actions does not support KVM, -/// so we cannot run tests that require nested virtualization. -pub fn skip_test() -> bool { - std::env::var("OAK_KVM_TESTS").unwrap_or_default().to_lowercase() == "skip" -}