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

platformio init: change source directory #83

Closed
makefu opened this issue Feb 17, 2015 · 16 comments
Closed

platformio init: change source directory #83

makefu opened this issue Feb 17, 2015 · 16 comments
Assignees
Milestone

Comments

@makefu
Copy link

makefu commented Feb 17, 2015

Maybe i missed something but is it correct that there is currently no way to change the source directory path?
I am currently trying to migrate my arduino projects to platformio and for me the best case would be to simply throw a platformio.ini file in the base directory of my projects and compile my projects with different source directories.
i also hate the arduino ide requirement that every source file of a project must be named like the project, what a buill ...

Being able to choose my folder and file naming means a lot to me :)

@ivankravets ivankravets self-assigned this Feb 17, 2015
@ivankravets
Copy link
Member

simply throw a platformio.ini file in the base directory of my projects and compile my projects with different source directories.

I want to break main concept of PlatformIO - "to build the single source code with the multiple development platforms". platformio.ini file should be configured per unique source directory src.

See example how to build single "blink" code for the multiple Arduino boards.

P.S: You should estimate all benefits of platformio.ini and start use it per project.

@makefu
Copy link
Author

makefu commented Feb 17, 2015

Thanks for the heads-up, i think i already understood the main concept.

What i am looking for is a way to provide a source-folder other than ./src either in the platformio.ini or when initializing the project.

Regards

@ivankravets
Copy link
Member

The lib, src, .pioenvs and platformio.ini are hard-coded names. You can't change them. The one thing which you can change is lib directory, you can setup alternative location for your project's libs.

Could I ask you: "Why do you need other than ./src folder? 😊

As I understand, you just need to initialize project in the another folder and use it. For example,

> cd /my/project/dir
> platformio run

# or

> cd /my/project/dir && platformio run

@aphelps
Copy link

aphelps commented Feb 18, 2015

The reason is likely that the Arduino IDE forces certain naming and structural constraints, namely that a project named 'TestProject' must be within a folder named 'TestProject' and include a main file named 'TestProject/TestProject.ino'. While I do think full compatibility is a good idea, I've been working around this by using directory links. ie:
$BASE_DIR/TestProject/TestProject.io
$BASE_DIR/platformion.ini
$BASE_DIR/src -> ./TestProject

@MrCustomizer
Copy link

I came here to open an issue with exactly the same feature request. Now I see, someone else has already done that ;). I will try to clarify the problem a little bit:

I'm using platformio to build my Arduino projects while at the same time maintaining compatibility with the Arduino IDE.

As makefu and aphelps already described, one really annoying limitation of the Arduino IDE is the fact, that the ino-source file has to have the exact same name as the parent directory, the source file resides in. Don't ask me, why they did that…

One way to solve this, is by using links like aphelp proposed, which probably will not be suitable if you want to work on different operating systems in the same project. Also, this solution will likely cause trouble when using a version control system.

My current solution is to name my ino-file "src.ino". This way, the Arduino IDE is happy, because it can open a file with the name "src", which is located in a folder named "src" and platformio is happy, because the source file resides in a directory with the name "src". Working on several source files from different Arduino projects in the same IDE (which I'm doing a lot, lately) gets pretty confusing with this hack, though, as a lot of source files are named "src.ino".

The problem could be solved, if the name of the src-folder was configurable, as makefu proposed.

@ivankravets ivankravets added this to the 1.0.0 milestone Feb 22, 2015
@ivankravets
Copy link
Member

Hey @makefu, @aphelps, @franciscoruiz, @valeros

You convinced me 👍 😊 . See src_dir option in documentation.

@MrCustomizer
Copy link

Works like a charm, thank you!

@makefu
Copy link
Author

makefu commented Feb 22, 2015

that is great to hear, thanks for the improvement!

@aphelps
Copy link

aphelps commented Feb 22, 2015

Thanks for the change, I'll try that out as an alternative to my linking.

As a note on a comment above regarding links and version control, at least with git and Unix based platforms you can commit a symbolic link and it behaves properly when cloned. I haven't tried this with Windows, but MacOS and Ubuntu are fine.

@gsavin
Copy link

gsavin commented Mar 11, 2015

Does src_dir support multiple paths ? To share commun code between several projects for example.

@ivankravets
Copy link
Member

Does src_dir support multiple paths ? To share commun code between several projects for example.

Sure, please read detailed information in documentation: http://docs.platformio.org/en/latest/projectconf.html#src-dir

P.S: But... I'm not sure that I've got you. The main idea of PlatformIO and platformio.ini is to keep single code within single project and define multiple environments for cross-platform compilation.

@gsavin
Copy link

gsavin commented Mar 11, 2015

Actually, I've already checked the docs, but I understand that only one path is possible :)
I have two projects which are working together, so they share some code, like a local library. So, I have two projects with their own src directory, but I would like to add an other and common directory. Something like src_dir = src/ ; ../src/. But maybe I am following a complete wrong way for doing this !

@ivankravets
Copy link
Member

Dear @gsavin,

so they share some code, like a local library

You've just answered on this question 😄

Just move "common code for library" to folder, which will be located in "Project #1", then use the lib folder from "Project #1" in "Project #2". For example,

Project #1 platformio.ini

[platformio]
lib_dir = /path/to/own/libdir

[env:my_project_1]
# some data

Project #2 platformio.ini

[platformio]
lib_dir = /path/to/own/libdir

[env:my_project_2]
# some data

Then, create new folder (use any names, like common_code or etc) in /path/to/own/libdir and put common source code here.

P.S: You can keep common code in Project 1 or 2, and then use lib_dir from one the projects. You don't need to override lib_dir in both projects.

@gsavin
Copy link

gsavin commented Mar 11, 2015

Thanks :) Sounds good.
I guess that my installed libraries will not be usable anymore, but I can copy them into the new lib folder !
Great tool btw.

@ivankravets
Copy link
Member

Great tool btw.

Thanks! 👍 Let's wait for the new release... 😊 + 3 new development platforms (NXP, Freescale & Nordic), +30 boards, + full support for mbed platforms and mbed framework http://developer.mbed.org/platforms/

Please follow us on Twitter @PlatformIO_Org

@ThomasDevoogdt
Copy link

I do something like this:

//
// Created by thomas on 25/11/17.
//

//#define sensor_log
#define sensor_bmp

// sensor_log example
#ifdef sensor_log

#include "../../examples/sensor_log/sensor_log.ino"

#endif

// sensor_bmp example
#ifdef sensor_bmp

#include "../../examples/sensor_bmp/BMPholder.h"
#include "../../examples/sensor_bmp/BMPholder.cpp"
#include "../../examples/sensor_bmp/sensor_bmp.ino"

#endif

Just include the .ino files of the custom location in your main.ino in src

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

No branches or pull requests

6 participants