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

Change rbx_reflection_database to support loading from FS #376

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

Dekkonot
Copy link
Member

As part of the effort to get the reflection database loadable locally, it's probably a good idea to have a central place that decides locations for the entire ecosystem. This will prevent consumers like Lune and Rojo from having to re-implement this logic.

The obvious choice for this, in my opinion, is rbx_reflection_database. It's a requirement for everything that uses the reflection database already, and its public API can be extended to take things from the file system into account without any issues. I've implemented it and documented it thoroughly in the README for rbx_reflection_database.

However, it also sacrifices the 'purity' of the module because it fundamentally alters its purpose. I'm okay with that, but I understand not everyone will be. Please be honest with your thoughts.

I know for sure this works on Windows and Linux. I'm assuming it will also work on MacOS, but I don't own a machine I can use for testing. I don't know how to test this in CI, so we'll just have to be mindful of changes.

Specifically, databases are now loaded from a local directory
or from an environmental variable
if either exist.
Copy link
Member

@Corecii Corecii left a comment

Choose a reason for hiding this comment

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

Some minor comments and future planning concerns

rbx_reflection_database/src/lib.rs Outdated Show resolved Hide resolved
rbx_reflection_database/README.md Outdated Show resolved Hide resolved
rbx_reflection_database/src/lib.rs Outdated Show resolved Hide resolved
rbx_reflection_database/src/lib.rs Outdated Show resolved Hide resolved
rbx_reflection_database/src/lib.rs Outdated Show resolved Hide resolved
@Dekkonot
Copy link
Member Author

Allowing the database to be replaced once it's initialized is complicated because it involves mutating a static variable, so for the time being I'm going to ignore it. Tools like Rojo and Lune can work out solutions without that.

@Dekkonot Dekkonot requested a review from Corecii November 14, 2023 18:33
Copy link
Member

@kennethloeffler kennethloeffler left a comment

Choose a reason for hiding this comment

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

Looking good, I left a few comments.

RE testing - it looks like the only code paths not covered right now are here:

} else {
// Due to concerns about the local data directory existing
// on Linux, we use the home directory instead.
#[cfg(target_os = "linux")]
let mut home = dirs::home_dir()?;
#[cfg(not(target_os = "linux"))]
let mut home = dirs::data_local_dir()?;
home.push(LOCAL_DIR_NAME);
home.push("database.msgpack");
Some(home)
}

Maybe we could add a test that simply compares the result of this to the expected path for the platform, and if we're very paranoid, add some CI targets for macOS and Windows?

rbx_reflection_database/src/lib.rs Outdated Show resolved Hide resolved
rbx_reflection_database/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines +73 to +75
pub fn get() -> Result<&'static ReflectionDatabase<'static>, Error> {
Ok(get_local()?.unwrap_or(&BUNDLED_DATABASE))
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm not totally sure if breaking this interface is the right call. The way I'm thinking about it is: if get_local fails, then probably 99% of the time, users of this function will immediately want to call get_bundled, so why not just have this function do that for them? That way it does the right thing most of the time, and we can avoid breakage.

On the other hand, then it's not clear that this function can fail, and removes the ability to e.g. print a warning if the local database is corrupt while using this function.

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'm not totally sold on breaking this either, but the other option is hiding failures from users. It might be worth taking a middleground and just emitting a message into stderr if the local database exists but is corrupted?

It may also be worth caching it if we do this though, so it doesn't print the message every time.

@LouieK22
Copy link

LouieK22 commented Jan 3, 2025

We should probably use a more generic top-level folder name (e.g. %localappdata%/rbx_dom on Windows, and ~/.rbx_dom on Mac/Linux) as it would give a better hint as to where these files came from. The reflection cache could be something like rbx_dom/cache/reflection.proto

This crate might come in handy for picking directories: https://crates.io/crates/directories

@Dekkonot
Copy link
Member Author

Dekkonot commented Jan 6, 2025

It's currently placed in %localappdata%/.rbx_reflection on Windows, $HOME/Library/Application Support/.rbxreflection on MacOS, and $HOME/.rbxreflection on Linux. .rbx_dom or something works too. It's not really important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants