From 300e894c23205ea7271aae53f459d178bf91b60a Mon Sep 17 00:00:00 2001 From: philippm Date: Thu, 12 Feb 2015 19:14:19 +0100 Subject: [PATCH] Fix build error after embedded framework changed Say you have an app that uses an embedded framework: # Rakefile Motion::Project::App.setup do |app| app.name = 'ABC' app.embedded_frameworks << "vendor/XYZ.framework" end When you run `rake` it copies the framework folder into the app bundle: build/.../ABC.app/Contents/Frameworks/XYZ.framework/ But when the framework changes -- for example when its recompiled, or updated to a newer version -- running `rake` again copies the newer version into a subfolder: build/.../ABC.app/Contents/Frameworks/XYZ.framework/XYZ.framework The result is that the app still links against the older version. Now when you run `rake` a third time, you get an error message along the lines of: Errno::EEXIST: File exists @ sys_fail2 - (Versions/Current/Headers, ./build/.../ABC.app/Contents/Frameworks/XYZ.framework/XYZ.framework/Headers) This commit fixes this problem by removing the old framework if a newer version is available. --- lib/motion/project/builder.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/motion/project/builder.rb b/lib/motion/project/builder.rb index 6246285c..db1372a9 100644 --- a/lib/motion/project/builder.rb +++ b/lib/motion/project/builder.rb @@ -396,7 +396,23 @@ def build(config, platform, opts) FileUtils.mkdir_p(app_frameworks) embedded_frameworks.each do |src_path| dest_path = File.join(app_frameworks, File.basename(src_path)) - if !File.exist?(dest_path) or File.mtime(src_path) > File.mtime(dest_path) + + # If the framework changed -- for example, it was recompiled or + # updated to a newer version -- then we need to first remove the old + # version from the app bundle in the build folder. + # + # Otherwise the copy command below copies the new framework version + # as a *subfolder* of the old one. + # + # Also, we can't simply pass `remove_destination: true` to the copy + # command below because that only works if the destination is a + # regular file, and not a directory. + if File.exist?(dest_path) and File.mtime(src_path) > File.mtime(dest_path) + App.info 'Remove', dest_path + FileUtils.rm_r dest_path if File.exist?(dest_path) + end + + if !File.exist?(dest_path) App.info 'Copy', src_path FileUtils.cp_r(src_path, dest_path) end