-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.xml
312 lines (302 loc) · 42.3 KB
/
index.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Conight's Blog</title>
<link>https://conight.com/</link>
<description>Recent content on Conight's Blog</description>
<generator>Hugo -- gohugo.io</generator>
<language>en-us</language>
<copyright>© 2020 Conight All Rights Reserved.</copyright>
<lastBuildDate>Thu, 16 Jan 2020 00:00:00 +0000</lastBuildDate><atom:link href="https://conight.com/index.xml" rel="self" type="application/rss+xml" />
<item>
<title>Hugo with PWA</title>
<link>https://conight.com/posts/hugo-with-progressive-web-app/</link>
<pubDate>Thu, 16 Jan 2020 00:00:00 +0000</pubDate>
<guid>https://conight.com/posts/hugo-with-progressive-web-app/</guid>
<description>To make the web experience closer to native applications, Google introduced the concept of Progressive Web App (PWA) at 2016.
We will cook it with Hugo1 to make Hugo more modernization.
Service Workers Register First we add sw.js from offline-first-sw make Hugo support Service Workers.
After download, put it to Hugo&rsquo;s readable directory. Eg. /static
Add or modify footer based Partial Templates, then add code to register Service Workers.
if(&#39;serviceWorker&#39; in navigator) { const PREFETCH = true; const PREFETCH_LINK_RELS = [&#39;index&#39;,&#39;next&#39;, &#39;prev&#39;, &#39;prefetch&#39;]; function prefetchCache() { if(navigator.</description>
<content><p>To make the web experience closer to native applications,
Google introduced the concept of <code>Progressive Web App (PWA)</code> at 2016.</p>
<p>We will cook it with Hugo<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup> to make Hugo more modernization.</p>
<h1 id="service-workers">Service Workers</h1>
<h2 id="register">Register</h2>
<p>First we add <code>sw.js</code> from <a href="https://github.com/wildhaber/offline-first-sw">offline-first-sw</a> make Hugo support <code>Service Workers</code>.</p>
<p>After download, put it to Hugo&rsquo;s readable directory. Eg. <code>/static</code></p>
<p>Add or modify <code>footer</code> based <code>Partial Templates</code>, then add code to register <code>Service Workers</code>.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-js" data-lang="js"><span style="display:flex;"><span><span style="color:#66d9ef">if</span>(<span style="color:#e6db74">&#39;serviceWorker&#39;</span> <span style="color:#66d9ef">in</span> <span style="color:#a6e22e">navigator</span>) {
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">PREFETCH</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">true</span>;
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">PREFETCH_LINK_RELS</span> <span style="color:#f92672">=</span> [<span style="color:#e6db74">&#39;index&#39;</span>,<span style="color:#e6db74">&#39;next&#39;</span>, <span style="color:#e6db74">&#39;prev&#39;</span>, <span style="color:#e6db74">&#39;prefetch&#39;</span>];
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">function</span> <span style="color:#a6e22e">prefetchCache</span>() {
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span>(<span style="color:#a6e22e">navigator</span>.<span style="color:#a6e22e">serviceWorker</span>.<span style="color:#a6e22e">controller</span>) {
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">let</span> <span style="color:#a6e22e">links</span> <span style="color:#f92672">=</span> document.<span style="color:#a6e22e">querySelectorAll</span>(
</span></span><span style="display:flex;"><span> <span style="color:#a6e22e">PREFETCH_LINK_RELS</span>.<span style="color:#a6e22e">map</span>((<span style="color:#a6e22e">rel</span>) =&gt; {
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> <span style="color:#e6db74">&#39;link[rel=&#39;</span><span style="color:#f92672">+</span><span style="color:#a6e22e">rel</span><span style="color:#f92672">+</span><span style="color:#e6db74">&#39;]&#39;</span>;
</span></span><span style="display:flex;"><span> }).<span style="color:#a6e22e">join</span>(<span style="color:#e6db74">&#39;,&#39;</span>)
</span></span><span style="display:flex;"><span> );
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span>(<span style="color:#a6e22e">links</span>.<span style="color:#a6e22e">length</span> <span style="color:#f92672">&gt;</span> <span style="color:#ae81ff">0</span>) {
</span></span><span style="display:flex;"><span> Array.<span style="color:#a6e22e">from</span>(<span style="color:#a6e22e">links</span>)
</span></span><span style="display:flex;"><span> .<span style="color:#a6e22e">map</span>((<span style="color:#a6e22e">link</span>) =&gt; {
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">let</span> <span style="color:#a6e22e">href</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">link</span>.<span style="color:#a6e22e">getAttribute</span>(<span style="color:#e6db74">&#39;href&#39;</span>);
</span></span><span style="display:flex;"><span> <span style="color:#a6e22e">navigator</span>.<span style="color:#a6e22e">serviceWorker</span>.<span style="color:#a6e22e">controller</span>.<span style="color:#a6e22e">postMessage</span>({
</span></span><span style="display:flex;"><span> <span style="color:#a6e22e">action</span> <span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;cache&#39;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#a6e22e">url</span> <span style="color:#f92672">:</span> <span style="color:#a6e22e">href</span>,
</span></span><span style="display:flex;"><span> });
</span></span><span style="display:flex;"><span> });
</span></span><span style="display:flex;"><span> }
</span></span><span style="display:flex;"><span> }
</span></span><span style="display:flex;"><span> }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#a6e22e">navigator</span>.<span style="color:#a6e22e">serviceWorker</span>
</span></span><span style="display:flex;"><span> .<span style="color:#a6e22e">register</span>(<span style="color:#e6db74">&#39;/sw.js&#39;</span>, { <span style="color:#a6e22e">scope</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;/&#39;</span> })
</span></span><span style="display:flex;"><span> .<span style="color:#a6e22e">then</span>(() =&gt; {
</span></span><span style="display:flex;"><span> <span style="color:#a6e22e">console</span>.<span style="color:#a6e22e">log</span>(<span style="color:#e6db74">&#39;Service Worker Registered&#39;</span>);
</span></span><span style="display:flex;"><span> });
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#a6e22e">navigator</span>.<span style="color:#a6e22e">serviceWorker</span>
</span></span><span style="display:flex;"><span> .<span style="color:#a6e22e">ready</span>
</span></span><span style="display:flex;"><span> .<span style="color:#a6e22e">then</span>(() =&gt; {
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span>(<span style="color:#a6e22e">PREFETCH</span>) {
</span></span><span style="display:flex;"><span> <span style="color:#a6e22e">prefetchCache</span>();
</span></span><span style="display:flex;"><span> }
</span></span><span style="display:flex;"><span> });
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><h2 id="configuration">Configuration</h2>
<h3 id="cache_version--number-">CACHE_VERSION <code>{ number }</code></h3>
<blockquote>
<p>The CACHE_VERSION is important when you update your service-worker. The cache-location will be updated and the old legacy cache is getting deleted.</p>
</blockquote>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-js" data-lang="js"><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">CACHE_VERSION</span> <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>;
</span></span></code></pre></div><h3 id="base_cache_files--array-">BASE_CACHE_FILES <code>{ array }</code></h3>
<blockquote>
<p>Define files that in this list which always needs to be cached from the beginning.</p>
</blockquote>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-js" data-lang="js"><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">BASE_CACHE_FILES</span> <span style="color:#f92672">=</span> [
</span></span><span style="display:flex;"><span> <span style="color:#75715e">// page cache
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#e6db74">&#39;/&#39;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#39;/about/&#39;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#39;/zh/about/&#39;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#39;/showcase/&#39;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#39;/zh/showcase/&#39;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#75715e">// assets cache
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#e6db74">&#39;/assets/main.js&#39;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#39;/assets/prism.js&#39;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#39;/assets/style.css&#39;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#39;/manifest.json&#39;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#75715e">// ico cache
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> <span style="color:#e6db74">&#39;/favicon.ico&#39;</span>,
</span></span><span style="display:flex;"><span>];
</span></span></code></pre></div><h3 id="offline_cache_files--array-">OFFLINE_CACHE_FILES <code>{ array }</code></h3>
<blockquote>
<p>Define files necessary for your offline page.</p>
</blockquote>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-js" data-lang="js"><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">OFFLINE_CACHE_FILES</span> <span style="color:#f92672">=</span> [
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#39;/offline.html&#39;</span>,
</span></span><span style="display:flex;"><span>];
</span></span></code></pre></div><h3 id="not_found_cache_files--array-">NOT_FOUND_CACHE_FILES <code>{ array }</code></h3>
<blockquote>
<p>Define files necessary for your 404 page.</p>
</blockquote>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-js" data-lang="js"><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">NOT_FOUND_CACHE_FILES</span> <span style="color:#f92672">=</span> [
</span></span><span style="display:flex;"><span> <span style="color:#e6db74">&#39;/404.html&#39;</span>,
</span></span><span style="display:flex;"><span>];
</span></span></code></pre></div><h3 id="cache_blacklist--array">CACHE_BLACKLIST <code>{ array}</code></h3>
<blockquote>
<p>This is a list of functions a URL gets checked against if it should be cached or not.
If one method returns true this resource will not be cached.</p>
</blockquote>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-js" data-lang="js"><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">CACHE_BLACKLIST</span> <span style="color:#f92672">=</span> [
</span></span><span style="display:flex;"><span> (<span style="color:#a6e22e">str</span>) =&gt; {
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> <span style="color:#f92672">!</span><span style="color:#a6e22e">str</span>.<span style="color:#a6e22e">startsWith</span>(<span style="color:#e6db74">&#39;https://conight.com&#39;</span>);
</span></span><span style="display:flex;"><span> <span style="color:#75715e">// return !str.startsWith(&#39;http://localhost&#39;) &amp;&amp; !str.startsWith(&#39;https://conight.com&#39;);
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> },
</span></span><span style="display:flex;"><span>];
</span></span></code></pre></div><p>It will cache all you specified resource or path.
You&rsquo;ll find it in Chrome&rsquo;s <code>Developer's Tools -&gt; Cache Storage</code> tab.</p>
<p><img src="https://conight.com/posts_assets/attachment/hugo-with-progressive-web-app/Cache.webp" alt="Cache Storage" title="Cache Storage">
<em>Cache Storage</em></p>
<h1 id="manifestjson">manifest.json</h1>
<p><code>manifest</code> is a decliner file to tell browser how is your PWA look like,.
You can find all manifest properties at <a href="https://developers.google.com/web/fundamentals/web-app-manifest/">Official website</a> 。</p>
<p>My blog&rsquo;s <code>manifest</code> blow:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;Conight&#39;s Blog&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;short_name&#34;</span>: <span style="color:#e6db74">&#34;Conight&#39;s Blog&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;description&#34;</span>: <span style="color:#e6db74">&#34;Share the world.&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;icons&#34;</span>: [
</span></span><span style="display:flex;"><span> {
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;src&#34;</span>: <span style="color:#e6db74">&#34;/android-chrome-192x192.png&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;sizes&#34;</span>: <span style="color:#e6db74">&#34;192x192&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;type&#34;</span>: <span style="color:#e6db74">&#34;image/png&#34;</span>
</span></span><span style="display:flex;"><span> },
</span></span><span style="display:flex;"><span> {
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;src&#34;</span>: <span style="color:#e6db74">&#34;/android-chrome-512x512.png&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;sizes&#34;</span>: <span style="color:#e6db74">&#34;512x512&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;type&#34;</span>: <span style="color:#e6db74">&#34;image/png&#34;</span>
</span></span><span style="display:flex;"><span> }
</span></span><span style="display:flex;"><span> ],
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;start_url&#34;</span>: <span style="color:#e6db74">&#34;/&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;display&#34;</span>: <span style="color:#e6db74">&#34;standalone&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;orientation&#34;</span>: <span style="color:#e6db74">&#34;portrait&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;background_color&#34;</span>: <span style="color:#e6db74">&#34;#222128&#34;</span>,
</span></span><span style="display:flex;"><span> <span style="color:#f92672">&#34;theme_color&#34;</span>: <span style="color:#e6db74">&#34;#222128&#34;</span>
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><ul>
<li>You must provide at least the <code>short_name</code> or <code>name</code> property.</li>
<li><code>icons</code> is an array of image objects. Each object should include the src, a sizes property, and the type of image.
You can use online tools if you like: <a href="https://favicomatic.com/">favicomatic.com</a> or <a href="https://realfavicongenerator.net/">realfavicongenerator.net</a>.</li>
</ul>
<p>Then put it in <code>head</code> template:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>&lt;<span style="color:#f92672">link</span> <span style="color:#a6e22e">rel</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;manifest&#34;</span> <span style="color:#a6e22e">href</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;/manifest.json&#34;</span>&gt;
</span></span></code></pre></div><ul>
<li>It will automatic contain <code>manifest</code> file if you use <a href="https://realfavicongenerator.net/">realfavicongenerator.net</a>.</li>
</ul>
<h1 id="lighthouse">Lighthouse</h1>
<blockquote>
<p>Lighthouse, an open-source, automated tool for improving the quality of your Progressive Web Apps,
eliminates much of the manual testing that was previously required.
You can even use Lighthouse in continuous integration systems to catch regressions.</p>
</blockquote>
<p>Enter Chrome&rsquo;s <code>Developer's Tools -&gt; Audits</code>, and check <code>Progressive Web Apps</code>.
After tests, it will show you website&rsquo;s report.</p>
<p><img src="https://conight.com/posts_assets/attachment/hugo-with-progressive-web-app/Lighthouse.webp" alt="Lighthouse" title="Lighthouse">
<em>Lighthouse PWA Audits</em></p>
<p>If configure right, browser which support PWA will show <code>Install</code> button or notice you add to desktop.</p>
<p><img src="https://conight.com/posts_assets/attachment/hugo-with-progressive-web-app/InstallNotice.webp" alt="Install Notice" title="InstallNotice">
<em>Install Notice</em></p>
<p>If not, Enter Chrome&rsquo;s <code>Developer's Tools -&gt; Manifest</code> and <code>Installability</code> may show reason.</p>
<p><img src="https://conight.com/posts_assets/attachment/hugo-with-progressive-web-app/Installability.webp" alt="Installability" title="Installability">
<em>Manifest Installability</em></p>
<h2 id="expand">Expand</h2>
<ul>
<li><a href="https://blog.jeremylikness.com/blog/implement-progressive-web-app-hugo/">Implement a Progressive Web App (PWA) in your Static Website</a></li>
<li><a href="https://github.com/wildhaber/offline-first-sw">offline-first-sw</a></li>
<li><a href="https://developers.google.com/web/progressive-web-apps/">Progressive Web Apps</a></li>
</ul>
<section class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1" role="doc-endnote">
<p><code>Golang</code> Based static blog framework. <a href="https://gohugo.io/" title="Hugo">Official website</a>&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</section>
</content>
</item>
<item>
<title>About</title>
<link>https://conight.com/about/</link>
<pubDate>Wed, 15 Jan 2020 00:00:00 +0000</pubDate>
<guid>https://conight.com/about/</guid>
<description>Hi there enjoy!</description>
<content><h1 id="hi-there">Hi there</h1>
<p>enjoy!</p>
</content>
</item>
<item>
<title>Showcase</title>
<link>https://conight.com/showcase/</link>
<pubDate>Wed, 15 Jan 2020 00:00:00 +0000</pubDate>
<guid>https://conight.com/showcase/</guid>
<description>Hi there Showcase</description>
<content><h1 id="hi-there">Hi there</h1>
<p>Showcase</p>
</content>
</item>
<item>
<title>Oops, you are offline.</title>
<link>https://conight.com/offline/</link>
<pubDate>Wed, 01 Jan 2020 00:00:00 +0800</pubDate>
<guid>https://conight.com/offline/</guid>
<description>You should try to find some internet connection to browse here.</description>
<content><p>You should try to find some internet connection to browse here.</p>
</content>
</item>
<item>
<title>Compile install python raise uuid error on Centos</title>
<link>https://conight.com/posts/fix-python-compile-uuid-error/</link>
<pubDate>Fri, 11 Jan 2019 00:00:00 +0000</pubDate>
<guid>https://conight.com/posts/fix-python-compile-uuid-error/</guid>
<description>System environment CentOS Linux release 7.6.1810 (Core) gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) Python-3.7.2 uuid-devel.x86_64 1.6.2-26.el7 Scene Description Compile install Python 3.7.2 on Centos7 with error blow
building &#39;_uuid&#39; extension gcc -pthread -fPIC -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -I./Include -I/home/tt/py37/include -I. -I/usr/local/include -I/home/tt/Python-3.7.2/Include -I/home/tt/Python-3.7.2 -c /home/tt/Python-3.7.2/Modules/_uuidmodule.c -o build/temp.linux-x86_64-3.7/home/tt/Python-3.7.2/Modules/_uuidmodule.o In file included from /home/tt/Python-3.7.2/Modules/_uuidmodule.c:8:0: /usr/include/uuid.h:94:24: error: conflicting types for ‘uuid_t’ typedef struct uuid_st uuid_t; ^ In file included from /home/tt/Python-3.</description>
<content><h1 id="system-environment">System environment</h1>
<pre tabindex="0"><code>CentOS Linux release 7.6.1810 (Core)
gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
Python-3.7.2
uuid-devel.x86_64 1.6.2-26.el7
</code></pre><h1 id="scene">Scene</h1>
<h2 id="description">Description</h2>
<p>Compile install <code>Python 3.7.2</code> on <code>Centos7</code> with error blow</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>building <span style="color:#e6db74">&#39;_uuid&#39;</span> extension
</span></span><span style="display:flex;"><span>gcc -pthread -fPIC -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -std<span style="color:#f92672">=</span>c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror<span style="color:#f92672">=</span>implicit-function-declaration -I./Include -I/home/tt/py37/include -I. -I/usr/local/include -I/home/tt/Python-3.7.2/Include -I/home/tt/Python-3.7.2 -c /home/tt/Python-3.7.2/Modules/_uuidmodule.c -o build/temp.linux-x86_64-3.7/home/tt/Python-3.7.2/Modules/_uuidmodule.o
</span></span><span style="display:flex;"><span>In file included from /home/tt/Python-3.7.2/Modules/_uuidmodule.c:8:0:
</span></span><span style="display:flex;"><span>/usr/include/uuid.h:94:24: error: conflicting types <span style="color:#66d9ef">for</span> ‘uuid_t’
</span></span><span style="display:flex;"><span> typedef struct uuid_st uuid_t;
</span></span><span style="display:flex;"><span> ^
</span></span><span style="display:flex;"><span>In file included from /home/tt/Python-3.7.2/Modules/_uuidmodule.c:5:0:
</span></span><span style="display:flex;"><span>/usr/include/uuid/uuid.h:44:23: note: previous declaration of ‘uuid_t’ was here
</span></span><span style="display:flex;"><span> typedef unsigned char uuid_t<span style="color:#f92672">[</span>16<span style="color:#f92672">]</span>;
</span></span><span style="display:flex;"><span> ^
</span></span><span style="display:flex;"><span>In file included from /home/tt/Python-3.7.2/Modules/_uuidmodule.c:8:0:
</span></span><span style="display:flex;"><span>/usr/include/uuid.h:107:22: error: conflicting types <span style="color:#66d9ef">for</span> ‘uuid_compare’
</span></span><span style="display:flex;"><span> extern uuid_rc_t uuid_compare <span style="color:#f92672">(</span>const uuid_t *_uuid, const uuid_t *_uuid2, int *_result<span style="color:#f92672">)</span>;
</span></span><span style="display:flex;"><span> ^
</span></span><span style="display:flex;"><span>In file included from /home/tt/Python-3.7.2/Modules/_uuidmodule.c:5:0:
</span></span><span style="display:flex;"><span>/usr/include/uuid/uuid.h:73:5: note: previous declaration of ‘uuid_compare’ was here
</span></span><span style="display:flex;"><span> int uuid_compare<span style="color:#f92672">(</span>const uuid_t uu1, const uuid_t uu2<span style="color:#f92672">)</span>;
</span></span><span style="display:flex;"><span> ^
</span></span><span style="display:flex;"><span>/home/tt/Python-3.7.2/Modules/_uuidmodule.c: In <span style="color:#66d9ef">function</span> ‘py_uuid_generate_time_safe’:
</span></span><span style="display:flex;"><span>/home/tt/Python-3.7.2/Modules/_uuidmodule.c:15:12: error: storage size of ‘uuid’ isn’t known
</span></span><span style="display:flex;"><span> uuid_t uuid;
</span></span><span style="display:flex;"><span> ^
</span></span><span style="display:flex;"><span>/home/tt/Python-3.7.2/Modules/_uuidmodule.c:15:12: warning: unused variable ‘uuid’ <span style="color:#f92672">[</span>-Wunused-variable<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>/home/tt/Python-3.7.2/Modules/_uuidmodule.c:35:1: warning: control reaches end of non-void <span style="color:#66d9ef">function</span> <span style="color:#f92672">[</span>-Wreturn-type<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span> ^
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>The following modules found by detect_modules<span style="color:#f92672">()</span> in setup.py, have been
</span></span><span style="display:flex;"><span>built by the Makefile instead, as configured by the Setup files:
</span></span><span style="display:flex;"><span>_abc atexit pwd
</span></span><span style="display:flex;"><span>time
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Failed to build these modules:
</span></span><span style="display:flex;"><span>_uuid
</span></span></code></pre></div><h1 id="analyse">Analyse</h1>
<p>According error message, compiler read two different head file <code>uuid.h</code>,
but variable <code>uuid_t uuid_compare</code> in both files have different type,
causes <code>(conflicting types)</code> and compile failed.</p>
<p>Enter <code>/usr/include</code>, there are two head file <code>uuid.h</code> <code>uuid/uuid.h</code>.
Just remove one to fix this.</p>
<ul>
<li><code>/usr/include/uuid.h</code> provided by <code>uuid-devel</code></li>
<li><code>/usr/include/uuid/uuid.h</code> provided by <code>libuuid-devel</code></li>
</ul>
<h1 id="resolve">Resolve</h1>
<p>Change source code in <code>Modules/_uuidmodule.c</code></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>vi Modules/_uuidmodule.c
</span></span></code></pre></div><p>Delete line 6 and change line 7 as blow</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c" data-lang="c"><span style="display:flex;"><span><span style="color:#75715e">#elif defined(HAVE_UUID_H)
</span></span></span></code></pre></div><p>or patch this file</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-diff" data-lang="diff"><span style="display:flex;"><span><span style="color:#f92672">--- Modules/_uuidmodule.c.orignal 2019-01-11 15:38:46.995000000 -0500
</span></span></span><span style="display:flex;"><span><span style="color:#f92672"></span><span style="color:#a6e22e">+++ Modules/_uuidmodule.c 2019-01-11 15:39:04.470000000 -0500
</span></span></span><span style="display:flex;"><span><span style="color:#a6e22e"></span><span style="color:#75715e">@@ -3,8 +3,7 @@
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span> #include &#34;Python.h&#34;
</span></span><span style="display:flex;"><span> #ifdef HAVE_UUID_UUID_H
</span></span><span style="display:flex;"><span> #include &lt;uuid/uuid.h&gt;
</span></span><span style="display:flex;"><span><span style="color:#f92672">-#endif
</span></span></span><span style="display:flex;"><span><span style="color:#f92672">-#ifdef HAVE_UUID_H
</span></span></span><span style="display:flex;"><span><span style="color:#f92672"></span><span style="color:#a6e22e">+#elif defined(HAVE_UUID_H)
</span></span></span><span style="display:flex;"><span><span style="color:#a6e22e"></span> #include &lt;uuid.h&gt;
</span></span><span style="display:flex;"><span> #endif
</span></span></code></pre></div><p>Download <a href="https://conight.com/posts_assets/attachment/fix-python-compile-uuid-error/uuidmodule.patch" title="uuidmodule.patch"><code>uuidmodule.patch</code></a>
to Python source code root path and execute</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>patch -p0 &lt; uuidmodule.patch
</span></span></code></pre></div><p>All done!</p>
</content>
</item>
</channel>
</rss>