-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read the target name from Makefile (#468)
* Read the target name and target dir from Makefile and set it in settings
- Loading branch information
1 parent
b8d5526
commit 03bdffa
Showing
6 changed files
with
167 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright 2024, the Genio team | ||
* All rights reserved. Distributed under the terms of the MIT license. | ||
*/ | ||
|
||
// TODO: Very basic, it only reads the "NAME" from haiku makefiles. | ||
// Should implement a real makefile reader | ||
|
||
#include "MakeFileHandler.h" | ||
|
||
#include <fstream> | ||
#include <iostream> | ||
|
||
#include "TextUtils.h" | ||
|
||
MakeFileHandler::MakeFileHandler() | ||
{ | ||
} | ||
|
||
|
||
MakeFileHandler::MakeFileHandler(const char* path) | ||
{ | ||
SetTo(path); | ||
} | ||
|
||
|
||
MakeFileHandler::~MakeFileHandler() | ||
{ | ||
} | ||
|
||
|
||
status_t | ||
MakeFileHandler::SetTo(const char* path) | ||
{ | ||
std::ifstream inFile(path); | ||
std::string line; | ||
bool foundName = false; | ||
bool foundDir = false; | ||
while (std::getline(inFile, line)) { | ||
if (!foundName) { | ||
size_t pos = line.find("NAME"); | ||
if (pos != std::string::npos) { | ||
line = line.substr(pos); | ||
pos = line.find("="); | ||
if (pos != std::string::npos) { | ||
std::string str = line.substr(pos + 1).c_str(); | ||
Trim(str); | ||
fTargetName = str.c_str(); | ||
foundName = true; | ||
} | ||
} | ||
} | ||
if (!foundDir) { | ||
size_t pos = line.find("TARGET_DIR"); | ||
if (pos != std::string::npos) { | ||
line = line.substr(pos); | ||
pos = line.find("="); | ||
if (pos != std::string::npos) { | ||
std::string str = line.substr(pos + 1).c_str(); | ||
Trim(str); | ||
fTargetDir = str.c_str(); | ||
foundDir = true; | ||
} | ||
} | ||
} | ||
} | ||
return B_OK; | ||
} | ||
|
||
|
||
void | ||
MakeFileHandler::GetTargetName(BString& outName) const | ||
{ | ||
outName = fTargetName; | ||
} | ||
|
||
|
||
void | ||
MakeFileHandler::SetTargetName(const BString& inName) | ||
{ | ||
fTargetName = inName; | ||
} | ||
|
||
|
||
void | ||
MakeFileHandler::GetTargetDirectory(BString& outDir) const | ||
{ | ||
outDir = fTargetDir; | ||
} | ||
|
||
|
||
void | ||
MakeFileHandler::SetTargetDirectory(const BString& inDir) | ||
{ | ||
fTargetDir = inDir; | ||
} | ||
|
||
|
||
void | ||
MakeFileHandler::GetFullTargetName(BString &fullName) const | ||
{ | ||
if (!fTargetDir.IsEmpty()) { | ||
fullName = fTargetDir; | ||
fullName.Append("/"); | ||
} | ||
fullName.Append(fTargetName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2024, the Genio team | ||
* All rights reserved. Distributed under the terms of the MIT license. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <String.h> | ||
|
||
class MakeFileHandler { | ||
public: | ||
MakeFileHandler(); | ||
MakeFileHandler(const char* path); | ||
virtual ~MakeFileHandler(); | ||
|
||
status_t SetTo(const char* path); | ||
|
||
void GetTargetName(BString &name) const; | ||
void SetTargetName(const BString& name); | ||
|
||
void GetTargetDirectory(BString& dir) const; | ||
void SetTargetDirectory(const BString& dir); | ||
|
||
void GetFullTargetName(BString& fullName) const; | ||
|
||
private: | ||
BString fTargetName; | ||
BString fTargetDir; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters