4

編譯Gem時出現錯誤的解決方式

 2 years ago
source link: https://blog.niclin.tw/2016/11/08/%E7%B7%A8%E8%AD%AFgem%E6%99%82%E5%87%BA%E7%8F%BE%E9%8C%AF%E8%AA%A4%E7%9A%84%E8%A7%A3%E6%B1%BA%E6%96%B9%E5%BC%8F/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Nic Lin's Blog

喜歡在地上滾的工程師

這陣子在玩Rebuilding Rails,在教學裡面需要自己做一隻Gem也就是library,雖然對現在來講是兩年前的教學,但電子書寫的非常清楚也很好懂,不過在build gem的時候發生了一些錯誤,就把他筆記下來囉。

當我們下指令 gem build rulers.gemspec

編譯成功的結果應該是

  Successfully built RubyGem
  Name: rulers
  Version: 0.0.1
  File: rulers-0.0.1.gem

但當我們第二次進行編譯時,我拿到一個警告並且無法編譯成功

WARNING:  See http://guides.rubygems.org/specification-reference/ for help
ERROR:  While executing gem ... (Gem::InvalidSpecificationException)
    rulers-0.0.1 contains itself (rulers-0.0.1.gem), check your files list

因為要做套件更新,所以必須重新編譯,但發生了這個錯誤我們嘗試把這隻已編譯的檔案刪除

rm rulers-0.0.1.gem

這時候請在編譯前先做git add .,不然會得到["rulers-0.0.1.gem"] are not files的一個訊息,這是因為編譯時仰賴的rulers.gemspec會去call git並且尋找有什麼檔案是包含在這隻gem裡面,我們可以在這隻檔案的設定裡面看到的定義如下

...
spec.files  = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
...

git ls-files會顯示出每一個git所追蹤的檔案,如果你建立或重新編輯新檔案時,務必在rebuild之前進行git add .

否則就會出現這樣的一個錯誤導致gem無法build。

參考資源: - Working with gems - Day 2


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK