Skip to content

Commit 6fdb3cd

Browse files
committed
Fix swift-mode:debug-swift-module
1 parent c532c1e commit 6fdb3cd

File tree

1 file changed

+55
-39
lines changed

1 file changed

+55
-39
lines changed

swift-mode-repl.el

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,9 @@ Return a JSON object."
293293
The manifest file is searched from the PROJECT-DIRECTORY, defaults to
294294
`default-directory', or its ancestors."
295295
(let* ((description (swift-mode:describe-package project-directory))
296-
(modules (cdr (assoc 'modules description))))
296+
(modules (cdr (assoc 'targets description))))
297297
(seq-find
298-
(lambda (module) (not (eq :json-true (cdr (assoc 'is_test module)))))
298+
(lambda (module) (not (equal "test" (cdr (assoc 'type module)))))
299299
modules)))
300300

301301
(defun swift-mode:read-package-name (project-directory)
@@ -352,9 +352,9 @@ Return a directory path if found. Return nil otherwise."
352352
(swift-mode:find-ancestor-or-self-directory
353353
'swift-mode:swift-project-directory-p directory))
354354

355-
(defun swift-mode:read-project-directory ()
356-
"Read a project directory from the minibuffer."
357-
(expand-file-name (read-directory-name "Project directory: " nil nil t)))
355+
(defun swift-mode:read-project-directory (default)
356+
"Read a project directory from the minibuffer with DEFAULT directory."
357+
(expand-file-name (read-directory-name "Project directory: " default nil t)))
358358

359359
(defun swift-mode:ensure-swift-project-directory (project-directory)
360360
"Check PROJECT-DIRECTORY contains the manifest file Package.swift.
@@ -460,8 +460,8 @@ passed as a destination to xcodebuild."
460460
,scheme
461461
"-showBuildSettings")))
462462
(when (and device-identifier
463-
(not (eql device-identifier
464-
swift-mode:ios-local-device-identifier)))
463+
(not (equal device-identifier
464+
swift-mode:ios-local-device-identifier)))
465465
(setq arglist
466466
(append arglist
467467
`("-destination"
@@ -489,7 +489,8 @@ passed as a destination to xcodebuild."
489489
490490
xcodebuild is executed in PROJECT-DIRECTORY."
491491
(let* ((json (swift-mode:xcodebuild-list project-directory))
492-
(project (cdr (assoc 'project json)))
492+
(project (or (cdr (assoc 'project json))
493+
(cdr (assoc 'workspace json))))
493494
(schemes (cdr (assoc 'schemes project)))
494495
(choices (seq-map
495496
(lambda (scheme) (cons scheme scheme))
@@ -520,9 +521,11 @@ If PROJECT-DIRECTORY is nil or omited, it is searched from `default-directory'
520521
or its ancestors.
521522
An list ARGS are appended for builder command line arguments."
522523
(interactive
523-
(let ((project-directory (if current-prefix-arg
524-
(swift-mode:read-project-directory)
525-
(swift-mode:find-swift-project-directory))))
524+
(let* ((default-project-directory (swift-mode:find-swift-project-directory))
525+
(project-directory
526+
(if current-prefix-arg
527+
(swift-mode:read-project-directory default-project-directory)
528+
default-project-directory)))
526529
(list
527530
project-directory
528531
(if (string-equal (swift-mode:read-module-type project-directory)
@@ -539,7 +542,7 @@ An list ARGS are appended for builder command line arguments."
539542
(zerop
540543
(apply 'swift-mode:call-process
541544
swift-mode:swift-build-executable
542-
"--chdir" project-directory
545+
"--package-path" project-directory
543546
args))
544547
(compilation-mode)
545548
(goto-char (point-min))
@@ -563,9 +566,14 @@ equal to `swift-mode:ios-local-device-identifier', a local device is used via
563566
SCHEME is the name of the project scheme in Xcode. If it is nil or omitted,
564567
the value of `swift-mode:ios-project-scheme' is used."
565568
(interactive
566-
(let ((project-directory (if current-prefix-arg
567-
(swift-mode:read-project-directory)
568-
(swift-mode:find-xcode-project-directory))))
569+
(let* ((default-project-directory
570+
(or
571+
(swift-mode:find-xcode-workspace-directory)
572+
(swift-mode:find-xcode-project-directory)))
573+
(project-directory
574+
(if current-prefix-arg
575+
(swift-mode:read-project-directory default-project-directory)
576+
default-project-directory)))
569577
(list
570578
project-directory
571579
(if current-prefix-arg
@@ -596,7 +604,7 @@ the value of `swift-mode:ios-project-scheme' is used."
596604
(xcodebuild-args `(,swift-mode:xcodebuild-executable
597605
"-configuration" "Debug"
598606
"-scheme" ,scheme)))
599-
(if (eql device-identifier swift-mode:ios-local-device-identifier)
607+
(if (equal device-identifier swift-mode:ios-local-device-identifier)
600608
(setq xcodebuild-args (append xcodebuild-args '("-sdk" "iphoneos")))
601609
(setq xcodebuild-args
602610
(append xcodebuild-args
@@ -655,15 +663,17 @@ STRING is passed to the command."
655663
(defun swift-mode:debug-swift-module-library (project-directory)
656664
"Run debugger on a Swift library module in the PROJECT-DIRECTORY."
657665
(let* ((c99name (swift-mode:read-c99-name project-directory))
658-
(import-statement (concat "import " c99name)))
666+
(import-statement (concat "import " c99name))
667+
(build-debug-directory
668+
(swift-mode:join-path project-directory ".build" "debug")))
659669
(unless c99name (error "Cannot get module name"))
660670
(swift-mode:build-swift-module project-directory)
661671
(swift-mode:run-repl
662672
(append
663673
(swift-mode:command-string-to-list swift-mode:repl-executable)
664674
(list
665-
"-I" (swift-mode:join-path project-directory ".build" "debug")
666-
"-L" project-directory
675+
"-I" build-debug-directory
676+
"-L" build-debug-directory
667677
(concat "-l" c99name)))
668678
nil t)
669679
(swift-mode:enqueue-repl-commands import-statement)))
@@ -691,10 +701,11 @@ STRING is passed to the command."
691701
If PROJECT-DIRECTORY is nil or omited, it is searched from `default-directory'
692702
or its ancestors."
693703
(interactive
694-
(list
695-
(if current-prefix-arg
696-
(swift-mode:read-project-directory)
697-
(swift-mode:find-swift-project-directory))))
704+
(let ((default-project-directory (swift-mode:find-swift-project-directory)))
705+
(list
706+
(if current-prefix-arg
707+
(swift-mode:read-project-directory default-project-directory)
708+
default-project-directory))))
698709
(setq project-directory
699710
(swift-mode:ensure-swift-project-directory project-directory))
700711
(if (string-equal (swift-mode:read-module-type project-directory) "library")
@@ -818,20 +829,20 @@ PRODUCT-BUNDLE-IDENTIFIER is the name of the product bundle identifier used
818829
in Xcode build settings."
819830
(swift-mode:build-ios-app project-directory device-identifier scheme)
820831
(let* ((devices (swift-mode:list-ios-simulator-devices))
821-
(target-device
832+
(target-device
822833
(seq-find
823-
(lambda (device)
824-
(string-equal (cdr (assoc 'udid device)) device-identifier))
825-
devices))
826-
(active-devices
834+
(lambda (device)
835+
(string-equal (cdr (assoc 'udid device)) device-identifier))
836+
devices))
837+
(active-devices
827838
(seq-filter
828-
(lambda (device)
829-
(string-equal (cdr (assoc 'state device)) "Booted"))
830-
devices))
831-
(target-booted
839+
(lambda (device)
840+
(string-equal (cdr (assoc 'state device)) "Booted"))
841+
devices))
842+
(target-booted
832843
(string-equal (cdr (assoc 'state target-device)) "Booted"))
833-
(simulator-running (consp active-devices))
834-
(progress-reporter
844+
(simulator-running (consp active-devices))
845+
(progress-reporter
835846
(make-progress-reporter "Waiting for simulator...")))
836847
(cond
837848
(target-booted
@@ -886,9 +897,14 @@ it is equal to `swift-mode:ios-local-device-identifier', a local build via
886897
SCHEME is the name of the project scheme in Xcode. If it is nil or omitted,
887898
the value of `swift-mode:ios-project-scheme' is used."
888899
(interactive
889-
(let ((project-directory (if current-prefix-arg
890-
(swift-mode:read-project-directory)
891-
(swift-mode:find-xcode-project-directory))))
900+
(let* ((default-project-directory
901+
(or
902+
(swift-mode:find-xcode-workspace-directory)
903+
(swift-mode:find-xcode-project-directory)))
904+
(project-directory
905+
(if current-prefix-arg
906+
(swift-mode:read-project-directory default-project-directory)
907+
default-project-directory)))
892908
(list
893909
project-directory
894910
(if current-prefix-arg
@@ -911,8 +927,8 @@ the value of `swift-mode:ios-project-scheme' is used."
911927
swift-mode:ios-project-scheme
912928
(swift-mode:read-project-scheme project-directory))))
913929
(setq swift-mode:ios-project-scheme scheme)
914-
(let* ((local-device-build (eql device-identifier
915-
swift-mode:ios-local-device-identifier))
930+
(let* ((local-device-build (equal device-identifier
931+
swift-mode:ios-local-device-identifier))
916932
(sdk (if local-device-build "iphoneos" "iphonesimulator"))
917933
(build-settings
918934
(swift-mode:read-xcode-build-settings

0 commit comments

Comments
 (0)