Skip to content

Commit

Permalink
Merge branch 'main' into docs/insecure-randomness
Browse files Browse the repository at this point in the history
  • Loading branch information
tamasvajk authored Nov 17, 2023
2 parents 9a8ad7d + 8a8031d commit b2c8049
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 30 deletions.
4 changes: 2 additions & 2 deletions csharp/ql/integration-tests/all-platforms/dotnet_pack/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from create_database_utils import *
from diagnostics_test_utils import *

run_codeql_database_create(['dotnet pack'], db=None, lang="csharp")
run_codeql_database_create(['dotnet pack -o nugetpackage'], db=None, lang="csharp")

## Check that the NuGet package is created.
if not os.path.isfile("bin/Debug/dotnet_pack.1.0.0.nupkg"):
if not os.path.isfile("nugetpackage/dotnet_pack.1.0.0.nupkg"):
raise Exception("The NuGet package was not created.")

check_diagnostics()
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<IsPackable>false</IsPackable>
<OutputType>Exe</OutputType>
<SelfContained>false</SelfContained>
</PropertyGroup>

<ItemGroup>
Expand Down
27 changes: 10 additions & 17 deletions java/kotlin-extractor/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def write_arg_file(arg_file, args):
raise Exception('Single quote in argument: ' + arg)
f.write("'" + arg.replace('\\', '/') + "'\n")

def compile_to_dir(build_dir, srcs, language_version, classpath, java_classpath, output):
def compile_to_dir(build_dir, srcs, version, classpath, java_classpath, output):
# Use kotlinc to compile .kt files:
kotlin_arg_file = build_dir + '/kotlin.args'
kotlin_args = ['-Werror',
Expand All @@ -96,7 +96,7 @@ def compile_to_dir(build_dir, srcs, language_version, classpath, java_classpath,
'-d', output,
'-module-name', 'codeql-kotlin-extractor',
'-Xsuppress-version-warnings',
'-language-version', language_version,
'-language-version', version.toLanguageVersionString(),
'-no-reflect', '-no-stdlib',
'-jvm-target', '1.8',
'-classpath', classpath] + srcs
Expand All @@ -116,14 +116,14 @@ def compile_to_dir(build_dir, srcs, language_version, classpath, java_classpath,
run_process([javac, '@' + java_arg_file])


def compile_to_jar(build_dir, tmp_src_dir, srcs, language_version, classpath, java_classpath, output):
def compile_to_jar(build_dir, tmp_src_dir, srcs, version, classpath, java_classpath, output):
class_dir = build_dir + '/classes'

if os.path.exists(class_dir):
shutil.rmtree(class_dir)
os.makedirs(class_dir)

compile_to_dir(build_dir, srcs, language_version, classpath, java_classpath, class_dir)
compile_to_dir(build_dir, srcs, version, classpath, java_classpath, class_dir)

run_process(['jar', 'cf', output,
'-C', class_dir, '.',
Expand Down Expand Up @@ -161,7 +161,7 @@ def transform_to_embeddable(srcs):
f.write(content)


def compile(jars, java_jars, dependency_folder, transform_to_embeddable, output, build_dir, current_version):
def compile(jars, java_jars, dependency_folder, transform_to_embeddable, output, build_dir, version_str):
classpath = bases_to_classpath(dependency_folder, jars)
java_classpath = bases_to_classpath(dependency_folder, java_jars)

Expand All @@ -179,31 +179,24 @@ def compile(jars, java_jars, dependency_folder, transform_to_embeddable, output,
with open(resource_dir + '/extractor.name', 'w') as f:
f.write(output)

parsed_current_version = kotlin_plugin_versions.version_string_to_tuple(
current_version)
version = kotlin_plugin_versions.version_string_to_version(version_str)

for version in kotlin_plugin_versions.many_versions:
parsed_version = kotlin_plugin_versions.version_string_to_tuple(
version)
if parsed_version[0] < parsed_current_version[0] or \
(parsed_version[0] == parsed_current_version[0] and parsed_version[1] < parsed_current_version[1]) or \
(parsed_version[0] == parsed_current_version[0] and parsed_version[1] == parsed_current_version[1] and parsed_version[2] <= parsed_current_version[2]):
for a_version in kotlin_plugin_versions.many_versions_versions_asc:
if a_version.lessThanOrEqual(version):
d = tmp_src_dir + '/main/kotlin/utils/versions/v_' + \
version.replace('.', '_')
a_version.toString().replace('.', '_')
if os.path.exists(d):
# copy and overwrite files from the version folder to the include folder
shutil.copytree(d, include_version_folder, dirs_exist_ok=True)

language_version = str(parsed_current_version[0]) + '.' + str(parsed_current_version[1])

# remove all version folders:
shutil.rmtree(tmp_src_dir + '/main/kotlin/utils/versions')

srcs = find_sources(tmp_src_dir)

transform_to_embeddable(srcs)

compile_to_jar(build_dir, tmp_src_dir, srcs, language_version, classpath, java_classpath, output)
compile_to_jar(build_dir, tmp_src_dir, srcs, version, classpath, java_classpath, output)

shutil.rmtree(tmp_src_dir)

Expand Down
41 changes: 30 additions & 11 deletions java/kotlin-extractor/kotlin_plugin_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,40 @@ def is_windows():
return True
return False

def version_tuple_to_string(version):
return f'{version[0]}.{version[1]}.{version[2]}{version[3]}'
class Version:
def __init__(self, major, minor, patch, tag):
self.major = major
self.minor = minor
self.patch = patch
self.tag = tag

def version_string_to_tuple(version):
def toTupleWithTag(self):
return [self.major, self.minor, self.patch, self.tag]

def toTupleNoTag(self):
return [self.major, self.minor, self.patch]

def lessThanOrEqual(self, other):
return self.toTupleNoTag() <= other.toTupleNoTag()

def toString(self):
return f'{self.major}.{self.minor}.{self.patch}{self.tag}'

def toLanguageVersionString(self):
return f'{self.major}.{self.minor}'

def version_string_to_version(version):
m = re.match(r'([0-9]+)\.([0-9]+)\.([0-9]+)(.*)', version)
return tuple([int(m.group(i)) for i in range(1, 4)] + [m.group(4)])
return Version(int(m.group(1)), int(m.group(2)), int(m.group(3)), m.group(4))

# Version number used by CI.
ci_version = '1.9.0'

many_versions = [ '1.5.0', '1.5.10', '1.5.20', '1.5.30', '1.6.0', '1.6.20', '1.7.0', '1.7.20', '1.8.0', '1.9.0-Beta', '1.9.20-Beta' ]

many_versions_tuples = [version_string_to_tuple(v) for v in many_versions]
many_versions_versions = [version_string_to_version(v) for v in many_versions]
many_versions_versions_asc = sorted(many_versions_versions, key = lambda v: v.toTupleWithTag())
many_versions_versions_desc = reversed(many_versions_versions_asc)

class KotlincNotFoundException(Exception):
pass
Expand All @@ -40,13 +61,11 @@ def get_single_version(fakeVersionOutput = None):
m = re.match(r'.* kotlinc-jvm ([0-9]+\.[0-9]+\.[0-9]+-?[a-zA-Z]*) .*', versionOutput)
if m is None:
raise Exception('Cannot detect version of kotlinc (got ' + str(versionOutput) + ')')
current_version = version_string_to_tuple(m.group(1))

many_versions_tuples.sort(reverse = True)
current_version = version_string_to_version(m.group(1))

for version in many_versions_tuples:
if version[0:3] <= current_version[0:3]:
return version_tuple_to_string(version)
for version in many_versions_versions_desc:
if version.lessThanOrEqual(current_version):
return version.toString()

raise Exception(f'No suitable kotlinc version found for {current_version} (got {versionOutput}; know about {str(many_versions)})')

Expand Down

0 comments on commit b2c8049

Please sign in to comment.