Debian Codegraph @

samples/hello/README.md

raw
1 # Sample "hello"
2
3 This sample explains how to use ESSTRA with a simple C source code. The
4 document is structured as a step-by-step guide, allowing you to easily
5 understand the basic operations of ESSTRA by following each step in sequence.
6
7 First, in this sample, we will compile [`hello.c`](./hello.c), which is
8 provided in this directory, using the [ESSTRA Core](/core/README.md) to
9 generate the binary file `hello`. This binary has metadata embedded that
10 contains information about all source files involved in the compilation, such
11 as absolute paths and checksums. We will verify this using the
12 [ESSTRA Utility](/util/README.md).
13
14 Next, we will demonstrate how to use the
15 [ESSTRA Utility](/util/README.md)'s feature that adds
16 license information of source files to the metadata.
17 In this sample, we will use a prepared license information file
18 [`SPDX2TV_esstra.spdx`](../output-examples/SPDX2TV_esstra.spdx).
19 Using this information, we will update the metadata with the ESSTRA
20 Utility and verify that the license information has been correctly associated
21 with the metadata.
22
23 The license information file
24 [`SPDX2TV_esstra.spdx`](../output-examples/SPDX2TV_esstra.spdx)
25 was generated using the open-source license analysis tool
26 [FOSSology](https://github.com/fossology/fossology).
27 If you are interested in how to use FOSSology, please refer to the document
28 [License Analysis Using FOSSology](./README_FOSSOLOGY.md).
29
30 ## Building and Installing ESSTRA
31
32 First, build and install ESSTRA on your system. In the top directory, enter:
33
34 ```sh
35 $ make
36 ```
37
38 If there are no errors, the build is complete. Then, enter:
39
40 ```sh
41 $ sudo make install
42 ```
43
44 This will install the [ESSTRA Core](/core/README.md) and the
45 [ESSTRA Utility](/util/README.md) on your system.
46
47 ## Source Code to Compile
48
49 In this sample, we will compile the source code [`hello.c`](./hello.c) using
50 the ESSTRA Core. The content of the code is as follows, and it is a very simple
51 program that just prints `Hello, world!` to the standard output:
52
53 ```c
54 #include <stdio.h>
55
56 int main(void)
57 {
58 printf("Hello, world!\n");
59 return 0;
60 }
61 ```
62
63 Additionally, at the beginning of the source code, we explicitly state the
64 license so that FOSSology can scan it:
65
66 ```c
67 // SPDX-License-Identifier: MIT
68 ```
69
70 This declaration indicates that this file is available under the
71 [MIT License](https://spdx.org/licenses/MIT.html).
72
73 ## Compiling with ESSTRA Core
74
75 Use the following command line to compile [`hello.c`](./hello.c) and generate
76 the binary `hello`. By involving the [ESSTRA Core](/core/README.md)
77 during compilation, metadata will be embedded into `hello`.
78 Since we are using GCC version 11 on an x86\_64 PC, the command line would be as follows:
79
80 ```sh
81 $ gcc -fplugin=/usr/local/lib/gcc/x86_64-linux-gnu/11/plugin/esstracore.so hello.c -o hello
82 ```
83
84 If you have already [installed the Spec File](/README.md#installing-spec-file),
85 the ESSTRA Core will intervene in the compilation without needing the
86 `-fplugin=` option, yielding the same result as above:
87
88 ```sh
89 $ gcc hello.c -o hello
90 ```
91
92 Note that the [ESSTRA Core](/core/README.md) does not affect the behavior
93 of the binary. When you run the generated binary `hello`, you will get the
94 following result:
95
96 ```sh
97 $ ./hello
98 Hello, world!
99 ```
100
101 ## Verifying Metadata in the Binary
102
103 To display metadata embedded in the binary file `hello`, type:
104
105 ```sh
106 $ esstra show hello
107 ```
108
109 You can see a list of directories and files as well as SHA-1 hashes in YAML
110 format. These files are all involved in the compilation of the file `hello`:
111
112 ```yaml
113 #
114 # BinaryFileName: hello
115 # BinaryPath: /home/snagao/esstra/samples/hello/hello
116 #
117 Headers:
118 ToolName: ESSTRA Core
119 ToolVersion: 0.2.0
120 DataFormatVersion: 0.1.0
121 InputFileNames:
122 - hello.c
123 SourceFiles:
124 - Directory: /home/snagao/esstra/samples/hello
125 Files:
126 - File: hello.c
127 SHA1: 4bbee85215cbcb6a4f1625e4851cca19b0d3f6e2
128 - Directory: /usr/include
129 Files:
130 - File: features-time64.h
131 SHA1: 57c3c8093c3af70e5851f6d498600e2f6e24fdeb
132 - File: features.h
133 SHA1: d8725bb98129d6d70ddcbf010021c2841db783f7
134 - File: stdc-predef.h
135 SHA1: 2fef05d80514ca0be77efec90bda051cf87d771f
136 - File: stdio.h
137 SHA1: c7181b48c4194cd122024971527aab4056baf600
138 - Directory: /usr/include/x86_64-linux-gnu/bits
139 Files:
140 - File: floatn-common.h
141 SHA1: 3f37104123a2e6180621331c1da87125808e47bd
142 - File: floatn.h
143 SHA1: 806b759ab6894a09a3b3a422eec5f2414ba7dab7
144 - File: libc-header-start.h
145 SHA1: e0a400c194cd3962a342a6504a441920163b799c
146 - File: long-double.h
147 SHA1: 4e3f5928e816ad29079d1c7d75f3a510a0939ffb
148 - File: stdio.h
149 SHA1: 521d7cd0f6572f70122386784120cc55d84899bc
150 - File: stdio2.h
151 SHA1: 6c3ee923db9679a79941a688de72e114a794fc54
152 - File: stdio_lim.h
153 SHA1: 6210c8ae410ee0f39a6096b0adb9fa86febd3517
154 - File: time64.h
155 SHA1: ab2017da21608498b58eea37b2aa6a3387ee978c
156 - File: timesize.h
157 SHA1: f1dd8d62a4d75288654626933edfc82ccf2394a7
158 - File: types.h
159 SHA1: e5893a9c4c523615c73a51feb9680279608027c6
160 - File: typesizes.h
161 SHA1: ee94b5a60d007c23bdda9e5c46c8ba40f4eb402c
162 - File: wordsize.h
163 SHA1: 281ddd3c93f1e8653e809a45b606574c9b691092
164 - Directory: /usr/include/x86_64-linux-gnu/bits/types
165 Files:
166 - File: FILE.h
167 SHA1: 497924e329d53517631713ae52acb73e870d7d65
168 - File: __FILE.h
169 SHA1: 274242343e85d1c06e7f5ccc5abf15e120f6e957
170 - File: __fpos64_t.h
171 SHA1: ac38e294b004f6e2bf18f1c55e03dc80f48d6830
172 - File: __fpos_t.h
173 SHA1: 760ef77769ac1921f4b1f908cbf06863e2506775
174 - File: __mbstate_t.h
175 SHA1: e3a4f2ee55e635520db0b4610d2b361e9ce41de7
176 - File: struct_FILE.h
177 SHA1: 1dbf8bac589cb09e09aa4c1d36913e549a57bcf0
178 - Directory: /usr/include/x86_64-linux-gnu/gnu
179 Files:
180 - File: stubs-64.h
181 SHA1: f7603fa3908b56e9d1b33c91590db3252e13a799
182 - File: stubs.h
183 SHA1: be168037b7503a82b1cf694cdbac8c063bb6e476
184 - Directory: /usr/include/x86_64-linux-gnu/sys
185 Files:
186 - File: cdefs.h
187 SHA1: a419a6372029d89ba38ada0811d34f51df8d09b7
188 - Directory: /usr/lib/gcc/x86_64-linux-gnu/11/include
189 Files:
190 - File: stdarg.h
191 SHA1: fa23f49da8a0a5068b781dff7182f1a1c363dc30
192 - File: stddef.h
193 SHA1: 0de70008ffa3f198baf55c7b3f3d03b4ca11c21f
194 ```
195
196 The output of the `show` command is in YAML format and includes the following
197 information about all source files involved in the compilation:
198
199 * Absolute path of the source file in the compilation environment
200 * SHA-1 checksum of the source file
201
202 The structure of the output YAML data is as follows, with the information for
203 each file grouped by directory:
204
205 ```yaml
206 #
207 # BinaryFileName: <specified_binary_name>
208 # BinaryPath: <absolute_path_of_the_specified_binary>
209 #
210 Headers:
211 ToolName: <esstra_tool_name>
212 ToolVersion: <esstra_tool_version>
213 DataFormatVersion: <data_format_version>
214 InputFileNames:
215 - <filename_passed_to_gcc>
216 :
217 :
218 SourceFiles:
219 - Directory: <directory_name>
220 Files:
221 - File: <filename>
222 SHA1: <sha1_checksum>
223 - File: <filename>
224 SHA1: <sha1_checksum>
225 - Directory: <directory name>
226 Files:
227 - File: <filename>
228 SHA1: <sha1_checksum>
229 - File: <filename>
230 SHA1: <sha1_checksum>
231 :
232 :
233 ```
234
235 The metadata of the binary `hello` includes not only the source code
236 [`hello.c`](./hello.c) specified at compile time and the explicitly
237 `#include`'d `stdio.h` from `hello.c`, but also additional header files. This
238 is because GCC implicitly `#include`'s the header file `stdc-predef.h` and all
239 the header files recursively `#include`'d from `stdio.h`.
240
241 ## Adding License Information to Metadata
242
243 Here, we have to prepare an SPDX 2.3 tag-value format file that contains the
244 license information for [`hello.c`](./hello.c). In this case, we will use the
245 license information file that has already been prepared,
246 [`SPDX2TV_esstra.spdx`](../output-examples/SPDX2TV_esstra.spdx),
247 generated using the open-source license analysis tool
248 [FOSSology](https://github.com/fossology/fossology).
249 To associate the license information with the metadata in the binary using the
250 [ESSTRA Utility](/util/README.md), execute the following command:
251
252 ```sh
253 $ esstra update hello -i SPDX2TV_esstra.spdx
254 * processing 'hello'...
255 * done.
256 ```
257
258 If no errors occur, the process is successful. To display the metadata content
259 of the binary `hello`, execute the command:
260
261 ```sh
262 $ esstra show hello
263 ```
264
265 The result will be as follows:
266
267 ```yaml
268 #
269 # BinaryFileName: hello
270 # BinaryPath: /home/snagao/esstra/samples/hello/hello
271 #
272 Headers:
273 ToolName: ESSTRA Core
274 ToolVersion: 0.2.0
275 DataFormatVersion: 0.1.0
276 InputFileNames:
277 - hello.c
278 SourceFiles:
279 - Directory: /home/snagao/esstra/samples/hello
280 Files:
281 - File: hello.c
282 SHA1: 4bbee85215cbcb6a4f1625e4851cca19b0d3f6e2
283 LicenseInfo:
284 - MIT
285 - Directory: /usr/include
286 Files:
287 - File: features-time64.h
288 SHA1: 57c3c8093c3af70e5851f6d498600e2f6e24fdeb
289 :
290 ```
291
292 From the above result, we can see that the file [`hello.c`](./hello.c) has
293 been tagged with `LicenseInfo`, and the value assigned to it is `MIT`.
294
295 Please note that the file
296 [`SPDX2TV_esstra.spdx`](../output-examples/SPDX2TV_esstra.spdx) only contains
297 license information for the files present in the
298 [ESSTRA GitHub repository](https://github.com/sony/esstra).
299 Therefore, in this sample, license information will not be associated with any
300 files other than [`hello.c`](./hello.c).
301
302 You can also prepare an SPDX 2.3 tag-value format file for files other than
303 [`hello.c`](./hello.c) and provide it to the
304 [ESSTRA Utility](/util/README.md) to associate
305 license information with those files.
306
307 ## Summary
308
309 In this sample, we first compiled the source file [`hello.c`](./hello.c) using
310 the [ESSTRA Core](/core/README.md) to generate the binary `hello`, and
311 confirmed that the metadata in `hello` contains information about all files
312 involved in the compilation.
313
314 Then, using a file in SPDX 2.3 tag-value format, we updated the metadata in the
315 binary `hello` with the [ESSTRA Utility](/util/README.md)'s feature to
316 associate license information with the metadata.