public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
Improve the Boost copying script: don't overwrite existing files, ever.
Hongli Lai (Phusion) (author)
Mon May 19 03:34:40 -0700 2008
commit  e80e5c2f26280433019907f1aa28cd73dc69c7b5
tree    b943d08c96a6be7cf32c8cb93ba45468856dee7a
parent  8469c8c36e4331d7a7cf5f4f146290786eab2ddc
...
1
 
 
 
 
 
 
 
2
3
4
...
6
7
8
9
10
 
11
12
13
14
15
 
16
17
18
...
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
 
...
1
2
3
4
5
6
7
8
9
10
11
...
13
14
15
 
 
16
17
 
 
 
18
19
20
21
22
...
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
0
@@ -1,4 +1,11 @@
0
 #!/usr/bin/env ruby
0
+ESSENTIALS = [
0
+ "boost/detail/{limits,endian}.hpp",
0
+ "boost/config/*",
0
+ "boost/detail/sp_counted_*",
0
+ "boost/detail/atomic_count*",
0
+ "libs/thread/src/*"
0
+]
0
 PROGRAM_SOURCE = %q{
0
   #include <boost/shared_ptr.hpp>
0
   #include <boost/thread.hpp>
0
@@ -6,13 +13,10 @@ PROGRAM_SOURCE = %q{
0
   #include <boost/bind.hpp>
0
   #include <boost/date_time/posix_time/posix_time.hpp>
0
 }
0
-
0
-boost_dir = ARGV[0]
0
+BOOST_DIR = ARGV[0]
0
 Dir.chdir(File.dirname(__FILE__) + "/../ext")
0
-File.open("test.cpp", "w") do |f|
0
- f.write(PROGRAM_SOURCE)
0
-end
0
 
0
+# Run the given command, and abort on error.
0
 def sh(*command)
0
   puts command.join(" ")
0
   if !system(*command)
0
@@ -21,30 +25,78 @@ def sh(*command)
0
   end
0
 end
0
 
0
-done = false
0
-while !done
0
- missing_headers = `g++ test.cpp -c -I. 2>&1`.
0
- split("\n").
0
- grep(/error: .*: No such file/).
0
- map do |line|
0
- file = line.sub(/.*error: (.*): .*/, '\1')
0
- if file =~ /^boost\//
0
- file
0
- else
0
- line =~ /(.*?):/
0
- source = $1
0
- File.dirname(source) + "/" + file
0
+def install(source_filename, target_filename)
0
+ command = ["install", "-D", "--mode=u+rw,g+r,o+r", source_filename, target_filename]
0
+ sh(*command)
0
+end
0
+
0
+def copy_boost_files(*patterns)
0
+ patterns.each do |pattern|
0
+ Dir["#{BOOST_DIR}/#{pattern}"].each do |source|
0
+ if File.directory?(source)
0
+ source.slice!(0 .. BOOST_DIR.size)
0
+ copy_boost_files("#{source}/*")
0
+ else
0
+ target = source.slice(BOOST_DIR.size + 1 .. source.size - 1)
0
+ target.sub!(%r{^libs/thread/}, 'boost/')
0
+ if !File.exist?(target)
0
+ install(source, target)
0
+ end
0
+ end
0
+ end
0
+ end
0
+end
0
+
0
+def copy_essential_files
0
+ copy_boost_files(*ESSENTIALS)
0
+end
0
+
0
+def prepare
0
+ File.open("test.cpp", "w") do |f|
0
+ f.write(PROGRAM_SOURCE)
0
+ end
0
+end
0
+
0
+def cleanup
0
+ File.unlink("test.cpp") rescue nil
0
+end
0
+
0
+# Compile PROGRAM_SOURCE and copy whatever missing header files the compiler needs.
0
+def copy_dependencies
0
+ done = false
0
+ while !done
0
+ missing_headers = `g++ test.cpp -c -I. 2>&1`.
0
+ split("\n").
0
+ grep(/error: .*: No such file/).
0
+ map do |line|
0
+ file = line.sub(/.*error: (.*): .*/, '\1')
0
+ if file =~ /^boost\//
0
+ file
0
+ else
0
+ line =~ /(.*?):/
0
+ source = $1
0
+ File.dirname(source) + "/" + file
0
+ end
0
     end
0
+ missing_headers.each do |header|
0
+ install("#{BOOST_DIR}/#{header}", header)
0
+ end
0
+ done = missing_headers.empty?
0
+ end
0
+end
0
+
0
+def start
0
+ if BOOST_DIR.nil? || BOOST_DIR.empty?
0
+ puts "Usage: copy_boost_headers.rb <boost source directory>"
0
+ exit 1
0
   end
0
- missing_headers.each do |header|
0
- command = ["install", "-D", "--mode=u+rw,g+r,o+r", "#{boost_dir}/#{header}", header]
0
- sh(*command)
0
+ begin
0
+ prepare
0
+ copy_essential_files
0
+ copy_dependencies
0
+ ensure
0
+ cleanup
0
   end
0
- done = missing_headers.empty?
0
 end
0
 
0
-sh "cp #{boost_dir}/boost/detail/{limits,endian}.hpp boost/detail/"
0
-sh "cp -R #{boost_dir}/boost/config/* boost/config/"
0
-sh "cp -R #{boost_dir}/boost/detail/sp_counted_* boost/detail/"
0
-sh "cp -R #{boost_dir}/boost/detail/atomic_count* boost/detail/"
0
-sh "mkdir -p boost/src && cp -R #{boost_dir}/libs/thread/src/* boost/src/"
0
+start

Comments

    No one has commented yet.