From 67b8c5f3974e178e31519846d46af82d9770ad6e Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sat, 23 Oct 2021 16:18:05 +0100 Subject: [PATCH] feat(docs): embed C source files and set source-directory accordingly This enables the original C source to be linked to when describing entities which are written in C. --- build-emacs-for-macos | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/build-emacs-for-macos b/build-emacs-for-macos index 8dc308c..1f4e9f9 100755 --- a/build-emacs-for-macos +++ b/build-emacs-for-macos @@ -107,6 +107,7 @@ class Build handle_native_lisp(app) add_cli_helper(app) + CSourcesEmbedder.new(app, @source_dir).embed LibEmbedder.new(app, brew_dir, extra_libs, options[:relink_eln]).embed GccLibEmbedder.new(app, gcc_info).embed if options[:native_comp] @@ -758,6 +759,38 @@ class AbstractEmbedder def lib_dir File.join(invocation_dir, 'lib') end + + def resources_dir + File.join(app, 'Contents', 'Resources') + end +end + +class CSourcesEmbedder < AbstractEmbedder + attr_reader :source_dir + def initialize(app, source_dir) + super(app) + + @source_dir = source_dir + end + + def embed + info 'Embedding C source files into Emacs.app for documentation purposes' + + FileUtils.cp_r( + File.join(source_dir, 'src'), + File.join(resources_dir, 'src') + ) + + File.open(subdirs_el_file, 'a') do |f| + f.puts("(setq source-directory (expand-file-name \"..\"))\n") + end + end + + private + + def subdirs_el_file + @subdirs_el_file ||= File.join(resources_dir, 'lisp', 'subdirs.el') + end end class LibEmbedder < AbstractEmbedder