[haiku-development] Re: find_directory()/find_path() and secondary architecture

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Tue, 12 Nov 2013 17:01:18 +0100

On 11/06/2013 10:44 PM, Ingo Weinhold wrote:
Anyway, I agree that an API (and command) to get the current
architecture, the architecture of a file (if possible to determine), and
all installed architectures is a good idea.

I thought a bit on that and here's my suggestion:

const char* get_architecture();
const char* get_primary_architecture();
size_t get_secondary_architectures(const char** architectures,
        size_t count);
const char* guess_architecture_for_path(const char* path);

get_architecture() returns this libroot's (and thus the caller's) architecture and get_primary_architecture() the primary architecture. get_secondary_architectures() returns the number of secondary architecture actually currently usable (i.e. 0 for a gcc 2 only Haiku, but 1 as soon as the gcc 4 secondary part is installed) and writes their names to the "architectures" array.

guess_architecture_for_path() tries to determine the architecture for the given path. If the path is invalid or doesn't point to anything, the primary architecture is returned.

I would add a command line tool getarch to provide that functionality in the shell. I think this is also a good time to introduce a setarch shell function to manipulate PATH to switch the compiler. getarch without arguments would return the set architecture, with respective arguments it would return the primary architecture, the secondary architectures, respectively the architecture guessed for a path.

The find_path*() API would change to:

status_t find_path(const void* codePointer,
        path_base_directory baseDirectory, const char* subPath,
        char* pathBuffer, size_t bufferSize);

status_t find_path_etc(const void* codePointer, const char* dependency,
        const char* architecture, path_base_directory baseDirectory,
        const char* subPath, uint32 flags, char* pathBuffer,
        size_t bufferSize);

status_t find_path_for_path(const char* path,
        path_base_directory baseDirectory, const char* subPath,
        char* pathBuffer, size_t bufferSize);

status_t find_path_for_path_etc(const char* path,
        const char* dependency, const char* architecture,
        path_base_directory baseDirectory, const char* subPath,
        uint32 flags, char* pathBuffer, size_t bufferSize);

status_t find_paths(path_base_directory baseDirectory,
        const char* subPath, char*** _paths, size_t* _pathCount);

status_t find_paths_etc(const char* architecture,
        path_base_directory baseDirectory, const char* subPath,
        uint32 flags, char*** _paths, size_t* _pathCount);

The *_etc() versions are like the previous versions, extended with an "architecture" parameter. The basic functions have lost the "dependency" and "flags" parameters -- they just call the *_etc() versions with NULL/0 arguments for the additional arguments.

find_path_etc()/find_paths_etc() would return the path(s) for the caller's architecture, when the "architecture" argument is NULL, otherwise for the specified architecture. find_path_for_path_etc() would, however, use guess_architecture_for_path(path), when a NULL "architecture" argument is given.

A _FIND_PATH_PRIMARY_ARCHITECTURE flag as suggested in an earlier mail would no longer be necessary. One can pass the return value of get_primary_architecture() if that behavior is desired.

The C++ API would remain unchanged save for an additional FindPath() and FindPaths() version with the "architecture" parameter.

The findpaths command would grow an "-a/--architecture <architecture>" option. If not specified, `getarch` respectively, when a path is specified, `getarch <path>` would be used.

How does that sound?

CU, Ingo


Other related posts: