Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
surf: build infrastructure
Browse files Browse the repository at this point in the history
When we attempted to publish the new version of `radicle-surf` we ran
into issues with the `build.rs` file executing -- it was missing the
path to `data/git-platinum.tgz` in its isolated environment.

The fix here is to move the `data` artifacts into the `surf` directory
and add the `git-platinum.tgz` file as an `include` artifact.
When the `build.rs` file executes it will detect whether it ran with
`cargo build` or `cargo publish` by looking at the current directory.
Depending on which it is using it will unpack the tar file into the
correct directory.

Moving the `data` directory required us to also change the tests to
point to the correct directory.

Signed-off-by: Fintan Halpenny <[email protected]>
  • Loading branch information
FintanH committed May 4, 2021
1 parent 314ca22 commit 1490586
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ Cargo.lock

# This is an inner git repo unpacked (if necessary) from the archive.
# Git doesn't like nested repos, and we don't really want to use submodules.
/data/git-platinum
/surf/data/git-platinum
2 changes: 1 addition & 1 deletion source/src/revision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ where
}

/// Provide the [`Revisions`] for the given `peer_id`, looking for the
/// branches as [`BranchType::Local`].
/// branches as [`BranchSelector::Local`].
///
/// If there are no branches then this returns `None`.
///
Expand Down
1 change: 1 addition & 0 deletions surf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ license = "GPL-3.0-or-later"
include = [
"**/*.rs",
"Cargo.toml",
"data/git-platinum.tgz",
]

[features]
Expand Down
38 changes: 35 additions & 3 deletions surf/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,46 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use std::{fs::File, path::Path};
use std::{
env,
fs::File,
io,
path::{Path, PathBuf},
};

use flate2::read::GzDecoder;
use tar::Archive;

enum Command {
Build(PathBuf),
Publish(PathBuf),
}

impl Command {
fn new() -> io::Result<Self> {
let current = env::current_dir()?;
Ok(if current.ends_with("surf") {
Self::Build(current)
} else {
Self::Publish(PathBuf::from(
env::var("OUT_DIR").map_err(|err| io::Error::new(io::ErrorKind::Other, err))?,
))
})
}

fn target(&self) -> PathBuf {
match self {
Self::Build(path) => path.join("data"),
Self::Publish(path) => path.join("data"),
}
}
}

fn main() {
let git_platinum_tarball = "../data/git-platinum.tgz";
let target = "../data/";
let target = Command::new()
.expect("could not determine the cargo command")
.target();
let git_platinum_tarball = "./data/git-platinum.tgz";

unpack(git_platinum_tarball, target).expect("Failed to unpack git-platinum");

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions surf/examples/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn main() {
git::Browser::new(&repo, git::Branch::local("master")).expect("failed to create browser:");

match options.head_revision {
HeadRevision::HEAD => {
HeadRevision::Head => {
reset_browser_to_head_or_exit(&mut browser);
},
HeadRevision::Commit(id) => {
Expand Down Expand Up @@ -148,7 +148,7 @@ struct Options {
}

enum HeadRevision {
HEAD,
Head,
Commit(String),
}

Expand All @@ -168,7 +168,7 @@ impl Options {
let base_revision = args[2].clone();
let head_revision = {
if args[3].eq_ignore_ascii_case("HEAD") {
HeadRevision::HEAD
HeadRevision::Head
} else {
HeadRevision::Commit(args[3].clone())
}
Expand Down
2 changes: 1 addition & 1 deletion surf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
//!
//! # fn main() -> Result<(), Box<dyn Error>> {
//! // We're going to point to this repo.
//! let repo = git::Repository::new("../data/git-platinum")?;
//! let repo = git::Repository::new("./data/git-platinum")?;
//!
//! // Here we initialise a new Broswer for a the git repo.
//! let mut browser = git::Browser::new(&repo, git::Branch::local("master"))?;
Expand Down
Loading

0 comments on commit 1490586

Please sign in to comment.