Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap Rust protoc in Oak utils #533

Merged
merged 24 commits into from
Feb 4, 2020
Merged

Conversation

ipetr0v
Copy link
Contributor

@ipetr0v ipetr0v commented Jan 28, 2020

This change:

  • Adds oak_utils crate, that runs protoc/protoc_grpc and checks updated files
  • Updates build.rs files to use oak_utils

Fixes #510

Checklist

  • Pull request affects core Oak functionality (e.g. runtime, SDK, ABI)
    • I have written tests that cover the code changes.
    • I have checked that these tests are run by Cloudbuild
    • I have updated documentation accordingly.
    • I have raised an issue to
      cover any TODOs and/or unfinished work.
  • Pull request includes prototype/experimental work that is under
    construction.

@ipetr0v ipetr0v changed the title Oak utils Wrap Rust protoc in Oak utils Jan 28, 2020
@ipetr0v ipetr0v added the WIP Work in progress label Jan 28, 2020
@ipetr0v ipetr0v marked this pull request as ready for review January 28, 2020 14:33
@ipetr0v
Copy link
Contributor Author

ipetr0v commented Jan 30, 2020

protoc-rust-grpc was updated due to these errors: #510 (comment)

@ipetr0v ipetr0v removed the WIP Work in progress label Jan 30, 2020
@@ -68,7 +67,7 @@ pub fn run(args: Args) -> Result<()> {

let mut includes = args.includes;
if includes.is_empty() {
static DOT_SLICE: &'static [&'static str] = &["."];
static DOT_SLICE: &[&str] = &["."];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes were just introduced in #531 , why do they need to be reverted now?
/cc @blaxill

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it due to this error: #510 (comment)
that started appearing after I added a dependency (not a build-dependency) on a protoc-rust-grpc

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah interesting, so it seems that these changes were made by us to satisfy clippy. @blaxill do you remember why it was necessary to revert them?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pulled from upstream, the important change was the less restrictive Cargo.toml 2.8 -> 2 change, so that it could generate 2.10 protoc files similar to the other generated proto files.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did nothing break when these changes were undone though?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't get "clippy'ed" as a build/dev dependency, but since we are wrapping it it is a full dependency of oak_utils and so is clippy'ed now.

- [Persistent Storage](#persistent-storage)
- [Testing](#testing)
- [Testing Multi-Node Applications](#testing-multi-node-applications)
- [Programming Oak](#programming-oak)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note it is not common to include the title in the TOC, or was this generated by some automated tool?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't touch this file, it was changed by the format.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From within Docker? But why did it change it now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fwiw [Programming Oak](#programming-oak) is an addition, perhaps from a merge or by accident?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll revert this change then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I get it
This change is automatically applied by VSCode, when I save the file.

sdk/rust/oak_utils/src/lib.rs Outdated Show resolved Hide resolved
sdk/rust/oak_utils/src/lib.rs Outdated Show resolved Hide resolved
@@ -68,7 +67,7 @@ pub fn run(args: Args) -> Result<()> {

let mut includes = args.includes;
if includes.is_empty() {
static DOT_SLICE: &'static [&'static str] = &["."];
static DOT_SLICE: &[&str] = &["."];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did nothing break when these changes were undone though?

sdk/rust/oak_utils/src/lib.rs Outdated Show resolved Hide resolved
sdk/rust/oak_utils/src/lib.rs Outdated Show resolved Hide resolved
sdk/rust/oak_utils/src/lib.rs Outdated Show resolved Hide resolved
sdk/rust/oak_utils/src/lib.rs Outdated Show resolved Hide resolved
sdk/rust/oak_utils/src/lib.rs Show resolved Hide resolved
sdk/rust/oak_utils/src/tests.rs Outdated Show resolved Hide resolved
sdk/rust/oak_utils/src/tests.rs Outdated Show resolved Hide resolved

// This function returns a list of files in the `new_dir` that are different from files with
// same names in the `old_dir`.
fn get_changed_and_removed_files(old_dir: &Path, new_dir: &Path) -> (Vec<String>, Vec<String>) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the return type and the logic are getting a bit too complicated.

Perhaps another solution could be:

  • collect filenames from both maps in a single set

  • iterate over the set, and get the value from both the old and new map (as options)

  • collect the old and new option types in a struct like:

    struct FileDiff {
      old_content: Option<String>,
      new_content: Option<String>,
    }
  • add a method on FileDiff::action() to figure out what to do about the file, perhaps it should return one value of some enum:

    enum FileAction {
      Ignore,
      Update{ new_content: String },
      Remove`,
    }
  • apply the necessary change based on this enum value in a final step.

WDYT? I think it should be more readable, and kind of fun to implement in a "functional" style, but if you don't think that's worth it feel free to submit as it is (or do it in a future PR).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be fixed in #548


// This function returns a list of files in the `new_dir` that are different from files with
// same names in the `old_dir`.
fn get_changed_and_removed_files(old_dir: &Path, new_dir: &Path) -> (Vec<String>, Vec<String>) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function would be much easier to test if it took as input the corresponding maps, instead of figuring them out from the actual file system. Then the unit tests would look trivial, since you can just pass the maps without having to create any temp files. Up to you anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be fixed in #548

@ipetr0v ipetr0v added the WIP Work in progress label Feb 4, 2020
@ipetr0v ipetr0v mentioned this pull request Feb 4, 2020
@ipetr0v ipetr0v merged commit dfb8ff7 into project-oak:master Feb 4, 2020
@ipetr0v ipetr0v deleted the oak_utils branch February 4, 2020 12:06
@daviddrysdale
Copy link
Contributor

I don't think this is cleaning up its temporary directories properly – I've got about 10GiB of /tmp subdirectories that look to be produced by this.

@ipetr0v
Copy link
Contributor Author

ipetr0v commented Feb 12, 2020

I don't see temporary directories on my machine and inside Docker.
Could you please send directory names?

@daviddrysdale
Copy link
Contributor

~/src/oak{master}:ls -d /tmp/*/debug
ls: cannot access '/tmp/*/debug': No such file or directory
~/src/oak{master}:cd examples/hello_world/module/
~/src/oak/examples/hello_world/module{master}:cargo test > /dev/null 2>&1
~/src/oak/examples/hello_world/module{master}:ls -d /tmp/*/debug
/tmp/k2aaC3wmhUuB/debug  /tmp/Wcd3O4sir75w/debug  /tmp/ZUzEvTgIe9Eg/debug
~/src/oak/examples/hello_world/module{master}:du -m -s /tmp/k2aaC3wmhUuB /tmp/Wcd3O4sir75w /tmp/ZUzEvTgIe9Eg
459	/tmp/k2aaC3wmhUuB
355	/tmp/Wcd3O4sir75w
531	/tmp/ZUzEvTgIe9Eg

@blaxill
Copy link
Contributor

blaxill commented Feb 12, 2020

@daviddrysdale this likely could this be #578 switching to not controlling out-dir, and parsing cargo json for the cargo defined directory may fix it.

@daviddrysdale
Copy link
Contributor

Ah, that makes more sense – sorry for the false alarm @ipetr0v.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes WIP Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rust build cache invalidated by build.rs execution
5 participants