14
14
:group 'unity )
15
15
16
16
(defcustom unity-code-shim-source-directory
17
- (file-name-directory (or (locate-library " unity" ) load-file-name))
17
+ (file-name-directory (or (locate-library " unity" )
18
+ load-file-name
19
+ buffer-file-name))
18
20
" Directory containing the code shim source."
19
21
:type 'directory
20
22
:group 'unity )
@@ -43,7 +45,8 @@ See https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line."
43
45
44
46
(defun unity--project-path-p (path )
45
47
" Return t if PATH is in a Unity project."
46
- (string-match-p " /[Aa]ssets/" path))
48
+ (let ((case-fold-search t ))
49
+ (if (string-match-p " /assets/" path) t )))
47
50
48
51
(defun unity--rename-file-advice (file newname &optional ok-if-already-exists )
49
52
" Advice function for `rename-file' for renaming Unity files.
@@ -61,14 +64,14 @@ FILE, NEWNAME, and OK-IF-ALREADY-EXISTS are documented by `rename-file'."
61
64
" code.exe"
62
65
" code" )))
63
66
64
- (defun unity--code-source-file ( )
65
- " Return the file name of the code shim source ."
66
- (concat unity-code-shim-source-directory
67
- ( if ( eq system-type 'windows-nt )
68
- " code-windows.c "
69
- " code-unix.c " )))
67
+ (defun unity--build- code-shim-unix ( subprocess-buffer )
68
+ " Build the code shim on Unix and output to SUBPROCESS-BUFFER ."
69
+ (call-process unity-cc nil subprocess-buffer nil
70
+ " -O2 " ( expand-file-name " code-unix.c "
71
+ unity- code-shim-source-directory)
72
+ " -o " (unity--code-binary-file )))
70
73
71
- (defun unity--build-code-shim-call-process- windows (subprocess-buffer )
74
+ (defun unity--build-code-shim-windows (subprocess-buffer )
72
75
" Build the code shim on Windows and output to SUBPROCESS-BUFFER."
73
76
(let ((temp-script (make-temp-file " emacs-unity" nil " .bat" ))
74
77
(temp-object (make-temp-file " emacs-unity" nil " .obj" )))
@@ -88,7 +91,8 @@ cl /nologo /O2 \"%s\" /Fo\"%s\" /Fe\"%s\" user32.lib shlwapi.lib || exit /b 1"
88
91
unity-vcvarsall-arch
89
92
; ; cl.
90
93
(convert-standard-filename
91
- (expand-file-name (unity--code-source-file)))
94
+ (expand-file-name " code-windows.c"
95
+ unity-code-shim-source-directory))
92
96
(convert-standard-filename
93
97
(expand-file-name temp-object))
94
98
(convert-standard-filename
@@ -99,40 +103,29 @@ cl /nologo /O2 \"%s\" /Fo\"%s\" /Fe\"%s\" user32.lib shlwapi.lib || exit /b 1"
99
103
(delete-file temp-script)
100
104
(delete-file temp-object)))))
101
105
102
- (defun unity--build-code-shim-call-process-unix (subprocess-buffer )
103
- " Build the code shim on Unix and output to SUBPROCESS-BUFFER."
104
- (call-process unity-cc nil subprocess-buffer nil
105
- " -O2" (unity--code-source-file) " -o" (unity--code-binary-file)))
106
-
107
- (defun unity--build-code-shim ()
108
- " Build the code shim."
109
- (make-directory unity-var-directory t )
110
- (when (get-buffer " *unity-subprocess*" )
111
- (kill-buffer " *unity-subprocess*" ))
112
- (let ((subprocess-buffer (get-buffer-create " *unity-subprocess*" )))
113
- (if (eq (if (eq system-type 'windows-nt )
114
- (unity--build-code-shim-call-process-windows subprocess-buffer)
115
- (unity--build-code-shim-call-process-unix subprocess-buffer))
116
- 0 )
106
+ (defun unity-build-code-shim (&optional force-rebuild )
107
+ " Build the code shim.
108
+
109
+ This function is a no-op if the code shim is already built unless
110
+ FORCE-REBUILD is t. This argument is always t when invoked
111
+ interactively."
112
+ (interactive '(t ))
113
+ (when (or (not (file-exists-p (unity--code-binary-file)))
114
+ force-rebuild)
115
+ (make-directory unity-var-directory t )
116
+ (when (get-buffer " *unity-subprocess*" )
117
+ (kill-buffer " *unity-subprocess*" ))
118
+ (let ((subprocess-buffer (get-buffer-create " *unity-subprocess*" )))
119
+ (if (eq (if (eq system-type 'windows-nt )
120
+ (unity--build-code-shim-windows subprocess-buffer)
121
+ (unity--build-code-shim-unix subprocess-buffer))
122
+ 0 )
123
+ (progn
124
+ (kill-buffer subprocess-buffer)
125
+ (message " Unity code shim built successfully. " ))
117
126
(progn
118
- (kill-buffer subprocess-buffer)
119
- (message " Unity code shim built successfully. " ))
120
- (progn
121
- (switch-to-buffer-other-window subprocess-buffer)
122
- (special-mode )))))
123
-
124
- (defun unity-build-code-shim ()
125
- " Build the code shim if it's not already built."
126
- (interactive )
127
- (unless (file-exists-p (unity--code-binary-file))
128
- (unity--build-code-shim)))
129
-
130
- (defun unity-rebuild-code-shim ()
131
- " Force rebuild the code shim."
132
- (interactive )
133
- (when (file-exists-p (unity--code-binary-file))
134
- (delete-file (unity--code-binary-file)))
135
- (unity--build-code-shim))
127
+ (switch-to-buffer-other-window subprocess-buffer)
128
+ (special-mode ))))))
136
129
137
130
(defun unity-setup ()
138
131
" Activate Unity.el integration."
0 commit comments