Skip to content

Commit

Permalink
ignore non-json lines in cargoBuildLog (#234)
Browse files Browse the repository at this point in the history
Fixes issues with non-json values in cargoBuildLog: rust-lang/cargo#8179
---------

Co-authored-by: Ivan Petkov <ivanppetkov@gmail.com>
  • Loading branch information
GauravBholaris and ipetkov committed Feb 11, 2023
1 parent 0f41cc0 commit fd9359f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## Unreleased

### Fixed
* `buildPackage` is more tolerant of misbehaving proc macros which write to
stdout during the build

## [0.11.1] - 2023-01-21

### Changed
Expand Down
16 changes: 16 additions & 0 deletions checks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ in
touch $out
'';

# https://github.com/ipetkov/crane/pull/234
nonJsonCargoBuildLog =
let
nonJson = ''
db_id attr "field_id" Attribute { pound_token: Pound, style: Outer, bracket_token: Bracket, path: Path { leading_colon: None, segments: [PathSegment { ident: Ident { ident: "db_id", span: #0 bytes(8250..8255) }, arguments: None }] }, tokens: TokenStream [] }
'';
in
myLib.buildPackage {
src = myLib.cleanCargoSource ./simple;
buildPhaseCargoCommand = ''
cargoBuildLog=$(mktemp cargoBuildLogXXXX.json)
cargoWithProfile build --message-format json-render-diagnostics >"$cargoBuildLog"
echo "${nonJson}" >>"$cargoBuildLog"
'';
};

# https://github.com/ipetkov/crane/discussions/203
dependencyBuildScriptPerms = myLib.cargoClippy {
src = ./dependencyBuildScriptPerms;
Expand Down
7 changes: 5 additions & 2 deletions lib/setupHooks/installFromCargoBuildLogHook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ function installFromCargoBuildLog() (

echo searching for bins/libs to install from cargo build log at ${log}

local logs
logs=$(jq -R 'fromjson?' <"${log}")

local select_non_test='select(.reason == "compiler-artifact" and .profile.test == false)'
local select_bins="${select_non_test} | .executable | select(.!= null)"
local select_lib_files="${select_non_test}"'
Expand All @@ -29,12 +32,12 @@ function installFromCargoBuildLog() (
rmdir --ignore-fail-on-non-empty "${loc}"
}

jq -r <"${log}" "${select_bins}" | installArtifacts "${dest}/bin"
echo "${logs}" | jq -r "${select_bins}" | installArtifacts "${dest}/bin"

command cargo metadata --format-version 1 | jq '.workspace_members[]' | (
while IFS= read -r ws_member; do
local select_member_libs="select(.package_id == ${ws_member}) | ${select_lib_files}"
jq -r <"${log}" "${select_member_libs}" | installArtifacts "${dest}/lib"
echo "${logs}" | jq -r "${select_member_libs}" | installArtifacts "${dest}/lib"
done
)

Expand Down

0 comments on commit fd9359f

Please sign in to comment.