Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ought to include a link to setting up VS code #4

Open
bdlabitt opened this issue Dec 10, 2023 · 15 comments
Open

Ought to include a link to setting up VS code #4

bdlabitt opened this issue Dec 10, 2023 · 15 comments

Comments

@bdlabitt
Copy link

What's the best way to do this? Download direct from MS? Homebrew? As a new user, and new to macos, I don't have these tools on my MacBookPro M3 Max.

Might be useful to have a link which shows a set up from scratch. Most won't have to follow the link, but some, like myself, would find it quite useful.

FWIW, I'm just trying to follow your instructions on building FreeCAD. It may seem obvious to you, but having vs installed (as a prerequisite) wasn't so obvious to me. When I got "zsh: command not found: code", then I realized I didn't have vs, and it was needed. Sorry to be uninformed, but we all have to start from somewhere...

I have built FreeCAD from source using Linux, but doing it on Macos is an entirely new experience for me.

@bdlabitt
Copy link
Author

After installation from MS, it appears that inside the VS application, the FreeCAD folder has no .VS folder, unlike what you show. Therefore, I can't select the same options as you can. I have no buttons at the bottom at all, is it possible to provide a generic profile (or some configuration file) that would make going forward possible?

Fancy IDE's are great - if they have been setup. Any tips or assistance would be most appreciated.
vs

@oursland
Copy link
Owner

Yes, the .vscode/ path has been moved to contrib/.vscode/ as it was interfering with the customization of some developers.

Run cp -a contrib/.vscode . to make it available to VS Code.

@bdlabitt
Copy link
Author

Thanks for that. Now the .vscode is available. No buttons are displayed, nor are there CMake related commands available in the command line. Do I add the configuration launch.json? Sorry, haven't ever used vs before. Not sure how to set it up.

@oursland
Copy link
Owner

Now that VSCode is configured and you've installed the .vscode/ directory, you need to ensure that the appropriate VS Code extensions have been installed. At a minimum you should have the C/C++ Extension Pack and Python.

Next we need to install the conda environment. Run brew install miniforge to install miniforge. Then run ./conda/setup-environment.sh which will install the conda build environment into .conda/freecad. This will take some time.

Once that has completed, you will need to reload the VS Code window. This can be done with CMD-Shift-P to bring up the command prompt in VS Code, and running Developer: Reload Window. Then we need to ensure that our development environment is activated correctly. Run CMD-Shift-P and select Python: Select Interpreter and select the interpreter with the path ./.conda/freecad/bin/python.

Now we may configure and build FreeCAD. Press CMD-Shift-P and run CMake: Select Configure Preset and select Conda Debug. The configuration should now begin. Once complete press CMD-Shift-P and run CMake: Build to build FreeCAD.

After FreeCAD has been built, you should be able to use the Run and Debug panel to launch FreeCAD within a debugging environment.

@bdlabitt
Copy link
Author

It compiled. Run & Debug started the process. FreeCAD GUI came up, but there seems to be a problem. In VS I get a small window stating there is an error. The terminal process "/bin/zsh '-l', '-c', 'python /Users/me/myApps/FreeCAD/.vscode/scripts/WaitForDebugpy.py'" terminated with exit code: 1.

Getting there! Almost. The gui just shows the colored spin wheel, however, the top menu bar is there, but the windows have names, but no contents. Still, quite encouraging.

@oursland
Copy link
Owner

OK. That's interesting, I've not encountered that. I suspect that the wrong python interpreter may be called. Did you select the python interpreter associated with the conda environment with Python: Select Interpreter?

You can manually run FreeCAD without the debugging environment via the command line with ./build/debug/bin/FreeCAD.

@Pesc0 have you any suggestions on resolving the debugger issue?

@Pesc0
Copy link

Pesc0 commented Dec 11, 2023

Yessir i know that issue. Basically freecad launches, then stops to wait for the debugger to attach. At the same time the debugger is waiting (up to 30 sec) for freecad to launch before attaching. Those 30 seconds have run out and everything hangs. Solution: close fc, close the debuggers, make sure everything is stopped then try again, if it still doesnt work increase the timeout (located in .vscode/scripts/waitfordebugpy)

Weird, I thought i had suppressed the error message

Also note that jacob's guide is not up to date with the latest changes, please take a look at FreeCAD/DevelopersHandbook#52

@oursland
Copy link
Owner

I'm encountering a different issue. On macOS at least, the call to check_socket() indicates that the socket opened for testing to see if debugpy is ready returns that it is ready on the first iteration. As this is not accurate, the attempt to connect to the debugger fails, but FreeCAD is waiting for the attachment before continuing.

@Pesc0
Copy link

Pesc0 commented Dec 11, 2023

Yeah it's quite a hack, I couldn't come up with anything better. The thing is you cant probe debugpy at all, yet you still need some kind of sync mechanism. perhaps writing to a tempfile would be a better solution?

let's say we're working with the tempfile .vscode/.debug-tempfile

  1. you press f5, a task deletes any residual tempfile
  2. fcmacro gets executed on launch, creates .debug-tempfile
  3. waitfordebugpy probes to see if .debug-tempfile exists

@bdlabitt
Copy link
Author

OK. That's interesting, I've not encountered that. I suspect that the wrong python interpreter may be called. Did you select the python interpreter associated with the conda environment with Python: Select Interpreter?

Yes, I did. It also happened to be the recommended interpreter. Choices were the freecad:conda python, the homebrew python, or the system python.

  • Python 3.11.6 ('freecad':conda) ./.conda/freecad/bin/python. "Recommended"
  • Python 3.10.12 ('base') /opt/homebrew/Caskroom/mambaforge/base/bin/python. "Conda"
  • Python 3.9.6 64-bit /usr/bin/python3. "Global"

I picked the first item in the list python.

@oursland
Copy link
Owner

@Pesc0 I think the tempfile approach is worth trying. It is less likely to have conflicts (I have port 6000 in service elsewhere).

@bdlabitt You may be encountering the issue I did, which is that the behavior of some sockets differ on the macOS platform than on Linux. A quick hack to get FreeCAD to launch would be to edit the file .vscode/launch.json and in the section C/C++ debugger, remove the following lines:

"args": ["${workspaceFolder}/.vscode/scripts/VSCodeAutostartDebug.FCMacro"],

and

  "presentation": {
    "hidden": true,
  }

This will make a new item in the Run and Debug layout for C/C++ debugger which will launch FreeCAD without waiting for a Python debugger to connect.

@bdlabitt
Copy link
Author

Yessir i know that issue. Basically freecad launches, then stops to wait for the debugger to attach. At the same time the debugger is waiting (up to 30 sec) for freecad to launch before attaching. Those 30 seconds have run out and everything hangs. Solution: close fc, close the debuggers, make sure everything is stopped then try again, if it still doesnt work increase the timeout (located in .vscode/scripts/waitfordebugpy)

Weird, I thought i had suppressed the error message

Also note that jacob's guide is not up to date with the latest changes, please take a look at FreeCAD/DevelopersHandbook#52

FYI at least on my M3 Max, when FreeCAD hangs, it requires a Force Quit, the first level Quit does nothing.

F5 for the stop debugger command? I will try increasing the timeout to 120, just to see if it works. Nothing ventured, nothing gained...

@bdlabitt
Copy link
Author

@Pesc0 I think the tempfile approach is worth trying. It is less likely to have conflicts (I have port 6000 in service elsewhere).

@bdlabitt You may be encountering the issue I did, which is that the behavior of some sockets differ on the macOS platform than on Linux. A quick hack to get FreeCAD to launch would be to edit the file .vscode/launch.json and in the section C/C++ debugger, remove the following lines:

"args": ["${workspaceFolder}/.vscode/scripts/VSCodeAutostartDebug.FCMacro"],

and

  "presentation": {
    "hidden": true,
  }

This will make a new item in the Run and Debug layout for C/C++ debugger which will launch FreeCAD without waiting for a Python debugger to connect.

Not familiar with editing launch.json, is there a way to comment things out? Generally don't like deleting things until everything is sorted out ;). Deleting stuff (and forgetting exactly what it was) has been problematic in the past for me. You think you will remember, but often you don't remember everything!

@bdlabitt
Copy link
Author

For the moment, simply changing the timeout from 30 to 120 seconds in the file WaitForDebugpy.py has allowed FreeCAD to start in debug mode. I'd bet it would work at 31 seconds, as there wasn't much of a delay at all. This copy of compiled FreeCAD seems to be functional at this point, at least to the point of opening a few of my files. During Cmake, I noticed it said that it couldn't find blas, is this a problem?

Can you tell me why on earth FreeCAD is looking into my TimeMachine drive? Isn't that snooping where it shouldn't be looking? Seems highly suspicious for an application to do something like that?

Cannot read file: /Volumes/.timemachine/26EB37B5-4772-4F16-9687-A3F5AE69619B/2023-12-02-183009.backup/2023-12-02-183009.backup/Data/Users/me/Documents/freecad/boringbarholder/boringbarholder.FCStd Why is it looking in timemachine for a file I backed up, when the file is in my local freecad datafile directory?

@oursland
Copy link
Owner

For the moment, simply changing the timeout from 30 to 120 seconds in the file WaitForDebugpy.py has allowed FreeCAD to start in debug mode.

That's great news!

During Cmake, I noticed it said that it couldn't find blas, is this a problem?

No.

Can you tell me why on earth FreeCAD is looking into my TimeMachine drive? Isn't that snooping where it shouldn't be looking? Seems highly suspicious for an application to do something like that?

The open files dialog does it's own thing, perhaps that is in your Recents or is somehow referenced by the open files dialog?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants