|
@@ -146,7 +146,27 @@ namespace Usm {
|
|
|
|
|
|
|
|
|
|
|
|
|
public Subprocess run_build(string build_path, Paths paths, SubprocessFlags flags, ProgressDelegate? progress_delegate = null) throws Error {
|
|
public Subprocess run_build(string build_path, Paths paths, SubprocessFlags flags, ProgressDelegate? progress_delegate = null) throws Error {
|
|
|
- var path = Path.build_filename(Environment.get_current_dir(), executables.build);
|
|
|
|
|
|
|
+ // Handle SIMPLE_BUILD_ENVIRONMENT flag
|
|
|
|
|
+ string original_working_dir = Environment.get_current_dir();
|
|
|
|
|
+ string working_dir = original_working_dir;
|
|
|
|
|
+ string effective_build_path = build_path;
|
|
|
|
|
+
|
|
|
|
|
+ if (this.flags.contains(ManifestFlag.SIMPLE_BUILD_ENVIRONMENT)) {
|
|
|
|
|
+ // Copy the full source tree to the build directory
|
|
|
|
|
+ var source_dir = File.new_for_path(working_dir);
|
|
|
|
|
+ var build_dir = File.new_for_path(build_path);
|
|
|
|
|
+
|
|
|
|
|
+ // Copy all files from source to build directory
|
|
|
|
|
+ copy_directory(source_dir, build_dir);
|
|
|
|
|
+
|
|
|
|
|
+ // Use build directory as working directory
|
|
|
|
|
+ working_dir = build_path;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var path = Path.build_filename(working_dir, executables.build);
|
|
|
|
|
+
|
|
|
|
|
+ // Change to the working directory for subprocess execution
|
|
|
|
|
+ Environment.set_current_dir(working_dir);
|
|
|
paths.set_envs();
|
|
paths.set_envs();
|
|
|
|
|
|
|
|
// Check if NINJA_STYLE_PROGRESS flag is set and progress delegate is provided
|
|
// Check if NINJA_STYLE_PROGRESS flag is set and progress delegate is provided
|
|
@@ -159,7 +179,7 @@ namespace Usm {
|
|
|
}
|
|
}
|
|
|
modified_flags = modified_flags | SubprocessFlags.STDOUT_PIPE;
|
|
modified_flags = modified_flags | SubprocessFlags.STDOUT_PIPE;
|
|
|
|
|
|
|
|
- var proc = new Subprocess.newv(new string[] { path, build_path }, modified_flags);
|
|
|
|
|
|
|
+ var proc = new Subprocess.newv(new string[] { path, effective_build_path }, modified_flags);
|
|
|
|
|
|
|
|
// Start a new thread to monitor STDOUT for progress information
|
|
// Start a new thread to monitor STDOUT for progress information
|
|
|
ThreadFunc<void> progress_thread_func = () => {
|
|
ThreadFunc<void> progress_thread_func = () => {
|
|
@@ -215,9 +235,16 @@ namespace Usm {
|
|
|
warning(@"Failed to start progress monitoring thread: $(e.message)");
|
|
warning(@"Failed to start progress monitoring thread: $(e.message)");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // Restore original working directory after subprocess completes
|
|
|
|
|
+ Environment.set_current_dir(original_working_dir);
|
|
|
|
|
+
|
|
|
return proc;
|
|
return proc;
|
|
|
} else {
|
|
} else {
|
|
|
- var proc = new Subprocess.newv(new string[] { path, build_path }, flags);
|
|
|
|
|
|
|
+ var proc = new Subprocess.newv(new string[] { path, effective_build_path }, flags);
|
|
|
|
|
+
|
|
|
|
|
+ // Restore original working directory after subprocess completes
|
|
|
|
|
+ Environment.set_current_dir(original_working_dir);
|
|
|
|
|
+
|
|
|
return proc;
|
|
return proc;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -226,8 +253,20 @@ namespace Usm {
|
|
|
if(executables.rebuild == null) {
|
|
if(executables.rebuild == null) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- var path = Path.build_filename(Environment.get_current_dir(), executables.rebuild);
|
|
|
|
|
|
|
+ string original_working_dir = Environment.get_current_dir();
|
|
|
|
|
+ string working_dir = original_working_dir;
|
|
|
|
|
+ if (this.flags.contains(ManifestFlag.SIMPLE_BUILD_ENVIRONMENT)) {
|
|
|
|
|
+ working_dir = build_path;
|
|
|
|
|
+ }
|
|
|
|
|
+ var path = Path.build_filename(working_dir, executables.rebuild);
|
|
|
|
|
+
|
|
|
|
|
+ // Change to the working directory for subprocess execution
|
|
|
|
|
+ Environment.set_current_dir(working_dir);
|
|
|
var proc = new Subprocess.newv(new string[] { path, build_path }, flags);
|
|
var proc = new Subprocess.newv(new string[] { path, build_path }, flags);
|
|
|
|
|
+
|
|
|
|
|
+ // Restore original working directory after subprocess completes
|
|
|
|
|
+ Environment.set_current_dir(original_working_dir);
|
|
|
|
|
+
|
|
|
return proc;
|
|
return proc;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -235,7 +274,9 @@ namespace Usm {
|
|
|
if(executables.acquire == null) {
|
|
if(executables.acquire == null) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- var path = Path.build_filename(Environment.get_current_dir(), executables.acquire);
|
|
|
|
|
|
|
+ string working_dir = Environment.get_current_dir();
|
|
|
|
|
+ // Note: acquire doesn't have a build_path parameter, so it can't use SIMPLE_BUILD_ENVIRONMENT
|
|
|
|
|
+ var path = Path.build_filename(working_dir, executables.acquire);
|
|
|
var proc = new Subprocess.newv(new string[] { path }, flags);
|
|
var proc = new Subprocess.newv(new string[] { path }, flags);
|
|
|
return proc;
|
|
return proc;
|
|
|
}
|
|
}
|
|
@@ -244,13 +285,25 @@ namespace Usm {
|
|
|
if(executables.install == null) {
|
|
if(executables.install == null) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- var path = Path.build_filename(Environment.get_current_dir(), executables.install);
|
|
|
|
|
|
|
+ string original_working_dir = Environment.get_current_dir();
|
|
|
|
|
+ string working_dir = original_working_dir;
|
|
|
|
|
+ if (this.flags.contains(ManifestFlag.SIMPLE_BUILD_ENVIRONMENT)) {
|
|
|
|
|
+ working_dir = build_path;
|
|
|
|
|
+ }
|
|
|
|
|
+ var path = Path.build_filename(working_dir, executables.install);
|
|
|
|
|
|
|
|
// Override destination environment variable
|
|
// Override destination environment variable
|
|
|
var new_paths = paths.clone();
|
|
var new_paths = paths.clone();
|
|
|
new_paths.destination = install_path;
|
|
new_paths.destination = install_path;
|
|
|
|
|
+
|
|
|
|
|
+ // Change to the working directory for subprocess execution
|
|
|
|
|
+ Environment.set_current_dir(working_dir);
|
|
|
new_paths.set_envs();
|
|
new_paths.set_envs();
|
|
|
var proc = new Subprocess.newv(new string[] { path, build_path, install_path, type.to_string() }, flags);
|
|
var proc = new Subprocess.newv(new string[] { path, build_path, install_path, type.to_string() }, flags);
|
|
|
|
|
+
|
|
|
|
|
+ // Restore original working directory after subprocess completes
|
|
|
|
|
+ Environment.set_current_dir(original_working_dir);
|
|
|
|
|
+
|
|
|
return proc;
|
|
return proc;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -258,8 +311,20 @@ namespace Usm {
|
|
|
if(executables.post_install == null) {
|
|
if(executables.post_install == null) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- var path = Path.build_filename(Environment.get_current_dir(), executables.post_install);
|
|
|
|
|
|
|
+ string original_working_dir = Environment.get_current_dir();
|
|
|
|
|
+ string working_dir = original_working_dir;
|
|
|
|
|
+ if (this.flags.contains(ManifestFlag.SIMPLE_BUILD_ENVIRONMENT)) {
|
|
|
|
|
+ working_dir = build_path;
|
|
|
|
|
+ }
|
|
|
|
|
+ var path = Path.build_filename(working_dir, executables.post_install);
|
|
|
|
|
+
|
|
|
|
|
+ // Change to the working directory for subprocess execution
|
|
|
|
|
+ Environment.set_current_dir(working_dir);
|
|
|
var proc = new Subprocess.newv(new string[] { path, build_path, type.to_string() }, flags);
|
|
var proc = new Subprocess.newv(new string[] { path, build_path, type.to_string() }, flags);
|
|
|
|
|
+
|
|
|
|
|
+ // Restore original working directory after subprocess completes
|
|
|
|
|
+ Environment.set_current_dir(original_working_dir);
|
|
|
|
|
+
|
|
|
return proc;
|
|
return proc;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -267,7 +332,9 @@ namespace Usm {
|
|
|
if(executables.remove == null) {
|
|
if(executables.remove == null) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- var path = Path.build_filename(Environment.get_current_dir(), executables.remove);
|
|
|
|
|
|
|
+ string working_dir = Environment.get_current_dir();
|
|
|
|
|
+ // Note: remove doesn't have a build_path parameter, so it can't use SIMPLE_BUILD_ENVIRONMENT
|
|
|
|
|
+ var path = Path.build_filename(working_dir, executables.remove);
|
|
|
var proc = new Subprocess.newv(new string[] { path, type.to_string() }, flags);
|
|
var proc = new Subprocess.newv(new string[] { path, type.to_string() }, flags);
|
|
|
return proc;
|
|
return proc;
|
|
|
}
|
|
}
|
|
@@ -276,8 +343,20 @@ namespace Usm {
|
|
|
if(executables.test == null) {
|
|
if(executables.test == null) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- var path = Path.build_filename(Environment.get_current_dir(), executables.test);
|
|
|
|
|
|
|
+ string original_working_dir = Environment.get_current_dir();
|
|
|
|
|
+ string working_dir = original_working_dir;
|
|
|
|
|
+ if (this.flags.contains(ManifestFlag.SIMPLE_BUILD_ENVIRONMENT)) {
|
|
|
|
|
+ working_dir = build_path;
|
|
|
|
|
+ }
|
|
|
|
|
+ var path = Path.build_filename(working_dir, executables.test);
|
|
|
|
|
+
|
|
|
|
|
+ // Change to the working directory for subprocess execution
|
|
|
|
|
+ Environment.set_current_dir(working_dir);
|
|
|
var proc = new Subprocess.newv(new string[] { path, build_path }, flags);
|
|
var proc = new Subprocess.newv(new string[] { path, build_path }, flags);
|
|
|
|
|
+
|
|
|
|
|
+ // Restore original working directory after subprocess completes
|
|
|
|
|
+ Environment.set_current_dir(original_working_dir);
|
|
|
|
|
+
|
|
|
return proc;
|
|
return proc;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -393,6 +472,29 @@ namespace Usm {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void copy_directory(File source, File destination) throws Error {
|
|
|
|
|
+ // Ensure destination directory exists
|
|
|
|
|
+ if (!destination.query_exists()) {
|
|
|
|
|
+ destination.make_directory_with_parents();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var enumerator = source.enumerate_children(FileAttribute.STANDARD_NAME + "," + FileAttribute.STANDARD_TYPE, FileQueryInfoFlags.NONE);
|
|
|
|
|
+ FileInfo file_info;
|
|
|
|
|
+
|
|
|
|
|
+ while ((file_info = enumerator.next_file()) != null) {
|
|
|
|
|
+ var source_child = source.get_child(file_info.get_name());
|
|
|
|
|
+ var destination_child = destination.get_child(file_info.get_name());
|
|
|
|
|
+
|
|
|
|
|
+ if (file_info.get_file_type() == FileType.DIRECTORY) {
|
|
|
|
|
+ // Recursively copy subdirectories
|
|
|
|
|
+ copy_directory(source_child, destination_child);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // Copy files
|
|
|
|
|
+ source_child.copy(destination_child, FileCopyFlags.OVERWRITE | FileCopyFlags.ALL_METADATA);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -465,7 +567,8 @@ namespace Usm {
|
|
|
public enum ManifestFlag {
|
|
public enum ManifestFlag {
|
|
|
BUILD_IN_SOURCE_TREE,
|
|
BUILD_IN_SOURCE_TREE,
|
|
|
SET_MANIFEST_PROPERTY_ENVS,
|
|
SET_MANIFEST_PROPERTY_ENVS,
|
|
|
- NINJA_STYLE_PROGRESS;
|
|
|
|
|
|
|
+ NINJA_STYLE_PROGRESS,
|
|
|
|
|
+ SIMPLE_BUILD_ENVIRONMENT;
|
|
|
|
|
|
|
|
public string to_string() {
|
|
public string to_string() {
|
|
|
switch (this) {
|
|
switch (this) {
|
|
@@ -475,6 +578,8 @@ namespace Usm {
|
|
|
return "setManifestPropertyEnvs";
|
|
return "setManifestPropertyEnvs";
|
|
|
case ManifestFlag.NINJA_STYLE_PROGRESS:
|
|
case ManifestFlag.NINJA_STYLE_PROGRESS:
|
|
|
return "ninjaStyleProgress";
|
|
return "ninjaStyleProgress";
|
|
|
|
|
+ case ManifestFlag.SIMPLE_BUILD_ENVIRONMENT:
|
|
|
|
|
+ return "simpleBuildEnvironment";
|
|
|
default:
|
|
default:
|
|
|
assert_not_reached();
|
|
assert_not_reached();
|
|
|
}
|
|
}
|
|
@@ -488,6 +593,8 @@ namespace Usm {
|
|
|
return ManifestFlag.SET_MANIFEST_PROPERTY_ENVS;
|
|
return ManifestFlag.SET_MANIFEST_PROPERTY_ENVS;
|
|
|
case "ninjaStyleProgress":
|
|
case "ninjaStyleProgress":
|
|
|
return ManifestFlag.NINJA_STYLE_PROGRESS;
|
|
return ManifestFlag.NINJA_STYLE_PROGRESS;
|
|
|
|
|
+ case "simpleBuildEnvironment":
|
|
|
|
|
+ return ManifestFlag.SIMPLE_BUILD_ENVIRONMENT;
|
|
|
default:
|
|
default:
|
|
|
throw new ManifestError.INVALID_FLAG(@"Unknown flag \"$str\".");
|
|
throw new ManifestError.INVALID_FLAG(@"Unknown flag \"$str\".");
|
|
|
}
|
|
}
|