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

Overhaul platform, build/detect API #2

Merged
merged 2 commits into from
Dec 30, 2020
Merged

Overhaul platform, build/detect API #2

merged 2 commits into from
Dec 30, 2020

Conversation

Malax
Copy link
Member

@Malax Malax commented Dec 27, 2020

  • Platform now resides in its own file and was overhauled to make implementation of new Platforms easier.
  • Introduced GenericDetectContext and GenericBuildContext for the default use-case. This removes generics for the standard use-case.
  • BuildFromPath has been removed since we don't need the additional complexity it adds.
  • platform.rs now has some rustdoc
  • Streamlined detect and build function API, both return a Result<_, BuildpackError> now
  • Introduced BuildpackError trait with implementation for all std::err::Error traits. We can add support for error handling frameworks by adding trait implementations for those frameworks.

@Malax Malax requested a review from hone December 27, 2020 14:28

fn main() {
libcnb::detect::cnb_runtime_detect(detect)
}

fn detect(_context: DetectContext<GenericPlatform>) -> DetectResult {
fn detect(_context: GenericDetectContext) -> Result<DetectOutcome, std::io::Error> {
Copy link
Member

Choose a reason for hiding this comment

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

Should we return our own Error type here?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is a custom error type defined here: https://github.com/Malax/libcnb/pull/2/files#diff-c11e72174294250d95d68429cbb5e9ec58c16ac64087d428736be92bd22cd688R24-R26

I wanted it to be flexible so buildpack authors don't need to know anything about our error types. We can also implement the BuildpackError for other Error libraries if we need to. Using io::Error here was basically just a test if that works as I expected.

Do you want me to change the example?

Copy link
Member

Choose a reason for hiding this comment

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

nah, I don't care about custom error types on the example. I expect a buildpack author to be "sloppy" and do convenience things to start.

vars: HashMap<OsString, String>,
}

impl PlatformEnv {
Copy link
Member

Choose a reason for hiding this comment

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

should we implement a fn vars or do you think people won't want an iterator?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I stopped there since I couldn't properly emulate the std::env API and we discussed we wanted that. I'll leave this unimplemented for now.

@Malax Malax merged commit 5d21723 into master Dec 30, 2020
@Malax Malax deleted the fndetect branch December 30, 2020 19:06
schneems added a commit that referenced this pull request Jan 19, 2024
* Refactor background timer logic

The background timer prints dots to the UI while the buildpack performs some expensive operation. This requires we use threading and Rust really wants to be sure that we're not going to have data races and that our data is secure.

The original version of the code relied on wrapping our IO in an Arc<Mutex<W>> so that we don't "lose" it when we pass it to the background thread. This worked, but was overly complicated based on my limited understanding of working with lifetimes and threads. This version instead relies on the ability to retrieve a struct when we join the thread to get the IO object back out. This reduces complexity that the BuildLog interface needs to know about.

# This is the commit message #2:

Inject tick state

The tick values for the printer was hardcoded. Passing in the values allows us to remove the `style` module dependency and makes the tests simpler.

# This is the commit message #3:

Rename modules and add docs

The prior name `print_dots` isn't technically valid anymore as it could be printing something else. I also moved the guard struct into it's own module to make it a bit safer (ensure that Option is always Some at creation time).

# This is the commit message #4:

Clarify intention that option is Some in code

The debug_assert adds a stronger signal that the option must be Some when it is being constructed.

* [Stacked PR] Remove warn_later from output

The `warn_later` functionality relies on global state in a way that we're not thrilled about putting into everyone's build packs by default. This removes the feature, plain and simple.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants