0

私は GitHub を初めて使用し、私のグループがカスタム ハードウェア セットアップとのインターフェイスに取り組んでいるソフトウェア プロジェクトの 1 つです。ハードウェアのセットアップごとに異なるバージョンのコードベースが必要ですが、GitHub でこれを行う最善の方法が少しわかりません。異なるセットアップごとにブランチを作成することもできますが、それは最終的にマスターにマージされることを意味します。他の誰かがこれに遭遇したことがありますか、またはこれを処理する最良の方法を知っていますか?

4

2 に答える 2

2

I don't think this is related to Git/GitHub in particular, in the sense that this shouldn't be tied to a specific version control system. I rather see this from a project setup perspective.

If I correctly understand your question, you're building a system with some core functionalities that should run on different kind of platforms. And each target platform will be running a different binary. This binary will contain the core functionalities and the specificities required to run on this target platform.

Usually, one tend to use branches to create new functionalities or fix bugs. In a multiplatform context, those bugfixes and new functionalities should be tested and deployed on all the target platforms.

A very good example of such a project is libgit2 which is a 100% cross-platform pure C implementation of the Git core methods.

This library runs on Windows, Linux, MacOSX, Amiga, ... And each of those platforms have specific requirements (Different 64-bit data models, different APIs to interact with the filesystem, network, ...).

For each area that requires a specific code per platform, the project defines some interfaces that the core functionalities interact with. Those interfaces are then implemented for each platform, in different source files. At build time, the specific source files are packaged along with the core ones according to the selected target platform.

In order to achieve this, the project relies on CMake, which is able to build a VisualStudio project (when targetting Windows), or a gcc (or clang) one (for *nix). The way CMake works is by applying a project "recipe" described in a CMakeList.txt file which describes what file to include, what compiler macros to define, ...

On top on this, in order to make sure that everything works ok, the project is hooked on a Continuous Integration server which builds the binaries and run the tests on each different target configuration. When working on GitHub, Travis CI (free for open source project) is a good choice (TeamCity is also pretty well integrated). It's quite easy to configure it to automatically build and run the tests on all (or a subset) of your branches. Moreover, each Pull request is automatically tested as well!

FWIW, This goodness is not limited to C. For instance, LibGit2Sharp, the Mono/.Net bindings of libgit2 use similar concepts and leverage both Travis and TeamCity to make sure all the tests pass on .Net/Win32, .Net/Win64 and Mono/Linux, in Debug and Release versions.

In summary:

  • Do not use branches for platform specifcities.
  • Use branches for new features and bug fixes
  • Cover your code with unit tests (making sure that those tests also exercize the platform specific code)
  • Use a CI server to ensure that everything build/runs ok on all your target platforms

Some resources for further inspiration:

于 2013-06-27T09:40:44.320 に答える