@@ -409,6 +409,10 @@ class Build
409
409
410
410
patches . each { |patch | apply_patch ( patch , target ) }
411
411
412
+ # Keep a copy of src after patches have been applied. This will be used to
413
+ # embed C sources into the output Emacs.app bundle.
414
+ cmd ( 'cp' , '-a' , File . join ( target , 'src' ) , File . join ( target , 'src.orig' ) )
415
+
412
416
target
413
417
end
414
418
@@ -1136,8 +1140,12 @@ class AbstractEmbedder
1136
1140
@app = app
1137
1141
end
1138
1142
1139
- def relative_path ( path )
1140
- Pathname . new ( path ) . relative_path_from ( Pathname . new ( app ) ) . to_s
1143
+ def relative_path ( base , path )
1144
+ Pathname . new ( path ) . relative_path_from ( Pathname . new ( base ) ) . to_s
1145
+ end
1146
+
1147
+ def relative_app_path ( path )
1148
+ relative_path ( app , path )
1141
1149
end
1142
1150
1143
1151
def invocation_dir
@@ -1207,30 +1215,44 @@ class CSourcesEmbedder < AbstractEmbedder
1207
1215
def embed
1208
1216
info 'Bundling C source files into Emacs.app for documentation purposes...'
1209
1217
1218
+ orig_src_dir = File . join ( source_dir , 'src.orig' )
1210
1219
src_dir = File . join ( source_dir , 'src' )
1211
1220
target_dir = File . join ( resources_dir , 'src' )
1212
- debug "Copying *.c and *.h files from '#{ src_dir } ' " \
1213
- "to: #{ relative_path ( target_dir ) } "
1214
1221
1215
- Dir [ File . join ( src_dir , '**' , '*.{c,h}' ) ] . each do |f |
1216
- rel = f [ src_dir . size + 1 ..-1 ]
1217
- target = File . join ( target_dir , rel )
1218
- FileUtils . mkdir_p ( File . dirname ( target ) )
1219
- cmd ( 'cp' , '-pRL' , f , target )
1222
+ debug "Copying Emacs C sources to #{ relative_app_path ( target_dir ) } "
1223
+
1224
+ if File . exist? ( orig_src_dir )
1225
+ copy_sources ( orig_src_dir , target_dir )
1226
+ else
1227
+ copy_sources (
1228
+ src_dir , target_dir , File . join ( '**' , '*.{awk,c,cc,h,in,m,mk}' )
1229
+ )
1220
1230
end
1221
1231
1222
1232
if File . exist? ( site_start_el_file ) &&
1223
1233
File . read ( site_start_el_file ) . include? ( PATH_PATCH )
1224
1234
return
1225
1235
end
1226
1236
1227
- debug "Patching '#{ relative_path ( site_start_el_file ) } ' to allow Emacs to " \
1228
- 'find bundled C sources'
1237
+ debug "Patching '#{ relative_app_path ( site_start_el_file ) } ' to allow " \
1238
+ 'Emacs to find bundled C sources'
1229
1239
File . open ( site_start_el_file , 'a' ) { |f | f . puts ( "\n #{ PATH_PATCH } " ) }
1230
1240
end
1231
1241
1232
1242
private
1233
1243
1244
+ def copy_sources ( src_dir , target_dir , pattern = File . join ( '**' , '*' ) )
1245
+ Dir [ File . join ( src_dir , pattern ) ] . each do |f |
1246
+ next if File . directory? ( f ) ||
1247
+ File . basename ( f ) . downcase . start_with? ( 'changelog' )
1248
+
1249
+ rel = relative_path ( src_dir , f )
1250
+ target = File . join ( target_dir , rel )
1251
+ FileUtils . mkdir_p ( File . dirname ( target ) )
1252
+ run_cmd ( 'cp' , '-pRL' , f , target )
1253
+ end
1254
+ end
1255
+
1234
1256
def site_start_el_file
1235
1257
@site_start_el_file ||= File . join ( resources_dir , 'lisp' , 'site-start.el' )
1236
1258
end
@@ -1256,10 +1278,9 @@ class LibEmbedder < AbstractEmbedder
1256
1278
binary ||= bin
1257
1279
1258
1280
FileUtils . cd ( File . dirname ( app ) ) do
1259
- rel_path = Pathname . new ( lib_dir ) . relative_path_from (
1260
- Pathname . new ( File . dirname ( binary ) )
1261
- ) . to_s
1262
- rpath = File . join ( '@executable_path' , rel_path )
1281
+ rpath = File . join (
1282
+ '@executable_path' , relative_path ( File . dirname ( binary ) , lib_dir )
1283
+ )
1263
1284
1264
1285
copy , relink = build_bundle_plan ( binary )
1265
1286
@@ -1300,7 +1321,7 @@ class LibEmbedder < AbstractEmbedder
1300
1321
1301
1322
return if mf . rpaths . include? ( rpath )
1302
1323
1303
- debug "Setting rpath for '#{ relative_path ( macho_file ) } ' to: #{ rpath } "
1324
+ debug "Setting rpath for '#{ relative_app_path ( macho_file ) } ' to: #{ rpath } "
1304
1325
mf . add_rpath ( rpath )
1305
1326
while_writable ( macho_file ) { mf . write! }
1306
1327
end
@@ -1330,7 +1351,7 @@ class LibEmbedder < AbstractEmbedder
1330
1351
1331
1352
if macho_file . start_with? ( app )
1332
1353
debug 'Calculating bundling instructions for: ' \
1333
- "#{ relative_path ( macho_file ) } "
1354
+ "#{ relative_app_path ( macho_file ) } "
1334
1355
else
1335
1356
debug "Calculating bundling instructions for: #{ macho_file } "
1336
1357
end
@@ -1413,7 +1434,8 @@ class LibEmbedder < AbstractEmbedder
1413
1434
1414
1435
next if File . exist? ( target )
1415
1436
1416
- debug "Copying '#{ source } ' to: '#{ relative_path ( target ) } ' ('#{ dylib_id } ')"
1437
+ debug "Copying '#{ source } ' to: " \
1438
+ "'#{ relative_app_path ( target ) } ' ('#{ dylib_id } ')"
1417
1439
FileUtils . mkdir_p ( File . dirname ( target ) )
1418
1440
cmd ( 'cp' , '-pRL' , source , target )
1419
1441
@@ -1434,7 +1456,7 @@ class LibEmbedder < AbstractEmbedder
1434
1456
1435
1457
relink_files = relink . group_by { |r | r [ :target_file ] }
1436
1458
relink_files . each do |target_file , relinks |
1437
- debug "Changing linked dylibs in: '#{ relative_path ( target_file ) } '"
1459
+ debug "Changing linked dylibs in: '#{ relative_app_path ( target_file ) } '"
1438
1460
mf = MachO . open ( target_file )
1439
1461
changed = false
1440
1462
@@ -1556,7 +1578,7 @@ class GccLibEmbedder < AbstractEmbedder
1556
1578
rpaths = mf . rpaths . reject { |r | r == '@loader_path' }
1557
1579
next if rpaths . none?
1558
1580
1559
- debug "Tidying up rpaths from: #{ relative_path ( file_path ) } "
1581
+ debug "Tidying up rpaths from: #{ relative_app_path ( file_path ) } "
1560
1582
rpaths . each { |r | mf . delete_rpath ( r ) }
1561
1583
mf . write!
1562
1584
end
@@ -1586,10 +1608,6 @@ class GccLibEmbedder < AbstractEmbedder
1586
1608
gcc_info . darwin_lib_dir
1587
1609
end
1588
1610
1589
- def relative_dir ( path , root )
1590
- Pathname . new ( path ) . relative_path_from ( Pathname . new ( root ) ) . to_s
1591
- end
1592
-
1593
1611
def site_start_el_file
1594
1612
@site_start_el_file ||= File . join ( resources_dir , 'lisp' , 'site-start.el' )
1595
1613
end
@@ -1676,17 +1694,17 @@ class GccInfo
1676
1694
1677
1695
def app_bundle_target_lib_dir
1678
1696
@app_bundle_target_lib_dir ||=
1679
- relative_dir (
1680
- File . join ( embedder . lib_dir , target_lib_dir ) ,
1681
- embedder . invocation_dir
1697
+ relative_path (
1698
+ embedder . invocation_dir ,
1699
+ File . join ( embedder . lib_dir , target_lib_dir )
1682
1700
)
1683
1701
end
1684
1702
1685
1703
def app_bundle_target_darwin_lib_dir
1686
1704
@app_bundle_target_darwin_lib_dir ||=
1687
- relative_dir (
1688
- File . join ( embedder . lib_dir , sanitized_target_darwin_lib_dir ) ,
1689
- embedder . invocation_dir
1705
+ relative_path (
1706
+ embedder . invocation_dir ,
1707
+ File . join ( embedder . lib_dir , sanitized_target_darwin_lib_dir )
1690
1708
)
1691
1709
end
1692
1710
@@ -1761,8 +1779,8 @@ class GccInfo
1761
1779
@embedder ||= AbstractEmbedder . new ( Dir . mktmpdir ( %w[ Emacs .app ] ) )
1762
1780
end
1763
1781
1764
- def relative_dir ( path , root )
1765
- Pathname . new ( path ) . relative_path_from ( Pathname . new ( root ) ) . to_s
1782
+ def relative_path ( base , path )
1783
+ Pathname . new ( path ) . relative_path_from ( Pathname . new ( base ) ) . to_s
1766
1784
end
1767
1785
end
1768
1786
0 commit comments