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

Use standard directories when running on Linux #91

Merged
merged 71 commits into from
Nov 26, 2020
Merged

Conversation

agersant
Copy link
Owner

Proposed fix for #39

Copy link

@fgaz fgaz left a comment

Choose a reason for hiding this comment

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

I just took a quick look for now

General suggestions:

#39 (comment)

NixOS-specific suggestions:

Nixos tries really hard to build packages in an isolated and reproducible manner. Because of this, we have a wrapper for cargo that downloads and checksums the dependencies separately, so it'd be great to have separate targets to build/install the binary and to install the data files (nixos would only use the latter).

Something like this:

.PHONY: all build install install-bin install-data clean uninstall

[...set the variables...]

build:
	cargo build --release

install: install-bin install-data

install-bin: build
	install -Dm755 ./target/release/polaris $(BINDIR)/polaris

install-data:
	install -d $(DATADIR)
	cp -r ./web $(DATADIR)/web
	cp -r ./swagger $(DATADIR)/swagger

Copy link

@fgaz fgaz left a comment

Choose a reason for hiding this comment

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

Just a couple suggestions for now.

i'm still testing this, but I think there'll also be some regressions:

  • Not being able to run the installed program as a normal user, since as far as I can see there's no way to override the data/cache/log directory
  • Not being able to run the tests after running make (not that important)

Comment on lines 3 to 4
BINDIR ?= /usr/local/bin
DATADIR ?= /usr/local/share
Copy link

Choose a reason for hiding this comment

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

Suggested change
BINDIR ?= /usr/local/bin
DATADIR ?= /usr/local/share
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
DATADIR ?= $(PREFIX)/share

Copy link
Owner Author

@agersant agersant Aug 20, 2020

Choose a reason for hiding this comment

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

I just pushed some follow-up changes. Your suggestion lead me to following the Make manual more closely. The data/cache/log directories are now also under /usr/local by default, but can be overridden by setting LOCALSTATEDIR.

Tests should work regardless of all this as they do not rely on any of these values (with the caveat they only validate the software, not its installation).

Comment on lines 21 to 42
rm -r $(POLARIS_BIN_DIR)
rm -r $(POLARIS_DATA_DIR)
rm $(POLARIS_BIN_PATH)
rm -r $(POLARIS_WEB_DIR)
rm -r $(POLARIS_SWAGGER_DIR)
rm -r $(POLARIS_DB_DIR)
rm -r $(POLARIS_LOG_DIR)
rm -r $(POLARIS_CACHE_DIR)
rm -r $(POLARIS_PID_DIR)
Copy link

@fgaz fgaz Aug 19, 2020

Choose a reason for hiding this comment

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

I think data files shouldn't be removed on uninstall (most programs leave them there)

Copy link
Owner Author

Choose a reason for hiding this comment

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

I can't find any official recommendation on this, but I think as a user I would prefer everything gone from my system. I will leave this as-is unless there is a strong argument for leaving files behind.

@agersant
Copy link
Owner Author

I still want to give this a quick test in a Linux VM myself before merging it, but is it all-clear on your end @fgaz?

Also cc @ogarcia as this will probably have impact on polaris-docker.

@fgaz
Copy link

fgaz commented Aug 27, 2020

Sorry, I've been a bit busy. I'll give this some proper testing next week

@agersant
Copy link
Owner Author

No worries!

@fgaz
Copy link

fgaz commented Sep 25, 2020

next week

Or next month ;)

res/unix/Makefile Outdated Show resolved Hide resolved
src/main.rs Outdated
Comment on lines 137 to 141
options.optopt("", "log", "set the path to the log file", "FILE");
options.optopt("", "pid", "set the path to the pid file", "FILE");
options.optopt(
"l",
"log",
Copy link

Choose a reason for hiding this comment

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

Conflicting options

Copy link
Owner Author

@agersant agersant Sep 27, 2020

Choose a reason for hiding this comment

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

Good catch. This PR is already fat breaking changes so I think I'll rename the old log option to log-level.

@fgaz
Copy link

fgaz commented Sep 27, 2020

I just tested again, and found a problem with the -system/-xdg split. If I do:

make PREFIX=whatever
make install-system PREFIX=whatever (or install-xdg)

then the default data paths are going to be relative to the current directory. This is because the installed executable is the one that as built with make all (-> make build), which does not set the variables.

@agersant
Copy link
Owner Author

Wow, I would 100% have missed that and shipped it. Thanks again for your help with this work.

I fixed this issue by splitting the build command into build-system and build-xdg, defaulting to build-system when running through make all or make build.

@agersant
Copy link
Owner Author

@fgaz Would you have time to give this another try before I merge it for good?

@fgaz
Copy link

fgaz commented Nov 26, 2020

@agersant I just did a quick test, and it seems to work great!

@codecov-io
Copy link

Codecov Report

Merging #91 (d0d4581) into master (0927f38) will decrease coverage by 0.16%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #91      +/-   ##
==========================================
- Coverage   70.27%   70.11%   -0.17%     
==========================================
  Files          22       22              
  Lines        1440     1442       +2     
==========================================
- Hits         1012     1011       -1     
- Misses        428      431       +3     
Impacted Files Coverage Δ
src/db/mod.rs 88.37% <ø> (-0.27%) ⬇️
src/main.rs 0.00% <0.00%> (ø)
src/utils.rs 88.23% <ø> (+20.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0927f38...5b5fcdd. Read the comment docs.

@agersant agersant merged commit 538b41a into master Nov 26, 2020
@agersant agersant deleted the directories branch November 26, 2020 23:57
@agersant agersant restored the directories branch December 8, 2020 06:22
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.

4 participants