luzidchris / svd2ada

Modified version of AdaCore's project to generate code from hardware description files in SVD format
GNU General Public License v3.0
0 stars 0 forks source link

License text string returned by `Get_Value (Child)` doesn't contain new lines, `Set_License_Text` will dump a single line #1

Closed luzidchris closed 1 year ago

luzidchris commented 1 year ago

When using a SVD file with a license text, Set_License_Text is called to print the text to each source code file. Unfortunately, the license text comment will only have a single line.

It seems this is caused by one of the sub-routines called to read the license text tag text from the XML data (beginning with Get_Value of package Base_Types).

luzidchris commented 1 year ago

To reproduce: Official Espressif ESP32 SVD file

  <vendor>ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD.</vendor>
  <vendorID>ESPRESSIF</vendorID>
  <name>ESP32</name>
  <series>ESP32</series>
  <version>8</version>
  <description>32-bit MCU &amp; 2.4 GHz Wi-Fi &amp; Bluetooth/Bluetooth LE</description>
  <licenseText>
    Copyright 2022 Espressif Systems (Shanghai) PTE LTD

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,

    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

    See the License for the specific language governing permissions and
    limitations under the License.
</licenseText>

Resulting code:

pragma Style_Checks (Off);

--  Copyright 2022 Espressif Systems (Shanghai) PTE LTD    Licensed under the Apache License, Version 2.0 (the "License");    you may not use this file except in compliance with the License.    You may obtain a copy of the License at        http://www.apache.org/licenses/LICENSE-2.0    Unless required by applicable law or agreed to in writing, software    distributed under the License is distributed on an "AS IS" BASIS,    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.    See the License for the specific language governing permissions and    limitations under the License.

--  This spec has been automatically generated from esp32.svd

pragma Restrictions (No_Elaboration_Code);

Added some debug logging to Set_License_Text, there are no newlines in the string, i.e., it's not a bug in this routine but an issue of the routine(s) used to read from the XML document.

luzidchris commented 1 year ago

Checked license text of another SVD file, and it's obviously necessary to add newline \n chars to the text in the tag:

      3 <device schemaVersion="1.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" noNamespaceSchemaLocation="CMSIS-SVD.xsd">
      4   <vendor>Nordic Semiconductor</vendor>
      5   <vendorID>Nordic</vendorID>
      6   <name>nrf52833</name>
      7   <series>nrf52</series>
      8   <version>1</version>
      9   <description>nRF52833 reference description for radio MCU with ARM 32-bit Cortex-M4 Microcontroller </description>
     10   <licenseText>
     11 Copyright (c) 2010 - 2021, Nordic Semiconductor ASA All rights reserved.\n
     12 \n    
     13 Redistribution and use in source and binary forms, with or without\n
     14 modification, are permitted provided that the following conditions are met:\n
     15 \n
     16 1. Redistributions of source code must retain the above copyright notice, this\n
     17    list of conditions and the following disclaimer.\n
     18 \n
     19 2. Redistributions in binary form must reproduce the above copyright\n
     20    notice, this list of conditions and the following disclaimer in the\n
     21    documentation and/or other materials provided with the distribution.\n
     22 \n
     23 3. Neither the name of Nordic Semiconductor ASA nor the names of its\n
     24    contributors may be used to endorse or promote products derived from this\n
     25    software without specific prior written permission.\n
     26 \n
     27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\n
     28 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n
     29 IMPLIED WARRANTIES OF MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE\n
     30 ARE DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE\n
     31 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n
     32 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n
     33 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n
     34 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n
     35 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n
     36 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n
     37 POSSIBILITY OF SUCH DAMAGE.\n
     38         </licenseText>
     39   <addressUnitBits>8</addressUnitBi

So, this is not a bug, the SVD file is not correct.