Skip to content

Commit 11a8041

Browse files
committed
Anonymize paths (positions)
1 parent 6992bf1 commit 11a8041

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

skiplang/compiler/src/Config.sk

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ private class Config{
6363
static_libraries: Array<String>,
6464
link_args: Array<String>,
6565
preambles: Array<String>,
66+
canonize_paths: Bool,
6667
cwd: WorkingDirectory,
6768
} {
6869
static fun make(results: Cli.ParseResults): this {
@@ -252,6 +253,7 @@ private class Config{
252253
link_args,
253254
preambles,
254255
cwd,
256+
canonize_paths,
255257
}
256258
}
257259

skiplang/compiler/src/compile.sk

+9
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,20 @@ fun compile(
358358
Array[TickConfigFile((context.tick.value, config))],
359359
);
360360

361+
make_input_source_path = (pkg_base_dir, src_path) ~> {
362+
res = Path.join(pkg_base_dir, src_path);
363+
if (config.canonize_paths) {
364+
!res = config.cwd.makeRelative(res);
365+
};
366+
res
367+
};
368+
361369
FileCache.writeFiles(
362370
context,
363371
fileNames,
364372
config.dependencies,
365373
config.lib_name,
374+
make_input_source_path,
366375
);
367376

368377
context.update()

skiplang/compiler/src/skipParse.sk

+29-9
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ fun updatePackageFiles(
111111
name: ?String,
112112
pkg: InputPackageFiles,
113113
get_file_contents: String ~> String,
114+
make_input_source_path: (String, String) ~> String,
114115
): void {
115116
(modified_files, removed_files) = packageDir.unsafeMaybeGet(
116117
context,
@@ -122,14 +123,14 @@ fun updatePackageFiles(
122123
for ((pkg_base_dir, src_path) in modified_files) {
123124
fileDir.writeArray(
124125
context,
125-
InputSource(name, Path.join(pkg_base_dir, src_path)),
126+
InputSource(name, make_input_source_path(pkg_base_dir, src_path)),
126127
Array[SKStore.StringFile(get_file_contents(src_path))],
127128
)
128129
};
129130
for ((pkg_base_dir, src_path) in removed_files) {
130131
fileDir.writeArray(
131132
context,
132-
InputSource(name, Path.join(pkg_base_dir, src_path)),
133+
InputSource(name, make_input_source_path(pkg_base_dir, src_path)),
133134
Array[SKStore.StringFile("")],
134135
)
135136
};
@@ -141,6 +142,7 @@ fun writeFiles(
141142
file_names: Array<String>,
142143
dependencies: Map<String, (String, Sklib.Metadata)>,
143144
lib_name_opt: ?String,
145+
make_input_source_path: (String, String) ~> String,
144146
): void {
145147
// TODO: If `lib_name_opt` is `Some(_)`, ensure there is a
146148
// `Skargo.toml` in the cwd.
@@ -153,9 +155,15 @@ fun writeFiles(
153155
.map(fn -> (fn, FileSystem.getLastModificationTime(fn)))
154156
.collect(Array),
155157
);
156-
updatePackageFiles(context, lib_name_opt, pkg, src ~> {
157-
FileSystem.readTextFile(src)
158-
})
158+
updatePackageFiles(
159+
context,
160+
lib_name_opt,
161+
pkg,
162+
src ~> {
163+
FileSystem.readTextFile(src)
164+
},
165+
make_input_source_path,
166+
)
159167
};
160168

161169
// For each (transitive) dependency, invalidate files that were
@@ -172,14 +180,26 @@ fun writeFiles(
172180
dep_meta.pkg_dir,
173181
dep_meta.sources.map(s -> (s.i0, s.i1)).collect(Array),
174182
);
175-
updatePackageFiles(context, Some(dep_name), pkg, src ~> {
176-
dep_meta.sources.find(f -> f.i0 == src).fromSome().i2
177-
})
183+
updatePackageFiles(
184+
context,
185+
Some(dep_name),
186+
pkg,
187+
src ~> {
188+
dep_meta.sources.find(f -> f.i0 == src).fromSome().i2
189+
},
190+
make_input_source_path,
191+
)
178192
};
179193

180194
if (lib_name_opt is Some _) {
181195
// Invalidate non-package source files when building a package.
182-
updatePackageFiles(context, None(), InputPackageFiles("", Array[]), _ ~> "")
196+
updatePackageFiles(
197+
context,
198+
None(),
199+
InputPackageFiles("", Array[]),
200+
_ ~> "",
201+
make_input_source_path,
202+
)
183203
}
184204
}
185205

0 commit comments

Comments
 (0)