Skip to content

Commit ac687e9

Browse files
authored
rust: Copy template files on compile (#848)
Fixes #608 (comment)
1 parent 388d354 commit ac687e9

File tree

6 files changed

+35
-33
lines changed

6 files changed

+35
-33
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
* @sonnyp
1+
/src/langs/javascript/ @sonnyp
2+
*.js @sonnyp
23

34
/src/langs/vala/ @lw64
45
*.vala @lw64

.gitignore

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,3 @@ __pycache__
1717

1818
# IDEs / editors
1919
.idea
20-
21-
# Project files - sync with Makefile
22-
src/Library/**/settings
23-
src/Library/**/workbench.vala
24-
src/Library/**/main.ui
25-
src/Library/**/libworkbenchcode.so
26-
src/Library/**/__pycache__

data/app.metainfo.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<name translatable="no">Workbench</name>
66
<!-- developer_name tag deprecated with Appstream 1.0 -->
77
<developer_name translatable="no">Sonny Piers</developer_name>
8-
<developer id="gitlab.com">
8+
<developer>
99
<name translatable="no">Sonny Piers</name>
1010
</developer>
1111
<update_contact>sonnyp@gnome.org</update_contact>

src/langs/rust/Compiler.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import Gio from "gi://Gio";
22
import GLib from "gi://GLib";
33
import dbus_previewer from "../../Previewer/DBusPreviewer.js";
4-
import { decode, encode } from "../../util.js";
4+
import { copyDirectory, decode, encode } from "../../util.js";
5+
6+
const rust_template_dir = Gio.File.new_for_path(
7+
pkg.pkgdatadir,
8+
).resolve_relative_path("langs/rust/template");
59

610
export default function Compiler({ session }) {
711
const { file } = session;
@@ -15,6 +19,8 @@ export default function Compiler({ session }) {
1519
let savedRustcVersion;
1620

1721
async function compile() {
22+
copyDirectory(rust_template_dir, file);
23+
1824
rustcVersion ||= await getRustcVersion();
1925
savedRustcVersion ||= await getSavedRustcVersion({ rustcVersionFile });
2026

src/sessions.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import {
77
ensureDir,
88
getNowForFilename,
99
demos_dir,
10-
rust_template_dir,
1110
settings as global_settings,
1211
encode,
1312
languages,
1413
settings,
14+
copyDirectory,
1515
} from "./util.js";
1616

1717
export const sessions_dir = data_dir.get_child("sessions");
@@ -64,7 +64,6 @@ export function createSessionFromDemo(demo) {
6464

6565
const { file, settings } = session;
6666
copyDirectory(demo_dir, file);
67-
copyDirectory(rust_template_dir, file);
6867

6968
settings.set_string("name", name);
7069
settings.set_boolean("show-code", panels.includes("code"));
@@ -79,24 +78,6 @@ export function createSessionFromDemo(demo) {
7978
return session;
8079
}
8180

82-
// There is no copy directory function
83-
function copyDirectory(source, destination) {
84-
for (const file_info of source.enumerate_children(
85-
"",
86-
Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
87-
null,
88-
)) {
89-
if (file_info.get_file_type() === Gio.FileType.DIRECTORY) continue;
90-
const child = source.get_child(file_info.get_name());
91-
child.copy(
92-
destination.get_child(child.get_basename()),
93-
Gio.FileCopyFlags.NONE,
94-
null,
95-
null,
96-
);
97-
}
98-
}
99-
10081
export async function deleteSession(session) {
10182
// There is no method to recursively delete a folder so we trash instead
10283
// https://github.com/flatpak/xdg-desktop-portal/issues/630 :/

src/util.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,30 @@ export const demos_dir = Gio.File.new_for_path(
177177
pkg.pkgdatadir,
178178
).resolve_relative_path("demos");
179179

180-
export const rust_template_dir = Gio.File.new_for_path(
181-
pkg.pkgdatadir,
182-
).resolve_relative_path("langs/rust/template");
180+
// There is no copy directory function
181+
export function copyDirectory(source, destination) {
182+
for (const file_info of source.enumerate_children(
183+
"",
184+
Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
185+
null,
186+
)) {
187+
if (file_info.get_file_type() === Gio.FileType.DIRECTORY) continue;
188+
const child = source.get_child(file_info.get_name());
189+
190+
try {
191+
child.copy(
192+
destination.get_child(child.get_basename()),
193+
Gio.FileCopyFlags.NONE,
194+
null,
195+
null,
196+
);
197+
} catch (err) {
198+
if (!err.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.EXISTS)) {
199+
throw err;
200+
}
201+
}
202+
}
203+
}
183204

184205
export function getNowForFilename() {
185206
return new GLib.DateTime().format("%Y-%m-%d %H-%M-%S");

0 commit comments

Comments
 (0)