Skip to content

Commit

Permalink
feat!: add url to lockfile
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Jan 4, 2025
1 parent 7dfdc61 commit e789652
Show file tree
Hide file tree
Showing 30 changed files with 390 additions and 119 deletions.
9 changes: 6 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions rocks-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ walkdir = "2.5.0"
which = "7.0.0"
indicatif = "0.17.8"
path-absolutize = "3.1.1"
url = "2.5.4"

[dev-dependencies]
assert_fs = "1.1.2"

[dependencies.rocks-lib]
path = "../rocks-lib/"
Expand Down
3 changes: 2 additions & 1 deletion rocks-bin/src/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ pub async fn fetch_remote(data: UnpackRemote, config: Config) -> Result<()> {

let rockspec = Download::new(&package_req, &config, &bar)
.download_rockspec()
.await?;
.await?
.rockspec;

let destination = data
.path
Expand Down
3 changes: 2 additions & 1 deletion rocks-bin/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ pub async fn info(data: Info, config: Config) -> Result<()> {

let rockspec = Download::new(&data.package, &config, &bar)
.download_rockspec()
.await?;
.await?
.rockspec;

bar.map(|b| b.finish_and_clear());

Expand Down
5 changes: 3 additions & 2 deletions rocks-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use rocks_lib::{
config::{ConfigBuilder, LuaVersion},
lockfile::PinnedState::{Pinned, Unpinned},
};
use url::Url;

/// A fast and efficient Lua package manager.
#[derive(Parser)]
Expand All @@ -42,12 +43,12 @@ pub struct Cli {
/// Fetch rocks/rockspecs from this server (takes priority
/// over config file).
#[arg(long, value_name = "server")]
pub server: Option<String>,
pub server: Option<Url>,

/// Fetch rocks/rockspecs from this server in addition to the main server
/// (overrides any entries in the config file).
#[arg(long, value_name = "extra-server")]
pub extra_servers: Option<Vec<String>>,
pub extra_servers: Option<Vec<Url>>,

/// Restrict downloads to paths matching the given URL.
#[arg(long, value_name = "url")]
Expand Down
2 changes: 1 addition & 1 deletion rocks-bin/src/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn set_pinned_state(data: ChangePin, config: Config, pin: PinnedState) -> Re
match tree.match_rocks_and(&data.package.clone().into_package_req(), |package| {
pin != package.pinned()
})? {
RockMatches::Single(mut rock) => Ok(operations::set_pinned_state(&mut rock, &tree, pin)?),
RockMatches::Single(rock) => Ok(operations::set_pinned_state(&rock, &tree, pin)?),
RockMatches::Many(_) => {
todo!("Add an error here about many conflicting types and to use `all:`")
}
Expand Down
9 changes: 8 additions & 1 deletion rocks-bin/src/run_lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ Options:

#[cfg(test)]
mod test {
use std::path::PathBuf;

use rocks_lib::config::ConfigBuilder;

use super::*;
Expand All @@ -123,7 +125,12 @@ mod test {
args: Some(vec!["-v".into()]),
..RunLua::default()
};
let config = ConfigBuilder::new().build().unwrap();
let temp: PathBuf = assert_fs::TempDir::new().unwrap().path().into();
let config = ConfigBuilder::new()
.tree(Some(temp.clone()))
.luarocks_tree(Some(temp))
.build()
.unwrap();
run_lua(args, config).await.unwrap()
}
}
1 change: 1 addition & 0 deletions rocks-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ async-recursion = "1.1.1"
shell-words = "1.1.0"
shlex = "1.3.0"
pkg-config = "0.3.31"
url = "2.5.4"

[dev-dependencies]
httptest = { version = "0.16.1" }
Expand Down
5 changes: 4 additions & 1 deletion rocks-lib/resources/test/sample-tree/5.1/lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"48ec344951668eca0e0a4ff284d804a11e4e709194df3191a72ed8fac89cf2e0"
],
"constraint": null,
"source": "luarocks+https://luarocks.org/",
"hashes": {
"rockspec": "sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=",
"source": "sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek="
Expand All @@ -20,6 +21,7 @@
"pinned": false,
"dependencies": [],
"constraint": null,
"source": "luarocks+https://luarocks.org/",
"hashes": {
"rockspec": "sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=",
"source": "sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek="
Expand All @@ -33,6 +35,7 @@
"48ec344951668eca0e0a4ff284d804a11e4e709194df3191a72ed8fac89cf2e0"
],
"constraint": null,
"source": "luarocks+https://luarocks.org/",
"hashes": {
"rockspec": "sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=",
"source": "sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek="
Expand All @@ -43,4 +46,4 @@
"d7164c4921869877c7f29fce3f14b8ea78e0aec0d0c36123a3a920a894785ea5",
"aa0a5bcd396f3b8e59fa9dd8059a06c3bf4952f48473214d96fc46895edb59f0"
]
}
}
17 changes: 17 additions & 0 deletions rocks-lib/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
operations::{self, FetchSrcRockError},
package::PackageSpec,
progress::{Progress, ProgressBar},
remote_package_source::RemotePackageSource,
rockspec::{Build as _, BuildBackendSpec, LuaVersionError, Rockspec},
tree::{RockLayout, Tree},
};
Expand Down Expand Up @@ -43,6 +44,7 @@ pub struct Build<'a> {
pin: PinnedState,
constraint: LockConstraint,
behaviour: BuildBehaviour,
source: Option<RemotePackageSource>,
}

impl<'a> Build<'a> {
Expand All @@ -59,6 +61,7 @@ impl<'a> Build<'a> {
pin: PinnedState::default(),
constraint: LockConstraint::default(),
behaviour: BuildBehaviour::default(),
source: None,
}
}

Expand All @@ -77,13 +80,25 @@ impl<'a> Build<'a> {
Self { behaviour, ..self }
}

/// Sets the remote source of the package to be built.
pub(crate) fn source(self, source: RemotePackageSource) -> Self {
Self {
source: Some(source),
..self
}
}

/// Builds the package.
pub async fn build(self) -> Result<LocalPackage, BuildError> {
let source = self.source.unwrap_or_else(|| {
RemotePackageSource::RockspecContent(self.rockspec.raw_content.clone())
});
build(
self.rockspec,
self.pin,
self.constraint,
self.behaviour,
source,
self.config,
self.progress,
)
Expand Down Expand Up @@ -252,6 +267,7 @@ async fn build(
pinned: PinnedState,
constraint: LockConstraint,
behaviour: BuildBehaviour,
source: RemotePackageSource,
config: &Config,
progress: &Progress<ProgressBar>,
) -> Result<LocalPackage, BuildError> {
Expand Down Expand Up @@ -308,6 +324,7 @@ async fn build(
let mut package = LocalPackage::from(
&PackageSpec::new(rockspec.package.clone(), rockspec.version.clone()),
constraint,
source,
hashes,
);
package.spec.pinned = pinned;
Expand Down
19 changes: 10 additions & 9 deletions rocks-lib/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{
collections::HashMap, env, fmt::Display, io, path::PathBuf, str::FromStr, time::Duration,
};
use thiserror::Error;
use url::Url;

use crate::{
build::{
Expand Down Expand Up @@ -145,8 +146,8 @@ pub struct NoValidHomeDirectory;
#[derive(Debug, Clone)]
pub struct Config {
enable_development_rockspecs: bool,
server: String,
extra_servers: Vec<String>,
server: Url,
extra_servers: Vec<Url>,
only_sources: Option<String>,
namespace: String,
lua_dir: PathBuf,
Expand Down Expand Up @@ -197,11 +198,11 @@ impl Config {
self.enable_development_rockspecs
}

pub fn server(&self) -> &String {
pub fn server(&self) -> &Url {
&self.server
}

pub fn extra_servers(&self) -> &Vec<String> {
pub fn extra_servers(&self) -> &Vec<Url> {
self.extra_servers.as_ref()
}

Expand Down Expand Up @@ -285,8 +286,8 @@ pub enum ConfigError {
#[derive(Default)]
pub struct ConfigBuilder {
enable_development_rockspecs: Option<bool>,
server: Option<String>,
extra_servers: Option<Vec<String>>,
server: Option<Url>,
extra_servers: Option<Vec<Url>>,
only_sources: Option<String>,
namespace: Option<String>,
lua_dir: Option<PathBuf>,
Expand Down Expand Up @@ -317,11 +318,11 @@ impl ConfigBuilder {
}
}

pub fn server(self, server: Option<String>) -> Self {
pub fn server(self, server: Option<Url>) -> Self {
Self { server, ..self }
}

pub fn extra_servers(self, extra_servers: Option<Vec<String>>) -> Self {
pub fn extra_servers(self, extra_servers: Option<Vec<Url>>) -> Self {
Self {
extra_servers,
..self
Expand Down Expand Up @@ -431,7 +432,7 @@ impl ConfigBuilder {
enable_development_rockspecs: self.enable_development_rockspecs.unwrap_or(false),
server: self
.server
.unwrap_or_else(|| "https://luarocks.org/".to_string()),
.unwrap_or_else(|| Url::parse("https://luarocks.org/").unwrap()),
extra_servers: self.extra_servers.unwrap_or_default(),
only_sources: self.only_sources,
namespace: self.namespace.unwrap_or_default(),
Expand Down
2 changes: 2 additions & 0 deletions rocks-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub mod rockspec;
pub mod tree;
pub mod upload;

pub(crate) mod remote_package_source;

/// An internal string describing the server-side API version that we support.
/// Whenever we connect to a server (like `luarocks.org`), we ensure that these
/// two versions match (meaning we can safely communicate with the server).
Expand Down
Loading

0 comments on commit e789652

Please sign in to comment.