Changeset 13966


Ignore:
Timestamp:
Nov 6, 2019 5:51:55 PM (8 days ago)
Author:
mjohnsson
Message:

#5870 Checksum of generated files

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/CHANGELOG.txt

    r13897 r13966  
    11================= Unreleased ==================
     2# Change ; Minor ; Compiler; #5870
     3Debug log now contains checksums of all generated c-files.
     4
    25# Fixed ; Minor ; Compiler; #5864
    36Fixed bug where partial variability propagation lead to unbalanced equation systems.
  • trunk/Compiler/ModelicaCompiler/src/jastadd/ModelicaCompiler.jrag

    r13946 r13966  
    13701370        fc.guidManager().setSourceFile(new File(outDir, "modelDescription.xml"));
    13711371        fc.guidManager().processDependentFiles();
    1372        
     1372        fc.guidManager().writeFileMD5(log);
    13731373        log.debug("... code generated.");
    13741374        ASTNode.endStep("generateCode()");
     
    21772177            SplitFilesCodeStream stream = new SplitFilesCodeStream(outFile, debugGen, header);
    21782178            gen.generate(tmpl, stream, header);
     2179           
    21792180            for (File file : stream.files()) {
     2181                try {
     2182                    fc.guidManager().createFileMD5(outFile, log);
     2183                } catch (FileNotFoundException e) {
     2184                    throw e;
     2185                } catch (IOException e) {
     2186                    // Should not happen
     2187                }
     2188               
    21802189                log.debug("Generated file '" + file + "'.");
    21812190                if (fc != null) {
  • trunk/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/common/GUIDManager.java

    r13732 r13966  
    55import java.io.ByteArrayOutputStream;
    66import java.io.File;
     7import java.io.FileReader;
     8import java.io.FileWriter;
    79import java.io.IOException;
    810import java.io.InputStream;
     
    2123import java.util.List;
    2224
     25import org.jmodelica.util.logging.ModelicaLogger;
     26
    2327public class GUIDManager {
    2428
     
    8589    public void addDependentString(String input, ByteArrayOutputStream output) {
    8690        dependentFiles.add(new StringOpenable(input, output));
     91    }
     92   
     93    public ArrayList<String> filesMd5 = new ArrayList<String>();
     94
     95    public void writeFileMD5(ModelicaLogger log) {
     96        for (String fileMd5 : filesMd5) {
     97            log.debug(fileMd5);
     98        }
     99    }
     100
     101    public void createFileMD5(File file, ModelicaLogger log) throws IOException {
     102        MessageDigest md5;
     103        try {
     104            md5 = MessageDigest.getInstance("MD5");
     105        } catch (NoSuchAlgorithmException e) {
     106            return;
     107        }
     108
     109        try (final BufferedReader reader = new BufferedReader(new FileReader(file))) {
     110            String line = reader.readLine();
     111            while (line != null) {
     112                // A naive implementation that is expected to create a digest different from what a command
     113                // line tool would create. No lines breaks are included in the digest, and no
     114                // character encodings are specified.
     115                md5.update(line.getBytes(Charset.forName("UTF-8")));
     116                line = reader.readLine();
     117            }
     118        }
     119       
     120        String Value = new BigInteger(1,md5.digest()).toString(16);
     121        filesMd5.add("CheckSum of " + file.getName() + " :" + Value);
    87122    }
    88123
  • trunk/Compiler/ModelicaFrontEnd/test/junit/org/jmodelica/test/common/GUIDManagerTest.java

    r13732 r13966  
    33import static org.junit.Assert.assertEquals;
    44import static org.junit.Assert.assertFalse;
     5import static org.junit.Assert.assertNull;
    56import static org.junit.Assert.assertTrue;
    67
     8import java.io.BufferedOutputStream;
     9import java.io.BufferedReader;
    710import java.io.ByteArrayOutputStream;
     11import java.io.File;
     12import java.io.Reader;
    813
    914import org.jmodelica.common.GUIDManager;
     15import org.jmodelica.util.logging.Level;
     16import org.jmodelica.util.logging.ModelicaLogger;
    1017import org.junit.Before;
    1118import org.junit.Test;
     
    117124        assertEquals(ignoreWhitespace(expected), ignoreWhitespace(actual));
    118125    }
     126   
     127    @Test
     128    public void checksumOfFilesOnlyWrittenAtDebug() {
     129        TestLogger log = new TestLogger(Level.VERBOSE);
     130        guidManager.filesMd5.add("DummyHash");
     131        guidManager.writeFileMD5(log);
     132        assertNull(log.next());
     133       
     134        log = new TestLogger(Level.DEBUG);
     135        guidManager.filesMd5.add("DummyHash");
     136        guidManager.writeFileMD5(log);
     137        assertEquals("DEBUG: DummyHash", log.next());
     138
     139    }
    119140
    120141}
Note: See TracChangeset for help on using the changeset viewer.