Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d24a3803 authored by Martin Geisler's avatar Martin Geisler Committed by Gerrit Code Review
Browse files

Merge changes Icea91f71,I40cf3f24,I79c35434

* changes:
  pdl: Change &String to &str for a simpler API
  pdl: Propagate exit code from first failure
  pdl: Fix docstring which promises too much
parents b4a20bc6 4d31842f
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -64,6 +64,9 @@ rust_test_host {

genrule_defaults {
    name: "pdl_rust_generator_defaults",
    cmd: "set -o pipefail;" +
        " $(location :pdl) --output-format rust $(in) |" +
        " $(location :rustfmt) > $(out)",
    tools: [
        ":pdl",
        ":rustfmt",
@@ -74,7 +77,6 @@ genrule_defaults {
genrule {
    name: "pdl_le_backend",
    defaults: ["pdl_rust_generator_defaults"],
    cmd: "$(location :pdl) --output-format rust $(in) | $(location :rustfmt) > $(out)",
    srcs: ["tests/canonical/le_rust_test_file.pdl"],
    out: ["le_backend.rs"],
}
@@ -82,7 +84,6 @@ genrule {
genrule {
    name: "pdl_be_backend",
    defaults: ["pdl_rust_generator_defaults"],
    cmd: "$(location :pdl) --output-format rust $(in) | $(location :rustfmt) > $(out)",
    srcs: ["tests/canonical/be_rust_test_file.pdl"],
    out: ["be_backend.rs"],
}
@@ -135,7 +136,9 @@ genrule_defaults {

genrule {
    name: "pdl_rust_generator_tests_le_src",
    cmd: "$(location :pdl_generate_tests) $(in) pdl_le_backend | $(location :rustfmt) > $(out)",
    cmd: "set -o pipefail;" +
        " $(location :pdl_generate_tests) $(in) pdl_le_backend |" +
        " $(location :rustfmt) > $(out)",
    srcs: ["tests/canonical/le_test_vectors.json"],
    out: ["le_canonical.rs"],
    defaults: ["pdl_rust_generator_src_defaults"],
@@ -143,7 +146,9 @@ genrule {

genrule {
    name: "pdl_rust_generator_tests_be_src",
    cmd: "$(location :pdl_generate_tests) $(in) pdl_be_backend | $(location :rustfmt) > $(out)",
    cmd: "set -o pipefail;" +
        " $(location :pdl_generate_tests) $(in) pdl_be_backend |" +
        " $(location :rustfmt) > $(out)",
    srcs: ["tests/canonical/be_test_vectors.json"],
    out: ["be_canonical.rs"],
    defaults: ["pdl_rust_generator_src_defaults"],
@@ -183,7 +188,8 @@ genrule_defaults {
genrule {
    name: "pdl_python_generator_le_test_gen",
    defaults: ["pdl_python_generator_defaults"],
    cmd: "$(location :pdl) $(in) |" +
    cmd: "set -o pipefail;" +
        " $(location :pdl) $(in) |" +
        " $(location :pdl_python_generator)" +
        " --output $(out) --custom-type-location tests.custom_types",
    tool_files: [
@@ -202,7 +208,8 @@ genrule {
genrule {
    name: "pdl_python_generator_be_test_gen",
    defaults: ["pdl_python_generator_defaults"],
    cmd: "$(location :pdl) $(in) |" +
    cmd: "set -o pipefail;" +
        " $(location :pdl) $(in) |" +
        " $(location :pdl_python_generator)" +
        " --output $(out) --custom-type-location tests.custom_types",
    tool_files: [
+4 −3
Original line number Diff line number Diff line
@@ -128,7 +128,8 @@ def get_packet_ancestor(
        return get_packet_ancestor(decl.file.packet_scope[decl.parent_id])


def get_derived_packets(decl: Union[PacketDeclaration, StructDeclaration]
def get_derived_packets(
    decl: Union[PacketDeclaration, StructDeclaration]
) -> List[Tuple[List[Constraint], Union[PacketDeclaration, StructDeclaration]]]:
    """Return the list of packets or structs that immediately derive from the
    selected packet or struct, coupled with the field constraints.
@@ -269,7 +270,7 @@ def get_field_offset_from_end(field: Field) -> Optional[int]:
def is_bit_field(field: Field) -> bool:
    """Identify fields that can have bit granularity.
    These include: ScalarField, FixedField, TypedefField with enum type,
    SizeField, and CountField. Returns the size of the field in bits."""
    SizeField, and CountField."""

    if isinstance(field, (ScalarField, SizeField, CountField, FixedField, ReservedField)):
        return True
+2 −2
Original line number Diff line number Diff line
@@ -240,7 +240,7 @@ impl Decl {
        }
    }

    pub fn id(&self) -> Option<&String> {
    pub fn id(&self) -> Option<&str> {
        match self {
            Decl::Test { .. } => None,
            Decl::Checksum { id, .. }
@@ -271,7 +271,7 @@ impl Field {
        }
    }

    pub fn id(&self) -> Option<&String> {
    pub fn id(&self) -> Option<&str> {
        match self {
            Field::Checksum { .. }
            | Field::Padding { .. }
+2 −2
Original line number Diff line number Diff line
@@ -369,7 +369,7 @@ impl<'d> PacketScope<'d> {
        // Check field shadowing.
        for f in self.fields.iter().map(|f| f.0.last().unwrap()) {
            if let Some(id) = f.id() {
                if let Some(prev) = self.all_fields.insert(id.clone(), f) {
                if let Some(prev) = self.all_fields.insert(id.to_string(), f) {
                    result.push(
                        Diagnostic::warning()
                            .with_message(format!("declaration of `{}` shadows parent field", id))
@@ -1292,7 +1292,7 @@ impl File {
        // TODO: switch to try_insert when stable
        for decl in &self.declarations {
            if let Some(id) = decl.id() {
                if let Some(prev) = scope.typedef.insert(id.clone(), decl) {
                if let Some(prev) = scope.typedef.insert(id.to_string(), decl) {
                    result.err_redeclared(id, decl.kind(), decl.loc(), prev.loc())
                }
            }