Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
a-kenji committed Oct 8, 2023
1 parent 49e8ec6 commit 6e863bc
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 287 deletions.
45 changes: 3 additions & 42 deletions src/bin/fe/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{fs, path::PathBuf, sync::Mutex};
use tracing::Level;
use tracing_subscriber::{filter::EnvFilter, FmtSubscriber};

// use crate::consts::{LOG_ENV, LOG_PATH};
const LOG_ENV: &str = "FE_LOG";

/// Configuration of logging
pub fn init_logging(log_file: Option<PathBuf>) -> Result<(), std::io::Error> {
Expand All @@ -26,7 +26,7 @@ pub fn init_logging(log_file: Option<PathBuf>) -> Result<(), std::io::Error> {
.with_ansi(true)
.with_line_number(true);

if let Ok(env_filter) = EnvFilter::try_from_env("RUST_LOG") {
if let Ok(env_filter) = EnvFilter::try_from_env(LOG_ENV) {
let subscriber = subscriber.with_env_filter(env_filter).finish();
tracing::subscriber::set_global_default(subscriber)
.expect("setting default subscriber failed");
Expand All @@ -40,44 +40,5 @@ pub fn init_logging(log_file: Option<PathBuf>) -> Result<(), std::io::Error> {
}

pub fn init() -> Result<(), std::io::Error> {
init_logging(Some("/tmp/flake-add/flk-add.log".into()))
}

pub fn log_err<S: Into<String> + std::fmt::Display>(err: S) {
tracing::error!("Received {}", err.into());
}

pub(crate) fn log_node_enter_info(node: &rowan::NodeOrToken<rnix::SyntaxNode, rnix::SyntaxToken>) {
tracing::debug!("Start Enter: {node}");
log_node_debug_info(node);
tracing::debug!("End Enter: {node}");
}

pub(crate) fn log_node_leave_info(node: &rowan::NodeOrToken<rnix::SyntaxNode, rnix::SyntaxToken>) {
tracing::debug!("Start Leave: {node}");
log_node_debug_info(node);
tracing::debug!("End Leave: {node}");
}

pub(crate) fn log_node_debug_info(node: &rowan::NodeOrToken<rnix::SyntaxNode, rnix::SyntaxToken>) {
tracing::debug!("Index: {:?}", node.index());
tracing::debug!("Kind: {:?}", node.kind());
tracing::debug!("Parent: {:?}", node.parent());
if let Some(parent) = node.parent() {
tracing::debug!("Parent Node: {:?}", parent);
tracing::debug!("Parent Node Kind: {:?}", parent.kind());
}
if let Some(node) = node.as_node() {
tracing::debug!("Green Kind: {:?}", node.green().kind());
for child in node.children() {
tracing::debug!("Children: {:?}", child);
tracing::debug!("Children Kind: {:?}", child.green().kind());
}
tracing::debug!("Node Next Sibling: {:?}", node.next_sibling());
tracing::debug!("Node Prev Sibling: {:?}", node.prev_sibling());
}
if let Some(token) = node.as_token() {
tracing::debug!("Token: {}", token);
}
tracing::debug!("Node Index: {}", node.index());
init_logging(Some("/tmp/fe/fe.log".into()))
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct State {
changes: Vec<Change>,
}

#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
pub enum Change {
#[default]
None,
Expand Down
248 changes: 6 additions & 242 deletions tests/fixtures/root.flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,252 +8,16 @@

rust-overlay = {
url = "github:oxalica/rust-overlay";
# inputs.nixpkgs.follows = "nixpkgs";
# inputs.flake-utils.follows = "flake-utils";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
crane = {
url = "github:ipetkov/crane";
# inputs.nixpkgs.follows = "nixpkgs";
# inputs.rust-overlay.follows = "rust-overlay";
# inputs.flake-utils.follows = "flake-utils";
inputs.nixpkgs.follows = "nixpkgs";
inputs.rust-overlay.follows = "rust-overlay";
inputs.flake-utils.follows = "flake-utils";
};
};

outputs =
{
self,
nixpkgs,
flake-utils,
flake-utelinos,
rust-overlay,
crane,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
stdenv =
if pkgs.stdenv.isLinux then
pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv
else
pkgs.stdenv
;
overlays = [ (import rust-overlay) ];
rustPkgs = import nixpkgs { inherit system overlays; };
src = self;
RUST_TOOLCHAIN = src + "/rust-toolchain.toml";
RUSTFMT_TOOLCHAIN = src + "/.rustfmt-toolchain.toml";

cargoTOML = builtins.fromTOML (builtins.readFile (src + "/Cargo.toml"));
inherit (cargoTOML.package) version name;
# rustToolchainTOML = rustPkgs.rust-bin.fromRustupToolchainFile RUST_TOOLCHAIN;
rustToolchainTOML = rustPkgs.rust-bin.stable.latest.minimal;

rustFmtToolchainTOML =
rustPkgs.rust-bin.fromRustupToolchainFile
RUSTFMT_TOOLCHAIN;

rustToolchainDevTOML = rustToolchainTOML.override {
extensions = [
"clippy"
"rust-analysis"
"rust-docs"
];
targets = [ ];
};
gitDate = "${builtins.substring 0 4 self.lastModifiedDate}-${
builtins.substring 4 2 self.lastModifiedDate
}-${builtins.substring 6 2 self.lastModifiedDate}";
gitRev = self.shortRev or "Not committed yet.";
cargoLock = {
lockFile = builtins.path {
path = self + "/Cargo.lock";
name = "Cargo.lock";
};
allowBuiltinFetchGit = true;
};
rustc = rustToolchainTOML;
cargo = rustToolchainTOML;

buildInputs = [ pkgs.installShellFiles ];

devInputs = [
rustToolchainDevTOML
rustFmtToolchainTOML
# pkgs.just
# pkgs.lychee
pkgs.taplo
pkgs.cargo-watch
pkgs.cargo-tarpaulin
#
# pkgs.cargo-deny
# pkgs.cargo-bloat
# pkgs.cargo-machete
# pkgs.cargo-outdated
# pkgs.cargo-flamegraph
# pkgs.cargo-diet
# pkgs.cargo-modules
# pkgs.cargo-nextest
# pkgs.cargo-dist
# pkgs.cargo-public-api
# pkgs.cargo-unused-features
#
# # snapshot testing
pkgs.cargo-insta
#
# (pkgs.symlinkJoin {
# name = "cargo-udeps-wrapped";
# paths = [pkgs.cargo-udeps];
# nativeBuildInputs = [pkgs.makeWrapper];
# postBuild = ''
# wrapProgram $out/bin/cargo-udeps \
# --prefix PATH : ${pkgs.lib.makeBinPath [
# (rustPkgs.rust-bin.selectLatestNightlyWith
# (toolchain: toolchain.default))
# ]}
# '';
# })
# (pkgs.symlinkJoin {
# name = "cargo-careful-wrapped";
# paths = [pkgs.cargo-careful];
# nativeBuildInputs = [pkgs.makeWrapper];
# postBuild = ''
# wrapProgram $out/bin/cargo-careful \
# --prefix PATH : ${pkgs.lib.makeBinPath [
# (rustPkgs.rust-bin.selectLatestNightlyWith
# (
# toolchain:
# toolchain
# .default
# .override {
# extensions = ["rust-src"];
# }
# ))
# ]}
# '';
# })
#alternative linker
pkgs.clang
];
shellInputs =
[
# pkgs.shellcheck
# pkgs.actionlint
];
fmtInputs = [
pkgs.alejandra
pkgs.treefmt
pkgs.taplo
pkgs.typos
];
editorConfigInputs =
[
# pkgs.editorconfig-checker
];
actionlintInputs = [ pkgs.actionlint ];
# Common arguments for the crane build
commonArgs = {
inherit stdenv version name;
pname = name;
src = pkgs.lib.cleanSourceWith {
src = craneLib.path ./.; # The original, unfiltered source
};
};
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchainTOML;
# Build *just* the cargo dependencies, so we can reuse
# all of that work (e.g. via cachix) when running in CI
assetDir = "target/assets";
postInstall = name: ''
# install the manpage
installManPage ${assetDir}/${name}.1
# explicit behavior
cp ${assetDir}/${name}.bash ./completions.bash
installShellCompletion --bash --name ${name}.bash ./completions.bash
cp ${assetDir}/${name}.fish ./completions.fish
installShellCompletion --fish --name ${name}.fish ./completions.fish
cp ${assetDir}/_${name} ./completions.zsh
installShellCompletion --zsh --name _${name} ./completions.zsh
'';

cargoArtifacts = craneLib.buildDepsOnly commonArgs;
meta = with pkgs.lib; {
homepage = "https://github.com/a-kenji/flake-add";
description = "Manage your flake inputs comfortably.";
license = [ licenses.mit ];
};
in
rec {
devShells = {
default = devShells.fullShell;
fullShell = (pkgs.mkShell.override { inherit stdenv; }) {
buildInputs = shellInputs ++ fmtInputs ++ devInputs;
inherit name;
ASSET_DIR = assetDir;
RUST_LOG = "debug";
RUST_BACKTRACE = true;
# RUSTFLAGS = "-C linker=clang -C link-arg=-fuse-ld=${pkgs.mold}/bin/mold -C target-cpu=native";
RUSTFLAGS = "-C linker=clang -C link-arg=-fuse-ld=${pkgs.mold}/bin/mold";
};
editorConfigShell = pkgs.mkShell { buildInputs = editorConfigInputs; };
actionlintShell = pkgs.mkShell { buildInputs = actionlintInputs; };
fmtShell = pkgs.mkShell { buildInputs = fmtInputs; };
};
packages = {
default = packages.crane;
upstream = (pkgs.makeRustPlatform { inherit cargo rustc; }).buildRustPackage {
cargoDepsName = name;
GIT_DATE = gitDate;
GIT_REV = gitRev;
ASSET_DIR = assetDir;
doCheck = false;
version = "unstable" + gitDate;
inherit
assetDir
buildInputs
cargoLock
meta
name
postInstall
src
stdenv
;
};
crane = craneLib.buildPackage (
commonArgs
// {
cargoExtraArgs = "-p ${name}";
GIT_DATE = gitDate;
GIT_REV = gitRev;
ASSET_DIR = assetDir;
doCheck = false;
version = "unstable-" + gitDate;
# pname = name;
pname = "fe";
name = "fe";
# installPhase = ''
# runHook preInstall
# mkdir -p $out/bin
# cp target/release/flake-add $out/bin/fe
# runHook postInstall
# '';
postInstall = postInstall "fe";
inherit
assetDir
buildInputs
cargoArtifacts
meta
# name

stdenv
;
}
);
};
apps.default = {
type = "app";
program = "${packages.default}/bin/${name}";
};
formatter = pkgs.alejandra;
}
);
outputs = _: { };
}
28 changes: 28 additions & 0 deletions tests/snapshots/walker__load_root.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
source: tests/walker.rs
expression: walker.inputs
info:
flake_nix: ""
changes: []
---
crane:
id: crane
flake: true
url: "\"github:ipetkov/crane\""
follows: []
flake-utelinos:
id: flake-utelinos
flake: true
url: "\"github:numtide/flake-utils\""
follows: []
nixpkgs:
id: nixpkgs
flake: true
url: "\"github:nixos/nixpkgs/nixos-unstable\""
follows: []
rust-overlay:
id: rust-overlay
flake: true
url: "\"github:oxalica/rust-overlay\""
follows: []

35 changes: 35 additions & 0 deletions tests/snapshots/walker__root_add_toplevel_id_uri.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
source: tests/walker.rs
expression: change.to_string()
info:
flake_nix: ""
changes:
- Add:
id: vmsh
uri: "github:mic92/vmsh"
---
{
description = "Manage your flake inputs comfortably.";

inputs = {
vmsh.url = "github:mic92/vmsh";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";

flake-utelinos.url = "github:numtide/flake-utils";

rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
inputs.rust-overlay.follows = "rust-overlay";
inputs.flake-utils.follows = "flake-utils";
};
};

outputs = _: { };
}

Loading

0 comments on commit 6e863bc

Please sign in to comment.