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

Add input file SHA256 hash consts to Go/Rust generated code #89

Merged
merged 16 commits into from
Jun 18, 2022
11 changes: 10 additions & 1 deletion lib/xdrgen/generators/go.rb
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,16 @@ def render_top_matter(out)

"github.com/stellar/go-xdr/xdr3"
)

EOS
out.break
out.puts <<-EOS.strip_heredoc
// XdrFilesSHA256 is the SHA256 hashes of source files.
var XdrFilesSHA256 = map[string]string{
#{@output.relative_source_path_sha256_hashes.map(){ |path, hash| %{"#{path}": "#{hash}"} }.join(",\n")}
}
EOS
out.break
out.puts <<-EOS.strip_heredoc
type xdrType interface {
xdrType()
}
Expand Down
10 changes: 10 additions & 0 deletions lib/xdrgen/generators/rust.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ def render_top_matter(out)
// #{@output.relative_source_paths.join("\n// ")}
EOS
out.break
out.puts "#![allow(clippy::missing_errors_doc, clippy::unreadable_literal)]"
out.break
source_paths_sha256_hashes = @output.relative_source_path_sha256_hashes
out.puts <<-EOS.strip_heredoc
/// `XDR_FILES_SHA256` is a list of pairs of source files and their SHA256 hashes.
pub const XDR_FILES_SHA256: [(&str, &str); #{source_paths_sha256_hashes.count}] = [
#{source_paths_sha256_hashes.map(){ |path, hash| %{("#{path}", "#{hash}")} }.join(",\n")}
];
EOS
out.break
end

def render_lib(out)
Expand Down
2 changes: 0 additions & 2 deletions lib/xdrgen/generators/rust/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(clippy::missing_errors_doc, clippy::unreadable_literal)]

use core::{fmt, fmt::Debug, ops::Deref};

// When feature alloc is turned off use static lifetime Box and Vec types.
Expand Down
7 changes: 6 additions & 1 deletion lib/xdrgen/output.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'fileutils'
require 'digest'

module Xdrgen
class Output
Expand All @@ -13,7 +14,11 @@ def initialize(source_paths, output_dir)
end

def relative_source_paths
@source_paths.map { |p| Pathname.new(p).expand_path.relative_path_from(Dir.pwd) }
@source_paths.map { |p| Pathname.new(p).expand_path.relative_path_from(Dir.pwd).to_s }.sort
end

def relative_source_path_sha256_hashes
relative_source_paths.map { |p| [p, Digest::SHA256.file(p).hexdigest] }.to_h
end

def open(child_path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import (
"github.com/stellar/go-xdr/xdr3"
)

// XdrFilesSHA256 is the SHA256 hashes of source files.
var XdrFilesSHA256 = map[string]string{
"spec/fixtures/generator/block_comments.x": "e13131bc4134f38da17b9d5e9f67d2695a69ef98e3ef272833f4c18d0cc88a30"
}

type xdrType interface {
xdrType()
}
Expand Down
5 changes: 5 additions & 0 deletions spec/output/generator_spec_go/const.x/MyXDR_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import (
"github.com/stellar/go-xdr/xdr3"
)

// XdrFilesSHA256 is the SHA256 hashes of source files.
var XdrFilesSHA256 = map[string]string{
"spec/fixtures/generator/const.x": "0bff3b37592fcc16cad2fe10b9a72f5d39d033a114917c24e86a9ebd9cda9c37"
}

type xdrType interface {
xdrType()
}
Expand Down
5 changes: 5 additions & 0 deletions spec/output/generator_spec_go/enum.x/MyXDR_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import (
"github.com/stellar/go-xdr/xdr3"
)

// XdrFilesSHA256 is the SHA256 hashes of source files.
var XdrFilesSHA256 = map[string]string{
"spec/fixtures/generator/enum.x": "35cf5e97e2057039640ed260e8b38bb2733a3c3ca8529c93877bdec02a999d7f"
}

type xdrType interface {
xdrType()
}
Expand Down
5 changes: 5 additions & 0 deletions spec/output/generator_spec_go/nesting.x/MyXDR_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import (
"github.com/stellar/go-xdr/xdr3"
)

// XdrFilesSHA256 is the SHA256 hashes of source files.
var XdrFilesSHA256 = map[string]string{
"spec/fixtures/generator/nesting.x": "5537949272c11f1bd09cf613a3751668b5018d686a1c2aaa3baa91183ca18f6a"
}

type xdrType interface {
xdrType()
}
Expand Down
5 changes: 5 additions & 0 deletions spec/output/generator_spec_go/optional.x/MyXDR_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import (
"github.com/stellar/go-xdr/xdr3"
)

// XdrFilesSHA256 is the SHA256 hashes of source files.
var XdrFilesSHA256 = map[string]string{
"spec/fixtures/generator/optional.x": "3241e832fcf00bca4315ecb6c259621dafb0e302a63a993f5504b0b5cebb6bd7"
}

type xdrType interface {
xdrType()
}
Expand Down
5 changes: 5 additions & 0 deletions spec/output/generator_spec_go/struct.x/MyXDR_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import (
"github.com/stellar/go-xdr/xdr3"
)

// XdrFilesSHA256 is the SHA256 hashes of source files.
var XdrFilesSHA256 = map[string]string{
"spec/fixtures/generator/struct.x": "c6911a83390e3b499c078fd0c579132eacce88a4a0538d3b8b5e57747a58db4a"
}

type xdrType interface {
xdrType()
}
Expand Down
5 changes: 5 additions & 0 deletions spec/output/generator_spec_go/test.x/MyXDR_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import (
"github.com/stellar/go-xdr/xdr3"
)

// XdrFilesSHA256 is the SHA256 hashes of source files.
var XdrFilesSHA256 = map[string]string{
"spec/fixtures/generator/test.x": "d29a98a6a3b9bf533a3e6712d928e0bed655e0f462ac4dae810c65d52ca9af41"
}

type xdrType interface {
xdrType()
}
Expand Down
5 changes: 5 additions & 0 deletions spec/output/generator_spec_go/union.x/MyXDR_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import (
"github.com/stellar/go-xdr/xdr3"
)

// XdrFilesSHA256 is the SHA256 hashes of source files.
var XdrFilesSHA256 = map[string]string{
"spec/fixtures/generator/union.x": "c251258d967223b341ebcf2d5bb0718e9a039b46232cb743865d9acd0c4bbe41"
}

type xdrType interface {
xdrType()
}
Expand Down
5 changes: 5 additions & 0 deletions spec/output/generator_spec_rust/block_comments.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

#![allow(clippy::missing_errors_doc, clippy::unreadable_literal)]

/// `XDR_FILES_SHA256` is a list of pairs of source files and their SHA256 hashes.
pub const XDR_FILES_SHA256: [(&str, &str); 1] = [
("spec/fixtures/generator/block_comments.x", "e13131bc4134f38da17b9d5e9f67d2695a69ef98e3ef272833f4c18d0cc88a30")
];

use core::{fmt, fmt::Debug, ops::Deref};

// When feature alloc is turned off use static lifetime Box and Vec types.
Expand Down
5 changes: 5 additions & 0 deletions spec/output/generator_spec_rust/const.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

#![allow(clippy::missing_errors_doc, clippy::unreadable_literal)]

/// `XDR_FILES_SHA256` is a list of pairs of source files and their SHA256 hashes.
pub const XDR_FILES_SHA256: [(&str, &str); 1] = [
("spec/fixtures/generator/const.x", "0bff3b37592fcc16cad2fe10b9a72f5d39d033a114917c24e86a9ebd9cda9c37")
];

use core::{fmt, fmt::Debug, ops::Deref};

// When feature alloc is turned off use static lifetime Box and Vec types.
Expand Down
5 changes: 5 additions & 0 deletions spec/output/generator_spec_rust/enum.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

#![allow(clippy::missing_errors_doc, clippy::unreadable_literal)]

/// `XDR_FILES_SHA256` is a list of pairs of source files and their SHA256 hashes.
pub const XDR_FILES_SHA256: [(&str, &str); 1] = [
("spec/fixtures/generator/enum.x", "35cf5e97e2057039640ed260e8b38bb2733a3c3ca8529c93877bdec02a999d7f")
];

use core::{fmt, fmt::Debug, ops::Deref};

// When feature alloc is turned off use static lifetime Box and Vec types.
Expand Down
5 changes: 5 additions & 0 deletions spec/output/generator_spec_rust/nesting.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

#![allow(clippy::missing_errors_doc, clippy::unreadable_literal)]

/// `XDR_FILES_SHA256` is a list of pairs of source files and their SHA256 hashes.
pub const XDR_FILES_SHA256: [(&str, &str); 1] = [
("spec/fixtures/generator/nesting.x", "5537949272c11f1bd09cf613a3751668b5018d686a1c2aaa3baa91183ca18f6a")
];

use core::{fmt, fmt::Debug, ops::Deref};

// When feature alloc is turned off use static lifetime Box and Vec types.
Expand Down
5 changes: 5 additions & 0 deletions spec/output/generator_spec_rust/optional.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

#![allow(clippy::missing_errors_doc, clippy::unreadable_literal)]

/// `XDR_FILES_SHA256` is a list of pairs of source files and their SHA256 hashes.
pub const XDR_FILES_SHA256: [(&str, &str); 1] = [
("spec/fixtures/generator/optional.x", "3241e832fcf00bca4315ecb6c259621dafb0e302a63a993f5504b0b5cebb6bd7")
];

use core::{fmt, fmt::Debug, ops::Deref};

// When feature alloc is turned off use static lifetime Box and Vec types.
Expand Down
5 changes: 5 additions & 0 deletions spec/output/generator_spec_rust/struct.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

#![allow(clippy::missing_errors_doc, clippy::unreadable_literal)]

/// `XDR_FILES_SHA256` is a list of pairs of source files and their SHA256 hashes.
pub const XDR_FILES_SHA256: [(&str, &str); 1] = [
("spec/fixtures/generator/struct.x", "c6911a83390e3b499c078fd0c579132eacce88a4a0538d3b8b5e57747a58db4a")
];

use core::{fmt, fmt::Debug, ops::Deref};

// When feature alloc is turned off use static lifetime Box and Vec types.
Expand Down
5 changes: 5 additions & 0 deletions spec/output/generator_spec_rust/test.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

#![allow(clippy::missing_errors_doc, clippy::unreadable_literal)]

/// `XDR_FILES_SHA256` is a list of pairs of source files and their SHA256 hashes.
pub const XDR_FILES_SHA256: [(&str, &str); 1] = [
("spec/fixtures/generator/test.x", "d29a98a6a3b9bf533a3e6712d928e0bed655e0f462ac4dae810c65d52ca9af41")
];

use core::{fmt, fmt::Debug, ops::Deref};

// When feature alloc is turned off use static lifetime Box and Vec types.
Expand Down
5 changes: 5 additions & 0 deletions spec/output/generator_spec_rust/union.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

#![allow(clippy::missing_errors_doc, clippy::unreadable_literal)]

/// `XDR_FILES_SHA256` is a list of pairs of source files and their SHA256 hashes.
pub const XDR_FILES_SHA256: [(&str, &str); 1] = [
("spec/fixtures/generator/union.x", "c251258d967223b341ebcf2d5bb0718e9a039b46232cb743865d9acd0c4bbe41")
];

use core::{fmt, fmt::Debug, ops::Deref};

// When feature alloc is turned off use static lifetime Box and Vec types.
Expand Down