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

Add loading of packaged libraries by feature flag #51

Merged
merged 2 commits into from
Dec 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build-test-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: build
args: --package ${{ matrix.crate }} --release --target ${{ matrix.target }}
args: --manifest-path ${{ matrix.crate }}/Cargo.toml --release --target ${{ matrix.target }} --features "packaged"

- name: Test ${{ matrix.crate }}
uses: actions-rs/cargo@v1
with:
command: test
args: --package ${{ matrix.crate }} --release --target ${{ matrix.target }}
args: --manifest-path ${{ matrix.crate }}/Cargo.toml --release --target ${{ matrix.target }} --features "packaged"

- name: rustfmt
if: matrix.os == 'ubuntu-latest' && matrix.rust == 'stable'
Expand Down
6 changes: 5 additions & 1 deletion vhdl_ls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ env_logger = "0.6.0"

[dev-dependencies]
tempfile = "^3"
pretty_assertions = "^0"
pretty_assertions = "^0"

[features]
default = []
packaged = ["vhdl_parser/packaged"]
6 changes: 5 additions & 1 deletion vhdl_parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ parking_lot = "^0"
[dev-dependencies]
tempfile = "^3"
pretty_assertions = "^0"
assert_matches = "^1"
assert_matches = "^1"

[features]
default = []
packaged = []
28 changes: 28 additions & 0 deletions vhdl_parser/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use self::fnv::FnvHashMap;
use self::toml::Value;
use crate::data::*;
use fnv;
use std::env;
use std::fs::File;
use std::io;
use std::io::prelude::*;
Expand Down Expand Up @@ -191,6 +192,32 @@ impl Config {
}
}

/// Load configuration file from installation folder
fn load_installed_config(&mut self, messages: &mut dyn MessageHandler) {
let config_relative_path = if cfg!(feature = "packaged") {
// relative to packaged bin folder
"../vhdl_libraries"
} else {
// relative to target/debug or target/release
"../../vhdl_libraries"
};

let exe_path = env::current_exe().expect("Executable path needed");
let exe_folder = exe_path.parent().expect("Executable folder must exist");

let mut file_name = exe_folder.join(config_relative_path);
file_name.push("vhdl_ls.toml");

if !file_name.exists() {
panic!(
"Couldn't find installed libraries at {}.",
file_name.to_string_lossy()
);
}

self.load_config(&file_name, "Installation", messages);
}

/// Load configuration file from home folder
fn load_home_config(&mut self, messages: &mut dyn MessageHandler) {
if let Some(home_dir) = dirs::home_dir() {
Expand Down Expand Up @@ -234,6 +261,7 @@ impl Config {

/// Load all external configuration
pub fn load_external_config(&mut self, messages: &mut dyn MessageHandler) {
self.load_installed_config(messages);
self.load_home_config(messages);
self.load_env_config("VHDL_LS_CONFIG", messages);
}
Expand Down